Example usage for java.lang.reflect Method isBridge

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

Introduction

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

Prototype

public boolean isBridge() 

Source Link

Document

Returns true if this method is a bridge method; returns false otherwise.

Usage

From source file:org.grails.datastore.mapping.proxy.JavassistProxyFactory.java

protected Class getProxyClass(Class type) {

    Class proxyClass = PROXY_FACTORIES.get(type);
    if (proxyClass == null) {
        javassist.util.proxy.ProxyFactory pf = new ProxyFactory();
        pf.setSuperclass(type);//from   w  w w.  j  a  v a  2s  .  c o m
        pf.setInterfaces(new Class[] { EntityProxy.class });
        pf.setFilter(new MethodFilter() {
            public boolean isHandled(Method method) {
                final String methodName = method.getName();
                if (methodName.indexOf("super$") > -1) {
                    return false;
                }
                if (method.getParameterTypes().length == 0 && (methodName.equals("finalize"))) {
                    return false;
                }
                if (EXCLUDES.contains(methodName) || method.isSynthetic() || method.isBridge()) {
                    return false;
                }
                return true;
            }
        });
        proxyClass = pf.createClass();
        PROXY_FACTORIES.put(type, proxyClass);
    }
    return proxyClass;
}

From source file:com.p5solutions.core.utils.ReflectionUtility.java

/**
 * Find get methods with no params. All getters that aren't Native, Static,
 * Abstract, Synthetic, or Bridge are returned.
 * //from   ww w .  j a v a  2s . com
 * @param clazz
 *          the clazz
 * @return the list
 */
public synchronized static List<Method> findGetMethodsWithNoParams(Class<?> clazz) {

    /* if a cache already exists simply return it */
    List<Method> returnMethods = cachedMethods.get(clazz);

    if (returnMethods == null) {
        /* create a new cache and return it */
        returnMethods = new ArrayList<Method>();

        for (Method method : findAllMethods(clazz)) {

            // check for compiler introduced methods, as well as native methods.
            // simply ignore these methods, as they are probably not what we are
            // looking for.

            int modifiers = method.getModifiers();

            if (Modifier.isNative(modifiers) //
                    || Modifier.isStatic(modifiers) //
                    || Modifier.isAbstract(modifiers) //
                    || method.isSynthetic() //
                    || method.isBridge()) {
                continue;
            }

            // if its a getter then add it to the list
            if (isIs(method) || isGetter(method)) {
                if (!doesMethodHaveParams(method)) {
                    returnMethods.add(method);
                }
            }
        }

        cachedMethods.put(clazz, returnMethods);
    }

    return returnMethods;
}

From source file:org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator.java

protected Method[] processMethods(Method[] declaredMethods) throws Exception {
    ArrayList<Method> list = new ArrayList<Method>();
    //short the elements in the array
    Arrays.sort(declaredMethods, new MathodComparator());

    // since we do not support overload
    HashMap<String, Method> uniqueMethods = new LinkedHashMap<String, Method>();
    XmlSchemaComplexType methodSchemaType;
    XmlSchemaSequence sequence = null;// ww  w  . j av  a  2s  .c om

    for (Method jMethod : declaredMethods) {
        if (jMethod.isBridge()) {
            continue;
        }

        WebMethodAnnotation methodAnnon = JSR181Helper.INSTANCE.getWebMethodAnnotation(jMethod);
        String methodName = jMethod.getName();
        if (methodAnnon != null) {
            if (methodAnnon.isExclude()) {
                continue;
            }
            if (methodAnnon.getOperationName() != null) {
                methodName = methodAnnon.getOperationName();
            }
        }

        // no need to think abt this method , since that is system
        // config method
        if (excludeMethods.contains(methodName)) {
            continue;
        }

        if (!Modifier.isPublic(jMethod.getModifiers())) {
            // no need to generate Schema for non public methods
            continue;
        }

        if (uniqueMethods.get(methodName) != null) {
            log.warn("We don't support method overloading. Ignoring [" + methodName + "]");
            continue;
        }
        boolean addToService = false;
        AxisOperation axisOperation = service.getOperation(new QName(methodName));
        if (axisOperation == null) {
            axisOperation = Utils.getAxisOperationForJmethod(jMethod);
            //                if (WSDL2Constants.MEP_URI_ROBUST_IN_ONLY.equals(
            //                        axisOperation.getMessageExchangePattern())) {
            //                    AxisMessage outMessage = axisOperation.getMessage(
            //                            WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
            //                    if (outMessage != null) {
            //                        outMessage.setName(methodName + RESPONSE);
            //                    }
            //                }
            addToService = true;
        }
        // by now axis operation should be assigned but we better recheck & add the paramether
        if (axisOperation != null) {
            axisOperation.addParameter("JAXRSAnnotaion", JAXRSUtils.getMethodModel(this.classModel, jMethod));
        }
        // Maintain a list of methods we actually work with
        list.add(jMethod);

        processException(jMethod, axisOperation);
        uniqueMethods.put(methodName, jMethod);
        Class<?>[] parameters = jMethod.getParameterTypes();
        String parameterNames[] = null;
        AxisMessage inMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        if (inMessage != null) {
            inMessage.setName(methodName + Java2WSDLConstants.MESSAGE_SUFFIX);
        }
        if (parameters.length > 0) {
            parameterNames = methodTable.getParameterNames(methodName);
            // put the parameter names to use it for parsing
            service.addParameter(methodName, parameterNames);
        }

        // we need to add the method opration wrapper part even to
        // empty parameter operations 
        sequence = new XmlSchemaSequence();

        String requestElementSuffix = getRequestElementSuffix();
        String requestLocalPart = methodName;
        if (requestElementSuffix != null) {
            requestLocalPart += requestElementSuffix;
        }

        methodSchemaType = createSchemaTypeForMethodPart(requestLocalPart);
        methodSchemaType.setParticle(sequence);
        inMessage.setElementQName(typeTable.getQNamefortheType(requestLocalPart));

        Parameter param = service.getParameter(Java2WSDLConstants.MESSAGE_PART_NAME_OPTION_LONG);
        if (param != null) {
            inMessage.setPartName((String) param.getValue());
        }

        service.addMessageElementQNameToOperationMapping(methodSchemaType.getQName(), axisOperation);

        Annotation[][] parameterAnnotation = jMethod.getParameterAnnotations();

        Type[] genericParameterTypes = jMethod.getGenericParameterTypes();
        for (int j = 0; j < parameters.length; j++) {
            Class<?> methodParameter = parameters[j];
            String parameterName = getParameterName(parameterAnnotation, j, parameterNames);
            if (nonRpcMethods.contains(jMethod.getName())) {
                generateSchemaForType(sequence, null, jMethod.getName());
                break;
            } else {
                Type genericParameterType = genericParameterTypes[j];
                Type genericType = null;
                if (genericParameterType instanceof ParameterizedType) {
                    ParameterizedType aType = (ParameterizedType) genericParameterType;
                    Type[] parameterArgTypes = aType.getActualTypeArguments();
                    genericType = parameterArgTypes[0];
                    generateSchemaForType(sequence, genericType, parameterName, true);
                } else {
                    generateSchemaForType(sequence, methodParameter, parameterName);
                }
            }
        }
        // for its return type
        Class<?> returnType = jMethod.getReturnType();
        if (!"void".equals(jMethod.getReturnType().getName())) {
            String partQname = methodName + RESPONSE;
            methodSchemaType = createSchemaTypeForMethodPart(partQname);
            sequence = new XmlSchemaSequence();
            methodSchemaType.setParticle(sequence);
            WebResultAnnotation returnAnnon = JSR181Helper.INSTANCE.getWebResultAnnotation(jMethod);
            String returnName = "return";
            if (returnAnnon != null) {
                returnName = returnAnnon.getName();
                if (returnName == null || "".equals(returnName)) {
                    returnName = "return";
                }
            }
            Type genericParameterType = jMethod.getGenericReturnType();
            if (nonRpcMethods.contains(jMethod.getName())) {
                generateSchemaForType(sequence, null, returnName);
            } else if (genericParameterType instanceof ParameterizedType) {
                ParameterizedType aType = (ParameterizedType) genericParameterType;
                Type[] parameterArgTypes = aType.getActualTypeArguments();
                generateSchemaForType(sequence, parameterArgTypes[0], returnName, true);
            } else {
                generateSchemaForType(sequence, returnType, returnName);
            }

            AxisMessage outMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
            outMessage.setElementQName(typeTable.getQNamefortheType(partQname));
            outMessage.setName(partQname);

            Parameter outparam = service.getParameter(Java2WSDLConstants.MESSAGE_PART_NAME_OPTION_LONG);
            if (outparam != null) {
                outMessage.setPartName((String) outparam.getValue());
            }

            service.addMessageElementQNameToOperationMapping(methodSchemaType.getQName(), axisOperation);
        }
        if (addToService) {
            service.addOperation(axisOperation);
        }
    }
    return list.toArray(new Method[list.size()]);
}

From source file:org.apache.axis2.description.java2wsdl.DocLitBareSchemaGenerator.java

@Override
protected Method[] processMethods(Method[] declaredMethods) throws Exception {
    ArrayList<Method> list = new ArrayList<Method>();
    //short the elements in the array
    Arrays.sort(declaredMethods, new MathodComparator());

    // since we do not support overload
    HashMap<String, Method> uniqueMethods = new LinkedHashMap<String, Method>();
    XmlSchemaComplexType methodSchemaType;
    XmlSchemaSequence sequence;//w w  w .  j  a va 2 s. co m

    for (Method jMethod : declaredMethods) {
        if (jMethod.isBridge()) {
            continue;
        }
        WebMethodAnnotation methodAnnon = JSR181Helper.INSTANCE.getWebMethodAnnotation(jMethod);
        if (methodAnnon != null) {
            if (methodAnnon.isExclude()) {
                continue;
            }
        }
        String methodName = jMethod.getName();
        // no need to think abt this method , since that is system
        // config method
        if (excludeMethods.contains(methodName)) {
            continue;
        }

        if (uniqueMethods.get(methodName) != null) {
            log.warn("We don't support method overloading. Ignoring [" + methodName + "]");
            continue;
        }

        if (!Modifier.isPublic(jMethod.getModifiers())) {
            // no need to generate Schema for non public methods
            continue;
        }

        boolean addToService = false;
        AxisOperation axisOperation = service.getOperation(new QName(methodName));
        if (axisOperation == null) {
            axisOperation = Utils.getAxisOperationForJmethod(jMethod);
            if (WSDL2Constants.MEP_URI_ROBUST_IN_ONLY.equals(axisOperation.getMessageExchangePattern())) {
                AxisMessage outMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
                if (outMessage != null) {
                    outMessage.setName(methodName + RESULT);
                }
            }
            addToService = true;
        }

        // Maintain a list of methods we actually work with
        list.add(jMethod);
        processException(jMethod, axisOperation);
        uniqueMethods.put(methodName, jMethod);
        //create the schema type for the method wrapper

        uniqueMethods.put(methodName, jMethod);
        Class<?>[] paras = jMethod.getParameterTypes();
        String parameterNames[] = methodTable.getParameterNames(methodName);
        AxisMessage inMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        if (inMessage != null) {
            inMessage.setName(methodName + "RequestMessage");
        }
        Annotation[][] parameterAnnotation = jMethod.getParameterAnnotations();
        if (paras.length > 1) {
            sequence = new XmlSchemaSequence();
            methodSchemaType = createSchemaTypeForMethodPart(methodName);
            methodSchemaType.setParticle(sequence);
            inMessage.setElementQName(typeTable.getQNamefortheType(methodName));
            service.addMessageElementQNameToOperationMapping(methodSchemaType.getQName(), axisOperation);
            inMessage.setPartName(methodName);
            for (int j = 0; j < paras.length; j++) {
                Class<?> methodParameter = paras[j];
                String parameterName = getParameterName(parameterAnnotation, j, parameterNames);
                if (generateRequestSchema(methodParameter, parameterName, jMethod, sequence)) {
                    break;
                }
            }
        } else if (paras.length == 1) {
            if (paras[0].isArray()) {
                sequence = new XmlSchemaSequence();

                methodSchemaType = createSchemaTypeForMethodPart(methodName);
                methodSchemaType.setParticle(sequence);
                Class<?> methodParameter = paras[0];
                inMessage.setElementQName(typeTable.getQNamefortheType(methodName));
                service.addMessageElementQNameToOperationMapping(methodSchemaType.getQName(), axisOperation);
                inMessage.setPartName(methodName);
                String parameterName = getParameterName(parameterAnnotation, 0, parameterNames);
                if (generateRequestSchema(methodParameter, parameterName, jMethod, sequence)) {
                    break;
                }
            } else {
                String parameterName = getParameterName(parameterAnnotation, 0, parameterNames);
                Class<?> methodParameter = paras[0];
                Method processMethod = processedParameters.get(parameterName);
                if (processMethod != null) {
                    throw new AxisFault(
                            "Inavalid Java class," + " there are two methods [" + processMethod.getName()
                                    + " and " + jMethod.getName() + " ]which have the same parameter names");
                } else {
                    processedParameters.put(parameterName, jMethod);
                    generateSchemaForType(null, methodParameter, parameterName);
                    inMessage.setElementQName(typeTable.getQNamefortheType(parameterName));
                    inMessage.setPartName(parameterName);
                    inMessage.setWrapped(false);
                    service.addMessageElementQNameToOperationMapping(
                            typeTable.getQNamefortheType(parameterName), axisOperation);
                }
            }
        }

        // for its return type
        Class<?> returnType = jMethod.getReturnType();

        if (!"void".equals(jMethod.getReturnType().getName())) {
            AxisMessage outMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
            if (returnType.isArray()) {
                methodSchemaType = createSchemaTypeForMethodPart(jMethod.getName() + RESULT);
                sequence = new XmlSchemaSequence();
                methodSchemaType.setParticle(sequence);
                WebResultAnnotation returnAnnon = JSR181Helper.INSTANCE.getWebResultAnnotation(jMethod);
                String returnName = "return";
                if (returnAnnon != null) {
                    returnName = returnAnnon.getName();
                    if (returnName != null && !"".equals(returnName)) {
                        returnName = "return";
                    }
                }
                if (nonRpcMethods.contains(methodName)) {
                    generateSchemaForType(sequence, null, returnName);
                } else {
                    generateSchemaForType(sequence, returnType, returnName);
                }
            } else {
                generateSchemaForType(null, returnType, methodName + RESULT);
                outMessage.setWrapped(false);
            }
            outMessage.setElementQName(typeTable.getQNamefortheType(methodName + RESULT));
            outMessage.setName(methodName + "ResponseMessage");
            outMessage.setPartName(methodName + RESULT);
            service.addMessageElementQNameToOperationMapping(typeTable.getQNamefortheType(methodName + RESULT),
                    axisOperation);
        }
        if (addToService) {
            service.addOperation(axisOperation);
        }
    }
    return list.toArray(new Method[list.size()]);
}

From source file:org.apache.axis2.rpc.receivers.RPCMessageReceiver.java

/**
 * reflect and get the Java method - for each i'th param in the java method - get the first
 * child's i'th child -if the elem has an xsi:type attr then find the deserializer for it - if
 * not found, lookup deser for th i'th param (java type) - error if not found - deserialize &
 * save in an object array - end for/*from  w w w . jav  a2s.  c o m*/
 * <p/>
 * - invoke method and get the return value
 * <p/>
 * - look up serializer for return value based on the value and type
 * <p/>
 * - create response msg and add return value as grand child of <soap:body>
 *
 * @param inMessage incoming MessageContext
 * @param outMessage outgoing MessageContext
 * @throws AxisFault
 */

public void invokeBusinessLogic(MessageContext inMessage, MessageContext outMessage) throws AxisFault {
    Method method = null;
    try {
        // get the implementation class for the Web Service
        Object obj = getTheImplementationObject(inMessage);

        Class implClass = obj.getClass();

        AxisOperation op = inMessage.getOperationContext().getAxisOperation();
        method = (Method) (op.getParameterValue("myMethod"));
        // If the declaring class has changed, then the cached method is invalid, so we need to
        // reload it. This is to fix AXIS2-3947.
        if (method != null && method.getDeclaringClass() != implClass) {
            method = null;
        }
        AxisService service = inMessage.getAxisService();
        OMElement methodElement = inMessage.getEnvelope().getBody().getFirstElement();
        AxisMessage inAxisMessage = op.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        String messageNameSpace = null;

        if (method == null) {
            String methodName = op.getName().getLocalPart();
            Method[] methods = implClass.getMethods();

            for (Method method1 : methods) {
                if (method1.isBridge()) {
                    continue;
                }
                if (method1.getName().equals(methodName)) {
                    method = method1;
                    op.addParameter("myMethod", method);
                    break;
                }
            }
            if (method == null) {
                throw new AxisFault("No such method '" + methodName + "' in class " + implClass.getName());
            }
        }
        Object resObject = null;
        if (inAxisMessage != null) {
            resObject = RPCUtil.invokeServiceClass(inAxisMessage, method, obj, messageNameSpace, methodElement,
                    inMessage);
        }

        SOAPFactory fac = getSOAPFactory(inMessage);

        // Handling the response
        AxisMessage outaxisMessage = op.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
        if (outaxisMessage != null && outaxisMessage.getElementQName() != null) {
            messageNameSpace = outaxisMessage.getElementQName().getNamespaceURI();
        } else {
            messageNameSpace = service.getTargetNamespace();
        }

        OMNamespace ns = fac.createOMNamespace(messageNameSpace, service.getSchemaTargetNamespacePrefix());
        SOAPEnvelope envelope = fac.getDefaultEnvelope();
        OMElement bodyContent = null;

        if (WSDL2Constants.MEP_URI_ROBUST_IN_ONLY.equals(op.getMessageExchangePattern())) {
            OMElement bodyChild = fac.createOMElement(outMessage.getAxisMessage().getName(), ns);
            envelope.getBody().addChild(bodyChild);
            outMessage.setEnvelope(envelope);
            return;
        }
        Parameter generateBare = service.getParameter(Java2WSDLConstants.DOC_LIT_BARE_PARAMETER);
        if (generateBare != null && "true".equals(generateBare.getValue())) {
            RPCUtil.processResonseAsDocLitBare(resObject, service, envelope, fac, ns, bodyContent, outMessage);
        } else {
            RPCUtil.processResponseAsDocLitWrapped(resObject, service, method, envelope, fac, ns, bodyContent,
                    outMessage);
        }
        outMessage.setEnvelope(envelope);
    } catch (InvocationTargetException e) {
        String msg = null;
        Throwable cause = e.getCause();
        if (cause != null) {
            msg = cause.getMessage();
        }
        if (msg == null) {
            msg = "Exception occurred while trying to invoke service method "
                    + (method != null ? method.getName() : "null");
        }
        if (cause instanceof AxisFault) {
            log.debug(msg, cause);
            throw (AxisFault) cause;
        }

        Class[] exceptionTypes = method.getExceptionTypes();
        for (Class exceptionType : exceptionTypes) {
            if (exceptionType.getName().equals(cause.getClass().getName())) {
                // this is an bussiness logic exception so handle it properly
                String partQName = inMessage.getAxisService().getName() + getSimpleClassName(exceptionType);
                TypeTable typeTable = inMessage.getAxisService().getTypeTable();
                QName elementQName = typeTable.getQNamefortheType(partQName);
                SOAPFactory fac = getSOAPFactory(inMessage);
                OMElement exceptionElement = fac.createOMElement(elementQName);

                if (exceptionType.getName().equals(Exception.class.getName())) {
                    // this is an exception class. so create a element by hand and add the message
                    OMElement innterExceptionElement = fac.createOMElement(elementQName);
                    OMElement messageElement = fac.createOMElement("Message",
                            inMessage.getAxisService().getTargetNamespace(), null);
                    messageElement.setText(cause.getMessage());

                    innterExceptionElement.addChild(messageElement);
                    exceptionElement.addChild(innterExceptionElement);
                } else {
                    // if it is a normal bussiness exception we need to generate the schema assuming it is a pojo
                    QName innerElementQName = new QName(elementQName.getNamespaceURI(),
                            getSimpleClassName(exceptionType));
                    XMLStreamReader xr = BeanUtil.getPullParser(cause, innerElementQName, typeTable, true,
                            false);
                    StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(),
                            new StreamWrapper(xr));
                    OMElement documentElement = stAXOMBuilder.getDocumentElement();
                    exceptionElement.addChild(documentElement);
                }

                AxisFault axisFault = new AxisFault(cause.getMessage());
                axisFault.setDetail(exceptionElement);
                throw axisFault;
            }
        }

        log.error(msg, e);
        throw new AxisFault(msg, e);
    } catch (RuntimeException e) {
        log.error(e.getMessage(), e);
        throw AxisFault.makeFault(e);
    } catch (Exception e) {
        String msg = "Exception occurred while trying to invoke service method "
                + (method != null ? method.getName() : "null");
        log.error(msg, e);
        throw AxisFault.makeFault(e);
    }
}

From source file:org.apache.bval.jsr.JsrMetaBeanFactory.java

/**
 * Process class annotations, field and method annotations.
 * /*  w w  w .  ja va 2s .  c o  m*/
 * @param beanClass
 * @param metabean
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
private void processClass(Class<?> beanClass, MetaBean metabean)
        throws IllegalAccessException, InvocationTargetException {

    // if NOT ignore class level annotations
    if (!factory.getAnnotationIgnores().isIgnoreAnnotations(beanClass)) {
        annotationProcessor.processAnnotations(null, beanClass, beanClass, null,
                new AppendValidationToMeta(metabean));
    }

    final Collection<String> missingValid = new ArrayList<String>();

    final Field[] fields = Reflection.getDeclaredFields(beanClass);
    for (final Field field : fields) {
        MetaProperty metaProperty = metabean.getProperty(field.getName());
        // create a property for those fields for which there is not yet a
        // MetaProperty
        if (!factory.getAnnotationIgnores().isIgnoreAnnotations(field)) {
            AccessStrategy access = new FieldAccess(field);
            boolean create = metaProperty == null;
            if (create) {
                metaProperty = addMetaProperty(metabean, access);
            }
            if (!annotationProcessor.processAnnotations(metaProperty, beanClass, field, access,
                    new AppendValidationToMeta(metaProperty)) && create) {
                metabean.putProperty(metaProperty.getName(), null);
            }

            if (field.getAnnotation(ConvertGroup.class) != null) {
                missingValid.add(field.getName());
            }
        }
    }
    final Method[] methods = Reflection.getDeclaredMethods(beanClass);
    for (final Method method : methods) {
        if (method.isSynthetic() || method.isBridge()) {
            continue;
        }
        String propName = null;
        if (method.getParameterTypes().length == 0) {
            propName = MethodAccess.getPropertyName(method);
        }
        if (propName != null) {
            if (!factory.getAnnotationIgnores().isIgnoreAnnotations(method)) {
                AccessStrategy access = new MethodAccess(propName, method);
                MetaProperty metaProperty = metabean.getProperty(propName);
                boolean create = metaProperty == null;
                // create a property for those methods for which there is
                // not yet a MetaProperty
                if (create) {
                    metaProperty = addMetaProperty(metabean, access);
                }
                if (!annotationProcessor.processAnnotations(metaProperty, beanClass, method, access,
                        new AppendValidationToMeta(metaProperty)) && create) {
                    metabean.putProperty(propName, null);
                }
            }
        }
    }

    addXmlConstraints(beanClass, metabean);

    for (final String name : missingValid) {
        final MetaProperty metaProperty = metabean.getProperty(name);
        if (metaProperty != null && metaProperty.getFeature(JsrFeatures.Property.REF_CASCADE) == null) {
            throw new ConstraintDeclarationException("@ConvertGroup needs @Valid");
        }
    }
    missingValid.clear();
}

From source file:org.apache.camel.component.bean.BeanInfo.java

/**
 * Validates whether the given method is a valid candidate for Camel Bean Binding.
 *
 * @param clazz   the class//from   w w w .jav a2s. co  m
 * @param method  the method
 * @return true if valid, false to skip the method
 */
protected boolean isValidMethod(Class<?> clazz, Method method) {
    // must not be in the excluded list
    for (Method excluded : EXCLUDED_METHODS) {
        if (ObjectHelper.isOverridingMethod(excluded, method)) {
            // the method is overriding an excluded method so its not valid
            return false;
        }
    }

    // must be a public method
    if (!Modifier.isPublic(method.getModifiers())) {
        return false;
    }

    // return type must not be an Exchange and it should not be a bridge method
    if ((method.getReturnType() != null && Exchange.class.isAssignableFrom(method.getReturnType()))
            || method.isBridge()) {
        return false;
    }

    return true;
}

From source file:org.batoo.common.reflect.ReflectHelper.java

/**
 * Returns the property descriptors for the class.
 * /*  w w  w.  j av a2  s . com*/
 * @param clazz
 *            the class
 * @return the property descriptors
 * 
 * @since 2.0.1
 */
public static PropertyDescriptor[] getProperties(Class<?> clazz) {
    final List<PropertyDescriptor> properties = Lists.newArrayList();

    final Method[] methodList = clazz.getDeclaredMethods();

    // check each method.
    for (final Method method : methodList) {
        if (method == null) {
            continue;
        }

        // skip static and private methods.
        final int mods = method.getModifiers();
        if (Modifier.isStatic(mods) || !Modifier.isPublic(mods) || method.isBridge() || method.isSynthetic()) {
            continue;
        }

        final String name = method.getName();

        if (method.getParameterTypes().length == 0) {
            if (name.startsWith(ReflectHelper.GET_PREFIX)) {
                properties.add(new PropertyDescriptor(clazz, name.substring(3), method));
            } else if ((method.getReturnType() == boolean.class) && name.startsWith(ReflectHelper.IS_PREFIX)) {
                properties.add(new PropertyDescriptor(clazz, name.substring(2), method));
            }
        }
    }

    return properties.toArray(new PropertyDescriptor[properties.size()]);
}

From source file:org.batoo.jpa.parser.impl.metadata.type.ManagedTypeMetadatImpl.java

/**
 * Infers and returns the access type based on all persistence annotations being on fields or methods and parent parent access type.
 * /*from   w w  w.  ja  v  a  2s .  c om*/
 * @param parentAccessType
 *            the parent access type
 * @return the inferred access type
 * 
 * @since 2.0.0
 */
private AccessType inferAccessType(AccessType parentAccessType) {
    boolean methodsHasAnnotations = false;
    boolean fieldsHasAnnotations = false;

    final List<String> alternated = Lists.newArrayList();

    final Field[] fields = this.clazz.getDeclaredFields();
    final Method[] methods = this.clazz.getDeclaredMethods();

    // find the alternated ones with @Access
    for (final Method m : methods) {
        // skip static and private methods.
        final int mods = m.getModifiers();
        if (Modifier.isStatic(mods) || !Modifier.isPublic(mods) || m.isBridge() || m.isSynthetic()) {
            continue;
        }

        if ((m.getParameterTypes().length != 0) || (m.getReturnType() == null)) {
            continue;
        }

        final Access access = m.getAnnotation(Access.class);
        if (access != null) {
            final String name = m.getName();
            if ((m.getReturnType() == boolean.class) && name.startsWith("is")) {
                alternated.add(StringUtils.capitalize(name.substring(2)));
            } else if (name.startsWith("get")) {
                alternated.add(StringUtils.capitalize(name.substring(3)));
            }
        }
    }

    for (final Field f : fields) {
        final Access access = f.getAnnotation(Access.class);

        if (access != null) {
            alternated.add(StringUtils.capitalize(f.getName()));
        }
    }

    // check methods
    for (final Method m : methods) {
        for (final Annotation a : m.getAnnotations()) {
            // ignore @Access(PROPERTY)
            if (a instanceof Access) {
                if (((Access) a).value() != AccessType.PROPERTY) {
                    continue;
                }
            }

            // ignore @Transient
            if (a instanceof Transient) {
                continue;
            }

            if ((m.getReturnType() == null) || (m.getParameterTypes().length > 0)) {
                continue;
            }

            String name = a.annotationType().getName();
            // ignore the listener annotations
            if (name.startsWith("javax.persistence.Post") || name.startsWith("javax.persistence.Pre")) {
                continue;
            }

            if (name.startsWith("javax.persistence") || name.startsWith("org.batoo.jpa.annotation")) {
                name = m.getName();

                if ((boolean.class == m.getReturnType()) || name.startsWith("is")) {
                    name = name.substring(2);
                } else if (name.startsWith("get")) {
                    name = name.substring(3);
                }

                if (alternated.contains(StringUtils.capitalize(name))) {
                    continue;
                }

                methodsHasAnnotations = true;
                break;
            }
        }
    }

    // check fields
    for (final Field f : fields) {
        for (final Annotation a : f.getAnnotations()) {
            // ignore @Access(FIELD)
            if (a instanceof Access) {
                if (((Access) a).value() != AccessType.FIELD) {
                    continue;
                }
            }

            // ignore @Transient
            if (a instanceof Transient) {
                continue;
            }

            final String name = a.annotationType().getName();
            if (name.startsWith("javax.persistence") || name.startsWith("org.batoo.jpa.annotation")) {
                if (alternated.contains(StringUtils.capitalize(f.getName()))) {
                    continue;
                }

                fieldsHasAnnotations = true;
                break;
            }
        }
    }

    if (fieldsHasAnnotations && methodsHasAnnotations) {
        throw new PersistenceException(
                "At least one field and one method has persistence annotations: " + this.clazz.getName());
    }

    if (methodsHasAnnotations) {
        return AccessType.PROPERTY;
    }

    if (fieldsHasAnnotations) {
        return AccessType.FIELD;
    }

    if (parentAccessType != null) {
        return parentAccessType;
    }

    return AccessType.FIELD;
}

From source file:org.codehaus.groovy.grails.commons.metaclass.BaseApiProvider.java

private boolean isNotExcluded(Method method, final int modifiers) {
    final String name = method.getName();

    if (EXCLUDED_METHODS.contains(name))
        return false;

    boolean isStatic = Modifier.isStatic(modifiers);

    // skip plain setters/getters by default for instance methods (non-static)
    if (!isStatic && (GrailsClassUtils.isSetter(name, method.getParameterTypes())
            || GrailsClassUtils.isGetter(name, method.getParameterTypes()))) {
        return false;
    }/*  www.  j a v a  2s.  co  m*/

    int minParameters = isStatic ? 0 : 1;

    return Modifier.isPublic(modifiers) && !(method.isSynthetic() || method.isBridge())
            && !Modifier.isAbstract(modifiers) && !name.contains("$")
            && (method.getParameterTypes().length >= minParameters);
}