/** * Validate a single property only. Performs all validations * for this property. */ public static <VL extends ValidationListener> void validateProperty(ValidationContext<VL> context) { for (Validation validation : context.getMetaProperty().getValidations()) { validation.validate(context); } } }
protected <T extends ValidationListener> void validateMandatory(ValidationContext<T> context) { if (context.getMetaProperty().isMandatory()) { if (context.getPropertyValue() == null) { context.getListener().addError(MANDATORY, context); } } }
/** * Initialize from {@link ValidationContext}. */ public void init() { this.rawType = validationContext.getMetaBean().getBeanClass(); this.type = this.rawType; }
protected <T extends ValidationListener> void validateMaxValue(ValidationContext<T> context) { @SuppressWarnings("unchecked") Comparable<Object> maxValue = (Comparable<Object>) context.getMetaProperty().getFeature(MAX_VALUE); if (maxValue == null || context.getPropertyValue() == null) return; if (compare(context, maxValue, context.getPropertyValue()) < 0) { context.getListener().addError(MAX_VALUE, context); } }
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; }
/** * Validate a single bean only, no related beans will be validated. */ public static <VL extends ValidationListener> void validateBean(ValidationContext<VL> context) { // execute all property level validations for (MetaProperty prop : context.getMetaBean().getProperties()) { context.setMetaProperty(prop); validateProperty(context); } // execute all bean level validations context.setMetaProperty(null); for (Validation validation : context.getMetaBean().getValidations()) { validation.validate(context); } }
protected void computeRelationships(MetaBean beanInfo, Map<String, MetaBean> cached) { for (MetaProperty prop : beanInfo.getProperties()) { String beanRef = (String) prop.getFeature(REF_BEAN_ID); if (beanRef != null) { prop.setMetaBean(cached.get(beanRef)); } } }
/** * Compute all known relationships for <code>beanInfo</code>. must be called * AFTER cache.cache() to avoid endless loop * * @param beanInfo * - the bean for which to compute relationships */ protected void computeRelationships(MetaBean beanInfo) { for (final MetaProperty prop : beanInfo.getProperties()) { final String beanRef = prop.getFeature(REF_BEAN_ID); computeRelatedMetaBean(prop, beanRef); } }
/** * Resolve the type of this property to a class. * @return Class, <code>null</code> if cannot be determined */ public Class<?> getTypeClass() { Type targetType = type instanceof DynaType ? ((DynaType) type).getRawType() : type; if (targetType == null) { return null; } Type assigningType = getParentMetaBean() == null ? null : getParentMetaBean().getBeanClass(); return TypeUtils.getRawType(targetType, assigningType); }
/** * Create a new BeanDescriptorImpl instance. * * @param factoryContext * @param metaBean */ protected BeanDescriptorImpl(ApacheFactoryContext factoryContext, MetaBean metaBean) { super(metaBean, metaBean.getBeanClass(), metaBean.getValidations()); this.factoryContext = factoryContext; }
/** * {@inheritDoc} */ public <T extends Annotation> void performAppend(ConstraintValidation<T> validation) { feature.addValidation(validation); } }
/** * Get the specified feature. * * @param <T> * @param key * @return T */ public <T> T getFeature(String key) { return getFeature(key, (T) null); }
/** * Convenience method to access metaProperty.name * * @return null or the name of the current property */ @Override public String getPropertyName() { return metaProperty == null ? null : metaProperty.getName(); }
/** * Create a new ConstructorDescriptorImpl instance. * @param metaBean * @param validations */ protected ConstructorDescriptorImpl(MetaBean metaBean, Validation[] validations) { super(metaBean, metaBean.getBeanClass(), validations); }
/** * @param <VL> * @param context * The current validation context. * @return the current {@link DynamicMetaBean} in context, or * <code>null</code> if the current meta bean is not dynamic. */ private static <VL extends ValidationListener> DynamicMetaBean getDynamicMetaBean(ValidationContext<VL> context) { return context.getMetaBean() instanceof DynamicMetaBean ? (DynamicMetaBean) context.getMetaBean() : null; }
/** * Create an Error object. * @param reason * @param owner * @param propertyName * @return new {@link Error} */ protected Error createError(String reason, Object owner, String propertyName) { return new Error(reason, owner, propertyName); }
/** * Create a new DynaTypeEnum instance. * @param enumClass * @param names */ public DynaTypeEnum(Class<?> enumClass, String... names) { this(enumClass); setEnumNames(names); }
@Override public MetaBean getParentMetaBean() { return invocable.getParentMetaBean(); } }
/** * Set the enumeration value names. * @param names */ public void setEnumNames(String[] names) { enumConstants = new Value[names.length]; int i = 0; for (String each : names) { enumConstants[i++] = new Value(each); } }
protected <T extends ValidationListener> void validateMinValue(ValidationContext<T> context) { @SuppressWarnings("unchecked") Comparable<Object> minValue = (Comparable<Object>) context.getMetaProperty().getFeature(MIN_VALUE); if (minValue == null || context.getPropertyValue() == null) return; if (compare(context, minValue, context.getPropertyValue()) > 0) { context.getListener().addError(MIN_VALUE, context); } }