Package org.apache.bval.model

Examples of org.apache.bval.model.MetaProperty


        if (metaBean instanceof DynamicMetaBean) {
            metaBean = metaBean.resolveMetaBean(ObjectUtils.defaultIfNull(validationContext.getBean(), rawType));
            validationContext.setMetaBean(metaBean);
        }
        MetaProperty mp = metaBean.getProperty(token);
        if (mp == null) {
            // TODO this could indicate a property hosted on a superclass; should we shunt the context traversal down a path based on that type?

            PropertyAccess access = new PropertyAccess(rawType, token);
            if (access.isKnown()) {
                // add heretofore unknown, but valid, property on the fly:
                mp = JsrMetaBeanFactory.addMetaProperty(metaBean, access);
            } else {
                throw new UnknownPropertyException("unknown property '" + token + "' in " + metaBean.getId());
            }
        }
        validationContext.setMetaProperty(mp);
        setType(mp.getType());
    }
View Full Code Here


     * another property.
     *
     * @param validationContext
     */
    public void moveDownIfNecessary() {
        MetaProperty mp = validationContext.getMetaProperty();
        if (mp != null) {
            if (mp.getMetaBean() == null) {
                throw new UnknownPropertyException(String.format("Property %s.%s is not cascaded", mp
                    .getParentMetaBean().getId(), mp.getName()));
            }
            validationContext.moveDown(mp, new NullSafePropertyAccess(validationContext.getMetaBean().getBeanClass(),
                mp.getName()));
        }
    }
View Full Code Here

     */
    public PropertyDescriptor getConstraintsForProperty(String propertyName) {
        if (propertyName == null || propertyName.trim().length() == 0) {
            throw new IllegalArgumentException("propertyName cannot be null or empty");
        }
        MetaProperty prop = metaBean.getProperty(propertyName);
        if (prop == null)
            return null;
        // If no constraints and not cascaded, return null
        if (prop.getValidations().length == 0 && prop.getFeature(Features.Property.REF_CASCADE) == null) {
            return null;
        }
        return getPropertyDescriptor(prop);
    }
View Full Code Here

                        throw new ConstraintDeclarationException("@Valid on returned value can't be set more than once");
                    }
                }

                if (getter) {
                    final MetaProperty prop = metaBean.getProperty(Introspector.decapitalize(method.getName().substring(3)));
                    if (prop != null && prop.getFeature(Features.Property.REF_CASCADE) != null) {
                        methodDesc.setCascaded(true);
                    }
                }

                if (!methodDesc.getGroupConversions().isEmpty() && !methodDesc.isCascaded()) {
View Full Code Here

        if (meta.getName() == null && info.getBeanDescriptor() != null) {
            meta.setName(info.getBeanDescriptor().getName()); // (display?)name = simple class name!
        }
        for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
            if (!(pd instanceof IndexedPropertyDescriptor || pd.getName().equals("class"))) {
                MetaProperty metaProp = buildMetaProperty(pd, meta.getProperty(pd.getName()));
                meta.putProperty(pd.getName(), metaProp);
            }
        }
    }
View Full Code Here

     * @param pd
     * @param existing
     * @return MetaProperty
     */
    protected MetaProperty buildMetaProperty(PropertyDescriptor pd, MetaProperty existing) {
        MetaProperty meta = new MetaProperty();
        meta.setName(pd.getName());
        meta.setType(determineGenericPropertyType(pd));
        if (pd.isHidden()) {
            meta.putFeature(HIDDEN, Boolean.TRUE);
        }
        if (pd.isPreferred()) {
            meta.putFeature(PREFERRED, Boolean.TRUE);
        }
        if (pd.isConstrained()) {
            meta.putFeature(READONLY, Boolean.TRUE);
        }
        Enumeration<String> enumeration = pd.attributeNames();
        while (enumeration.hasMoreElements()) {
            String key = enumeration.nextElement();
            Object value = pd.getValue(key);
            meta.putFeature(key, value);
        }
        return meta;
    }
View Full Code Here

  }

  public void testBeanInfosCustomPatchGenerated()
      throws Exception {
    MetaBean mbean = mbm.findForClass(BusinessObject.class);
    MetaProperty mprop = mbean.getProperty("lastName");
    assertTrue(mprop.isMandatory());

    mbm.getCache().removeFromCache(mbean);
    mbm.addLoader(new XMLMetaBeanURLLoader(
        BusinessObject.class.getResource("test-beanInfos-custom.xml")));
    mbean = mbm.findForClass(BusinessObject.class);
    mprop = mbean.getProperty("lastName");
    assertTrue(!mprop.isMandatory());

    JSONGenerator converter = new JSONGenerator();

    List<MetaBean> metaBeans = new ArrayList(2);
    metaBeans.add(mbean);
View Full Code Here

    //System.out.println(json);
  }

  public void testJSON_dynaTypeEnum() throws Exception {
    MetaBean info = mbm.findForClass(BusinessObject.class);
    MetaProperty choice = info.getProperty("choice");
    choice.setType(new DynaTypeEnum(BusinessEnum.class, "CUSTOM_1", "CUSTOM_2"));

    JSONGenerator converter = new JSONGenerator();

    List<MetaBean> metaBeans = new ArrayList(1);
    metaBeans.add(info);
View Full Code Here

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

        final Field[] fields = Reflection.INSTANCE.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 (!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) {
                        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();
    }
View Full Code Here

        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) {
View Full Code Here

TOP

Related Classes of org.apache.bval.model.MetaProperty

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.