Package org.apache.bval.model

Examples of org.apache.bval.model.MetaBean


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

        MetaBean metaBean = validationContext.getMetaBean();

        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


     */
    static protected <VL extends ValidationListener> void validateArrayInContext(ValidationContext<VL> context, ValidateCallback s) {
        int index = 0;
        DynamicMetaBean dyn = getDynamicMetaBean(context);
        Object[] array = (Object[]) context.getBean();
        MetaBean metaBean = context.getMetaBean();
        context.setCurrentIndex(null);

        try {
            for (Object each : array) {
                context.setCurrentIndex(index++);
View Full Code Here

    static protected <VL extends ValidationListener> void validateIterableInContext(ValidationContext<VL> context, ValidateCallback s) {

        final boolean positional = context.getBean() instanceof List<?>;
        int index = 0;
        Iterable<?> iterable = (Iterable<?>) context.getBean();
        MetaBean metaBean = context.getMetaBean();
        context.setCurrentIndex(null);

        try {
            // jsr303 spec: Each object provided by the iterator is validated.
            final DynamicMetaBean dyn = getDynamicMetaBean(context);
View Full Code Here

     */
    static protected <VL extends ValidationListener> void validateMapInContext(ValidationContext<VL> context, ValidateCallback s) {
        // jsr303 spec: For Map, the value of each Map.Entry is validated (key
        // is not validated).
        Map<?, ?> currentBean = (Map<?, ?>) context.getBean();
        MetaBean metaBean = context.getMetaBean();
        final DynamicMetaBean dyn = getDynamicMetaBean(context);
        context.setCurrentKey(null);
        try {
            for (Map.Entry<?, ?> entry : currentBean.entrySet()) {
                Object value = entry.getValue();
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.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

        final AnnotationConstraintBuilder<A> builder =
            new AnnotationConstraintBuilder<A>(factoryContext.getConstraintValidatorFactory(), constraintClasses, annotation, owner, access, null);

        // JSR-303 3.4.4: Add implicit groups
        if (prop != null && prop.getParentMetaBean() != null) {
            MetaBean parentMetaBean = prop.getParentMetaBean();
            // If:
            // - the owner is an interface
            // - the class of the metabean being build is different than the
            // owner
            // - and only the Default group is defined
            // Then: add the owner interface as implicit groups
            if (builder.getConstraintValidation().getOwner().isInterface()
                && parentMetaBean.getBeanClass() != builder.getConstraintValidation().getOwner()
                && builder.getConstraintValidation().getGroups().size() == 1
                && builder.getConstraintValidation().getGroups().contains(Default.class)) {
                Set<Class<?>> groups = builder.getConstraintValidation().getGroups();
                groups.add(builder.getConstraintValidation().getOwner());
                builder.getConstraintValidation().setGroups(groups);
View Full Code Here

        checkGroups(groups);

        try {

            final Class<T> objectClass = (Class<T>) object.getClass();
            final MetaBean objectMetaBean = metaBeanFinder.findForClass(objectClass);
            final GroupValidationContext<T> context = createContext(objectMetaBean, object, objectClass, groups);
            return validateBeanWithGroups(context, context.getGroups());
        } catch (final RuntimeException ex) {
            throw unrecoverableValidationError(ex, object);
        }
View Full Code Here

    public BeanDescriptor getConstraintsForClass(final Class<?> clazz) {
        if (clazz == null) {
            throw new IllegalArgumentException("Class cannot be null");
        }
        try {
            final MetaBean metaBean = metaBeanFinder.findForClass(clazz); // don't throw an exception because of a missing validator here
            BeanDescriptorImpl edesc = metaBean.getFeature(JsrFeatures.Bean.BEAN_DESCRIPTOR);
            if (edesc == null) {
                edesc = metaBean.initFeature(JsrFeatures.Bean.BEAN_DESCRIPTOR, createBeanDescriptor(metaBean));
            }
            return edesc;
        } catch (final ConstraintDefinitionException definitionEx) {
            throw definitionEx;
        } catch (final ConstraintDeclarationException declarationEx) {
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.