Package org.apache.bval.model

Examples of org.apache.bval.model.MetaProperty


        super(name);
    }


    public void testGetTypeClass() throws Exception {
        MetaProperty prop = new MetaProperty();
        prop.setType(String.class);
        assertEquals(String.class, prop.getTypeClass());
        assertEquals(String.class, prop.getType());
        prop.setType(new DynaTypeEnum(BusinessEnum.class, BusinessEnum.VALUE1.name(),
              BusinessEnum.VALUE3.name()));
        assertEquals(BusinessEnum.class, prop.getTypeClass());
        assertEquals(2, ((DynaTypeEnum)prop.getType()).getEnumConstants().length);
    }
View Full Code Here


    }

    private static final String REG_EXP_PATTERN = "cachedRegExpPattern";

    protected <T extends ValidationListener> void validateRegExp(ValidationContext<T> context) {
        final MetaProperty meta = context.getMetaProperty();
        final String regExp = (String) meta.getFeature(REG_EXP);
        if (regExp == null) return;
        if (context.getPropertyValue() == null) return;

        final String value = String.valueOf(context.getPropertyValue());
        try {
            Pattern pattern = (Pattern) meta.getFeature(REG_EXP_PATTERN);
            if (pattern == null) {
                pattern = Pattern.compile(regExp);
                meta.putFeature(REG_EXP_PATTERN, pattern);
            }
            if (!pattern.matcher(value).matches()) {
                context.getListener().addError(REG_EXP, context);
            }
        } catch (PatternSyntaxException e) {
View Full Code Here

        }
    }

    protected MetaProperty enrichElement(MetaBean meta, XMLMetaElement xmlProp,
                                         XMLResult result) throws Exception {
        MetaProperty prop = meta.getProperty(xmlProp.getName());
        if (prop == null) {
            prop = new MetaProperty();
            prop.setName(xmlProp.getName());
            meta.putProperty(xmlProp.getName(), prop);
        }
        xmlProp.mergeInto(prop);
        enrichValidations(prop, xmlProp, result, true);
        return prop;
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.getBuilder().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

        mbm.addLoader(new XMLMetaBeanURLLoader(BusinessObject.class.getResource("test-beanInfos.xml")));
    }

    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<MetaBean>(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<MetaBean>(1);
        metaBeans.add(info);
View Full Code Here

        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 = Jsr303MetaBeanFactory.addMetaProperty(metaBean, access);
            } else {
                throw new UnknownPropertyException("unknown property '" + token + "' in " + metaBean.getId());
            }
        }
        validationContext.setMetaProperty(mp);
        setType(mp.getType());
    }
View Full Code Here

        }
    }

    protected MetaProperty enrichElement(MetaBean meta, XMLMetaElement xmlProp,
                                         XMLResult result) throws Exception {
        MetaProperty prop = meta.getProperty(xmlProp.getName());
        if (prop == null) {
            prop = new MetaProperty();
            prop.setName(xmlProp.getName());
            meta.putProperty(xmlProp.getName(), prop);
        }
        xmlProp.mergeInto(prop);
        enrichValidations(prop, xmlProp, result, true);
        return prop;
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

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.