Package org.grails.core
Class AbstractGrailsClass
- java.lang.Object
-
- org.grails.core.AbstractGrailsClass
-
- All Implemented Interfaces:
GrailsClass,GrailsApplicationAware,org.springframework.beans.factory.Aware
- Direct Known Subclasses:
AbstractInjectableGrailsClass,DefaultGrailsClass,DefaultGrailsDomainClass,DefaultGrailsUrlMappingsClass
public abstract class AbstractGrailsClass extends java.lang.Object implements GrailsClass
Abstract base class for Grails types that provides common functionality for evaluating conventions within classes.- Since:
- 0.1
-
-
Field Summary
Fields Modifier and Type Field Description protected GrailsApplicationgrailsApplication
-
Constructor Summary
Constructors Constructor Description AbstractGrailsClass(java.lang.Class<?> clazz, java.lang.String trailingName)Used by all child classes to create a new instance and get the name right.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description GrailsApplicationgetApplication()The GrailsApplication that this class belongs tojava.lang.Class<?>getClazz()Returns the actual clazz represented by the GrailsClass.java.lang.StringgetFullName()Returns the full name of the class in the application with the trailing convention part and with the package name.java.lang.StringgetLogicalPropertyName()Returns the logical name of the class as a property name.groovy.lang.MetaClassgetMetaClass()java.util.List<groovy.lang.MetaProperty>getMetaProperties()java.lang.StringgetName()Returns the logical name of the class in the application without the trailing convention part if applicable and without the package name.java.lang.StringgetNaturalName()Returns the name of the property in natural terms (eg.java.lang.StringgetPackageName()Returns the package name of the class.java.lang.StringgetPluginName()java.beans.PropertyDescriptor[]getPropertyDescriptors()Deprecated.UsegetMetaProperties()insteadjava.lang.StringgetPropertyName()Returns the name of the class as a property name.protected <T> TgetPropertyOrStaticPropertyOrFieldValue(java.lang.String name, java.lang.Class<T> type)Looks for a property of the reference instance with a given name and type.java.lang.Class<?>getPropertyType(java.lang.String typeName)java.lang.ObjectgetPropertyValue(java.lang.String propName)Gets the initial value of the given property on the class.<T> TgetPropertyValue(java.lang.String propName, java.lang.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)java.lang.ObjectgetPropertyValueObject(java.lang.String propertyNAme)java.lang.ObjectgetReferenceInstance()java.lang.StringgetShortName()Returns the short name of the class without package prefix.<T> TgetStaticPropertyValue(java.lang.String propName, java.lang.Class<T> type)Get the value of the named static property.booleanhasMetaMethod(java.lang.String methodName)booleanhasMetaMethod(java.lang.String methodName, java.lang.Object[] args)booleanhasMetaProperty(java.lang.String propName)booleanhasProperty(java.lang.String propName)Returns true if the class has the specified property.booleanisAbstract()Whether the class is abstract or notbooleanisActionMethod(java.lang.String methodName)booleanisReadableProperty(java.lang.String propName)java.lang.ObjectnewInstance()Creates a new instance of this class.voidsetGrailsApplication(GrailsApplication grailsApplication)This method is called by theApplicationContextthat loads the Grails application.java.lang.StringtoString()
-
-
-
Field Detail
-
grailsApplication
protected GrailsApplication grailsApplication
-
-
Constructor Detail
-
AbstractGrailsClass
public AbstractGrailsClass(java.lang.Class<?> clazz, java.lang.String trailingName)Used by all child classes to create a new instance and get the name right.- Parameters:
clazz- the Grails classtrailingName- the trailing part of the name for this class type
-
-
Method Detail
-
getPluginName
public java.lang.String getPluginName()
- Specified by:
getPluginNamein interfaceGrailsClass- Returns:
- The plugin where the artefact originates from
-
setGrailsApplication
public void setGrailsApplication(GrailsApplication grailsApplication)
Description copied from interface:GrailsApplicationAwareThis method is called by the
ApplicationContextthat loads the Grails application. TheGrailsApplicationinstance that represents the loaded Grails application is injected.- Specified by:
setGrailsApplicationin interfaceGrailsApplicationAware- Parameters:
grailsApplication- theGrailsApplicationobject that represents this Grails application
-
getApplication
public GrailsApplication getApplication()
Description copied from interface:GrailsClassThe GrailsApplication that this class belongs to- Specified by:
getApplicationin interfaceGrailsClass- Returns:
- The GrailsApplication instance
-
getShortName
public java.lang.String getShortName()
Description copied from interface:GrailsClassReturns the short name of the class without package prefix.- Specified by:
getShortNamein interfaceGrailsClass- Returns:
- The short name
-
getClazz
public java.lang.Class<?> getClazz()
Description copied from interface:GrailsClassReturns the actual clazz represented by the GrailsClass.- Specified by:
getClazzin interfaceGrailsClass- Returns:
- The class
-
newInstance
public java.lang.Object newInstance()
Description copied from interface:GrailsClassCreates a new instance of this class. This method can be used as factory method in the Spring application context.- Specified by:
newInstancein interfaceGrailsClass- Returns:
- A new instance of this class
-
getName
public java.lang.String getName()
Description copied from interface:GrailsClassReturns the logical name of the class in the application without the trailing convention part if applicable and without the package name.- Specified by:
getNamein interfaceGrailsClass- Returns:
- The logical name
-
getNaturalName
public java.lang.String getNaturalName()
Description copied from interface:GrailsClassReturns the name of the property in natural terms (eg. 'lastName' becomes 'Last Name')- Specified by:
getNaturalNamein interfaceGrailsClass- Returns:
- The natural property name.
-
getFullName
public java.lang.String getFullName()
Description copied from interface:GrailsClassReturns the full name of the class in the application with the trailing convention part and with the package name.- Specified by:
getFullNamein interfaceGrailsClass- Returns:
- The full name
-
getPropertyName
public java.lang.String getPropertyName()
Description copied from interface:GrailsClassReturns the name of the class as a property name.- Specified by:
getPropertyNamein interfaceGrailsClass- Returns:
- The property name representation
-
getLogicalPropertyName
public java.lang.String getLogicalPropertyName()
Description copied from interface:GrailsClassReturns the logical name of the class as a property name.- Specified by:
getLogicalPropertyNamein interfaceGrailsClass- Returns:
- The logical property name
-
getPackageName
public java.lang.String getPackageName()
Description copied from interface:GrailsClassReturns the package name of the class.- Specified by:
getPackageNamein interfaceGrailsClass- Returns:
- The package name
-
getReferenceInstance
public java.lang.Object getReferenceInstance()
- Specified by:
getReferenceInstancein interfaceGrailsClass- Returns:
- Sample (reference) instance for this Grails class
-
getPropertyDescriptors
@Deprecated public java.beans.PropertyDescriptor[] getPropertyDescriptors()
Deprecated.UsegetMetaProperties()instead
-
getMetaProperties
public java.util.List<groovy.lang.MetaProperty> getMetaProperties()
-
getPropertyType
public java.lang.Class<?> getPropertyType(java.lang.String typeName)
-
isReadableProperty
public boolean isReadableProperty(java.lang.String propName)
-
isActionMethod
public boolean isActionMethod(java.lang.String methodName)
-
hasMetaMethod
public boolean hasMetaMethod(java.lang.String methodName)
-
hasMetaMethod
public boolean hasMetaMethod(java.lang.String methodName, java.lang.Object[] args)
-
hasMetaProperty
public boolean hasMetaProperty(java.lang.String propName)
-
getPropertyOrStaticPropertyOrFieldValue
protected <T> T getPropertyOrStaticPropertyOrFieldValue(java.lang.String name, java.lang.Class<T> 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:
- Public static field
- Public static property with getter method
- 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(java.lang.String propName, java.lang.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(java.lang.String propName, java.lang.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:
getPropertyValuein interfaceGrailsClass- Parameters:
propName-type-- Returns:
- The property value or null
-
getPropertyValueObject
public java.lang.Object getPropertyValueObject(java.lang.String propertyNAme)
-
getPropertyValue
public java.lang.Object getPropertyValue(java.lang.String propName)
Description copied from interface:GrailsClassGets the initial value of the given property on the class.- Specified by:
getPropertyValuein interfaceGrailsClass- Parameters:
propName- The name of the property- Returns:
- The initial value
-
isAbstract
public boolean isAbstract()
Description copied from interface:GrailsClassWhether the class is abstract or not- Specified by:
isAbstractin interfaceGrailsClass- Returns:
- true if it is abstract
-
hasProperty
public boolean hasProperty(java.lang.String propName)
Description copied from interface:GrailsClassReturns true if the class has the specified property.- Specified by:
hasPropertyin interfaceGrailsClass- Parameters:
propName- The name of the property- Returns:
- true if it does
-
getMetaClass
public groovy.lang.MetaClass getMetaClass()
- Specified by:
getMetaClassin interfaceGrailsClass- Returns:
- the metaClass
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-