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:org.eclipse.smila.management.jmx.DynamicMBeanBuilder.java

/**
 * Builds the model m bean info.// ww w .ja v a 2 s. co  m
 * 
 * @return the model m bean info
 * 
 * @throws IllegalAccessException
 *           the illegal access exception
 * @throws InvocationTargetException
 *           the invocation target exception
 */
private ModelMBeanInfo buildModelMBeanInfo() throws IllegalAccessException, InvocationTargetException {
    // lists
    final List<ModelMBeanOperationInfo> operationsList = new ArrayList<ModelMBeanOperationInfo>();
    final List<ModelMBeanAttributeInfo> attributesList = new ArrayList<ModelMBeanAttributeInfo>();
    // arrays
    final ModelMBeanConstructorInfo[] dConstructors = new ModelMBeanConstructorInfo[0];
    final ModelMBeanNotificationInfo[] dNotifications = new ModelMBeanNotificationInfo[0];
    for (final Method method : _methods) {
        if (!_skippedMethodsSet.contains(method.getName())) {
            // process getter
            if (method.getParameterTypes().length == 0 && method.getName().startsWith("get")
                    && !method.getName().equals("get") && method.getReturnType() != void.class) {
                String attributeName = method.getName().substring(3);
                final Descriptor attributeDescriptor;
                final boolean isPoc = PerformanceCounter.class.isAssignableFrom(method.getReturnType());

                String measureUnitStr = null;
                if (method.isAnnotationPresent(MeasureUnit.class)) {
                    measureUnitStr = method.getAnnotation(MeasureUnit.class).value();
                }

                Method setter = null;
                Class setterSignatureClass = null;
                for (final Method method1 : _methods) {
                    if (method1.getParameterTypes().length == 1 && (method1.getName().startsWith("set"))
                            && (method1.getName().substring(NUMBER_3).equals(attributeName))) {
                        setter = method1;
                        setterSignatureClass = method1.getParameterTypes()[0];
                        break;
                    }
                }

                if (measureUnitStr != null) {
                    attributeName += (" (" + measureUnitStr + ") ");
                }

                if (setter != null) {
                    attributeDescriptor = new DescriptorSupport(
                            new String[] { "name=" + attributeName, "descriptorType=attribute",
                                    "getMethod=" + method.getName(), "setMethod=" + setter.getName(),
                                    "setterSignatureClass=" + setterSignatureClass.getName() });
                } else {
                    if (isPoc) {
                        attributeDescriptor = new DescriptorSupport(new String[] { "name=" + attributeName,
                                "descriptorType=attribute", "getMethod=" + method.getName() });
                    } else {
                        attributeDescriptor = new DescriptorSupport(new String[] { "name=" + attributeName,
                                "descriptorType=attribute", "getMethod=" + method.getName() });
                    }
                }
                try {
                    final ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(attributeName,
                            attributeName, method, setter, attributeDescriptor);
                    attributesList.add(info);
                } catch (final IntrospectionException exception) {
                    _log.error("Error creating MBeanAttributeInfo [" + attributeName + "]", exception);
                }
            }
            // }
            final ModelMBeanOperationInfo info = new ModelMBeanOperationInfo("", method);
            operationsList.add(info);
        }
    }
    final ModelMBeanOperationInfo[] dOperations = operationsList
            .toArray(new ModelMBeanOperationInfo[operationsList.size()]);

    final ModelMBeanAttributeInfo[] dAttributes = attributesList
            .toArray(new ModelMBeanAttributeInfo[attributesList.size()]);

    final Descriptor beanDesc = new DescriptorSupport(
            new String[] { ("name=" + _objectName), "descriptorType=mbean", ("displayName=" + _beanName) });

    final ModelMBeanInfoSupport dMBeanInfo = new ModelMBeanInfoSupport(_beanName, "", dAttributes,
            dConstructors, dOperations, dNotifications, beanDesc);
    return dMBeanInfo;

}

From source file:org.jnap.core.mvc.async.AsyncRequestInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {

    if (isAsync(request, handler)) {
        Method handlerMethod = (Method) request
                .getAttribute(RestfulHandlerAdapter.CURRENT_HANDLER_METHOD_ATTRIBUTE);
        if (handlerMethod != null) {
            LinkedList<AsyncResponseHandler> handlers = new LinkedList<AsyncResponseHandler>();
            AsyncResponseHandler responseHandler = null;

            if (AsyncResponseModel.class.isInstance(modelAndView)) {
                // TODO AsyncState.SUSPEND_RESPONSE
            }/*ww w . j  a v a 2  s .co  m*/

            if (handlerMethod.isAnnotationPresent(Broadcast.class)) {
                Broadcast annotation = handlerMethod.getAnnotation(Broadcast.class);
                int delay = annotation.delay();
                Class[] suspendTimeout = annotation.value();

                AsyncState state = annotation.resumeOnBroadcast() ? AsyncState.RESUME_ON_BROADCAST
                        : AsyncState.BROADCAST;
                responseHandler = new AsyncResponseHandler(state, delay, 0, SCOPE.APPLICATION, true,
                        suspendTimeout, null);
                handlers.addLast(responseHandler);

                if (handlerMethod.isAnnotationPresent(Cluster.class)) {
                    // TODO add @Cluster support
                }
            }

            if (handlerMethod.isAnnotationPresent(Suspend.class)) {
                Suspend annotation = handlerMethod.getAnnotation(Suspend.class);
                long suspendTimeout = annotation.period();
                suspendTimeout = TimeUnitConverter.convert(suspendTimeout, annotation.timeUnit());

                Suspend.SCOPE scope = annotation.scope();
                boolean outputComments = annotation.outputComments();

                boolean trackable = false;
                //               TODO add Trackable support
                //               if (TrackableResource.class.isAssignableFrom(am.getMethod().getReturnType())) {
                //                  trackable = true;
                //               }

                AsyncState state = annotation.resumeOnBroadcast() ? AsyncState.SUSPEND_RESUME
                        : AsyncState.SUSPEND;
                if (trackable) {
                    state = AsyncState.SUSPEND_TRACKABLE;
                }
                responseHandler = new AsyncResponseHandler(state, suspendTimeout, 0, scope, outputComments);
                responseHandler.setListeners(createListeners(annotation.listeners()));
                handlers.addFirst(responseHandler);
            }

            if (handlerMethod.isAnnotationPresent(Subscribe.class)) {
                boolean trackable = false;
                //               TODO add Trackable support
                //               if (TrackableResource.class.isAssignableFrom(am.getMethod().getReturnType())) {
                //                  trackable = true;
                //               }

                Subscribe annotation = handlerMethod.getAnnotation(Subscribe.class);
                AsyncState state = trackable ? AsyncState.SUBSCRIBE_TRACKABLE : AsyncState.SUBSCRIBE;
                String topic = annotation.value(); // TODO add SpEL support
                responseHandler = new AsyncResponseHandler(state, 30000, -1, Suspend.SCOPE.APPLICATION, false,
                        null, topic);
                responseHandler.setListeners(createListeners(annotation.listeners()));

                handlers.addFirst(responseHandler);
            }

            if (handlerMethod.isAnnotationPresent(Publish.class)) {
                String topic = handlerMethod.getAnnotation(Publish.class).value(); // TODO add SpEL support
                responseHandler = new AsyncResponseHandler(AsyncState.PUBLISH, 30000, -1,
                        Suspend.SCOPE.APPLICATION, false, null, topic);
                handlers.addFirst(responseHandler);
            }

            if (handlerMethod.isAnnotationPresent(Resume.class)) {
                handlers.addFirst(new AsyncResponseHandler(AsyncState.RESUME,
                        handlerMethod.getAnnotation(Resume.class).value()));
            }

            if (handlerMethod.isAnnotationPresent(Schedule.class)) {
                Schedule annotation = handlerMethod.getAnnotation(Schedule.class);
                AsyncState state = annotation.resumeOnBroadcast() ? AsyncState.SCHEDULE_RESUME
                        : AsyncState.SCHEDULE;
                handlers.addFirst(new AsyncResponseHandler(state, annotation.period(), annotation.waitFor()));
            }

            for (AsyncResponseHandler asyncHandler : handlers) {
                asyncHandler.handle(request, response, modelAndView);
            }
        } else {
            logger.warn("Atmosphere annotation support disabled on this request.");
        }
    }
}

From source file:com.evolveum.midpoint.prism.parser.PrismBeanInspector.java

private boolean isAttributeUncached(Field field, Method getter) {
    if (field == null && getter == null) {
        return false;
    }/*w  w  w  .j  av  a 2  s .  com*/

    if (field != null && field.isAnnotationPresent(XmlAttribute.class)) {
        return true;
    }

    if (getter != null && getter.isAnnotationPresent(XmlAttribute.class)) {
        return true;
    }

    return false;
}

From source file:com.connectsdk.cordova.JSCommandDispatcher.java

Method getMethod(String interfaceName, String methodName) {
    String name = interfaceName + "_" + methodName;

    Method method = methodCache.get(name);

    if (method == null) {
        try {/*  w w w  .  j  a  va2s.c  o  m*/
            method = this.getClass().getMethod(name, JSCommand.class, JSONObject.class);

            if (method.isAnnotationPresent(CommandMethod.class)) {
                methodCache.put(name, method);
            } else {
                Log.d("ConnectSDKCordova", "attempted to access method " + method.getName()
                        + " but method is not a command handler");
                method = null;
            }
        } catch (NoSuchMethodException e) {
        }
    }

    return method;
}

From source file:nz.co.senanque.vaadinsupport.MaduraPropertyWrapper.java

public MaduraPropertyWrapper(FieldMetadata fieldMetadata, ValidationObject owner, Method setter, Method getter,
        Hints hints, MessageSource messageSource) {
    m_name = fieldMetadata.getName();//from w  w  w. j  a  va 2 s.c  om
    m_label = fieldMetadata.getLabelName();
    m_description = fieldMetadata.getDescription();
    m_writePermission = fieldMetadata.getPermission();
    m_readPermission = fieldMetadata.getReadPermission();
    m_hints = hints;
    m_setter = setter;
    m_getter = getter;
    m_owner = owner;
    m_dataType = setter.getParameterTypes()[0];
    m_fieldMetadata = fieldMetadata;
    figureFormattedProperty();
    m_messageSource = messageSource;
    m_email = getter.isAnnotationPresent(Email.class);
}

From source file:net.ymate.platform.mvc.support.RequestMeta.java

/**
 * /*w  w w.j  av a2s .  c  o m*/
 * 
 * @param target 
 * @param rootMapping 
 * @param method 
 * @param interceptors ?
 */
@SuppressWarnings("unchecked")
public RequestMeta(Object target, String rootMapping, Method method,
        List<PairObject<Class<IFilter>, String>> interceptors) {
    this.target = target;
    this.mapping = this.buildRequestMapping(rootMapping, method);
    this.method = method;
    RequestMetodHandler _handlerAnno = method.getAnnotation(RequestMetodHandler.class);
    if (_handlerAnno != null && _handlerAnno.value() != null) {
        this.handler = ClassUtils.impl(_handlerAnno.value(), IRequestMethodHandler.class);
    } else {
        this.handler = null;
    }
    this.methodParamNames = ClassUtils.getMethodParamNames(method);
    this.parameterTypes = method.getParameterTypes();
    // ?
    boolean hasInterceptorClean = method.isAnnotationPresent(FilterClean.class);
    List<PairObject<Class<IFilter>, String>> _interceptors = hasInterceptorClean
            ? new ArrayList<PairObject<Class<IFilter>, String>>()
            : new ArrayList<PairObject<Class<IFilter>, String>>(interceptors);
    FilterGroup _interceptorGroup = method.getAnnotation(FilterGroup.class);
    if (_interceptorGroup != null && _interceptorGroup.value() != null
            && _interceptorGroup.value().length > 0) {
        Filter[] _interceptorArray = _interceptorGroup.value();
        if (_interceptorArray != null && _interceptorArray.length > 0) {
            for (Filter _interceptor : _interceptorArray) {
                _interceptors.add(new PairObject<Class<IFilter>, String>((Class<IFilter>) _interceptor.value(),
                        _interceptor.params()));
            }
        }
    } else {
        Filter _interceptor = method.getAnnotation(Filter.class);
        if (_interceptor != null) {
            _interceptors.add(new PairObject<Class<IFilter>, String>((Class<IFilter>) _interceptor.value(),
                    _interceptor.params()));
        }
    }
    this.interceptors = _interceptors;
}

From source file:org.broadleafcommerce.test.MergeTransactionalTestExecutionListener.java

/**
 * If the test method of the supplied {@link TestContext test context} is
 * configured to run within a transaction, this method will run
 * {@link BeforeTransaction @BeforeTransaction methods} and start a new
 * transaction.//from  w w  w .ja  v a2 s  .c o  m
 * <p>Note that if a {@link BeforeTransaction @BeforeTransaction method} fails,
 * remaining {@link BeforeTransaction @BeforeTransaction methods} will not
 * be invoked, and a transaction will not be started.
 * @see org.springframework.transaction.annotation.Transactional
 * @see org.springframework.test.annotation.NotTransactional
 */
@SuppressWarnings("serial")
@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
    final Method testMethod = testContext.getTestMethod();
    Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null");

    if (this.transactionContextCache.remove(testMethod) != null) {
        throw new IllegalStateException("Cannot start new transaction without ending existing transaction: "
                + "Invoke endTransaction() before startNewTransaction().");
    }

    if (!testMethod.isAnnotationPresent(Transactional.class)) {
        return;
    }

    TransactionAttribute transactionAttribute = this.attributeSource.getTransactionAttribute(testMethod,
            testContext.getTestClass());
    TransactionDefinition transactionDefinition = null;
    if (transactionAttribute != null) {
        transactionDefinition = new DelegatingTransactionAttribute(transactionAttribute) {
            public String getName() {
                return testMethod.getName();
            }
        };
    }

    if (transactionDefinition != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Explicit transaction definition [" + transactionDefinition
                    + "] found for test context [" + testContext + "]");
        }
        TransactionContext txContext = new TransactionContext(getTransactionManager(testContext),
                transactionDefinition);
        runBeforeTransactionMethods(testContext);
        startNewTransaction(testContext, txContext);
        this.transactionContextCache.put(testMethod, txContext);
    }
}

From source file:org.codehaus.enunciate.modules.rest.RESTOperation.java

/**
 * Construct a REST operation./*from   www. ja  va2  s.  co  m*/
 *
 * @param resource The resource for this operation.
 * @param contentType The content type of the operation.
 * @param verb     The verb for the operation.
 * @param method   The method.
 * @param parameterNames The parameter names.
 */
protected RESTOperation(RESTResource resource, String contentType, VerbType verb, Method method,
        String[] parameterNames) {
    this.resource = resource;
    this.verb = verb;
    this.method = method;
    this.contentType = contentType;

    int properNounIndex = -1;
    Class properNoun = null;
    Boolean properNounOptional = null;
    int nounValueIndex = -1;
    Class nounValue = null;
    Boolean nounValueOptional = Boolean.FALSE;
    int contentTypeParameterIndex = -1;
    adjectiveTypes = new HashMap<String, Class>();
    adjectiveIndices = new HashMap<String, Integer>();
    adjectivesOptional = new HashMap<String, Boolean>();
    complexAdjectives = new ArrayList<String>();
    contextParameterTypes = new HashMap<String, Class>();
    contextParameterIndices = new HashMap<String, Integer>();
    Class[] parameterTypes = method.getParameterTypes();
    HashSet<Class> contextClasses = new HashSet<Class>();
    for (int i = 0; i < parameterTypes.length; i++) {
        Class parameterType = Collection.class.isAssignableFrom(parameterTypes[i])
                ? getCollectionTypeAsArrayType(method, i)
                : parameterTypes[i];

        boolean isAdjective = true;
        String adjectiveName = "arg" + i;
        if ((parameterNames != null) && (parameterNames.length > i) && (parameterNames[i] != null)) {
            adjectiveName = parameterNames[i];
        }
        boolean adjectiveOptional = !parameterType.isPrimitive();
        boolean adjectiveComplex = false;
        Annotation[] parameterAnnotations = method.getParameterAnnotations()[i];
        for (Annotation annotation : parameterAnnotations) {
            if (annotation instanceof ProperNoun) {
                if (parameterType.isArray()) {
                    throw new IllegalStateException(
                            "Proper nouns must be simple types, found an array or collection for parameter " + i
                                    + " of method " + method.getDeclaringClass().getName() + "."
                                    + method.getName() + ".");
                } else if (properNoun == null) {
                    ProperNoun properNounInfo = (ProperNoun) annotation;
                    if (properNounInfo.optional()) {
                        if (parameterType.isPrimitive()) {
                            throw new IllegalStateException(
                                    "An optional proper noun cannot be a primitive type for method "
                                            + method.getDeclaringClass().getName() + "." + method.getName()
                                            + ".");
                        }

                        properNounOptional = true;
                    }

                    if (!properNounInfo.converter().equals(ProperNoun.DEFAULT.class)) {
                        try {
                            ConvertUtils.register((Converter) properNounInfo.converter().newInstance(),
                                    parameterType);
                        } catch (ClassCastException e) {
                            throw new IllegalArgumentException("Illegal converter class for method "
                                    + method.getDeclaringClass().getName() + "." + method.getName()
                                    + ". Must be an instance of org.apache.commons.beanutils.Converter.");
                        } catch (Exception e) {
                            throw new IllegalArgumentException("Unable to instantiate converter class "
                                    + properNounInfo.converter().getName() + " on method "
                                    + method.getDeclaringClass().getName() + "." + method.getName() + ".", e);
                        }
                    }

                    properNoun = parameterType;
                    properNounIndex = i;
                    isAdjective = false;
                    break;
                } else {
                    throw new IllegalStateException("There are two proper nouns for method "
                            + method.getDeclaringClass().getName() + "." + method.getName() + ".");
                }
            } else if (annotation instanceof NounValue) {
                if ((!parameterType.isAnnotationPresent(XmlRootElement.class))
                        && (!parameterType.equals(DataHandler.class)) && (!(parameterType.isArray()
                                && parameterType.getComponentType().equals(DataHandler.class)))) {
                    LOG.warn(
                            "Enunciate doesn't support unmarshalling objects of type " + parameterType.getName()
                                    + ". Unless a custom content type handler is provided, this operation ("
                                    + method.getDeclaringClass() + "." + method.getName() + ") will fail.");
                }

                if (nounValue == null) {
                    if (((NounValue) annotation).optional()) {
                        if (parameterType.isPrimitive()) {
                            throw new IllegalStateException(
                                    "An optional noun value cannot be a primitive type for method "
                                            + method.getDeclaringClass().getName() + "." + method.getName()
                                            + ".");
                        }

                        nounValueOptional = true;
                    }

                    nounValue = parameterType;
                    nounValueIndex = i;
                    isAdjective = false;
                    break;
                } else {
                    throw new IllegalStateException("There are two proper nouns for method "
                            + method.getDeclaringClass().getName() + "." + method.getName() + ".");
                }
            } else if (annotation instanceof ContextParameter) {
                ContextParameter contextParameterInfo = (ContextParameter) annotation;
                String contextParameterName = contextParameterInfo.value();

                if (!contextParameterInfo.converter().equals(ContextParameter.DEFAULT.class)) {
                    try {
                        ConvertUtils.register((Converter) contextParameterInfo.converter().newInstance(),
                                parameterType);
                    } catch (ClassCastException e) {
                        throw new IllegalArgumentException("Illegal converter class for method "
                                + method.getDeclaringClass().getName() + "." + method.getName()
                                + ". Must be an instance of org.apache.commons.beanutils.Converter.");
                    } catch (Exception e) {
                        throw new IllegalArgumentException(
                                "Unable to instantiate converter class "
                                        + contextParameterInfo.converter().getName() + " on method "
                                        + method.getDeclaringClass().getName() + "." + method.getName() + ".",
                                e);
                    }
                }

                contextParameterTypes.put(contextParameterName, parameterType);
                contextParameterIndices.put(contextParameterName, i);
                isAdjective = false;
                break;
            } else if (annotation instanceof ContentTypeParameter) {
                contentTypeParameterIndex = i;
                isAdjective = false;
                break;
            } else if (annotation instanceof Adjective) {
                Adjective adjectiveInfo = (Adjective) annotation;
                adjectiveOptional = adjectiveInfo.optional();
                if (adjectiveOptional && parameterType.isPrimitive()) {
                    throw new IllegalStateException(
                            "An optional adjective cannot be a primitive type for method "
                                    + method.getDeclaringClass().getName() + "." + method.getName() + ".");
                }

                if (!"##default".equals(adjectiveInfo.name())) {
                    adjectiveName = adjectiveInfo.name();
                }

                adjectiveComplex = adjectiveInfo.complex();

                if (!adjectiveInfo.converter().equals(Adjective.DEFAULT.class)) {
                    try {
                        ConvertUtils.register((Converter) adjectiveInfo.converter().newInstance(),
                                parameterType);
                    } catch (ClassCastException e) {
                        throw new IllegalArgumentException("Illegal converter class for method "
                                + method.getDeclaringClass().getName() + "." + method.getName()
                                + ". Must be an instance of org.apache.commons.beanutils.Converter.");
                    } catch (Exception e) {
                        throw new IllegalArgumentException("Unable to instantiate converter class "
                                + adjectiveInfo.converter().getName() + " on method "
                                + method.getDeclaringClass().getName() + "." + method.getName() + ".", e);
                    }
                }

                break;
            }
        }

        if (isAdjective) {
            this.adjectiveTypes.put(adjectiveName, parameterType);
            this.adjectiveIndices.put(adjectiveName, i);
            this.adjectivesOptional.put(adjectiveName, adjectiveOptional);
            if (adjectiveComplex) {
                this.complexAdjectives.add(adjectiveName);
            }
        }

        if (parameterType.isArray()) {
            contextClasses.add(parameterType.getComponentType());
        } else {
            contextClasses.add(parameterType);
        }
    }

    Class returnType = null;
    if (!Void.TYPE.equals(method.getReturnType())) {
        returnType = method.getReturnType();

        if (!returnType.isAnnotationPresent(XmlRootElement.class)
                && (!DataHandler.class.isAssignableFrom(returnType))) {
            LOG.warn("Enunciate doesn't support marshalling objects of type " + returnType.getName()
                    + ". Unless a custom content type handler is provided, this operation ("
                    + method.getDeclaringClass() + "." + method.getName() + ") will fail.");
        }

        contextClasses.add(returnType);
    }

    for (Class exceptionClass : method.getExceptionTypes()) {
        for (Method exceptionMethod : exceptionClass.getMethods()) {
            if ((exceptionMethod.isAnnotationPresent(RESTErrorBody.class))
                    && (exceptionMethod.getReturnType() != Void.TYPE)) {
                //add the error body to the context classes.
                contextClasses.add(exceptionMethod.getReturnType());
            }
        }
    }

    //now load any additional context classes as specified by @RESTSeeAlso
    if (method.isAnnotationPresent(RESTSeeAlso.class)) {
        contextClasses.addAll(Arrays.asList(method.getAnnotation(RESTSeeAlso.class).value()));
    }
    if (method.getDeclaringClass().isAnnotationPresent(RESTSeeAlso.class)) {
        contextClasses
                .addAll(Arrays.asList(method.getDeclaringClass().getAnnotation(RESTSeeAlso.class).value()));
    }
    if ((method.getDeclaringClass().getPackage() != null)
            && (method.getDeclaringClass().getPackage().isAnnotationPresent(RESTSeeAlso.class))) {
        contextClasses.addAll(Arrays
                .asList(method.getDeclaringClass().getPackage().getAnnotation(RESTSeeAlso.class).value()));
    }

    String jsonpParameter = null;
    JSONP jsonpInfo = method.getAnnotation(JSONP.class);
    if (jsonpInfo == null) {
        jsonpInfo = method.getDeclaringClass().getAnnotation(JSONP.class);
        if (jsonpInfo == null) {
            jsonpInfo = method.getDeclaringClass().getPackage().getAnnotation(JSONP.class);
        }
    }
    if (jsonpInfo != null) {
        jsonpParameter = jsonpInfo.paramName();
    }

    String charset = "utf-8";
    org.codehaus.enunciate.rest.annotations.ContentType contentTypeInfo = method
            .getAnnotation(org.codehaus.enunciate.rest.annotations.ContentType.class);
    if (contentTypeInfo == null) {
        contentTypeInfo = method.getDeclaringClass()
                .getAnnotation(org.codehaus.enunciate.rest.annotations.ContentType.class);
        if (contentTypeInfo == null) {
            contentTypeInfo = method.getDeclaringClass().getPackage()
                    .getAnnotation(org.codehaus.enunciate.rest.annotations.ContentType.class);
        }
    }
    if (contentTypeInfo != null) {
        charset = contentTypeInfo.charset();
    }

    String defaultNamespace = "";
    if (method.getDeclaringClass().getPackage() != null
            && method.getDeclaringClass().getPackage().isAnnotationPresent(XmlSchema.class)) {
        defaultNamespace = method.getDeclaringClass().getPackage().getAnnotation(XmlSchema.class).namespace();
    }

    this.properNounType = properNoun;
    this.properNounIndex = properNounIndex;
    this.properNounOptional = properNounOptional;
    this.nounValueType = nounValue;
    this.nounValueIndex = nounValueIndex;
    this.nounValueOptional = nounValueOptional;
    this.resultType = returnType;
    this.charset = charset;
    this.JSONPParameter = jsonpParameter;
    this.contextClasses = contextClasses;
    this.contentTypeParameterIndex = contentTypeParameterIndex;
    this.defaultNamespace = defaultNamespace;
}

From source file:com.googlecode.jdbcproc.daofactory.impl.block.service.ParametersSetterBlockServiceImpl.java

public List<IParametersSetterBlock> create(JdbcTemplate jdbcTemplate,
        ParameterConverterService converterService, Method method, StoredProcedureInfo procedureInfo,
        IMetaLoginInfoService aMetaLoginInfoService) {
    if (method.isAnnotationPresent(AMetaLoginInfo.class)) {
        if (aMetaLoginInfoService == null) {
            throw new IllegalStateException(
                    AMetaLoginInfo.class.getName() + " annotation is present but no implementation for "
                            + IMetaLoginInfoService.class.getName() + " was bound");
        }//from   ww  w . ja  v  a2 s  . co  m

        // is entity, e.g. void saveProcessor(TransactionProcessor) (meta login supported)
        if (procedureInfo.getArgumentsCounts() > method.getParameterTypes().length
                && method.getParameterTypes().length == 1
                && !BlockFactoryUtils.isSimpleType(method.getParameterTypes()[0])
                && !BlockFactoryUtils.isCollectionAssignableFrom(method.getParameterTypes()[0])) {
            return createSaveMethod(converterService, method, procedureInfo, aMetaLoginInfoService);

            // is entity with lists after it (meta login supported)
        } else if (isEntityWithListsAndMetaLogin(method, procedureInfo)) {

            return createSaveMethodWithLists(jdbcTemplate, converterService, method, procedureInfo,
                    aMetaLoginInfoService);

            // METHOD @AMetaLoginInfo
            // METHOD no parameter
            // PROCEDURE 2 parameters
        } else if (method.getParameterTypes().length == 0 && procedureInfo.getInputArgumentsCount() == 2) {
            return Collections.singletonList(
                    (IParametersSetterBlock) new ParametersSetterBlockMetaLoginInfo(aMetaLoginInfoService,
                            getArgument(procedureInfo, aMetaLoginInfoService.getUsernameParameterName()),
                            getArgument(procedureInfo, aMetaLoginInfoService.getRoleParameterName())));

            // if AMetaLoginInfo and parameters are simply put to procedure
        } else if (method.getParameterTypes().length + 2 == procedureInfo.getInputArgumentsCount()) {
            return createSimpleParametersWithMetaLoginInfo(aMetaLoginInfoService, converterService, method,
                    procedureInfo);

            // if both list and arguments parameters provides with MetaLoginInfo
        } else if (areListAndNonListParametersProvidesWithMetaLoginInfo(method, procedureInfo)) {
            return createListAndArgumentsWithMetaLoginInfo(jdbcTemplate, converterService, method,
                    procedureInfo, aMetaLoginInfoService);

            // else not supported
        } else {
            throw new IllegalStateException(method + " is Unsupported");
        }

    } else if (method.isAnnotationPresent(AConsumerKey.class)) {
        if (!String.class.equals(method.getParameterTypes()[0])) {
            throw new IllegalStateException(AConsumerKey.class.getName()
                    + " annotation is present but first argument is not String type");
        }
        // is entity, e.g. void saveProcessor(consumerKey, TransactionProcessor) (meta login not supported)
        if (procedureInfo.getArgumentsCounts() > method.getParameterTypes().length
                && method.getParameterTypes().length == 2
                && !BlockFactoryUtils.isSimpleType(method.getParameterTypes()[1])
                && !BlockFactoryUtils.isCollectionAssignableFrom(method.getParameterTypes()[1])) {
            return createSaveMethodConsumer(converterService, method, procedureInfo);

            // if parameters is simple putted to procedure
            //          } else if (method.getParameterTypes().length == procedureInfo.getInputArgumentsCount()) {
            //            return createSimpleParameters(converterService, method, procedureInfo);
            // if both list and arguments parameters provides with ConsumerKey 
            //          } else if (areListAndNonListParametersProvidesWithConsumer(method, procedureInfo)) {
            //              return createListAndArgumentsWithConsumer(jdbcTemplate, converterService, method, procedureInfo);
        } else {
            throw new IllegalStateException(method + " is Unsupported");
        }
    } else {
        // List getAll()
        if (BlockFactoryUtils.isGetAllMethod(method, procedureInfo)) {
            return createGetAll(procedureInfo);

            // is entity, e.g. void saveProcessor(TransactionProcessor) (meta login not supported)
        } else if (procedureInfo.getArgumentsCounts() >= method.getParameterTypes().length
                && method.getParameterTypes().length == 1
                && !BlockFactoryUtils.isSimpleType(method.getParameterTypes()[0])
                && !BlockFactoryUtils.isCollectionAssignableFrom(method.getParameterTypes()[0])) {
            return createSaveMethod(converterService, method, procedureInfo);

            // is entity with lists after it (meta login not supported)
        } else if (isEntityWithLists(method, procedureInfo)) {

            return createSaveMethodWithLists(jdbcTemplate, converterService, method, procedureInfo);

            // if no parameters
        } else if (method.getParameterTypes().length == 0 && procedureInfo.getInputArgumentsCount() == 0) {
            return Collections.emptyList();

            // if parameters are simply put to procedure
        } else if (method.getParameterTypes().length == procedureInfo.getInputArgumentsCount()) {
            return createSimpleParameters(converterService, method, procedureInfo);

            // if all parameters is list and no arguments
        } else if (areAllParametersListAndNoArguments(method, procedureInfo)) {
            return createAllList(jdbcTemplate, converterService, method, procedureInfo);

            // if both list and arguments parameters provides
        } else if (areListAndNonListParametersProvides(method, procedureInfo)) {
            return createListAndArguments(0, jdbcTemplate, converterService, method, procedureInfo);

            // else not supported
        } else {
            throw new IllegalStateException(method + " is Unsupported");
        }
    }
}

From source file:org.openspaces.events.AbstractEventListenerContainer.java

private void initializeExceptionHandler() {
    if (exceptionHandler == null && getActualEventListener() != null) {
        final AtomicReference<Method> ref = new AtomicReference<Method>();
        ReflectionUtils.doWithMethods(AopUtils.getTargetClass(getActualEventListener()),
                new ReflectionUtils.MethodCallback() {
                    public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
                        if (method.isAnnotationPresent(ExceptionHandler.class)) {
                            ref.set(method);
                        }//from   w  w  w  . j a v  a 2  s.  c  o  m
                    }
                });
        if (ref.get() != null) {
            ref.get().setAccessible(true);
            try {
                setExceptionHandler((EventExceptionHandler) ref.get().invoke(getActualEventListener()));
            } catch (Exception e) {
                throw new IllegalArgumentException(
                        "Failed to set EventExceptionHandler from method [" + ref.get().getName() + "]", e);
            }
        }
    }
}