Package org.apache.bval.model

Examples of org.apache.bval.model.MetaProperty


    public void testValidationResults() throws Exception {
        assertTrue(results.isEmpty());
        BeanValidationContext ctx = new BeanValidationContext(results);
        ctx.setBean(this);
        ctx.setMetaProperty(new MetaProperty());
        ctx.getMetaProperty().setName("prop");
        results.addError("test", ctx);
        assertFalse(results.isEmpty());
        assertTrue(results.hasErrorForReason("test"));
        assertTrue(results.hasError(this, "prop"));
View Full Code Here


     */
    public PropertyDescriptor getConstraintsForProperty(String propertyName) {
        if (propertyName == null || propertyName.isEmpty()) {
            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

                                "']' missing, invalid property format: " + propertyPath);
                    }
                    useIndexedValue(idx);
                    resolveMetaBean();
                } else if (!".".equals(token)) { // it is a property name
                    MetaProperty mp = getMetaBean().getProperty(token);
                    if (mp == null) {
                        throw new UnknownPropertyException(
                                "unknown property '" + token + "' in " + getMetaBean().getId());
                    }
                    if (getValue() != null) {
View Full Code Here

                  new AppendValidationToMeta(metabean));
        }

        Field[] fields = beanClass.getDeclaredFields();
        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)) {
                if (metaProperty == null) {
                    metaProperty = addMetaProperty(metabean, field.getName(), field.getType());
                    processAnnotations(metaProperty, beanClass, field,
                          new FieldAccess(field),
                          new AppendValidationToMeta(metaProperty));//) {
                } else {
                    processAnnotations(metaProperty, beanClass, field,
                          new FieldAccess(field),
                          new AppendValidationToMeta(metaProperty));
                }
            }
        }
        Method[] methods = beanClass.getDeclaredMethods();
        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)) {
                    MetaProperty metaProperty = metabean.getProperty(propName);
                    // create a property for those methods for which there is not yet a MetaProperty
                    if (metaProperty == null) {
                        metaProperty =
                              addMetaProperty(metabean, propName, method.getReturnType());
                        processAnnotations(metaProperty, beanClass, method,
View Full Code Here

    /** add cascade validation and constraints from xml mappings */
    private void addXmlConstraints(Class<?> beanClass, MetaBean metabean)
          throws IllegalAccessException, InvocationTargetException {
        for (MetaConstraint<?, ? extends Annotation> meta : factoryContext.getFactory()
              .getMetaConstraints(beanClass)) {
            MetaProperty metaProperty;
            if (meta.getAccessStrategy() == null) { // class level
                metaProperty = null;
            } else { // property level
                metaProperty =
                      metabean.getProperty(meta.getAccessStrategy().getPropertyName());
                if (metaProperty == null) {
                    metaProperty = addMetaProperty(metabean,
                          meta.getAccessStrategy().getPropertyName(),
                          meta.getAccessStrategy().getJavaType());
                }
            }
            Class<? extends ConstraintValidator<?, ?>>[] constraintClasses =
                  findConstraintValidatorClasses(meta.getAnnotation(), null);
            applyConstraint(meta.getAnnotation(), constraintClasses, metaProperty, beanClass,
                  meta.getAccessStrategy(), new AppendValidationToMeta(
                  metaProperty == null ? metabean : metaProperty));
        }
        for (AccessStrategy access : factoryContext.getFactory().getValidAccesses(beanClass)) {
            MetaProperty metaProperty = metabean.getProperty(access.getPropertyName());
            if (metaProperty == null) {
                metaProperty =
                      addMetaProperty(metabean, access.getPropertyName(), access.getJavaType());
            }
            processValid(metaProperty, access);
View Full Code Here

            processValid(metaProperty, access);
        }
    }

    private MetaProperty addMetaProperty(MetaBean parentMetaBean, String propName, Type type) {
        MetaProperty metaProperty;
        metaProperty = new MetaProperty();
        metaProperty.setName(propName);
        metaProperty.setType(type);
        parentMetaBean.putProperty(propName, metaProperty);
        return metaProperty;
    }
View Full Code Here

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

            }
        }
    }

    protected MetaProperty buildMetaProperty(PropertyDescriptor pd) {
        MetaProperty meta = new MetaProperty();
        meta.setName(pd.getName());
//        meta.setDisplayName(pd.getDisplayName());
        meta.setType(pd.getPropertyType());
        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 testValidationResults() throws Exception {
        assertTrue(results.isEmpty());
        BeanValidationContext ctx = new BeanValidationContext(results);
        ctx.setBean(this);
        ctx.setMetaProperty(new MetaProperty());
        ctx.getMetaProperty().setName("prop");
        results.addError("test", ctx);
        assertFalse(results.isEmpty());
        assertTrue(results.hasErrorForReason("test"));
        assertTrue(results.hasError(this, "prop"));
View Full Code Here

    public void setUp() throws Exception {
        super.setUp();
        validation = new StandardValidation();
        context = new BeanValidationContext<StandardValidationTest>(this);
        metaProperty = new MetaProperty();
        context.setBean(this, null);
        context.setMetaProperty(metaProperty);
    }
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.