private ConstrainedProperty getConstrainedProperty(String propertyName) {
   BeanWrapper constrainedBean = new BeanWrapperImpl(new TestClass());
   return new ConstrainedProperty(
       constrainedBean.getWrappedClass(),
       propertyName,
       constrainedBean.getPropertyType(propertyName));
 }
Пример #2
0
 @SuppressWarnings("unchecked")
 private boolean isEmbedded(BeanWrapper wrapper, String propertyName) {
   Object embedded =
       GrailsClassUtils.getStaticPropertyValue(
           wrapper.getWrappedClass(), GrailsDomainClassProperty.EMBEDDED);
   return embedded instanceof List && ((List) embedded).contains(propertyName);
 }
Пример #3
0
  /**
   * Create a new GrailsDataBinder instance.
   *
   * @param target target object to bind onto
   * @param objectName objectName of the target object
   */
  @SuppressWarnings("unchecked")
  public GrailsDataBinder(Object target, String objectName) {
    super(target, objectName);

    setAutoGrowNestedPaths(false);
    bean =
        (BeanWrapper) ((BeanPropertyBindingResult) super.getBindingResult()).getPropertyAccessor();

    Object tmpTransients =
        GrailsClassUtils.getStaticPropertyValue(
            bean.getWrappedClass(), GrailsDomainClassProperty.TRANSIENT);
    if (tmpTransients instanceof List) {
      transients = (List) tmpTransients;
    }

    String[] disallowed = new String[0];
    GrailsApplication grailsApplication = ApplicationHolder.getApplication();
    if (grailsApplication != null
        && grailsApplication.isArtefactOfType(DomainClassArtefactHandler.TYPE, target.getClass())) {
      if (target instanceof GroovyObject) {
        disallowed = GROOVY_DOMAINCLASS_DISALLOWED;
      } else {
        disallowed = DOMAINCLASS_DISALLOWED;
      }
      domainClass =
          (GrailsDomainClass)
              grailsApplication.getArtefact(
                  DomainClassArtefactHandler.TYPE, target.getClass().getName());
    } else if (target instanceof GroovyObject) {
      disallowed = GROOVY_DISALLOWED;
    }
    setDisallowedFields(disallowed);
    setAllowedFields(ALL_OTHER_FIELDS_ALLOWED_BY_DEFAULT);
    setIgnoreInvalidFields(true);
  }
 protected Errors validateConstraint(Constraint constraint, Object value, Boolean shouldVeto) {
   BeanWrapper constrainedBean = new BeanWrapperImpl(new TestClass());
   constrainedBean.setPropertyValue(constraint.getPropertyName(), value);
   Errors errors =
       new BindException(
           constrainedBean.getWrappedInstance(), constrainedBean.getWrappedClass().getName());
   if (!(constraint instanceof VetoingConstraint) || shouldVeto == null) {
     constraint.validate(constrainedBean.getWrappedInstance(), value, errors);
   } else {
     boolean vetoed =
         ((VetoingConstraint) constraint)
             .validateWithVetoing(constrainedBean.getWrappedInstance(), value, errors);
     if (shouldVeto.booleanValue() && !vetoed) fail("Constraint should veto");
     else if (!shouldVeto.booleanValue() && vetoed) fail("Constraint shouldn't veto");
   }
   return errors;
 }
Пример #5
0
 /**
  * Set the value for this attribute
  *
  * @param value
  */
 public void setValue(Object value) {
   Class claz = sourceObject.getPropertyType(attribute);
   if (claz == null)
     throw new IllegalArgumentException(
         "Atribute "
             + attribute
             + " does not exist in class "
             + sourceObject.getWrappedClass()
             + ". Cannot set value:"
             + value);
   value = ObjectConverter.convert(value, claz);
   sourceObject.setPropertyValue(attribute, value);
   //        if((sourceObject.getWrappedInstance() instanceof BindingComponent) &&
   // !(sourceObject.getWrappedInstance() instanceof BndIJComboBox)){
   //            logger.info("Setting bindingComponent ...");
   //
   //            ((BindingComponent)sourceObject.getWrappedInstance()).setValueToJComponent();
   //        }
 }