Package groovy.lang

Examples of groovy.lang.MetaProperty


    }
   
    static public boolean isJavaBeanPropertyWritable(Object instance, String propertyName) {
       
        MetaClass mc = InvokerHelper.getMetaClass(instance);
        MetaProperty metaProperty = mc.getMetaProperty(propertyName);
        if(metaProperty != null) {
            String setterName = MetaProperty.getSetterName(propertyName);
            return !mc.respondsTo(instance, setterName, new Class[]{metaProperty.getType()}).isEmpty();
        } else if(instance instanceof Script) {
            return ((Script)instance).getProperty(propertyName) != null;
        }
        return false;
    }
View Full Code Here


        }
    }
   
    static public ReadOnlyProperty getJavaBeanFXReadOnlyProperty(Object instance, String propertyName) throws NoSuchMethodException {
        MetaClass mc = InvokerHelper.getMetaClass(instance);
        MetaProperty metaProperty = mc.getMetaProperty(propertyName);
        if(metaProperty != null) {
            Class type = metaProperty.getType();
            if(type == Boolean.class || type == Boolean.TYPE) {
                ReadOnlyJavaBeanBooleanPropertyBuilder builder = ReadOnlyJavaBeanBooleanPropertyBuilder.create();
                builder.bean(instance);
                builder.name(propertyName);
                builder.beanClass(instance.getClass());
View Full Code Here

    }
    static public Property getJavaBeanFXWritableProperty(Object instance, String propertyName) throws NoSuchMethodException {
        MetaClass mc = InvokerHelper.getMetaClass(instance);
        //Object a = mc.getAttribute(instance, propertyName);
        MetaProperty metaProperty = mc.getMetaProperty(propertyName);
        if(metaProperty != null) {
            Class type = metaProperty.getType();
            if(type == Boolean.class || type == Boolean.TYPE) {
                JavaBeanBooleanPropertyBuilder builder = JavaBeanBooleanPropertyBuilder.create();
                builder.bean(instance);
                builder.name(propertyName);
                builder.beanClass(instance.getClass());
View Full Code Here

  /**
   * We see if there is a MetaProperty on the object with this key name, if so, we get its value.
   * Otherwise we retrieve any possible value in this map.
   */
  @Override public Object get(Object key) {
    MetaProperty prop = object.getMetaClass().getMetaProperty(String.valueOf(key));
    if (prop != null) return prop.getProperty(object);
    return super.get(key);
  }
View Full Code Here

  /**
   * We see if there is a MetaProperty on the object with this key name, if so, we try to set its value.
   * Otherwise we store the value in this map.
   */
  @Override public Object put(K key, Object value) {
    MetaProperty prop = object.getMetaClass().getMetaProperty(String.valueOf(key));
    if (prop != null) {
      Object oldValue = prop.getProperty(object);
      prop.setProperty(object, value);
      return oldValue;
    }
    return super.put(key, value);
  }
View Full Code Here

    if (expectedType != null) return expectedType;
    if (parent == null) return expectedType = Object.class;
    Object p = this.parent.get();
    if (p == null) return Object.class;
    MetaClass mc = InvokerHelper.getMetaClass(p);
    MetaProperty mp = mc.getMetaProperty(name);
    return expectedType = (mp == null ? Object.class : mp.getType());
//    try {
//      return expectedType = p.getClass().getField(name).getType();
//    } catch (NoSuchFieldException e) {
//      try {
//        Method m = p.getClass().getMethod("get" + name.substring(0, 1).toUpperCase() + name.substring(1));
View Full Code Here

      ((SelfAttributeApplicator)instance).applyAttributes(attributes);
    } else {
      MetaClass mc = ofi.getMetaClassForNode(nodeName);
      if (mc.getTheClass() != instance.getClass()) mc = InvokerHelper.getMetaClass(instance.getClass());
      for (Object key : attributes.keySet()) {
        MetaProperty prop = mc.getMetaProperty(String.valueOf(key));
        if (prop == null) {
          try {
            Field field = mc.getTheClass().getField(String.valueOf(key));
            field.set(instance, attributes.get(key));
          }
          catch (SecurityException e) {}
          catch (NoSuchFieldException e) {}
          catch (IllegalAccessException e) {}
         
          throw new RuntimeException("Could not find " + key + " property/attribute on " + instance);
        } else {
          prop.setProperty(instance, attributes.get(key));
        }
      }
    }
  }
View Full Code Here

                            ref.parent, ref.childName, child));

            // set parent afterwards
            String propertyName = relationNameResolver.resolveParentRelationName(ref.parentName,
                    ref.parent, ref.childName, child);
            MetaProperty metaProperty = InvokerHelper.getMetaClass(child)
                    .hasProperty(child, propertyName);
            if (metaProperty != null) {
                metaProperty.setProperty(child, ref.parent);
            }
        }
    }
View Full Code Here

        public String resolveChildRelationName(String parentName, Object parent, String childName,
                                               Object child) {
            boolean matchesIESRule = PLURAL_IES_PATTERN.matcher(childName).matches();
            String childNamePlural = matchesIESRule ? childName.substring(0, childName.length() - 1) + "ies" : childName + "s";

            MetaProperty metaProperty = InvokerHelper.getMetaClass(parent)
                    .hasProperty(parent, childNamePlural);

            return metaProperty != null ? childNamePlural : childName;
        }
View Full Code Here

                    parentName = (String) parentContext.get(NODE_NAME);
                }

                String propertyName = ogbuilder.relationNameResolver.resolveParentRelationName(
                        parentName, parent, childName, child);
                MetaProperty metaProperty = InvokerHelper.getMetaClass(child)
                        .hasProperty(child, propertyName);
                if (metaProperty != null) {
                    metaProperty.setProperty(child, parent);
                }
            }
        }
View Full Code Here

TOP

Related Classes of groovy.lang.MetaProperty

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.