Example usage for java.lang Class isAnnotationPresent

List of usage examples for java.lang Class isAnnotationPresent

Introduction

In this page you can find the example usage for java.lang Class isAnnotationPresent.

Prototype

@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) 

Source Link

Usage

From source file:org.broadinstitute.gatk.utils.help.GenericDocumentationHandler.java

@Override
public boolean includeInDocs(ClassDoc doc) {
    try {/*from w w  w .j a va 2 s  .c o  m*/
        Class type = DocletUtils.getClassForDoc(doc);
        boolean hidden = !getDoclet().showHiddenFeatures() && type.isAnnotationPresent(Hidden.class);
        return !hidden && JVMUtils.isConcrete(type);
    } catch (ClassNotFoundException e) {
        return false;
    }
}

From source file:org.apache.beehive.controls.runtime.bean.ControlBean.java

/**
 * Finds all of the EventSets extended by the input EventSet, and adds them to
 * the provided list. // ww  w  .j av a 2s.  c  om
 * @param eventSet
 * @param superEventSets
 */
private void getSuperEventSets(Class eventSet, List<Class> superEventSets) {
    Class[] superInterfaces = eventSet.getInterfaces();
    if (superInterfaces != null) {
        for (int i = 0; i < superInterfaces.length; i++) {
            Class superInterface = superInterfaces[i];
            if (superInterface.isAnnotationPresent(EventSet.class)) {
                superEventSets.add(superInterface);

                // Continue traversing up the EventSet inheritance hierarchy
                getSuperEventSets(superInterface, superEventSets);
            }
        }
    }
}

From source file:com.lucidtechnics.blackboard.Blackboard.java

private String determineWorkspaceIdentifierName(Object _event) {
    Class eventClass = _event.getClass();
    String propertyName = null;/* w  w  w  .  j  a  v a  2  s  .  c  o m*/

    if (eventClass.isAnnotationPresent(Event.class) == true) {
        Event event = (Event) eventClass.getAnnotation(Event.class);

        if (event.workspaceIdentifier() != null) {
            propertyName = event.workspaceIdentifier();
        }
    }

    return propertyName;
}

From source file:org.broadinstitute.gatk.utils.help.GenericDocumentationHandler.java

/**
 * Utility function that finds the values of ReadFilters annotation applied to an instance of class c.
 *
 * @param myClass the class to query for the annotation
 * @param bucket a container in which we store the annotations collected
 * @return a hash set of values, otherwise an empty set
 *//*from   w w  w .ja  v a 2s .com*/
private HashSet<HashMap<String, Object>> getReadFilters(Class myClass,
        HashSet<HashMap<String, Object>> bucket) {
    //
    // Retrieve annotation
    if (myClass.isAnnotationPresent(ReadFilters.class)) {
        final Annotation thisAnnotation = myClass.getAnnotation(ReadFilters.class);
        if (thisAnnotation instanceof ReadFilters) {
            final ReadFilters rfAnnotation = (ReadFilters) thisAnnotation;
            for (Class<?> filter : rfAnnotation.value()) {
                // make hashmap of simplename and url
                final HashMap<String, Object> nugget = new HashMap<String, Object>();
                nugget.put("name", filter.getSimpleName());
                nugget.put("filename", GATKDocUtils.htmlFilenameForClass(filter));
                bucket.add(nugget);
            }
        }
    }
    // Look up superclasses recursively
    final Class mySuperClass = myClass.getSuperclass();
    if (mySuperClass.getSimpleName().equals("Object")) {
        return bucket;
    }
    return getReadFilters(mySuperClass, bucket);
}

From source file:net.firejack.platform.model.service.reverse.ReverseEngineeringService.java

private void analyze(Collection<Class> classes, RegistryNodeModel model) throws IOException, JAXBException {
    Class service = null;//from ww w. ja va2 s  .  co m
    Class endpoint = null;
    for (Class clazz : classes) {
        if (clazz.isInterface() && clazz.isAnnotationPresent(WebService.class)) {
            service = clazz;
            if (!clazz.isAnnotationPresent(SOAPBinding.class))
                break;
        }
    }

    for (Class clazz : classes) {
        if (javax.xml.ws.Service.class.isAssignableFrom(clazz)) {
            endpoint = clazz;
            break;
        }
    }

    if (service == null)
        throw new BusinessFunctionException("Cannot find Service class");

    Wsdl wsdl = new Wsdl(endpoint, service);

    analyzeService(service.getDeclaredMethods(), model, wsdl);

    String name = SecurityHelper.generateRandomSequence(16);
    File temp = new File(FileUtils.getTempDirectory(), name);
    FileOutputStream stream = FileUtils.openOutputStream(temp);
    FileUtils.writeJAXB(wsdl, stream);
    IOUtils.closeQuietly(stream);

    saveResource(WSDL_SCHEME, model.getName() + ".sch", model, temp);
    FileUtils.forceDelete(temp);
}

From source file:com.all.client.model.LocalModelDao.java

public long count(final Class<?> objectClass) {

    return hibernateTemplate.execute(new HibernateCallback<Long>() {
        @Override/*from   w w  w. j a va2s  .  c  o m*/
        public Long doInHibernate(Session session) throws SQLException {
            String entityName = objectClass.getSimpleName();
            if (objectClass.isAnnotationPresent(Entity.class)) {
                Entity entity = objectClass.getAnnotation(Entity.class);
                if (StringUtils.isNotEmpty(entity.name())) {
                    entityName = entity.name();
                }
            }
            Query q = session.createQuery("select count(*) from " + entityName);
            return Long.valueOf(q.uniqueResult().toString());
        }
    });
}

From source file:org.cruxframework.crux.core.server.rest.core.registry.ResourceRegistry.java

/**
 * /*from  w  w w. j av a 2s .  c  o  m*/
 * @param base
 * @param clazz
 * @param method
 * @param restMethodNames 
 */
protected RestMethodRegistrationInfo processMethod(String base, Class<?> clazz, Method method,
        Set<String> restMethodNames) {
    if (method != null) {
        Path path = method.getAnnotation(Path.class);
        String httpMethod = null;
        try {
            httpMethod = HttpMethodHelper.getHttpMethod(method.getAnnotations());
        } catch (InvalidRestMethod e) {
            logger.error(
                    "Invalid Method: " + method.getDeclaringClass().getName() + "." + method.getName() + "().",
                    e);
        }

        boolean pathPresent = path != null;
        boolean restAnnotationPresent = pathPresent || (httpMethod != null);

        UriBuilder builder = new UriBuilder();
        if (base != null)
            builder.path(base);
        if (clazz.isAnnotationPresent(Path.class)) {
            builder.path(clazz);
        }
        if (path != null) {
            builder.path(method);
        }
        String pathExpression = builder.getPath();
        if (pathExpression == null) {
            pathExpression = "";
        }
        if (restAnnotationPresent && !Modifier.isPublic(method.getModifiers())) {
            logger.error("Rest annotations found at non-public method: " + method.getDeclaringClass().getName()
                    + "." + method.getName() + "(); Only public methods may be exposed as resource methods.");
        } else if (httpMethod != null) {
            if (restMethodNames.contains(method.getName())) {
                logger.error("Overloaded rest method: " + method.getDeclaringClass().getName() + "."
                        + method.getName() + " found. It is not supported for Crux REST services.");
            } else {
                ResourceMethod invoker = new ResourceMethod(clazz, method, httpMethod);
                rootSegment.addPath(pathExpression, invoker);
                restMethodNames.add(method.getName());
                size++;
                return new RestMethodRegistrationInfo(pathExpression, invoker);
            }
        } else {
            if (restAnnotationPresent) {
                logger.error("Method: " + method.getDeclaringClass().getName() + "." + method.getName()
                        + "() declares rest annotations, but it does not inform the methods it must handle. Use one of @PUT, @POST, @GET or @DELETE.");
            } else if (logger.isDebugEnabled()) {
                logger.debug("Method: " + method.getDeclaringClass().getName() + "." + method.getName()
                        + "() ignored. It is not a rest method.");
            }
        }
    }
    return null;
}

From source file:org.alfresco.rest.framework.core.ResourceInspector.java

/**
 * Inspects the entity resource and returns meta data about it
 * /*w ww  .j a  v a 2  s  .  c om*/
 * @param annot EntityResource
 * @param resource Class<?>
 */
private static List<ResourceMetadata> inspectEntity(EntityResource annot, Class<?> resource) {

    String urlPath = findEntityName(annot);
    logger.debug("Found EntityResource: " + urlPath);
    List<ResourceMetadata> metainfo = new ArrayList<ResourceMetadata>();
    Api api = inspectApi(resource);

    MetaHelper helper = new MetaHelper(resource);
    findOperation(EntityResourceAction.Create.class, HttpMethod.POST, helper);
    findOperation(EntityResourceAction.Read.class, HttpMethod.GET, helper);
    findOperation(EntityResourceAction.ReadById.class, HttpMethod.GET, helper);
    findOperation(EntityResourceAction.Update.class, HttpMethod.PUT, helper);
    findOperation(EntityResourceAction.Delete.class, HttpMethod.DELETE, helper);

    findOperation(EntityResourceAction.CreateWithResponse.class, HttpMethod.POST, helper);
    findOperation(EntityResourceAction.ReadWithResponse.class, HttpMethod.GET, helper);
    findOperation(EntityResourceAction.ReadByIdWithResponse.class, HttpMethod.GET, helper);
    findOperation(EntityResourceAction.UpdateWithResponse.class, HttpMethod.PUT, helper);
    findOperation(EntityResourceAction.DeleteWithResponse.class, HttpMethod.DELETE, helper);

    findOperation(MultiPartResourceAction.Create.class, HttpMethod.POST, helper);

    boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class);
    if (noAuth) {
        throw new IllegalArgumentException(
                "@WebApiNoAuth should not be on all (entity resource class) - only on individual methods: "
                        + urlPath);
    }

    Set<Class<? extends ResourceAction>> apiNoAuth = helper.apiNoAuth;

    if (resource.isAnnotationPresent(WebApiDeleted.class)) {
        metainfo.add(new ResourceMetadata(ResourceDictionary.resourceKey(urlPath, null), RESOURCE_TYPE.ENTITY,
                null, api, ALL_ENTITY_RESOURCE_INTERFACES, apiNoAuth, null));
    } else {
        if (!helper.apiDeleted.isEmpty() || !helper.operations.isEmpty()) {
            metainfo.add(new ResourceMetadata(ResourceDictionary.resourceKey(urlPath, null),
                    RESOURCE_TYPE.ENTITY, helper.operations, api, helper.apiDeleted, apiNoAuth, null));
        }
    }

    inspectAddressedProperties(api, resource, urlPath, metainfo);
    inspectOperations(api, resource, urlPath, metainfo);
    return metainfo;
}

From source file:net.firejack.platform.model.service.reverse.ReverseEngineeringService.java

private void analyzeField(String name, Type type, WebParam.Mode mode, boolean list, boolean holder,
        boolean _return, Service service) {
    if (type instanceof Class) {
        Class clazz = (Class) type;
        Parameter parameter = new Parameter(StringUtils.uncapitalize(name), clazz,
                clazz.isAnnotationPresent(XmlAccessorType.class), list, holder, mode);
        if (_return) {
            service.setReturn(parameter);
        } else {//ww w  .j ava2s  . co  m
            service.addParameter(parameter);
        }
    } else if (type instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) type;
        Type rawType = parameterizedType.getRawType();
        Type generic = parameterizedType.getActualTypeArguments()[0];
        if (rawType == Holder.class) {
            analyzeField(name, generic, mode, false, true, _return, service);
        } else if (rawType == List.class) {
            if (generic instanceof Class && ((Class) generic).isAnnotationPresent(XmlAccessorType.class)) {
                analyzeField(name, generic, mode, true, holder, _return, service);
            } else {
                analyzeField(name, rawType, mode, true, holder, _return, service);
            }
        } else {
            throw new IllegalStateException("Unknown type: " + type);
        }
    }
}