/** * Set this property as being mandatory (or not). * @param mandatory * @see {@link Features.Property#MANDATORY} */ public void setMandatory(boolean mandatory) { putFeature(MANDATORY, Boolean.valueOf(mandatory)); }
/** * Add the specified {@link AccessStrategy} to <code>prop</code>; noop if * <code>prop == null</code>. * * @param prop * @param access * @return whether anything took place. */ public boolean addAccessStrategy(MetaProperty prop, AccessStrategy access) { if (prop == null) { return false; } AccessStrategy[] strategies = prop.getFeature(Features.Property.REF_CASCADE); if (strategies == null) { strategies = new AccessStrategy[] { access }; prop.putFeature(Features.Property.REF_CASCADE, strategies); } else if (!ArrayUtils.contains(strategies, access)) { prop.putFeature(Features.Property.REF_CASCADE, ArrayUtils.add(strategies, access)); } return true; }
private PropertyDescriptor getPropertyDescriptor(MetaProperty prop) { PropertyDescriptorImpl edesc = prop.getFeature(Jsr303Features.Property.PropertyDescriptor); if (edesc == null) { edesc = new PropertyDescriptorImpl(prop); prop.putFeature(Jsr303Features.Property.PropertyDescriptor, edesc); } return edesc; }
@Override public void mergeInto(MetaProperty prop) throws ClassNotFoundException { super.mergeInto(prop); // call super! if (getMaxValue() != null) { prop.putFeature(MAX_VALUE, getMaxValue()); } if (getMinValue() != null) { prop.putFeature(MIN_VALUE, getMinValue()); } if (getRegexp() != null) { prop.putFeature(REG_EXP, getRegexp()); } if (getTimeLag() != null) { prop.putFeature(TIME_LAG, getTimeLag()); } } }
@Override public void mergeInto(MetaProperty prop) throws ClassNotFoundException { super.mergeInto(prop); // call super! if (getBeanId() != null) { prop.putFeature(Features.Property.REF_BEAN_ID, getBeanId()); } } }
/** * Create a {@link MetaProperty} from the specified {@link PropertyDescriptor}. * * @param pd * @param existing * @return MetaProperty */ protected MetaProperty buildMetaProperty(PropertyDescriptor pd, MetaProperty existing) { MetaProperty meta = new MetaProperty(); meta.setName(pd.getName()); meta.setType(determineGenericPropertyType(pd)); 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; }
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) { throw new IllegalArgumentException("regular expression malformed. regexp " + regExp + " at " + context, e); } }
public void mergeInto(MetaProperty prop) throws ClassNotFoundException { mergeFeaturesInto(prop); if (getType() != null && getType().length() > 0) { prop.setType(Reflection.toClass(getType())); // enhancement: or use getGenericType() ? } if (getHidden() != null) { prop.putFeature(HIDDEN, getHidden().booleanValue()); } if (getMandatory() != null) { prop.putFeature(MANDATORY, getMandatory().equals("true")); } if (getMaxLength() != null) { prop.putFeature(MAX_LENGTH, getMaxLength()); } if (getMinLength() != null) { prop.putFeature(MIN_LENGTH, getMinLength()); } if (getReadonly() != null) { prop.putFeature(READONLY, getReadonly()); } if (getDenied() != null) { prop.putFeature(DENIED, getDenied()); } } }