/**
  * Looks for a property of the reference instance with a given name and type.
  *
  * <p>If found its value is returned. We follow the Java bean conventions with augmentation for
  * groovy support and static fields/properties. We will therefore match, in this order:
  *
  * <ol>
  *   <li>Standard public bean property (with getter or just public field, using normal
  *       introspection)
  *   <li>Public static property with getter method
  *   <li>Public static field
  * </ol>
  *
  * @return property value or null if no property or static field was found
  */
 protected Object getPropertyOrStaticPropertyOrFieldValue(String name, Class type) {
   BeanWrapper ref = getReference();
   Object value = null;
   if (ref.isReadableProperty(name)) {
     value = ref.getPropertyValue(name);
   } else if (GrailsClassUtils.isPublicField(ref.getWrappedInstance(), name)) {
     value = GrailsClassUtils.getFieldValue(ref.getWrappedInstance(), name);
   } else {
     value = GrailsClassUtils.getStaticPropertyValue(clazz, name);
   }
   if ((value != null) && GrailsClassUtils.isGroovyAssignableFrom(type, value.getClass())) {
     return value;
   }
   return null;
 }
  /**
   * Get the value of the named property, with support for static properties in both Java and Groovy
   * classes (which as of Groovy JSR 1.0 RC 01 only have getters in the metaClass)
   *
   * @param name
   * @param type
   * @return The property value or null
   */
  public Object getPropertyValue(String name, Class type) {

    // Handle standard java beans normal or static properties
    BeanWrapper ref = getReference();
    Object value = null;
    if (ref.isReadableProperty(name)) {
      value = ref.getPropertyValue(name);
    } else {
      // Groovy workaround
      Object inst = ref.getWrappedInstance();
      if (inst instanceof GroovyObject) {
        final Map properties = DefaultGroovyMethods.getProperties(inst);
        if (properties.containsKey(name)) {
          value = properties.get(name);
        }
      }
    }

    if (value != null
        && (type.isAssignableFrom(value.getClass())
            || GrailsClassUtils.isMatchBetweenPrimativeAndWrapperTypes(type, value.getClass()))) {
      return value;
    } else {
      return null;
    }
  }
  public DefaultGrailsDomainClassProperty(
      GrailsDomainClass domainClass, PropertyDescriptor descriptor) {
    this.domainClass = domainClass;
    // persistant by default
    this.persistant = true;
    this.name = descriptor.getName();
    this.naturalName = GrailsNameUtils.getNaturalName(descriptor.getName());
    this.type = descriptor.getPropertyType();
    this.identity = descriptor.getName().equals(IDENTITY);

    // establish if property is persistant
    if (domainClass != null) {
      // figure out if this property is inherited
      if (!domainClass.isRoot()) {
        this.inherited = GrailsClassUtils.isPropertyInherited(domainClass.getClazz(), this.name);
      }
      List transientProps = getTransients(domainClass);
      checkIfTransient(transientProps);

      establishFetchMode();
    }
  }
 /** @return the metaClass */
 public MetaClass getMetaClass() {
   return GrailsClassUtils.getExpandoMetaClass(clazz);
 }
 public boolean isEnum() {
   return GrailsClassUtils.isJdk5Enum(getType());
 }