org.codehaus.groovy.grails.commons
Class AbstractGrailsClass

java.lang.Object
  extended by org.codehaus.groovy.grails.commons.AbstractGrailsClass
All Implemented Interfaces:
GrailsClass
Direct Known Subclasses:
AbstractGrailsPlugin.GrailsPluginClass, AbstractInjectableGrailsClass, DefaultGrailsBootstrapClass, DefaultGrailsClass, DefaultGrailsDomainClass, DefaultGrailsUrlMappingsClass, GrailsHibernateDomainClass

public abstract class AbstractGrailsClass
extends Object
implements GrailsClass

Abstract base class for Grails types that provides common functionality for evaluating conventions within classes.

Since:
0.1
Author:
Steven Devijver, Graeme Rocher

Constructor Summary
AbstractGrailsClass(Class<?> clazz, String trailingName)
          Used by all child classes to create a new instance and get the name right.
 
Method Summary
 Class<?> getClazz()
          Returns the actual clazz represented by the GrailsClass.
 String getFullName()
          Returns the full name of the class in the application with the the trailing convention part and with the package name.
 String getLogicalPropertyName()
          Returns the logical name of the class as a property name.
 groovy.lang.MetaClass getMetaClass()
           
 String getName()
          Returns the logical name of the class in the application without the trailing convention part if applicable and without the package name.
 String getNaturalName()
          Returns the name of the property in natural terms (eg.
 String getPackageName()
          Returns the package name of the class.
 PropertyDescriptor[] getPropertyDescriptors()
           
 String getPropertyName()
          Returns the name of the class as a property name.
protected  Object getPropertyOrStaticPropertyOrFieldValue(String name, Class<?> type)
          Looks for a property of the reference instance with a given name and type.
 Class<?> getPropertyType(String typeName)
           
 Object getPropertyValue(String propName)
          Gets the initial value of the given property on the class.
<T> T
getPropertyValue(String propName, Class<T> type)
          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)
 Object getPropertyValueObject(String propertyNAme)
           
 BeanWrapper getReference()
          Deprecated.  
 Object getReferenceInstance()
           
 String getShortName()
          Returns the short name of the class without package prefix.
<T> T
getStaticPropertyValue(String propName, Class<T> type)
          Get the value of the named static property.
 boolean hasMetaMethod(String methodName)
           
 boolean hasMetaMethod(String methodName, Object[] args)
           
 boolean hasMetaProperty(String propName)
           
 boolean hasProperty(String propName)
          Returns true if the class has the specified property.
 boolean isReadableProperty(String propName)
           
 Object newInstance()
          Creates a new instance of this class.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractGrailsClass

public AbstractGrailsClass(Class<?> clazz,
                           String trailingName)
Used by all child classes to create a new instance and get the name right.

Parameters:
clazz - the Grails class
trailingName - the trailing part of the name for this class type
Method Detail

getShortName

public String getShortName()
Description copied from interface: GrailsClass
Returns the short name of the class without package prefix.

Specified by:
getShortName in interface GrailsClass
Returns:
The short name

getClazz

public Class<?> getClazz()
Description copied from interface: GrailsClass
Returns the actual clazz represented by the GrailsClass.

Specified by:
getClazz in interface GrailsClass
Returns:
the class

newInstance

public Object newInstance()
Description copied from interface: GrailsClass
Creates a new instance of this class. This method can be used as factory method in the Spring application context.

Specified by:
newInstance in interface GrailsClass
Returns:
a new instance of this class

getName

public String getName()
Description copied from interface: GrailsClass
Returns the logical name of the class in the application without the trailing convention part if applicable and without the package name.

Specified by:
getName in interface GrailsClass
Returns:
the logical name

getNaturalName

public String getNaturalName()
Description copied from interface: GrailsClass
Returns the name of the property in natural terms (eg. 'lastName' becomes 'Last Name')

Specified by:
getNaturalName in interface GrailsClass
Returns:
The natural property name.

getFullName

public String getFullName()
Description copied from interface: GrailsClass
Returns the full name of the class in the application with the the trailing convention part and with the package name.

Specified by:
getFullName in interface GrailsClass
Returns:
the full name

getPropertyName

public String getPropertyName()
Description copied from interface: GrailsClass
Returns the name of the class as a property name.

Specified by:
getPropertyName in interface GrailsClass
Returns:
The property name representation

getLogicalPropertyName

public String getLogicalPropertyName()
Description copied from interface: GrailsClass
Returns the logical name of the class as a property name.

Specified by:
getLogicalPropertyName in interface GrailsClass
Returns:
The logical property name

getPackageName

public String getPackageName()
Description copied from interface: GrailsClass
Returns the package name of the class.

Specified by:
getPackageName in interface GrailsClass
Returns:
the package name

getReferenceInstance

public Object getReferenceInstance()
Specified by:
getReferenceInstance in interface GrailsClass
Returns:
Sample (reference) instance for this Grails class

getPropertyDescriptors

public PropertyDescriptor[] getPropertyDescriptors()

getPropertyType

public Class<?> getPropertyType(String typeName)

isReadableProperty

public boolean isReadableProperty(String propName)

hasMetaMethod

public boolean hasMetaMethod(String methodName)

hasMetaMethod

public boolean hasMetaMethod(String methodName,
                             Object[] args)

hasMetaProperty

public boolean hasMetaProperty(String propName)

getReference

@Deprecated
public BeanWrapper getReference()
Deprecated. 

Used to get configured property values.

Specified by:
getReference in interface GrailsClass
Returns:
BeanWrapper instance that holds reference

getPropertyOrStaticPropertyOrFieldValue

protected Object getPropertyOrStaticPropertyOrFieldValue(String name,
                                                         Class<?> type)

Looks for a property of the reference instance with a given name and type.

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:

  1. Public static field
  2. Public static property with getter method
  3. Standard public bean property (with getter or just public field, using normal introspection)

Returns:
property value or null if no property or static field was found

getStaticPropertyValue

public <T> T getStaticPropertyValue(String propName,
                                    Class<T> type)
Get the value of the named static property.

Parameters:
propName -
type -
Returns:
The property value or null

getPropertyValue

public <T> T getPropertyValue(String propName,
                              Class<T> type)
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)

Specified by:
getPropertyValue in interface GrailsClass
Parameters:
propName -
type -
Returns:
The property value or null

getPropertyValueObject

public Object getPropertyValueObject(String propertyNAme)

getPropertyValue

public Object getPropertyValue(String propName)
Description copied from interface: GrailsClass
Gets the initial value of the given property on the class.

Specified by:
getPropertyValue in interface GrailsClass
Parameters:
propName - The name of the property
Returns:
The initial value

hasProperty

public boolean hasProperty(String propName)
Description copied from interface: GrailsClass
Returns true if the class has the specified property.

Specified by:
hasProperty in interface GrailsClass
Parameters:
propName - The name of the property
Returns:
True if it does

getMetaClass

public groovy.lang.MetaClass getMetaClass()
Specified by:
getMetaClass in interface GrailsClass
Returns:
the metaClass

toString

public String toString()
Overrides:
toString in class Object