Example usage for java.lang Class getAnnotations

List of usage examples for java.lang Class getAnnotations

Introduction

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

Prototype

public Annotation[] getAnnotations() 

Source Link

Usage

From source file:org.mule.config.processors.DecoratingAnnotatedServiceProcessor.java

protected void processReply(Class componentFactoryClass, org.mule.api.service.Service service)
        throws MuleException {

    InboundEndpoint inboundEndpoint;//  ww w.  j a v a2  s. co  m
    for (int i = 0; i < componentFactoryClass.getAnnotations().length; i++) {
        Annotation annotation = componentFactoryClass.getAnnotations()[i];
        inboundEndpoint = tryInboundEndpointAnnotation(
                new AnnotationMetaData(componentFactoryClass, null, ElementType.TYPE, annotation),
                ChannelType.Reply);
        if (inboundEndpoint != null) {
            service.getAsyncReplyMessageSource().addSource(inboundEndpoint);
        }
    }

    //Lets process the reply routers
    processReplyRouters(componentFactoryClass, service);
}

From source file:org.neuro4j.studio.core.util.ParameterDefinitionLoader.java

private ParameterDefinitionList getParameterDefinitionListAnnotation(Class<?> aClass) {

    Annotation[] ans = aClass.getAnnotations();

    for (Annotation an : ans) {
        if (an.annotationType().toString().endsWith("ParameterDefinitionList")) {

            final Object obj = aClass.getAnnotation(an.annotationType());

            ParameterDefinitionList list = new ParameterDefinitionList() {

                @Override//from  w  w  w .java  2 s .  com
                public Class<? extends Annotation> annotationType() {

                    return org.neuro4j.workflow.common.ParameterDefinitionList.class;
                }

                @Override
                public ParameterDefinition[] input() {

                    Object[] parameterDefArray = null;
                    try {
                        parameterDefArray = (Object[]) MethodUtils.invokeExactMethod(obj, "input", null);
                        if (parameterDefArray == null) {
                            return EMPTY;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        return EMPTY;
                    }

                    List<ParameterDefinition> list = new ArrayList<ParameterDefinition>(5);
                    for (Object ob : parameterDefArray) {
                        try {
                            ParameterDefinition pd1 = getParameterDefinition(ob);
                            list.add(pd1);
                        } catch (Exception e) {
                            e.printStackTrace();
                            return EMPTY;
                        }
                    }

                    return list.toArray(new ParameterDefinition[list.size()]);
                }

                @Override
                public ParameterDefinition[] output() {
                    Object[] parameterDefArray = null;
                    try {
                        parameterDefArray = (Object[]) MethodUtils.invokeExactMethod(obj, "output", null);
                        if (parameterDefArray == null) {
                            return EMPTY;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        return EMPTY;
                    }

                    List<ParameterDefinition> list = new ArrayList<ParameterDefinition>(5);
                    for (Object ob : parameterDefArray) {
                        try {
                            ParameterDefinition pd1 = getParameterDefinition(ob);
                            list.add(pd1);
                        } catch (Exception e) {
                            e.printStackTrace();
                            return EMPTY;
                        }
                    }

                    return list.toArray(new ParameterDefinition[list.size()]);
                }

            };

            try {

            } catch (Exception e) {
                e.printStackTrace();
            }

            return list;
        }
    }

    return null;
}

From source file:io.github.jeddict.jpa.modeler.initializer.JPAModelerUtil.java

/**
 * This method is used, when modeler file is not created and version is
 * required.// w  w  w  .  j av  a 2 s . c o  m
 *
 * @return
 */
public static String getModelerFileVersion() {
    Class _class = JPAFileActionListener.class;
    Annotation[] annotations = _class.getAnnotations();

    for (Annotation annotation : annotations) {
        if (annotation instanceof DiagramModel) {
            DiagramModel diagramModel = (DiagramModel) annotation;
            return diagramModel.version();
        }
    }
    return "0.0";
}

From source file:net.mojodna.sprout.SproutAutoLoaderPlugIn.java

@SuppressWarnings("unchecked")
private void loadAction(final Class bean) {
    final Annotation[] annotations = bean.getAnnotations();

    for (int i = 0; i < annotations.length; i++) {
        final Annotation a = annotations[i];
        final Class type = a.annotationType();

        if (type.equals(SproutAction.class)) {
            final SproutAction form = (SproutAction) a;
            final String path = form.path();
            final Class<ActionConfig> mappingClass = form.mappingClass();
            final String scope = form.scope();
            final String name = form.name();
            final boolean validate = form.validate();
            final String input = form.input();
            final SproutProperty[] properties = form.properties();
            final SproutForward[] forwards = form.forwards();
            ActionConfig actionConfig = null;

            try {
                Constructor<ActionConfig> constructor = mappingClass.getDeclaredConstructor(new Class[] {});

                actionConfig = constructor.newInstance(new Object[] {});
            } catch (NoSuchMethodException nsme) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + nsme.getMessage());
            } catch (InstantiationException ie) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + ie.getMessage());
            } catch (IllegalAccessException iae) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + iae.getMessage());
            } catch (InvocationTargetException ite) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + ite.getMessage());
            }//from  w  w  w  . j  a  v a2  s. c om

            if (actionConfig != null) {
                actionConfig.setPath(path);
                actionConfig.setType(bean.getName());
                actionConfig.setScope(scope);
                actionConfig.setValidate(validate);

                if (name.length() > 0) {
                    actionConfig.setName(name);
                }
                if (input.length() > 0) {
                    actionConfig.setInput(input);
                }

                if (properties != null && properties.length > 0) {
                    Map actionConfigBeanMap = new BeanMap(actionConfig);

                    for (int j = 0; j < properties.length; j++) {
                        actionConfigBeanMap.put(properties[j].property(), properties[j].value());
                    }
                }

                if (forwards != null && forwards.length > 0) {
                    for (int j = 0; j < forwards.length; j++) {
                        String fcModule = forwards[j].module();

                        actionConfig.addForwardConfig(makeForward(forwards[j].name(), forwards[j].path(),
                                forwards[j].redirect(), fcModule.length() == 0 ? null : fcModule));
                    }
                }
            }

            if (log.isDebugEnabled()) {
                log.debug("Action " + path + " -> " + bean.getName());
            }

            getModuleConfig().addActionConfig(actionConfig);
        }
    }
}

From source file:org.lunarray.model.descriptor.scanner.AnnotationScannerUtil.java

/**
 * Transitively tests for marker marks.// w w  w . ja v  a  2  s  .com
 * 
 * @param marker
 *            The marker.
 * @param processed
 *            The processed annotations.
 * @param process
 *            The annotations to process.
 * @return True if and only if the marker marks any of the processed
 *         annotations.
 */
private boolean isMarkedTransiviteProcess(final Class<? extends Annotation> marker,
        final Set<Class<? extends Annotation>> processed, final Queue<Class<? extends Annotation>> process) {
    boolean marked = false;
    while (!process.isEmpty()) {
        final Class<? extends Annotation> poll = process.poll();
        processed.add(poll);
        if (poll.equals(marker)) {
            marked = true;
            process.clear();
        } else {
            for (final Annotation annotation : poll.getAnnotations()) {
                final Class<? extends Annotation> annotationType = annotation.annotationType();
                if (!processed.contains(annotationType)) {
                    process.add(annotationType);
                }
            }
        }
    }
    return marked;
}

From source file:es.osoco.grails.plugins.otp.access.AnnotationMultipleVoterFilterInvocationDefinition.java

private void findControllerAnnotations(final GrailsControllerClass controllerClass,
        final Map<String, Map<String, Set<String>>> actionRoleMap,
        final Map<String, Set<String>> classRoleMap) {

    Class<?> clazz = controllerClass.getClazz();
    String controllerName = WordUtils.uncapitalize(controllerClass.getName());

    Annotation annotation = findAnnotation(clazz.getAnnotations());
    if (annotation != null) {
        classRoleMap.put(controllerName, asSet(getValue(annotation)));
    }// ww  w  .  j  a  v  a  2 s.c  om

    Map<String, Set<String>> annotatedClosureNames = findActionRoles(clazz);
    if (annotatedClosureNames != null) {
        actionRoleMap.put(controllerName, annotatedClosureNames);
    }
}

From source file:org.openlegacy.support.DefaultRegistryLoader.java

@Override
public void loadSingleClass(EntitiesRegistry<?, ?, ?> entitiesRegistry, Class<?> beanClass,
        Boolean loadReferences) {

    if (org.openlegacy.utils.ClassUtils.isAbstract(beanClass)
            || beanClass.getSimpleName().contains("_Aspect")) {
        return;//from   w  w  w. jav  a  2 s. c  om
    }
    if (entitiesRegistry.contains(beanClass)) {
        // class is reloaded - define the registry as dirty for designtime usage
        ((AbstractEntitiesRegistry<?, ?, ?>) entitiesRegistry).setDirty(true);
    }
    Class<?> currentBeanClass = beanClass;
    // scan parent classes for annotations
    while (currentBeanClass != Object.class) {
        Annotation[] annotations = currentBeanClass.getAnnotations();
        processAnnotations(classAnnotationLoaders, entitiesRegistry, beanClass, annotations);
        currentBeanClass = currentBeanClass.getSuperclass();
    }
    // scan field for annotations
    handleEntityAnnotationFields(fieldAnnotationLoaders, entitiesRegistry, beanClass);
    handleEntityFields(fieldLoaders, entitiesRegistry, beanClass);

    if (loadReferences) {
        fillEntityReferences(entitiesRegistry, entitiesRegistry.get(beanClass));
    }
}

From source file:org.apache.stratos.metadata.service.handlers.StratosAuthorizingHandler.java

/**
 * Goes through the class hierarchy and find the authorization annotations
 * attached to a certain//  w w w.j  a  va 2  s.com
 * method.
 *
 * @param clazz                  class to be scanned
 * @param authorizationActionMap the map to be populated
 */
private void findAuthorizationActions(Class<?> clazz, Map<String, String> authorizationActionMap) {
    if (clazz == null || clazz == Object.class) {
        return;
    }
    String classAuthorizationActionsAllowed = getAuthorizationActions(clazz.getAnnotations(),
            AUTHORIZATION_ANNOTATION_CLASS_NAME);
    for (Method m : clazz.getMethods()) {
        if (SKIP_METHODS.contains(m.getName())) {
            continue;
        }
        String methodAuthorizationActionsAllowed = getAuthorizationActions(m.getAnnotations(),
                AUTHORIZATION_ANNOTATION_CLASS_NAME);
        String authorizationActions = methodAuthorizationActionsAllowed != null
                ? methodAuthorizationActionsAllowed
                : classAuthorizationActionsAllowed;
        if (authorizationActions != null) {
            authorizationActionMap.put(m.getName(), authorizationActions);
        }
    }
    if (!authorizationActionMap.isEmpty()) {
        return;
    }

    findAuthorizationActions(clazz.getSuperclass(), authorizationActionMap);

    if (!authorizationActionMap.isEmpty()) {
        return;
    }

    for (Class<?> interfaceCls : clazz.getInterfaces()) {
        findAuthorizationActions(interfaceCls, authorizationActionMap);
    }
}

From source file:org.omnaest.utils.reflection.ReflectionUtils.java

/**
 * Returns all {@link Class#getAnnotations()} as {@link List}
 * //from  www. j  a  v  a2 s  .  co m
 * @param type
 * @return
 */
public static List<Annotation> annotationList(Class<?> type) {
    //    
    List<Annotation> retlist = new ArrayList<Annotation>();

    //
    if (type != null) {
        //
        retlist.addAll(Arrays.asList(type.getAnnotations()));
    }

    //
    return retlist;
}