Package org.apache.bval.model

Examples of org.apache.bval.model.MetaBean


        }
    }

    public MetaBean findForClass(Class<?> clazz) {
        if (clazz == null) return null;
        MetaBean beanInfo = cache.findForClass(clazz);
        if (beanInfo != null) return beanInfo;
        try {
            beanInfo = builder.buildForClass(clazz);
            cache.cache(beanInfo);
            computeRelationships(beanInfo);
View Full Code Here


        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.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);
    MetaBean mbean2 = mbm.findForId("UnknownObject");
    metaBeans.add(mbean2);
    String json = converter.toJSON(metaBeans);
    assertNotNull(json);
    //System.out.println(json);
  }
View Full Code Here

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

  public void testJSON() throws Exception {
    MetaBean info = mbm.findForClass(BusinessObject.class);
    MetaBean info2 = info.getProperty("address").getMetaBean();

    // empty default bean without xml backup
    MetaBean info3 = mbm.findForClass(BusinessObjectAddress.class);
    JSONGenerator converter = new JSONGenerator();

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

    assertNotNull(json);
    //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);
View Full Code Here

     * @param clazz
     * @return MetaBean
     * @throws Exception
     */
    public MetaBean buildForClass(Class<?> clazz) throws Exception {
        MetaBean meta = new MetaBean();
        if (clazz != null) { // local class here?
            meta.setBeanClass(clazz);
            meta.setId(clazz.getName()); // default id = full class name!
        }
        for (MetaBeanFactory factory : factories) {
            factory.buildMetaBean(meta);
        }
        return meta;
View Full Code Here

     *
     * @param bean
     * @return results - validation results found
     */
    public T validate(Object bean) {
        MetaBean metaBean = getMetaBeanFinder().findForClass(bean.getClass());
        return validate(bean, metaBean);
    }
View Full Code Here

        AccessStrategy[] access = prop.getFeature(Features.Property.REF_CASCADE);
        if (access == null && prop.getMetaBean() != null) { // single property
                                                            // access strategy
            // save old values from context
            final Object bean = context.getBean();
            final MetaBean mbean = context.getMetaBean();
            // modify context state for relationship-target bean
            context.moveDown(prop, new PropertyAccess(bean.getClass(), prop.getName()));
            ValidationHelper.validateContext(context, new BeanValidatorCallback(context), treatMapsLikeBeans);
            // restore old values in context
            context.moveUp(bean, mbean);
        } else if (access != null) { // different accesses to relation
            // save old values from context
            final Object bean = context.getBean();
            final MetaBean mbean = context.getMetaBean();
            for (AccessStrategy each : access) {
                // modify context state for relationship-target bean
                context.moveDown(prop, each);
                ValidationHelper.validateContext(context, new BeanValidatorCallback(context), treatMapsLikeBeans);
                // restore old values in context
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public MetaBean findForId(final String beanInfoId) {
        MetaBean beanInfo = cache.findForId(beanInfoId);
        if (beanInfo != null) {
            return beanInfo;
        }

        try {
View Full Code Here

    public MetaBean findForClass(final Class<?> clazz) {
        if (clazz == null) {
            return null;
        }

        MetaBean beanInfo = cache.findForClass(clazz);
        if (beanInfo != null) {
            return beanInfo;
        }

        try {
View Full Code Here

        mbm = new XMLMetaBeanManager();
        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);
        MetaBean mbean2 = mbm.findForId("UnknownObject");
        metaBeans.add(mbean2);
        String json = converter.toJSON(metaBeans);
        assertNotNull(json);
        // System.out.println(json);
    }
View Full Code Here

TOP

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

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.