Ejemplo n.º 1
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);
  }
Ejemplo n.º 2
0
  protected DataRepositoryService getRepoService() {
    if (dataRepositoryService == null) {
      ApplicationContext ac = ApplicationHolder.getApplication().getMainContext();
      dataRepositoryService = ac.getBean(DataRepositoryService.class);
    }

    return dataRepositoryService;
  }
Ejemplo n.º 3
0
 @SuppressWarnings("unchecked")
 private Map resolveConstrainedProperties(Object object) {
   GrailsApplication grailsApplication = ApplicationHolder.getApplication();
   return resolveConstrainedProperties(
       object,
       (grailsApplication != null)
           ? ((GrailsDomainClass)
               grailsApplication.getArtefact(
                   DomainClassArtefactHandler.TYPE, object.getClass().getName()))
           : null);
 }
Ejemplo n.º 4
0
 private Class<?> getReferencedTypeForCollection(String name, Object target) {
   final GrailsApplication grailsApplication = ApplicationHolder.getApplication();
   if (grailsApplication != null) {
     GrailsDomainClass dc =
         (GrailsDomainClass)
             grailsApplication.getArtefact(
                 DomainClassArtefactHandler.TYPE, target.getClass().getName());
     if (dc != null) {
       GrailsDomainClassProperty domainProperty = dc.getPropertyByName(name);
       if (domainProperty != null) {
         return domainProperty.getReferencedPropertyType();
       }
     }
   }
   return null;
 }
Ejemplo n.º 5
0
 public DomainBuilder() {
   setChildPropertySetter(new DefaultGrailsChildPropertySetter());
   setClassLoader(ApplicationHolder.getApplication().getClassLoader());
 }