private static void applyLength(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( "org.hibernate.validator.constraints.Length".equals( descriptor.getAnnotation().annotationType().getName() ) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") int max = (Integer) descriptor.getAttributes().get( "max" ); @SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator(); if ( itor.hasNext() ) { final Selectable selectable = itor.next(); if ( Column.class.isInstance( selectable ) ) { Column col = (Column) selectable; if ( max < Integer.MAX_VALUE ) { col.setLength( max ); } } } } }
private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( Size.class.equals( descriptor.getAnnotation().annotationType() ) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor; int max = sizeConstraint.getAnnotation().max(); @SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator(); if ( itor.hasNext() ) { final Selectable selectable = itor.next(); Column col = (Column) selectable; if ( max < Integer.MAX_VALUE ) { col.setLength( max ); } } } }
private static void applyLength(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( "org.hibernate.validator.constraints.Length".equals(descriptor.getAnnotation().annotationType().getName()) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") int max = (Integer) descriptor.getAttributes().get( "max" ); Column col = ( Column ) property.getColumnIterator().next(); if ( max < Integer.MAX_VALUE ) { col.setLength( max ); } } }
private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( Size.class.equals( descriptor.getAnnotation().annotationType() ) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") ConstraintDescriptor<Size> sizeConstraint = ( ConstraintDescriptor<Size> ) descriptor; int max = sizeConstraint.getAnnotation().max(); Column col = ( Column ) property.getColumnIterator().next(); if ( max < Integer.MAX_VALUE ) { col.setLength( max ); } } }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_ELEMENTDESCRIPTOR, id = "a") public void testGetElementClass() { PropertyDescriptor descriptor = getPropertyDescriptor( Order.class, "orderNumber" ); assertEquals( descriptor.getElementClass(), Integer.class, "Wrong element class" ); }
private static void applyLength(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( "org.hibernate.validator.constraints.Length".equals( descriptor.getAnnotation().annotationType().getName() ) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") int max = (Integer) descriptor.getAttributes().get( "max" ); Column col = (Column) property.getColumnIterator().next(); if ( max < Integer.MAX_VALUE ) { col.setLength( max ); } } }
private static void applyLength(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( "org.hibernate.validator.constraints.Length".equals( descriptor.getAnnotation().annotationType().getName() ) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") int max = (Integer) descriptor.getAttributes().get( "max" ); Column col = (Column) property.getColumnIterator().next(); if ( max < Integer.MAX_VALUE ) { col.setLength( max ); } } }
/** * Returns the class of a given property, but only if it is a constrained property of the * parent class. Otherwise, it returns null. */ final private static Class<?> getConstrainedPropertyClass(BeanDescriptor beanDescriptor, String propertyName) { Class<?> clasz = null; for (PropertyDescriptor descriptor : beanDescriptor.getConstrainedProperties()) { if (descriptor.getPropertyName().equals(propertyName)) { clasz = descriptor.getElementClass(); break; } } return clasz; }
/** * Returns the class of a given property, but only if it is a constrained property of the * parent class. Otherwise, it returns null. */ final private static Class<?> getConstrainedPropertyClass(BeanDescriptor beanDescriptor, String propertyName) { Class<?> clasz = null; for (PropertyDescriptor descriptor : beanDescriptor.getConstrainedProperties()) { if (descriptor.getPropertyName().equals(propertyName)) { clasz = descriptor.getElementClass(); break; } } return clasz; }
private static void applyLength( PersistentAttributeMapping property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( "org.hibernate.validator.constraints.Length".equals( descriptor.getAnnotation().annotationType().getName() ) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") final int max = (Integer) descriptor.getAttributes().get( "max" ); final Column col = getColumn( property ); if ( max < Integer.MAX_VALUE ) { col.setLength( (long) max ); } } }
private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( Size.class.equals( descriptor.getAnnotation().annotationType() ) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor; int max = sizeConstraint.getAnnotation().max(); Column col = (Column) property.getColumnIterator().next(); if ( max < Integer.MAX_VALUE ) { col.setLength( max ); } } }
private static void applySize(PersistentAttributeMapping property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( Size.class.equals( descriptor.getAnnotation().annotationType() ) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") final ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor; final int max = sizeConstraint.getAnnotation().max(); final Column col = getColumn( property ); if ( max < Integer.MAX_VALUE ) { col.setLength( (long) max ); } } }
private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) { if ( Size.class.equals( descriptor.getAnnotation().annotationType() ) && String.class.equals( propertyDescriptor.getElementClass() ) ) { @SuppressWarnings("unchecked") ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor; int max = sizeConstraint.getAnnotation().max(); Column col = (Column) property.getColumnIterator().next(); if ( max < Integer.MAX_VALUE ) { col.setLength( max ); } } }
/** * Build a list of {@link org.resthub.web.validation.ValidationConstraint} associated to a given * {@link javax.validation.metadata.PropertyDescriptor} <tt>pd</tt> instance and a given {@link java.util.Locale} * <tt>locale</tt> */ private List<ValidationConstraint> getValidationConstraints(PropertyDescriptor pd, Locale locale) { List<ValidationConstraint> validationConstraints = new ArrayList<ValidationConstraint>(); // copy any directly defined constraint into wrapper for (ConstraintDescriptor cd : pd.getConstraintDescriptors()) { ValidationConstraint validationConstraint = new ValidationConstraint(); validationConstraint.setType(this.getType(cd)); validationConstraint.setMessage(this.getMessage(cd, locale)); validationConstraint.setAttributes(this.getAttributes(cd)); validationConstraints.add(validationConstraint); } // manage cascading option by adding a custom "Valid" type and referencing underling model class name if (pd.isCascaded()) { ValidationConstraint validationConstraint = new ValidationConstraint(); validationConstraint.setType("Valid"); validationConstraint.addAttribute("model", pd.getElementClass().getCanonicalName()); validationConstraints.add(validationConstraint); } return validationConstraints; }
/** * Creates the appropriate BeanHelper for a property on a bean. */ private void doCreateHelperForProp(PropertyDescriptor p, BeanHelper parent, TreeLogger logger, GeneratorContext context) throws UnableToCompleteException { Class<?> elementClass = p.getElementClass(); if (GwtSpecificValidatorCreator.isIterableOrMap(elementClass)) { if (parent.hasField(p)) { JClassType type = parent.getAssociationType(p, true); createHelper(type.getErasedType(), logger, context); } if (parent.hasGetter(p)) { JClassType type = parent.getAssociationType(p, false); createHelper(type.getErasedType(), logger, context); } } else { if (serverSideValidator.getConstraintsForClass(elementClass).isBeanConstrained()) { createHelper(elementClass, logger, context); } } }
sw.println(ppropertyDescription.getElementClass().getCanonicalName() + ".class,");
/** * Creates the appropriate BeanHelper for a property on a bean. */ private void doCreateHelperForProp(PropertyDescriptor p, BeanHelper parent, TreeLogger logger, GeneratorContext context) throws UnableToCompleteException { Class<?> elementClass = p.getElementClass(); if (GwtSpecificValidatorCreator.isIterableOrMap(elementClass)) { if (parent.hasField(p)) { JClassType type = parent.getAssociationType(p, true); createHelper(type.getErasedType(), logger, context); } if (parent.hasGetter(p)) { JClassType type = parent.getAssociationType(p, false); createHelper(type.getErasedType(), logger, context); } } else { if (serverSideValidator.getConstraintsForClass(elementClass).isBeanConstrained()) { createHelper(elementClass, logger, context); } } }
/** * Creates the appropriate BeanHelper for a property on a bean. */ private void doCreateHelperForProp(final PropertyDescriptor propertyDescriptor, final BeanHelper parent, final TreeLogger logger, final GeneratorContext context) throws UnableToCompleteException { final Class<?> elementClass = propertyDescriptor.getElementClass(); if (GwtSpecificValidatorCreator.isIterableOrMap(elementClass)) { if (parent.hasField(propertyDescriptor)) { final JClassType type = parent.getAssociationType(propertyDescriptor, true); this.createHelper(type.getErasedType(), logger, context); } if (parent.hasGetter(propertyDescriptor)) { final JClassType type = parent.getAssociationType(propertyDescriptor, false); this.createHelper(type.getErasedType(), logger, context); } } else { if (serverSideValidator.getConstraintsForClass(elementClass).isBeanConstrained()) { this.createHelper(elementClass, logger, context); } } }
sw.indent(); if (!isIterableOrMap(property.getElementClass())) { writeValidatePropertyCall(sw, property, true, false);
sw.indent(); if (!isIterableOrMap(property.getElementClass())) { writeValidatePropertyCall(sw, property, true, false);