Search in sources :

Example 36 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project OpenAttestation by OpenAttestation.

the class ValidationUtil method validateObjectArray.

/**
     *
     * @param object instance to validate
     * @param context is the Field or Method from which we obtained the object
     * instance; we look for
     * @Unchecked and
     * @Validator annotations
     * @param contextName is the name of the Field or Method from which we
     * obtained the object instance
     * @param parent is the instance containing the Field or Method from which
     * we obtained the object instance
     */
private static void validateObjectArray(Object[] array, AccessibleObject context, String contextName, Object parent, ArrayList<Object> visited) {
    if (context.isAnnotationPresent(Unchecked.class)) {
        log.debug("Object array of class {} in {} of {} is unchecked", array.getClass().getName(), contextName, parent.getClass().getName());
        return;
    }
    log.debug("validateObjectArray of length {}", array.length);
    // validate each item in the array
    for (int i = 0; i < array.length; i++) {
        Object object = array[i];
        validateObject(object, context, String.format("%s[%d]", contextName, i), parent, visited);
    }
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject)

Example 37 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project OpenAttestation by OpenAttestation.

the class ValidationUtil method validateObjectCollection.

/**
     *
     * @param object instance to validate
     * @param context is the Field or Method from which we obtained the object
     * instance; we look for
     * @Unchecked and
     * @Validator annotations
     * @param contextName is the name of the Field or Method from which we
     * obtained the object instance
     * @param parent is the instance containing the Field or Method from which
     * we obtained the object instance
     */
private static void validateObjectCollection(Collection<Object> collection, AccessibleObject context, String contextName, Object parent, ArrayList<Object> visited) {
    if (context.isAnnotationPresent(Unchecked.class)) {
        log.debug("Object collection of class {} in {} of {} is unchecked", collection.getClass().getName(), contextName, parent.getClass().getName());
        return;
    }
    log.debug("validateObjectCollection of size {}", collection.size());
    // TODO:  if it's an array and annotated with a specific @ArrayValidator , use it directly
    /*
         if( context.isAnnotationPresent(Validator.class)) {
         Class validatorClass = context.getAnnotation(Validator.class).value();
         validateWithValidatorClass(object, validatorClass);
         return;
         }
         */
    // validate each item in the collection
    /*
         ParameterizedType stringListType = (ParameterizedType) field.getGenericType();
         Class<?> stringListClass = (Class<?>) stringListType.getActualTypeArguments()[0];
         stringReturn = stringListClass.isAssignableFrom(String.class);
         * 
         */
    int i = 0;
    for (Object object : collection) {
        validateObject(object, context, String.format("%s[%d]", contextName, i), parent, visited);
        i++;
    }
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject)

Example 38 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project XobotOS by xamarin.

the class ViewDebug method getExportedPropertyFields.

private static Field[] getExportedPropertyFields(Class<?> klass) {
    if (sFieldsForClasses == null) {
        sFieldsForClasses = new HashMap<Class<?>, Field[]>();
    }
    if (sAnnotations == null) {
        sAnnotations = new HashMap<AccessibleObject, ExportedProperty>(512);
    }
    final HashMap<Class<?>, Field[]> map = sFieldsForClasses;
    Field[] fields = map.get(klass);
    if (fields != null) {
        return fields;
    }
    final ArrayList<Field> foundFields = new ArrayList<Field>();
    fields = klass.getDeclaredFields();
    int count = fields.length;
    for (int i = 0; i < count; i++) {
        final Field field = fields[i];
        if (field.isAnnotationPresent(ExportedProperty.class)) {
            field.setAccessible(true);
            foundFields.add(field);
            sAnnotations.put(field, field.getAnnotation(ExportedProperty.class));
        }
    }
    fields = foundFields.toArray(new Field[foundFields.size()]);
    map.put(klass, fields);
    return fields;
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) AccessibleObject(java.lang.reflect.AccessibleObject)

Example 39 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project wildfly by wildfly.

the class WSRefAnnotationProcessor method elementForInjectionTarget.

private static AnnotatedElement elementForInjectionTarget(final DeploymentUnit unit, final InjectionTarget injectionTarget) throws DeploymentUnitProcessingException {
    final Module module = unit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final DeploymentReflectionIndex deploymentReflectionIndex = unit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
    final String injectionTargetClassName = injectionTarget.getClassName();
    final String injectionTargetName = getInjectionTargetName(injectionTarget);
    final AccessibleObject fieldOrMethod = getInjectionTarget(injectionTargetClassName, injectionTargetName, module.getClassLoader(), deploymentReflectionIndex);
    return fieldOrMethod;
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject) Module(org.jboss.modules.Module) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Example 40 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project android_frameworks_base by AOSPA.

the class ViewDebug method getExportedPropertyMethods.

private static Method[] getExportedPropertyMethods(Class<?> klass) {
    if (sMethodsForClasses == null) {
        sMethodsForClasses = new HashMap<Class<?>, Method[]>(100);
    }
    if (sAnnotations == null) {
        sAnnotations = new HashMap<AccessibleObject, ExportedProperty>(512);
    }
    final HashMap<Class<?>, Method[]> map = sMethodsForClasses;
    Method[] methods = map.get(klass);
    if (methods != null) {
        return methods;
    }
    methods = klass.getDeclaredMethodsUnchecked(false);
    final ArrayList<Method> foundMethods = new ArrayList<Method>();
    for (final Method method : methods) {
        // Ensure the method return and parameter types can be resolved.
        try {
            method.getReturnType();
            method.getParameterTypes();
        } catch (NoClassDefFoundError e) {
            continue;
        }
        if (method.getParameterTypes().length == 0 && method.isAnnotationPresent(ExportedProperty.class) && method.getReturnType() != Void.class) {
            method.setAccessible(true);
            foundMethods.add(method);
            sAnnotations.put(method, method.getAnnotation(ExportedProperty.class));
        }
    }
    methods = foundMethods.toArray(new Method[foundMethods.size()]);
    map.put(klass, methods);
    return methods;
}
Also used : ArrayList(java.util.ArrayList) AccessibleObject(java.lang.reflect.AccessibleObject) Method(java.lang.reflect.Method)

Aggregations

AccessibleObject (java.lang.reflect.AccessibleObject)54 ArrayList (java.util.ArrayList)17 Method (java.lang.reflect.Method)14 Field (java.lang.reflect.Field)9 Annotation (java.lang.annotation.Annotation)8 PropertyModel (org.qi4j.runtime.property.PropertyModel)6 HashSet (java.util.HashSet)5 MethodInvocation (org.aopalliance.intercept.MethodInvocation)4 Property (org.qi4j.api.property.Property)4 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 BuilderEntityState (org.qi4j.runtime.unitofwork.BuilderEntityState)3 DynamicFinder (com.google.inject.persist.finder.DynamicFinder)2 Finder (com.google.inject.persist.finder.Finder)2 Constructor (java.lang.reflect.Constructor)2 InvocationHandler (java.lang.reflect.InvocationHandler)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)2 ResourceInjectionTargetMetaData (org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData)2 Module (org.jboss.modules.Module)2