Package org.apache.bval.util

Examples of org.apache.bval.util.AccessStrategy


     * {@inheritDoc}
     */
    public void handleIndexOrKey(String token) {
        moveDownIfNecessary();

        AccessStrategy access;
        if (IndexedAccess.getJavaElementType(type) != null) {
            try {
                Integer index = token == null ? null : Integer.valueOf(token);
                access = new IndexedAccess(type, index);
                validationContext.setCurrentIndex(index);
            } catch (NumberFormatException e) {
                throw new UnknownPropertyException(String.format("Cannot parse %s as an array/iterable index", token),
                    e);
            }
        } else if (KeyedAccess.getJavaElementType(type) != null) {
            access = new KeyedAccess(type, token);
            validationContext.setCurrentKey(token);
        } else {
            throw new UnknownPropertyException(String.format("Cannot determine index/key type for %s", type));
        }
        Object value = validationContext.getBean();
        Object child = value == null ? null : access.get(value);
        setType(child == null ? access.getJavaType() : child.getClass());
        validationContext.setBean(child,
            validationContext.getMetaBean().resolveMetaBean(child == null ? rawType : child));
    }
View Full Code Here


        for (Field field : fields) {
            MetaProperty metaProperty = metabean.getProperty(field.getName());
            // create a property for those fields for which there is not yet a
            // MetaProperty
            if (!factoryContext.getFactory().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);
                }
            }
        }
        final Method[] methods = doPrivileged(SecureActions.getDeclaredMethods(beanClass));
        for (Method method : methods) {
            String propName = null;
            if (method.getParameterTypes().length == 0) {
                propName = MethodAccess.getPropertyName(method);
            }
            if (propName != null) {
                if (!factoryContext.getFactory().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) {
View Full Code Here

     */
    private void addXmlConstraints(Class<?> beanClass, MetaBean metabean) throws IllegalAccessException,
        InvocationTargetException {
        for (MetaConstraint<?, ? extends Annotation> meta : factoryContext.getFactory().getMetaConstraints(beanClass)) {
            MetaProperty metaProperty;
            AccessStrategy access = meta.getAccessStrategy();
            boolean create = false;
            if (access == null) { // class level
                metaProperty = null;
            } else { // property level
                metaProperty = metabean.getProperty(access.getPropertyName());
                create = metaProperty == null;
                if (create) {
                    metaProperty = addMetaProperty(metabean, access);
                }
            }
            if (!annotationProcessor.processAnnotation(meta.getAnnotation(), metaProperty, beanClass,
                meta.getAccessStrategy(), new AppendValidationToMeta(metaProperty == null ? metabean : metaProperty))
                && create) {
                metabean.putProperty(access.getPropertyName(), null);
            }
        }
        for (AccessStrategy access : factoryContext.getFactory().getValidAccesses(beanClass)) {
            MetaProperty metaProperty = metabean.getProperty(access.getPropertyName());
            boolean create = metaProperty == null;
            if (create) {
                metaProperty = addMetaProperty(metabean, access);
            }
            if (!annotationProcessor.addAccessStrategy(metaProperty, access) && create) {
                metabean.putProperty(access.getPropertyName(), null);
            }
        }
    }
View Full Code Here

     * {@inheritDoc}
     */
    public void handleIndexOrKey(String token) {
        moveDownIfNecessary();

        AccessStrategy access;
        if (IndexedAccess.getJavaElementType(type) != null) {
            try {
                Integer index = token == null ? null : Integer.valueOf(token);
                access = new IndexedAccess(type, index);
                validationContext.setCurrentIndex(index);
            } catch (NumberFormatException e) {
                throw new UnknownPropertyException(String.format("Cannot parse %s as an array/iterable index", token),
                    e);
            }
        } else if (KeyedAccess.getJavaElementType(type) != null) {
            access = new KeyedAccess(type, token);
            validationContext.setCurrentKey(token);
        } else {
            throw new UnknownPropertyException(String.format("Cannot determine index/key type for %s", type));
        }
        Object value = validationContext.getBean();
        Object child = value == null ? null : access.get(value);
        setType(child == null ? access.getJavaType() : child.getClass());
        validationContext.setBean(child,
            validationContext.getMetaBean().resolveMetaBean(child == null ? rawType : child));
    }
View Full Code Here

        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 (!factoryContext.getFactory().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.INSTANCE.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 (!factoryContext.getFactory().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) {
View Full Code Here

     */
    private void addXmlConstraints(Class<?> beanClass, MetaBean metabean) throws IllegalAccessException,
        InvocationTargetException {
        for (final MetaConstraint<?, ? extends Annotation> metaConstraint : factoryContext.getFactory().getMetaConstraints(beanClass)) {
            Meta meta;
            AccessStrategy access = metaConstraint.getAccessStrategy();
            boolean create = false;
            if (access == null) { // class level
                meta = null;
            } else if (access.getElementType() == ElementType.METHOD && !metaConstraint.getMember().getName().startsWith("get")) { // TODO: better getter test
                final Method method = Method.class.cast(metaConstraint.getMember());
                meta = metabean.getMethod(method);
                final MetaMethod metaMethod;
                if (meta == null) {
                    meta = new MetaMethod(metabean, method);
                    metaMethod = MetaMethod.class.cast(meta);
                    metabean.addMethod(method, metaMethod);
                } else {
                    metaMethod = MetaMethod.class.cast(meta);
                }
                final Integer index = metaConstraint.getIndex();
                if (index != null && index >= 0) {
                    MetaParameter param = metaMethod.getParameter(index);
                    if (param == null) {
                        param = new MetaParameter(metaMethod, index);
                        metaMethod.addParameter(index, param);
                    }
                    param.addAnnotation(metaConstraint.getAnnotation());
                } else {
                    metaMethod.addAnnotation(metaConstraint.getAnnotation());
                }
                continue;
            } else if (access.getElementType() == ElementType.CONSTRUCTOR){
                final Constructor<?> constructor = Constructor.class.cast(metaConstraint.getMember());
                meta = metabean.getConstructor(constructor);
                final MetaConstructor metaConstructor;
                if (meta == null) {
                    meta = new MetaConstructor(metabean, constructor);
                    metaConstructor = MetaConstructor.class.cast(meta);
                    metabean.addConstructor(constructor, metaConstructor);
                } else {
                    metaConstructor = MetaConstructor.class.cast(meta);
                }
                final Integer index = metaConstraint.getIndex();
                if (index != null && index >= 0) {
                    MetaParameter param = metaConstructor.getParameter(index);
                    if (param == null) {
                        param = new MetaParameter(metaConstructor, index);
                        metaConstructor.addParameter(index, param);
                    }
                    param.addAnnotation(metaConstraint.getAnnotation());
                } else {
                    metaConstructor.addAnnotation(metaConstraint.getAnnotation());
                }
                continue;
            } else { // property level
                meta = metabean.getProperty(access.getPropertyName());
                create = meta == null;
                if (create) {
                    meta = addMetaProperty(metabean, access);
                }
            }
            if (!annotationProcessor.processAnnotation(metaConstraint.getAnnotation(), meta, beanClass,
                metaConstraint.getAccessStrategy(), new AppendValidationToMeta(meta == null ? metabean : meta), false)
                && create) {
                metabean.putProperty(access.getPropertyName(), null);
            }
        }
        for (final AccessStrategy access : factoryContext.getFactory().getValidAccesses(beanClass)) {
            if (access.getElementType() == ElementType.PARAMETER) {
                continue;
            }

            MetaProperty metaProperty = metabean.getProperty(access.getPropertyName());
            boolean create = metaProperty == null;
            if (create) {
                metaProperty = addMetaProperty(metabean, access);
            }
            if (!annotationProcessor.addAccessStrategy(metaProperty, access) && create) {
                metabean.putProperty(access.getPropertyName(), null);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.bval.util.AccessStrategy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.