Example usage for java.lang.reflect Method getDeclaringClass

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

Introduction

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

Prototype

@Override
public Class<?> getDeclaringClass() 

Source Link

Document

Returns the Class object representing the class or interface that declares the method represented by this object.

Usage

From source file:com.github.wshackle.java4cpp.J4CppMain.java

private static boolean checkMethod(Method m, List<Class> classes) {
    if (m.getDeclaringClass().getName().equals(m.getName())) {
        if (verbose) {
            System.out.println("checkMethod skipping " + m + " method same as classname.");
        }// ww w  . j a v a 2 s  .  c o  m
        return false;
    }
    if (m.getDeclaringClass().getName().endsWith("." + m.getName())) {
        if (verbose) {
            System.out.println("checkMethod skipping " + m + " method same as classname.");
        }
        return false;
    }
    if (m.isSynthetic()) {
        if (verbose) {
            System.out.println("checkMethod skipping " + m + " isSynthetic.");
        }
        return false;
    }
    if (!Modifier.isPublic(m.getModifiers())) {
        if (verbose) {
            System.out.println("checkMethod skipping " + m + " not public");
        }
        return false;
    }
    if (!checkClass(m.getReturnType(), classes)) {
        if (verbose) {
            System.out.println("checkMethod skipping " + m + " return type not in classes list.");
        }
        return false;
    }
    boolean ret = checkParameters(m.getParameterTypes(), classes);
    if (!ret) {
        if (verbose) {
            System.out.println("checkMethod skipping " + m + " a parameter type is not in classes list");
        }
    }
    return ret;
}

From source file:com.thoughtworks.selenium.SeleneseTestNgHelperVir.java

/**
 * Sets the test context./*from  w  ww. ja v  a 2 s . com*/
 * 
 * @param method
 *            the new test context
 */
@BeforeMethod
public final void setTestContext(final Method method) {
    setTestCaseFailedStatus(false);
    PropertyHandler propHandler = new PropertyHandler(propertiesLocation);
    propHandler.setRuntimeProperty("tcComment", "");

    totalExecutionTimeTaken = 0;
    testcaseStartTime = getCurrentTime();
    errorMessages = "Verification failures : \n";
    setOpenWindowHandleIndex(new ArrayList<String>());
    setBrowserString(System.getProperty("selenium.defaultBrowser"));
    this.cleanBrowserSessions();
    getLog().info("Starting a new selenium webdriver session.");

    this.startBrowserSession(getBrowserString());
    Logger log = getLog();
    log.info("Started the selenium webdriver session.");

    reporter.startReporter(method.getDeclaringClass().getCanonicalName(), method.getName());
    log.info(
            "Executing the test case : " + method.getDeclaringClass().getSimpleName() + "." + method.getName());

    getLogger(this.getClass());

    testPackageName = this.getClass().getPackage().toString().split("package ")[1];
    String testCaseName = method.getName();
    resultReporter.addNewTestCase(testCaseName);

    appendToCSVFileBuilder("\n", testCaseName, "\n");
    // logTimeCSVFileBuilder.append("\n").append(testCaseName).append("\n");
    startOfTestCase();

    log.info("Starting the test case..");
}

From source file:org.apache.cocoon.components.flow.java.JavaInterpreter.java

public void handleContinuation(String id, List params, Redirector redirector) throws Exception {
    if (!initialized)
        initialize();//from   w ww .j a v a 2s . c om

    WebContinuation parentwk = continuationsMgr.lookupWebContinuation(id, getInterpreterID());

    if (parentwk == null) {
        /*
         * Throw an InvalidContinuationException to be handled inside the
         * <map:handle-errors> sitemap element.
         */
        throw new InvalidContinuationException("The continuation ID " + id + " is invalid.");
    }

    Continuation parentContinuation = (Continuation) parentwk.getContinuation();
    ContinuationContext parentContext = (ContinuationContext) parentContinuation.getContext();
    ContinuationContext context = new ContinuationContext();
    context.setObject(parentContext.getObject());
    context.setMethod(parentContext.getMethod());
    context.setAvalonContext(avalonContext);
    context.setLogger(getLogger());
    context.setServiceManager(manager);
    context.setRedirector(redirector);
    Parameters parameters = new Parameters();
    for (Iterator i = params.iterator(); i.hasNext();) {
        Argument argument = (Argument) i.next();
        parameters.setParameter(argument.name, argument.value);
    }
    context.setParameters(parameters);

    Continuation continuation = new Continuation(parentContinuation, context);

    Request request = ContextHelper.getRequest(this.avalonContext);
    Session session = request.getSession(true);
    HashMap userScopes = (HashMap) session.getAttribute(USER_GLOBAL_SCOPE);

    Continuable flow = (Continuable) context.getObject();
    Method method = context.getMethod();

    WebContinuation wk = continuationsMgr.createWebContinuation(continuation, parentwk, timeToLive,
            getInterpreterID(), null);
    FlowHelper.setWebContinuation(ContextHelper.getObjectModel(this.avalonContext), wk);

    continuation.registerThread();
    try {

        method.invoke(flow, new Object[0]);

    } catch (InvocationTargetException ite) {
        if (ite.getTargetException() != null) {
            if (ite.getTargetException() instanceof Exception)
                throw (Exception) ite.getTargetException();
            else if (ite.getTargetException() instanceof Error)
                throw new ProcessingException("An internal error occured", ite.getTargetException());
            else if (ite.getTargetException() instanceof RuntimeException)
                throw (RuntimeException) ite.getTargetException();
            else
                throw ite;
        } else {
            throw ite;
        }
    } finally {
        // remove last object reference, which is not needed to reconstruct
        // the invocation path
        if (continuation.isCapturing())
            continuation.getStack().popReference();
        continuation.deregisterThread();
    }

    userScopes.put(method.getDeclaringClass(), flow);
    session.setAttribute(USER_GLOBAL_SCOPE, userScopes);
}

From source file:com.haulmont.cuba.core.sys.MetaModelLoader.java

protected MetadataObjectInfo<MetaProperty> loadProperty(MetaClassImpl metaClass, Method method, String name) {
    Collection<RangeInitTask> tasks = new ArrayList<>();

    MetaPropertyImpl property = new MetaPropertyImpl(metaClass, name);

    Map<String, Object> map = new HashMap<>();
    map.put("cardinality", Range.Cardinality.NONE);
    map.put("mandatory", false);
    Datatype datatype = getAdaptiveDatatype(method);
    map.put("datatype", datatype);

    Class<?> type;/*  w  w w  .  j a  v a2s .c  o  m*/
    Class typeOverride = getTypeOverride(method);
    if (typeOverride != null)
        type = typeOverride;
    else
        type = method.getReturnType();

    property.setMandatory(false);
    property.setReadOnly(!setterExists(method));
    property.setAnnotatedElement(method);
    property.setDeclaringClass(method.getDeclaringClass());
    property.setJavaType(method.getReturnType());

    MetadataObjectInfo<Range> info = loadRange(property, type, map);
    Range range = info.getObject();
    if (range != null) {
        ((AbstractRange) range).setCardinality(Range.Cardinality.NONE);
        property.setRange(range);
        assignPropertyType(method, property, range);
    }

    tasks.addAll(info.getTasks());

    return new MetadataObjectInfo<>(property, tasks);
}

From source file:com.github.wshackle.java4cpp.J4CppMain.java

private static String fixMethodName(Method m) {
    String mname = m.getName();//  w w  w  .  j  a  v a  2s.c om

    if (fixMultipleOverrides) {
        Method ma[] = m.getDeclaringClass().getMethods();
        int index = 0;
        boolean index_incremented = false;
        boolean has_match = false;
        Arrays.sort(ma, new Comparator<Method>() {
            @Override
            public int compare(Method o1, Method o2) {
                return Arrays.toString(o1.getParameterTypes())
                        .compareTo(Arrays.toString(o2.getParameterTypes()));
            }
        });
        List<Method> matchingMethods = new ArrayList<>();
        for (int i = 0; i < ma.length; i++) {
            Method method = ma[i];
            if (method.getParameterTypes().length > 0 && m.getParameterTypes().length > 0
                    && m.getParameterTypes()[0].isPrimitive() != method.getParameterTypes()[0].isPrimitive()) {
                continue;
            }
            if (!method.equals(m) && m.getName().equals(method.getName())
                    && m.getParameterTypes().length == method.getParameterTypes().length) {
                has_match = true;
                matchingMethods.add(method);
            }
        }
        for (int i = 0; i < ma.length; i++) {
            Method method = ma[i];
            if (method.equals(m)) {
                break;
            }
            if (method.getParameterTypes().length != m.getParameterTypes().length) {
                continue;
            }
            if (method.getParameterTypes().length > 0 && m.getParameterTypes().length > 0
                    && m.getParameterTypes()[0].isPrimitive() != method.getParameterTypes()[0].isPrimitive()) {
                continue;
            }
            if (m.getParameterTypes().length >= 1) {
                if (String.class.isAssignableFrom(m.getParameterTypes()[0]) != String.class
                        .isAssignableFrom(method.getParameterTypes()[0])) {
                    continue;
                }
            }
            if (method.getName().equals(m.getName())) {
                index++;
                index_incremented = true;
            }
        }
        int start_index = 0;
        while (index_incremented) {
            index_incremented = false;
            for (int i = 0; i < ma.length; i++) {
                Method method = ma[i];
                for (int j = start_index; j <= index; j++) {
                    if (method.getName().equals(m.getName() + j)
                            && m.getParameterTypes().length == method.getParameterTypes().length) {
                        index++;
                        index_incremented = true;
                    }
                }
            }
            start_index = index;
        }
        if (has_match) {
            String paramstring = "";
            Class[] paramclasses = m.getParameterTypes();
            for (int i = 0; i < paramclasses.length; i++) {
                paramstring += classToMethodAppendage(paramclasses[i]);
            }
            mname = mname + paramstring;
            if (mname.contains(";")) {
                System.out.println("paramclasses = " + paramclasses);
            }
        }
    }

    if (badNames.contains(mname)) {
        return mname + "Method";
    }
    return mname;
}

From source file:com.haulmont.chile.core.loader.ChileAnnotationsLoader.java

protected MetadataObjectInfo<MetaProperty> loadProperty(MetaClassImpl metaClass, Method method, String name) {
    Collection<MetadataObjectInitTask> tasks = new ArrayList<>();

    MetaPropertyImpl property = new MetaPropertyImpl(metaClass, name);

    Map<String, Object> map = new HashMap<>();
    map.put("cardinality", Range.Cardinality.NONE);
    map.put("mandatory", false);
    Datatype datatype = getDatatype(method);
    map.put("datatype", datatype);

    Class<?> type;/* ww  w .  ja v a2  s. c  om*/
    Class typeOverride = getTypeOverride(method);
    if (typeOverride != null)
        type = typeOverride;
    else
        type = method.getReturnType();

    MetadataObjectInfo<Range> info = loadRange(property, type, map);
    Range range = info.getObject();
    if (range != null) {
        ((AbstractRange) range).setCardinality(Range.Cardinality.NONE);
        property.setRange(range);
        assignPropertyType(method, property, range);
    }
    property.setMandatory(false);
    property.setReadOnly(!setterExists(method));
    property.setAnnotatedElement(method);
    property.setDeclaringClass(method.getDeclaringClass());
    property.setJavaType(method.getReturnType());

    tasks.addAll(info.getTasks());

    return new MetadataObjectInfo<>(property, tasks);
}

From source file:com.ocpsoft.pretty.faces.config.annotation.PrettyAnnotationHandler.java

/**
 * Creates a {@link UrlAction} object from the supplied {@link URLAction}
 * annotation/*from  w w  w .j a va 2 s.c  o  m*/
 * 
 * @param actionAnnotation The annotation
 * @param method The method that was annotated
 * @param classMappingIds the mapping IDs of the current class
 */
private void processPrettyActionAnnotation(URLAction actionAnnotation, Method method,
        String[] classMappingIds) {

    // Create ActionSpec
    ActionSpec actionSpec = new ActionSpec();
    actionSpec.setMethod(method);
    actionSpec.setOnPostback(actionAnnotation.onPostback());
    actionSpec.setInheritable(actionAnnotation.inheritable());
    actionSpec.setPhaseId(actionAnnotation.phaseId());

    // check which mapping the action belongs to
    if (!isBlank(actionAnnotation.mappingId())) {
        // action belongs to the mapping mentioned with mappingId attribute
        actionSpec.setMappingIds(new String[] { actionAnnotation.mappingId().trim() });
    } else if (classMappingIds != null && classMappingIds.length > 0) {
        // use the mapping found on the class
        actionSpec.setMappingIds(classMappingIds);
    } else {
        // No mapping found... throw an exception..
        throw new IllegalArgumentException("Unable to find a suitable mapping "
                + "for the action definied on method '" + method.getName() + "' in class '"
                + method.getDeclaringClass().getName() + "'. Either place a @URLMapping annotation on the "
                + "class or reference a foreign mapping using the 'mappingId' attribute.");
    }

    // add action to list of actions
    urlActions.add(actionSpec);

}

From source file:com.wantscart.jade.core.JadeDaoInvocationHandler.java

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (args != null) {
        for (int i = 0; i < args.length; i++) {
            Object arg = args[i];
            if (arg == null) {
                continue;
            }/*w  w w.j a  va 2  s. c  o m*/
            Class<?> argType = arg.getClass();
            if (!TypeUtils.isBaseType(argType) && !(arg instanceof Collection)) {
                TableSchema schema = TableSchema.getSchema(argType);
                if (schema != null) {
                    Map mapArg = new HashMap();
                    for (TableSchema.Column column : schema.getColumns()) {
                        Object field = column.getGetter().invoke(arg);
                        if (column.isSerializable()) {
                            if (column.getSerializer() instanceof NullSerializer
                                    && field instanceof Serializable) {
                                field = ((Serializable) field).serialize();
                            } else {
                                field = column.getSerializer().serialize(field);
                            }
                        }
                        mapArg.put(column.getOriginName(), field);
                    }
                    args[i] = mapArg;
                }
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("invoking  " + definition.getDAOClazz().getName() + "#" + method.getName());
    }

    if (Object.class == method.getDeclaringClass()) {
        String methodName = method.getName();
        if (methodName.equals("toString")) {
            return JadeDaoInvocationHandler.this.toString();
        }
        if (methodName.equals("hashCode")) {
            return definition.getDAOClazz().hashCode() * 13 + this.hashCode();
        }
        if (methodName.equals("equals")) {
            return args[0] == proxy;
        }
        if (methodName.equals("clone")) {
            throw new CloneNotSupportedException("clone is not supported for jade dao.");
        }
        throw new UnsupportedOperationException(definition.getDAOClazz().getName() + "#" + method.getName());
    }

    JadeOperation operation = jdbcOperations.get(method);
    if (operation == null) {
        synchronized (jdbcOperations) {
            operation = jdbcOperations.get(method);
            if (operation == null) {
                Modifier modifier = new Modifier(definition, method);
                operation = jdbcOperationFactory.getOperation(dataAccess, modifier);
                jdbcOperations.put(method, operation);
            }
        }
    }
    //
    // ?  Map
    Map<String, Object> parameters;
    if (args == null || args.length == 0) {
        parameters = new HashMap<String, Object>(4);
    } else {
        parameters = new HashMap<String, Object>(args.length * 2 + 4);
        SQLParam[] sqlParams = operation.getModifier().getParameterAnnotations(SQLParam.class);
        for (int i = 0; i < args.length; i++) {
            parameters.put(":" + (i + 1), args[i]);
            SQLParam sqlParam = sqlParams[i];
            if (sqlParam != null) {
                parameters.put(sqlParam.value(), args[i]);
            }
        }
    }
    //
    if (logger.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append("invoking ").append(definition.getDAOClazz().getName()).append("#").append(method.getName())
                .append("\n");
        sb.append("\toperation: ").append(operation.getClass().getSimpleName()).append("\n");
        sb.append("\tsql: ").append(operation.getModifier().getAnnotation(SQL.class).value()).append("\n");
        sb.append("\tparams: ");
        ArrayList<String> keys = new ArrayList<String>(parameters.keySet());
        Collections.sort(keys);
        for (String key : keys) {
            sb.append(key).append("='").append(parameters.get(key)).append("'  ");
        }
        logger.debug(sb.toString());
    }

    return operation.execute(parameters);
}

From source file:ca.uhn.fhir.rest.method.BaseMethodBinding.java

@SuppressWarnings("unchecked")
public static BaseMethodBinding<?> bindMethod(Method theMethod, FhirContext theContext, Object theProvider) {
    Read read = theMethod.getAnnotation(Read.class);
    Search search = theMethod.getAnnotation(Search.class);
    Metadata conformance = theMethod.getAnnotation(Metadata.class);
    Create create = theMethod.getAnnotation(Create.class);
    Update update = theMethod.getAnnotation(Update.class);
    Delete delete = theMethod.getAnnotation(Delete.class);
    History history = theMethod.getAnnotation(History.class);
    Validate validate = theMethod.getAnnotation(Validate.class);
    GetTags getTags = theMethod.getAnnotation(GetTags.class);
    AddTags addTags = theMethod.getAnnotation(AddTags.class);
    DeleteTags deleteTags = theMethod.getAnnotation(DeleteTags.class);
    Transaction transaction = theMethod.getAnnotation(Transaction.class);
    Operation operation = theMethod.getAnnotation(Operation.class);
    GetPage getPage = theMethod.getAnnotation(GetPage.class);
    Patch patch = theMethod.getAnnotation(Patch.class);

    // ** if you add another annotation above, also add it to the next line:
    if (!verifyMethodHasZeroOrOneOperationAnnotation(theMethod, read, search, conformance, create, update,
            delete, history, validate, getTags, addTags, deleteTags, transaction, operation, getPage, patch)) {
        return null;
    }//from w  w w .  j  a  v a  2  s  .  c  om

    if (getPage != null) {
        return new PageMethodBinding(theContext, theMethod);
    }

    Class<? extends IBaseResource> returnType;

    Class<? extends IBaseResource> returnTypeFromRp = null;
    if (theProvider instanceof IResourceProvider) {
        returnTypeFromRp = ((IResourceProvider) theProvider).getResourceType();
        if (!verifyIsValidResourceReturnType(returnTypeFromRp)) {
            throw new ConfigurationException("getResourceType() from " + IResourceProvider.class.getSimpleName()
                    + " type " + theMethod.getDeclaringClass().getCanonicalName() + " returned "
                    + toLogString(returnTypeFromRp) + " - Must return a resource type");
        }
    }

    Class<?> returnTypeFromMethod = theMethod.getReturnType();
    if (getTags != null) {
        if (!TagList.class.equals(returnTypeFromMethod)) {
            throw new ConfigurationException("Method '" + theMethod.getName() + "' from type "
                    + theMethod.getDeclaringClass().getCanonicalName() + " is annotated with @"
                    + GetTags.class.getSimpleName() + " but does not return type " + TagList.class.getName());
        }
    } else if (MethodOutcome.class.isAssignableFrom(returnTypeFromMethod)) {
        // returns a method outcome
    } else if (IBundleProvider.class.equals(returnTypeFromMethod)) {
        // returns a bundle provider
    } else if (Bundle.class.equals(returnTypeFromMethod)) {
        // returns a bundle
    } else if (void.class.equals(returnTypeFromMethod)) {
        // returns a bundle
    } else if (Collection.class.isAssignableFrom(returnTypeFromMethod)) {
        returnTypeFromMethod = ReflectionUtil.getGenericCollectionTypeOfMethodReturnType(theMethod);
        if (returnTypeFromMethod == null) {
            ourLog.trace("Method {} returns a non-typed list, can't verify return type", theMethod);
        } else if (!verifyIsValidResourceReturnType(returnTypeFromMethod)
                && !isResourceInterface(returnTypeFromMethod)) {
            throw new ConfigurationException("Method '" + theMethod.getName() + "' from "
                    + IResourceProvider.class.getSimpleName() + " type "
                    + theMethod.getDeclaringClass().getCanonicalName()
                    + " returns a collection with generic type " + toLogString(returnTypeFromMethod)
                    + " - Must return a resource type or a collection (List, Set) with a resource type parameter (e.g. List<Patient> or List<IBaseResource> )");
        }
    } else {
        if (!isResourceInterface(returnTypeFromMethod)
                && !verifyIsValidResourceReturnType(returnTypeFromMethod)) {
            throw new ConfigurationException(
                    "Method '" + theMethod.getName() + "' from " + IResourceProvider.class.getSimpleName()
                            + " type " + theMethod.getDeclaringClass().getCanonicalName() + " returns "
                            + toLogString(returnTypeFromMethod) + " - Must return a resource type (eg Patient, "
                            + Bundle.class.getSimpleName() + ", " + IBundleProvider.class.getSimpleName()
                            + ", etc., see the documentation for more details)");
        }
    }

    Class<? extends IBaseResource> returnTypeFromAnnotation = IBaseResource.class;
    if (read != null) {
        returnTypeFromAnnotation = read.type();
    } else if (search != null) {
        returnTypeFromAnnotation = search.type();
    } else if (history != null) {
        returnTypeFromAnnotation = history.type();
    } else if (delete != null) {
        returnTypeFromAnnotation = delete.type();
    } else if (patch != null) {
        returnTypeFromAnnotation = patch.type();
    } else if (create != null) {
        returnTypeFromAnnotation = create.type();
    } else if (update != null) {
        returnTypeFromAnnotation = update.type();
    } else if (validate != null) {
        returnTypeFromAnnotation = validate.type();
    } else if (getTags != null) {
        returnTypeFromAnnotation = getTags.type();
    } else if (addTags != null) {
        returnTypeFromAnnotation = addTags.type();
    } else if (deleteTags != null) {
        returnTypeFromAnnotation = deleteTags.type();
    }

    if (returnTypeFromRp != null) {
        if (returnTypeFromAnnotation != null && !isResourceInterface(returnTypeFromAnnotation)) {
            if (!returnTypeFromRp.isAssignableFrom(returnTypeFromAnnotation)) {
                throw new ConfigurationException("Method '" + theMethod.getName() + "' in type "
                        + theMethod.getDeclaringClass().getCanonicalName() + " returns type "
                        + returnTypeFromMethod.getCanonicalName() + " - Must return "
                        + returnTypeFromRp.getCanonicalName()
                        + " (or a subclass of it) per IResourceProvider contract");
            }
            if (!returnTypeFromRp.isAssignableFrom(returnTypeFromAnnotation)) {
                throw new ConfigurationException("Method '" + theMethod.getName() + "' in type "
                        + theMethod.getDeclaringClass().getCanonicalName() + " claims to return type "
                        + returnTypeFromAnnotation.getCanonicalName() + " per method annotation - Must return "
                        + returnTypeFromRp.getCanonicalName()
                        + " (or a subclass of it) per IResourceProvider contract");
            }
            returnType = returnTypeFromAnnotation;
        } else {
            returnType = returnTypeFromRp;
        }
    } else {
        if (!isResourceInterface(returnTypeFromAnnotation)) {
            if (!verifyIsValidResourceReturnType(returnTypeFromAnnotation)) {
                throw new ConfigurationException(
                        "Method '" + theMethod.getName() + "' from " + IResourceProvider.class.getSimpleName()
                                + " type " + theMethod.getDeclaringClass().getCanonicalName() + " returns "
                                + toLogString(returnTypeFromAnnotation)
                                + " according to annotation - Must return a resource type");
            }
            returnType = returnTypeFromAnnotation;
        } else {
            // if (IRestfulClient.class.isAssignableFrom(theMethod.getDeclaringClass())) {
            // Clients don't define their methods in resource specific types, so they can
            // infer their resource type from the method return type.
            returnType = (Class<? extends IBaseResource>) returnTypeFromMethod;
            // } else {
            // This is a plain provider method returning a resource, so it should be
            // an operation or global search presumably
            // returnType = null;
        }
    }

    if (read != null) {
        return new ReadMethodBinding(returnType, theMethod, theContext, theProvider);
    } else if (search != null) {
        if (search.dynamic()) {
            IDynamicSearchResourceProvider provider = (IDynamicSearchResourceProvider) theProvider;
            return new DynamicSearchMethodBinding(returnType, theMethod, theContext, provider);
        } else {
            return new SearchMethodBinding(returnType, theMethod, theContext, theProvider);
        }
    } else if (conformance != null) {
        return new ConformanceMethodBinding(theMethod, theContext, theProvider);
    } else if (create != null) {
        return new CreateMethodBinding(theMethod, theContext, theProvider);
    } else if (update != null) {
        return new UpdateMethodBinding(theMethod, theContext, theProvider);
    } else if (delete != null) {
        return new DeleteMethodBinding(theMethod, theContext, theProvider);
    } else if (patch != null) {
        return new PatchMethodBinding(theMethod, theContext, theProvider);
    } else if (history != null) {
        return new HistoryMethodBinding(theMethod, theContext, theProvider);
    } else if (validate != null) {
        if (theContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) {
            return new ValidateMethodBindingDstu1(theMethod, theContext, theProvider);
        } else {
            return new ValidateMethodBindingDstu2Plus(returnType, returnTypeFromRp, theMethod, theContext,
                    theProvider, validate);
        }
    } else if (getTags != null) {
        return new GetTagsMethodBinding(theMethod, theContext, theProvider, getTags);
    } else if (addTags != null) {
        return new AddTagsMethodBinding(theMethod, theContext, theProvider, addTags);
    } else if (deleteTags != null) {
        return new DeleteTagsMethodBinding(theMethod, theContext, theProvider, deleteTags);
    } else if (transaction != null) {
        return new TransactionMethodBinding(theMethod, theContext, theProvider);
    } else if (operation != null) {
        return new OperationMethodBinding(returnType, returnTypeFromRp, theMethod, theContext, theProvider,
                operation);
    } else {
        throw new ConfigurationException("Did not detect any FHIR annotations on method '" + theMethod.getName()
                + "' on type: " + theMethod.getDeclaringClass().getCanonicalName());
    }

    // // each operation name must have a request type annotation and be
    // unique
    // if (null != read) {
    // return rm;
    // }
    //
    // SearchMethodBinding sm = new SearchMethodBinding();
    // if (null != search) {
    // sm.setRequestType(SearchMethodBinding.RequestType.GET);
    // } else if (null != theMethod.getAnnotation(PUT.class)) {
    // sm.setRequestType(SearchMethodBinding.RequestType.PUT);
    // } else if (null != theMethod.getAnnotation(POST.class)) {
    // sm.setRequestType(SearchMethodBinding.RequestType.POST);
    // } else if (null != theMethod.getAnnotation(DELETE.class)) {
    // sm.setRequestType(SearchMethodBinding.RequestType.DELETE);
    // } else {
    // return null;
    // }
    //
    // return sm;
}

From source file:dstrelec.nats.annotation.NatsListenerAnnotationBeanPostProcessor.java

private Method checkProxy(Method methodArg, Object bean) {
    Method method = methodArg;
    if (AopUtils.isJdkDynamicProxy(bean)) {
        try {//w  w w .j a va 2 s. c  o m
            // Found a @NatsListener method on the target class for this JDK proxy ->
            // is it also present on the proxy itself?
            method = bean.getClass().getMethod(method.getName(), method.getParameterTypes());
            Class<?>[] proxiedInterfaces = ((Advised) bean).getProxiedInterfaces();
            for (Class<?> iface : proxiedInterfaces) {
                try {
                    method = iface.getMethod(method.getName(), method.getParameterTypes());
                    break;
                } catch (NoSuchMethodException noMethod) {
                }
            }
        } catch (SecurityException ex) {
            ReflectionUtils.handleReflectionException(ex);
        } catch (NoSuchMethodException ex) {
            throw new IllegalStateException(String.format(
                    "@NatsListener method '%s' found on bean target class '%s', "
                            + "but not found in any interface(s) for bean JDK proxy. Either "
                            + "pull the method up to an interface or switch to subclass (CGLIB) "
                            + "proxies by setting proxy-target-class/proxyTargetClass " + "attribute to 'true'",
                    method.getName(), method.getDeclaringClass().getSimpleName()), ex);
        }
    }
    return method;
}