Example usage for java.lang.reflect Method isAnnotationPresent

List of usage examples for java.lang.reflect Method isAnnotationPresent

Introduction

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

Prototype

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

Source Link

Usage

From source file:com.khs.sherpa.servlet.SherpaRequest.java

private void validateMethod(Method method) throws SherpaRuntimeException {
    if (target.getClass().getAnnotation(Endpoint.class).authenticated()) {
        if (!sessionStatus.equals(SessionStatus.AUTHENTICATED)) {
            throw new SherpaPermissionExcpetion("token is invalid or has expired");
        } else if (method.isAnnotationPresent(DenyAll.class)) {
            throw new SherpaPermissionExcpetion("method [" + method.getName() + "] in class ["
                    + target.getClass().getCanonicalName() + "] has `@DenyAll` annotation");
        } else if (method.isAnnotationPresent(RolesAllowed.class)) {
            for (String role : method.getAnnotation(RolesAllowed.class).value()) {
                if (service.getTokenService().hasRole(userid, token, role)) {
                    return;
                }/*from   w w  w.  j  a  v  a2s .co  m*/
            }
            throw new SherpaPermissionExcpetion("method [" + method.getName() + "] in class ["
                    + target.getClass().getCanonicalName() + "] has `@RolesAllowed` annotation");
        }
    }
}

From source file:org.globus.workspace.testing.NimbusTestBase.java

@AfterMethod(alwaysRun = true)
protected void springTestContextAfterTestMethod(Method testMethod) throws Exception {

    if (testMethod.isAnnotationPresent(DirtiesContext.class)) {
        logger.debug(LOG_SEP + "\n*** @DirtiesContext FOUND - STARTING CLEANUP: " + LOG_SEP);
        stopTimerManager();//from www  . j a v  a  2 s.com
        stopWorkspaceService();
        //shutdownDB();
        quickResetDB();
        logger.debug(LOG_SEP + "\n*** @DirtiesContext FOUND - FINISHED CLEANUP: " + LOG_SEP);
    }

    super.springTestContextAfterTestMethod(testMethod);
}

From source file:org.jboss.jaxb.intros.IntroductionsAnnotationReader.java

public boolean hasMethodAnnotation(Class<? extends Annotation> annotation, Method method) {
    MethodIntroConfig methodAnnotations = getMethodIntroConfig(method);

    if (methodAnnotations != null) {
        return isMemberAnnotationIntroAvailable(annotation, methodAnnotations);
    }//www . j a v a2 s  . c  o m

    return method.isAnnotationPresent(annotation);
}

From source file:de.taimos.dvalin.cloud.aws.AWSClientBeanPostProcessor.java

private InjectionMetadata buildResourceMetadata(Class<?> clazz) {
    LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<>();
    Class<?> targetClass = clazz;

    do {//  www.j a  va  2s . c o  m
        LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<>();
        for (Field field : targetClass.getDeclaredFields()) {
            if (field.isAnnotationPresent(AWSClient.class)) {
                if (Modifier.isStatic(field.getModifiers())) {
                    throw new IllegalStateException("@AWSClient annotation is not supported on static fields");
                }
                currElements.add(new AWSClientElement(field, null, field.getAnnotation(AWSClient.class)));
            }
        }
        for (Method method : targetClass.getDeclaredMethods()) {
            Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
            if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
                continue;
            }
            if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
                if (bridgedMethod.isAnnotationPresent(AWSClient.class)) {
                    if (Modifier.isStatic(method.getModifiers())) {
                        throw new IllegalStateException(
                                "@AWSClient annotation is not supported on static methods");
                    }
                    if (method.getParameterTypes().length != 1) {
                        throw new IllegalStateException(
                                "@AWSClient annotation requires a single-arg method: " + method);
                    }
                    PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
                    currElements.add(new AWSClientElement(method, pd, method.getAnnotation(AWSClient.class)));
                }
            }
        }
        elements.addAll(0, currElements);
        targetClass = targetClass.getSuperclass();
    } while ((targetClass != null) && (targetClass != Object.class));

    return new InjectionMetadata(clazz, elements);
}

From source file:com.tmall.wireless.tangram.MVHelper.java

private void loadMethod(BaseCell cell, View view) {
    if (view instanceof ITangramViewLifeCycle) {
        return;//from   www. j ava2s .c  o  m
    }
    if (methodMap.get(cell) != null) {
        return;
    }

    ArrayMap<Method, Object> paramMap = new ArrayMap<>();

    Method[] methods;
    if (methodCacheMap.get(view.getClass()) == null) {
        methods = view.getClass().getDeclaredMethods();
        methodCacheMap.put(view.getClass(), methods);
    } else {
        methods = methodCacheMap.get(view.getClass());
    }
    CellRender cellRender;
    Class[] paramClazz;
    for (Method method : methods) {
        cellRender = method.getAnnotation(CellRender.class);
        paramClazz = method.getParameterTypes();

        if (!method.isAnnotationPresent(CellRender.class) || paramClazz == null || paramClazz.length != 1)
            continue;

        if (method.getName().equals("postBindView")) {
            postBindMap.put(cell, method);
            continue;
        }

        if (method.getName().equals("postUnBindView")) {
            postUnBindMap.put(cell, method);
            continue;
        }

        if (method.getName().equals("cellInited")) {
            cellInitedMap.put(cell, method);
            continue;
        }

        if (!TextUtils.isEmpty(cellRender.key()) && cell.hasParam(cellRender.key())) {
            if ("null".equals(cell.optParam(cellRender.key()))) {
                paramMap.put(method, null);
            } else if (paramClazz[0].equals(Integer.class) || paramClazz[0].equals(int.class)) {
                paramMap.put(method, cell.optIntParam(cellRender.key()));
            } else if (paramClazz[0].equals(String.class)) {
                paramMap.put(method, cell.optStringParam(cellRender.key()));
            } else if (paramClazz[0].equals(Boolean.class) || paramClazz[0].equals(boolean.class)) {
                paramMap.put(method, cell.optBoolParam(cellRender.key()));
            } else if (paramClazz[0].equals(Double.class) || paramClazz[0].equals(double.class)) {
                paramMap.put(method, cell.optDoubleParam(cellRender.key()));
            } else if (paramClazz[0].equals(JSONArray.class)) {
                paramMap.put(method, cell.optJsonArrayParam(cellRender.key()));
            } else if (paramClazz[0].equals(Long.class) || paramClazz[0].equals(long.class)) {
                paramMap.put(method, cell.optLongParam(cellRender.key()));
            } else if (paramClazz[0].equals(JSONObject.class)) {
                paramMap.put(method, cell.optJsonObjectParam(cellRender.key()));
            } else {
                paramMap.put(method, cell.optParam(cellRender.key()));
            }
        } else if (cell.hasParam(method.getName())) {
            if ("null".equals(cell.optParam(method.getName()))) {
                paramMap.put(method, null);
            } else if (paramClazz[0].equals(Integer.class) || paramClazz[0].equals(int.class)) {
                paramMap.put(method, cell.optIntParam(method.getName()));
            } else if (paramClazz[0].equals(String.class)) {
                paramMap.put(method, cell.optStringParam(method.getName()));
            } else if (paramClazz[0].equals(Boolean.class) || paramClazz[0].equals(boolean.class)) {
                paramMap.put(method, cell.optBoolParam(method.getName()));
            } else if (paramClazz[0].equals(Double.class) || paramClazz[0].equals(double.class)) {
                paramMap.put(method, cell.optDoubleParam(method.getName()));
            } else if (paramClazz[0].equals(JSONArray.class)) {
                paramMap.put(method, cell.optJsonArrayParam(method.getName()));
            } else if (paramClazz[0].equals(Long.class) || paramClazz[0].equals(long.class)) {
                paramMap.put(method, cell.optLongParam(method.getName()));
            } else if (paramClazz[0].equals(JSONObject.class)) {
                paramMap.put(method, cell.optJsonObjectParam(method.getName()));
            } else {
                paramMap.put(method, cell.optParam(method.getName()));
            }
        } else {
            if (paramClazz[0].equals(Integer.class) || paramClazz[0].equals(int.class)) {
                paramMap.put(method, 0);
            } else if (paramClazz[0].equals(String.class)) {
                paramMap.put(method, "");
            } else if (paramClazz[0].equals(Boolean.class) || paramClazz[0].equals(boolean.class)) {
                paramMap.put(method, false);
            } else if (paramClazz[0].equals(Double.class) || paramClazz[0].equals(double.class)) {
                paramMap.put(method, 0);
            } else if (paramClazz[0].equals(JSONArray.class)) {
                paramMap.put(method, null);
            } else if (paramClazz[0].equals(Long.class) || paramClazz[0].equals(long.class)) {
                paramMap.put(method, 0);
            } else if (paramClazz[0].equals(JSONObject.class)) {
                paramMap.put(method, null);
            } else {
                paramMap.put(method, "");
            }
        }
    }

    if (!paramMap.isEmpty())
        methodMap.put(cell, paramMap);
}

From source file:com.evolveum.midpoint.repo.sql.query.definition.ClassDefinitionParser.java

private void updateEntityDefinition(EntityDefinition entity) {
    LOGGER.trace("### {}", new Object[] { entity.getJpaName() });
    addVirtualDefinitions(entity);//  ww w.j  a  va2  s  .c o m
    Method[] methods = entity.getJpaType().getMethods();

    entity.setEmbedded(entity.getJpaType().getAnnotation(Embeddable.class) != null);

    for (Method method : methods) {
        String methodName = method.getName();
        if (Modifier.isStatic(method.getModifiers()) || "getClass".equals(methodName)
                || !methodName.startsWith("is") && !methodName.startsWith("get")) {
            //it's not getter for property
            continue;
        }

        if (method.isAnnotationPresent(Transient.class)) {
            continue;
        }

        LOGGER.trace("# {}", new Object[] { methodName });

        QName jaxbName = getJaxbName(method);
        Class jaxbType = getJaxbType(method);
        String jpaName = getJpaName(method);
        Definition definition = createDefinition(jaxbName, jaxbType, jpaName, method);
        entity.addDefinition(definition);
    }
}

From source file:com.eclecticlogic.pedal.dialect.postgresql.CopyCommand.java

/**
 * Note: This method is now "ugly" and needs serious refactoring.
 * @param clz/*from   w ww.java2s . com*/
 * @param fieldMethods
 * @return Create a class to generate the copy row strings.
 */
@SuppressWarnings({ "unchecked" })
private <E extends Serializable> CopyExtractor<E> getExtractor(Class<E> clz, List<Method> fieldMethods) {
    ClassPool pool = ClassPool.getDefault();
    pool.insertClassPath(new ClassClassPath(clz));
    CtClass cc = pool.makeClass("com.eclecticlogic.pedal.dialect.postgresql." + clz.getSimpleName()
            + "$CopyExtractor_" + extractorNameSuffix.incrementAndGet());

    StringBuilder methodBody = new StringBuilder();
    try {
        cc.addInterface(pool.getCtClass(CopyExtractor.class.getName()));

        methodBody.append("public String getValueList(Object entity) {\n");
        methodBody.append("try {\n");
        methodBody.append("StringBuilder builder = new StringBuilder();\n");
        methodBody.append(clz.getName() + " typed = (" + clz.getName() + ")entity;\n");
        for (int i = 0; i < fieldMethods.size(); i++) {
            Method method = fieldMethods.get(i);
            if (method.isAnnotationPresent(CopyConverter.class)) {
                try {
                    Class<?> helper = method.getAnnotation(CopyConverter.class).value();
                    methodBody.append(helper.getName() + " c" + i + " = (" + helper.getName() + ")"
                            + helper.getName() + ".class.newInstance();\n");
                    methodBody
                            .append("builder.append(c" + i + ".convert(typed." + method.getName() + "()));\n");
                } catch (Exception e) {
                    throw new RuntimeException(e.getMessage(), e);
                }
            } else if (method.getReturnType().isPrimitive()) {
                methodBody.append("builder.append(typed." + method.getName() + "());\n");
            } else {
                methodBody.append(
                        method.getReturnType().getName() + " v" + i + " = typed." + method.getName() + "();\n");
                if (method.isAnnotationPresent(EmbeddedId.class)) {
                    // Embedded id
                    if (method.isAnnotationPresent(AttributeOverrides.class)) {
                        AttributeOverrides overrides = method.getAnnotation(AttributeOverrides.class);
                        for (int j = 0; j < overrides.value().length; j++) {
                            AttributeOverride override = overrides.value()[j];
                            methodBody.append("if (v" + i + " == null) {builder.append(\"\\\\N\");}\n");
                            methodBody.append("else {\n");
                            Method idMethod = BeanUtils
                                    .getPropertyDescriptor(method.getReturnType(), override.name())
                                    .getReadMethod();
                            methodBody.append("builder.append(v" + i + "." + idMethod.getName() + "());\n");
                            methodBody.append("}\n");
                            if (j != overrides.value().length - 1) {
                                methodBody.append("builder.append(\"\\t\");\n");
                            }
                        }
                    }
                } else if (method.getReturnType().isAnnotationPresent(Embeddable.class)) {
                    // Embeddable. If attribute overrides is present, we get the columns in the order of the 
                    // override annotations. Otherwise use method names.
                    if (method.isAnnotationPresent(AttributeOverrides.class)) {
                        AttributeOverrides overrides = method.getAnnotation(AttributeOverrides.class);
                        for (int j = 0; j < overrides.value().length; j++) {
                            AttributeOverride override = overrides.value()[j];
                            Method embedded = BeanUtils
                                    .getPropertyDescriptor(method.getReturnType(), override.name())
                                    .getReadMethod();
                            if (embedded.getReturnType().isPrimitive()) {
                                methodBody.append("builder.append(v" + i + "." + embedded.getName() + "());");
                            } else {
                                methodBody.append("if (v" + i + "." + embedded.getName()
                                        + "() == null) {builder.append(\"\\\\N\");}");
                                methodBody.append(
                                        "else {builder.append(v" + i + "." + embedded.getName() + "());}");
                            }
                            if (j != overrides.value().length - 1) {
                                methodBody.append("builder.append(\"\\t\");\n");
                            }
                        } // end loop over override values.
                    } else {
                        // Get columns as discovered by method traversal. Its assumed that @Column annotation exists
                        // on getter methods of interest.
                        List<Method> embeddedColumnMethods = new ArrayList<>();
                        for (Method embedded : method.getReturnType().getMethods()) {
                            if (embedded.isAnnotationPresent(Column.class)) {
                                embeddedColumnMethods.add(embedded);
                            }
                        }

                        for (int j = 0; j < embeddedColumnMethods.size(); j++) {
                            Method embedded = embeddedColumnMethods.get(j);
                            if (embedded.getReturnType().isPrimitive()) {
                                methodBody.append("builder.append(v" + i + "." + embedded.getName() + "());");
                            } else {
                                methodBody.append("if (v" + i + "." + embedded.getName()
                                        + "() == null) {builder.append(\"\\\\N\");}");
                                methodBody.append(
                                        "else {builder.append(v" + i + "." + embedded.getName() + "());}");
                            }
                            if (j != embeddedColumnMethods.size() - 1) {
                                methodBody.append("builder.append(\"\\t\");\n");
                            }
                        } // end loop over override values.

                    }
                } else {
                    methodBody.append("if (v" + i + " == null) {builder.append(\"\\\\N\");}\n");
                    methodBody.append("else {\n");

                    if (method.isAnnotationPresent(CopyAsBitString.class)) {
                        // Get number of bits from @Column annotation.
                        int bitCount = method.getAnnotation(Column.class).length();
                        methodBody.append("java.util.BitSet bs" + i + " = typed." + method.getName() + "();\n");
                        methodBody.append("for (int i = 0; i < " + bitCount + "; i++) {\n");
                        methodBody.append("builder.append(bs" + i + ".get(i) ? \"0\" : \"1\");\n");
                        methodBody.append("}\n");
                    } else if (Collection.class.isAssignableFrom(method.getReturnType())
                            && method.isAnnotationPresent(Convert.class) == false) {
                        // Postgreql array type.
                        if (method.isAnnotationPresent(CopyEmptyAsNull.class)) {
                            methodBody.append("if (typed." + method.getName() + "().isEmpty()) {\n");
                            methodBody.append("builder.append(\"\\\\N\");\n");
                            methodBody.append("} else {\n");
                            collectionExtractor(methodBody, i, method);
                            methodBody.append("}\n");
                        } else {
                            collectionExtractor(methodBody, i, method);
                        }
                    } else if (method.isAnnotationPresent(Convert.class)) {
                        Class<?> converterClass = method.getAnnotation(Convert.class).converter();
                        methodBody
                                .append(converterClass.getName() + " c" + i + " = (" + converterClass.getName()
                                        + ")" + converterClass.getName() + ".class.newInstance();\n");
                        methodBody.append("builder.append(c" + i + ".convertToDatabaseColumn(v" + i + "));\n");
                    } else if (method.isAnnotationPresent(JoinColumn.class)) {
                        // We need to get the id of the joined object.
                        for (Method method2 : method.getReturnType().getMethods()) {
                            if (method2.isAnnotationPresent(Id.class)) {
                                methodBody.append("builder.append(v" + i + "." + method2.getName() + "());\n");
                            }
                        }
                    } else {
                        methodBody.append("builder.append(v" + i + ");\n");
                    }
                    methodBody.append("}\n");
                }
            }
            if (i != fieldMethods.size() - 1) {
                methodBody.append("builder.append(\"\\t\");\n");
            }
        }
        methodBody.append("return builder.toString();\n");
        methodBody.append("} catch (Exception e) { throw new RuntimeException(e); } \n");
        methodBody.append("}\n");
        logger.trace(methodBody.toString());
        cc.addMethod(CtNewMethod.make(methodBody.toString(), cc));
    } catch (NotFoundException | CannotCompileException e) {
        logger.error(e.getMessage(), "Compiled body is:\n" + methodBody.toString());
        throw new RuntimeException(e.getMessage(), e);
    }

    try {
        return (CopyExtractor<E>) cc.toClass().newInstance();
    } catch (InstantiationException | IllegalAccessException | CannotCompileException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:org.traccar.database.QueryBuilder.java

public QueryBuilder setObject(Object object) throws SQLException {

    Method[] methods = object.getClass().getMethods();

    for (Method method : methods) {
        if (method.getName().startsWith("get") && method.getParameterTypes().length == 0
                && !method.isAnnotationPresent(QueryIgnore.class)) {
            String name = method.getName().substring(3);
            try {
                if (method.getReturnType().equals(boolean.class)) {
                    setBoolean(name, (Boolean) method.invoke(object));
                } else if (method.getReturnType().equals(int.class)) {
                    setInteger(name, (Integer) method.invoke(object));
                } else if (method.getReturnType().equals(long.class)) {
                    setLong(name, (Long) method.invoke(object), name.endsWith("Id"));
                } else if (method.getReturnType().equals(double.class)) {
                    setDouble(name, (Double) method.invoke(object));
                } else if (method.getReturnType().equals(String.class)) {
                    setString(name, (String) method.invoke(object));
                } else if (method.getReturnType().equals(Date.class)) {
                    setDate(name, (Date) method.invoke(object));
                } else if (method.getReturnType().equals(byte[].class)) {
                    setBlob(name, (byte[]) method.invoke(object));
                } else {
                    if (method.getReturnType().equals(Map.class)
                            && Context.getConfig().getBoolean("database.xml")) {
                        setString(name, MiscFormatter.toXmlString((Map) method.invoke(object)));
                    } else {
                        setString(name, Context.getObjectMapper().writeValueAsString(method.invoke(object)));
                    }//  w  ww .  j  a  v  a2 s  . c  o  m
                }
            } catch (IllegalAccessException | InvocationTargetException | JsonProcessingException error) {
                Log.warning(error);
            }
        }
    }

    return this;
}

From source file:org.mentawai.annotations.ApplicationManagerWithAnnotations.java

@SuppressWarnings("rawtypes")
public void loadAnnotatedClasses() {
    ActionConfig ac;/*from w  w  w  .j  av  a 2  s  . co m*/
    ArrayList<ActionConfig> acListForChains = new ArrayList<ActionConfig>();

    // Para carregamento das Chains
    ArrayList<String> actionName = new ArrayList<String>();
    ArrayList<String> innerActionName = new ArrayList<String>();
    ArrayList<String> actionChain = new ArrayList<String>();
    ArrayList<String> innerChain = new ArrayList<String>();

    if (resources == null) {
        System.out.println("NO RESOURCES DEFINED");
        return;
    }

    try {
        System.out.println("Searching for annotated classes inside package [" + resources + "]...");
        findAnnotatedClasses(resources);
    } catch (Exception e) {
        System.out.println("COULD NOT LOAD PACKAGE ANNOTATED CLASSES: ");
        e.printStackTrace();
        return;
    }
    HashSet<Class> annotatedRemove = new HashSet<Class>();
    for (Class<? extends Object> klass : annotatedClasses) {
        if (klass.getSuperclass().isAnnotationPresent(ActionClass.class)) {
            annotatedRemove.add(klass.getSuperclass());
            System.out.println("REMOVING " + klass.getSuperclass()
                    + ": this actions will be mapped by its subclass " + klass.getName() + ".");
        }
    }
    for (Class<? extends Object> klass2Remove : annotatedRemove) {
        annotatedClasses.remove(klass2Remove);
    }

    if (annotatedClasses.size() > 0) {
        for (Class<? extends Object> klass : annotatedClasses) {
            if (klass.isAnnotationPresent(ActionClass.class)) {
                System.out.println("LOADING ANNOTATED ACTION CLASS: " + klass.getName());

                // Mapear o prefixo da ao com a classe de ao
                ActionClass annotation = klass.getAnnotation(ActionClass.class);
                if (getActions().containsKey(annotation.prefix())) {
                    ac = getActions().get(annotation.prefix());
                    if (ac.getActionClass().isAssignableFrom(klass)) {
                        ac = new ActionConfig(annotation.prefix(), klass);
                    }
                } else
                    ac = new ActionConfig(annotation.prefix(), klass);

                // Mapear as consequencias default (sem mtodo de ao) da
                // classe
                ConsequenceOutput[] outputsClass = annotation.outputs();
                if (outputsClass != null && outputsClass.length > 0) {
                    for (ConsequenceOutput output : outputsClass) {
                        if (output.type() == ConsequenceType.FORWARD) {
                            // Caso seja a consequencia padro, mapear
                            // sucesso e erro para a mesma pgina
                            if (ConsequenceOutput.SUCCESS_ERROR.equals(output.result())) {
                                ac.addConsequence(SUCCESS, new Forward(output.page()));
                                ac.addConsequence(ERROR, new Forward(output.page()));
                            } else
                                ac.addConsequence(output.result(), new Forward(output.page()));
                        } else if (output.type() == ConsequenceType.REDIRECT) {
                            ac.addConsequence(output.result(),
                                    "".equals(output.page()) ? new Redirect(output.RedirectWithParameters())
                                            : new Redirect(output.page(), output.RedirectWithParameters()));
                        } else if (output.type() == ConsequenceType.STREAMCONSEQUENCE) {
                            ac.addConsequence(output.result(),
                                    "".equals(output.page()) ? new StreamConsequence()
                                            : new StreamConsequence(output.page()));
                        } else if (output.type() == ConsequenceType.AJAXCONSEQUENCE) {
                            try {
                                AjaxRenderer ajaxRender = (AjaxRenderer) Class.forName(output.page())
                                        .newInstance();
                                ac.addConsequence(output.result(), new AjaxConsequence(ajaxRender));
                            } catch (InstantiationException ex) {
                                ac.addConsequence(output.result(), new AjaxConsequence(new MapAjaxRenderer()));
                            } catch (Exception ex) {
                                System.out.println(
                                        "COULD NOT LOAD AJAX CONSEQUENCE, LOADED DEFAULT MapAjaxRenderer");
                                ex.printStackTrace();
                            }
                        } else if (output.type() == ConsequenceType.CUSTOM) {
                            try {
                                Consequence customObject = (Consequence) Class.forName(output.page())
                                        .newInstance();
                                ac.addConsequence(output.result(), customObject);
                            } catch (Exception ex) {
                                System.out.println("COULD NOT LOAD CUSTOM CONSEQUENCE: ACTION NOT LOADED: "
                                        + klass.getSimpleName());
                                ex.printStackTrace();
                            }
                        }
                    }
                }

                // Mapear os mtodos de aes da classe
                for (Method method : klass.getMethods()) {
                    if (method.isAnnotationPresent(Consequences.class)) {
                        System.out.println(
                                "LOADING CONSEQUENCE: " + annotation.prefix() + "." + method.getName());

                        // Buscar as consequencias anotadas na classe de
                        // ao
                        ConsequenceOutput[] mapConsequences = method.getAnnotation(Consequences.class)
                                .outputs();

                        // Mapeando as consequencias
                        if (mapConsequences != null && mapConsequences.length > 0) {
                            for (ConsequenceOutput output : mapConsequences) {
                                if (output.type() == ConsequenceType.FORWARD) {
                                    // Caso seja a consequencia padro,
                                    // mapear sucesso e erro para a mesma
                                    // pgina
                                    if (ConsequenceOutput.SUCCESS_ERROR.equals(output.result())) {
                                        ac.addConsequence(SUCCESS, method.getName(),
                                                new Forward(output.page()));
                                        ac.addConsequence(ERROR, method.getName(), new Forward(output.page()));
                                    } else
                                        ac.addConsequence(output.result(), method.getName(),
                                                new Forward(output.page()));
                                } else if (output.type() == ConsequenceType.REDIRECT) {
                                    Consequence c = null;
                                    if (output.page().equals("")) {
                                        c = new Redirect(output.RedirectWithParameters());
                                    } else {
                                        c = new Redirect(output.page(), output.RedirectWithParameters());
                                    }
                                    if (ConsequenceOutput.SUCCESS_ERROR.equals(output.result())) {
                                        ac.addConsequence(SUCCESS, method.getName(), c);
                                        ac.addConsequence(ERROR, method.getName(), c);
                                    } else {
                                        ac.addConsequence(output.result(), method.getName(), c);
                                    }
                                } else if (output.type() == ConsequenceType.STREAMCONSEQUENCE) {
                                    ac.addConsequence(output.result(), method.getName(),
                                            "".equals(output.page()) ? new StreamConsequence()
                                                    : new StreamConsequence(output.page()));
                                } else if (output.type() == ConsequenceType.AJAXCONSEQUENCE) {
                                    try {
                                        AjaxRenderer ajaxRender = (AjaxRenderer) Class.forName(output.page())
                                                .newInstance();
                                        ac.addConsequence(output.result(), method.getName(),
                                                new AjaxConsequence(ajaxRender));
                                    } catch (InstantiationException ex) {
                                        ac.addConsequence(output.result(), method.getName(),
                                                new AjaxConsequence(new MapAjaxRenderer()));
                                    } catch (Exception ex) {
                                        System.out.println(
                                                "COULD NOT LOAD AJAX CONSEQUENCE, LOADED DEFAULT MapAjaxRenderer");
                                        ex.printStackTrace();
                                    }
                                } else if (output.type() == ConsequenceType.CUSTOM) {
                                    try {
                                        Consequence customObject = (Consequence) Class.forName(output.page())
                                                .newInstance();
                                        ac.addConsequence(output.result(), method.getName(), customObject);
                                    } catch (Exception ex) {
                                        System.out.println(
                                                "COULD NOT LOAD CUSTOM CONSEQUENCE: ACTION NOT LOADED: "
                                                        + klass.getSimpleName() + "." + method.getName());
                                        ex.printStackTrace();
                                    }
                                } else if (output.type() == ConsequenceType.CHAIN) {
                                    String[] explodedParameter = output.page().split("\\."); // Usado
                                    // para
                                    // explodir
                                    // parameters
                                    // no
                                    // caso
                                    // de
                                    // uma
                                    // chain
                                    actionName.add(output.result());
                                    innerActionName.add(method.getName());
                                    actionChain.add(explodedParameter[0]);
                                    innerChain.add(explodedParameter.length > 1 ? explodedParameter[1] : null);
                                    acListForChains.add(ac);
                                }
                            }
                        }
                    }
                }
                add(ac);
            }
        }
    }

    // Carrega as chains atrasadas porque os ActionConfigs podem ainda nao
    // ter sido carregados
    int length = actionName.size();
    Chain chain;
    for (int i = 0; i < length; i++) {
        try {
            ac = acListForChains.get(i);
            if (innerChain.get(i) == null)
                chain = new Chain(getActionConfig(actionChain.get(i)));
            else
                chain = new Chain(getActionConfig(actionChain.get(i)), innerChain.get(i));
            if (actionName.get(i).equals(ConsequenceOutput.SUCCESS_ERROR)) {
                ac.addConsequence(SUCCESS, innerActionName.get(i), chain);
                ac.addConsequence(ERROR, innerActionName.get(i), chain);
            } else {
                ac.addConsequence(actionName.get(i), innerActionName.get(i), chain);
            }

        } catch (Exception e) {
            System.out.println("COULD NOT LOAD CHAIN CONSEQUENCE: ACTION NOT LOADED: " + actionChain.get(i)
                    + "." + innerActionName.get(i));
        }
    }
}

From source file:com.lp.server.util.logger.HvDtoLogger.java

private void findDifference(HvDtoLogClass logAnnotation, Method theMethod, Object object1, Object object2) {
    if (object1 == null || object2 == null)
        return;/*w ww  .  j a  va  2s .c  o  m*/

    try {
        Object v1 = theMethod.invoke(object1, (Object[]) null);
        Object v2 = theMethod.invoke(object2, (Object[]) null);

        if (isDifferent(v1, v2)) {
            setBaseId(object1);

            if (theMethod.isAnnotationPresent(HvDtoLogComplex.class)) {
                logImpl(v1, v2);
            } else {
                if (theMethod.isAnnotationPresent(HvDtoLogIdCnr.class)) {
                    v1 = getEntityCnr(theMethod, v1);
                    v2 = getEntityCnr(theMethod, v2);
                } else {
                    if (theMethod.isAnnotationPresent(HvDtoLogIdCBez.class)) {
                        v1 = getEntityCBez(theMethod, v1);
                        v2 = getEntityCBez(theMethod, v2);
                    }
                }

                logValues(logAnnotation, getKeyFromMethod(theMethod), getBaseId(object1), v1, v2);
            }
        }
    } catch (InvocationTargetException e) {
        System.out.println("invocation" + e.getMessage());
    } catch (IllegalAccessException e) {
        System.out.println("access" + e.getMessage());
    }
}