Search in sources :

Example 26 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class DefaultBeanInfo method getGetter.

@Override
public Method getGetter(final String propertyName, final Class<?> type) {
    final boolean isBoolean = Boolean.TYPE.equals(type);
    final String name = ((isBoolean) ? "is" : "get") + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
    final Method result = lookup(new Lookup<Method>() {

        @Override
        public Method lookup(ClassReflectionIndex index) {
            Collection<Method> methods = index.getAllMethods(name, 0);
            if (type == null) {
                if (methods.size() == 1)
                    return methods.iterator().next();
                else
                    return null;
            }
            for (Method m : methods) {
                Class<?> pt = m.getReturnType();
                if (pt.isAssignableFrom(type))
                    return m;
            }
            return null;
        }
    }, 0, Integer.MAX_VALUE);
    if (result == null)
        throw PojoLogger.ROOT_LOGGER.getterNotFound(type, beanClass.getName());
    return result;
}
Also used : ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) Collection(java.util.Collection) Method(java.lang.reflect.Method)

Example 27 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class DefaultBeanInfo method getSetter.

@Override
public Method getSetter(final String propertyName, final Class<?> type) {
    final String name = "set" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
    final Method result = lookup(new Lookup<Method>() {

        @Override
        public Method lookup(ClassReflectionIndex index) {
            Collection<Method> methods = index.getAllMethods(name, 1);
            if (type == null) {
                if (methods.size() == 1)
                    return methods.iterator().next();
                else
                    return null;
            }
            for (Method m : methods) {
                Class<?> pt = m.getParameterTypes()[0];
                if (pt.isAssignableFrom(type))
                    return m;
            }
            return null;
        }
    }, 0, Integer.MAX_VALUE);
    if (result == null)
        throw PojoLogger.ROOT_LOGGER.setterNotFound(type, beanClass.getName());
    return result;
}
Also used : ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) Collection(java.util.Collection) Method(java.lang.reflect.Method)

Example 28 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class DefaultBeanInfo method lookup.

/**
     * Do lazy lookup.
     *
     * @param lookup the lookup
     * @param start the start
     * @param depth the depth
     * @return reflection index result
     */
protected <U> U lookup(Lookup<U> lookup, int start, int depth) {
    int size;
    synchronized (indexes) {
        size = indexes.size();
        for (int i = start; i < depth && i < size; i++) {
            U result = lookup.lookup(indexes.get(i));
            if (result != null)
                return result;
        }
    }
    if (currentClass == null)
        return null;
    synchronized (indexes) {
        ClassReflectionIndex cri = index.getClassIndex(currentClass);
        indexes.add(cri);
        currentClass = currentClass.getSuperclass();
    }
    return lookup(lookup, size, depth);
}
Also used : ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex)

Example 29 with ClassReflectionIndex

use of org.jboss.as.server.deployment.reflect.ClassReflectionIndex in project wildfly by wildfly.

the class MethodAnnotationAggregator method runtimeAnnotationInformation.

public static <A extends Annotation, T> RuntimeAnnotationInformation<T> runtimeAnnotationInformation(final Class<?> componentClass, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex index, final Class<A> annotationType) {
    final HashSet<MethodIdentifier> methodIdentifiers = new HashSet<MethodIdentifier>();
    final Map<Method, List<T>> methods = new HashMap<Method, List<T>>();
    final Map<String, List<T>> classAnnotations = new HashMap<String, List<T>>();
    Class<?> c = componentClass;
    while (c != null && c != Object.class) {
        final ClassReflectionIndex classIndex = index.getClassIndex(c);
        final EEModuleClassDescription description = applicationClasses.getClassByName(c.getName());
        if (description != null) {
            ClassAnnotationInformation<A, T> annotationData = description.getAnnotationInformation(annotationType);
            if (annotationData != null) {
                if (!annotationData.getClassLevelAnnotations().isEmpty()) {
                    classAnnotations.put(c.getName(), annotationData.getClassLevelAnnotations());
                }
                for (Map.Entry<MethodIdentifier, List<T>> entry : annotationData.getMethodLevelAnnotations().entrySet()) {
                    final Method method = classIndex.getMethod(entry.getKey());
                    if (method != null) {
                        //we do not have to worry about private methods being overridden
                        if (Modifier.isPrivate(method.getModifiers()) || !methodIdentifiers.contains(entry.getKey())) {
                            methods.put(method, entry.getValue());
                        }
                    } else {
                        //but if it does, we give some info
                        throw EeLogger.ROOT_LOGGER.cannotResolveMethod(entry.getKey(), c, entry.getValue());
                    }
                }
            }
        }
        //so we can check if a method is overriden
        for (Method method : (Iterable<Method>) classIndex.getMethods()) {
            //we do not have to worry about private methods being overridden
            if (!Modifier.isPrivate(method.getModifiers())) {
                methodIdentifiers.add(MethodIdentifier.getIdentifierForMethod(method));
            }
        }
        c = c.getSuperclass();
    }
    return new RuntimeAnnotationInformation<T>(classAnnotations, methods);
}
Also used : HashMap(java.util.HashMap) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) Method(java.lang.reflect.Method) List(java.util.List) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

ClassReflectionIndex (org.jboss.as.server.deployment.reflect.ClassReflectionIndex)29 Method (java.lang.reflect.Method)24 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)11 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)8 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)5 ViewDescription (org.jboss.as.ee.component.ViewDescription)5 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)5 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)5 Module (org.jboss.modules.Module)5 ArrayList (java.util.ArrayList)4 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)4 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)4 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)4 WriteReplaceInterface (org.jboss.as.ee.component.serialization.WriteReplaceInterface)4 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)4 Map (java.util.Map)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3