org.codehaus.groovy.grails.commons
Class DefaultGrailsDomainClass

java.lang.Object
  extended by org.codehaus.groovy.grails.commons.AbstractGrailsClass
      extended by org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass
All Implemented Interfaces:
GrailsClass, GrailsDomainClass

public class DefaultGrailsDomainClass
extends AbstractGrailsClass
implements GrailsDomainClass

Since:
05-Jul-2005
Author:
Graeme Rocher

Field Summary
 
Fields inherited from interface org.codehaus.groovy.grails.commons.GrailsDomainClass
GORM, ORM_MAPPING
 
Constructor Summary
DefaultGrailsDomainClass(Class clazz)
           
 
Method Summary
 Map getAssociationMap()
          Retrieves the association map
 Map getConstrainedProperties()
          Returns a map of constraints applied to this domain class with the keys being the property name and the values being ConstrainedProperty instances
 String getFieldName(String propertyName)
          Returns the field name for the given property name
 GrailsDomainClassProperty getIdentifier()
          Returns the identifier property
 Map getMappedBy()
           
 String getMappingStrategy()
           
 String getName()
          Returns the logical name of the class in the application without the trailing convention part if applicable and without the package name.
 GrailsDomainClassProperty[] getPersistantProperties()
          Deprecated.  
 GrailsDomainClassProperty[] getPersistentProperties()
          Returns all of the persistant properties of the domain class
 GrailsDomainClassProperty[] getProperties()
          Returns all of the properties of the domain class
 GrailsDomainClassProperty getPropertyByName(String name)
          Returns the property for the given name
 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 getRelatedClassType(String propertyName)
          Returns the type of the related class of the given property
 Set getSubClasses()
          Returns the sub-classes for this class if any
 Validator getValidator()
          Retreives the validator for this domain class
 GrailsDomainClassProperty getVersion()
          Returns the version property
 boolean hasPersistentProperty(String propertyName)
          Returns true if this domain class has a persistent property for the given name
 boolean hasSubClasses()
          Returns true if the domain classes has sub classes
 boolean isBidirectional(String propertyName)
          Returns true if the given property is a bi-directional relationship
 boolean isManyToOne(String propertyName)
          Returns true if the given property is a many to one relationship
 boolean isOneToMany(String propertyName)
          Returns true if the given property is a one to many relationship
 boolean isOwningClass(Class domainClass)
           
 boolean isRoot()
          Whether the class is the root of a heirarchy
 void refreshConstraints()
          Refreshes the constraint defined on a domain class
 void setMappingStrategy(String strategy)
          Sets the strategy to use for ORM mapping.
 void setValidator(Validator validator)
          Sets the validator for this domain class
 
Methods inherited from class org.codehaus.groovy.grails.commons.AbstractGrailsClass
getClazz, getFullName, getLogicalPropertyName, getMetaClass, getNaturalName, getPackageName, getPropertyValue, getPropertyValue, getReference, getShortName, hasProperty, newInstance, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.codehaus.groovy.grails.commons.GrailsClass
getClazz, getFullName, getLogicalPropertyName, getMetaClass, getNaturalName, getPackageName, getPropertyValue, getPropertyValue, getReference, getShortName, hasProperty, newInstance
 

Constructor Detail

DefaultGrailsDomainClass

public DefaultGrailsDomainClass(Class clazz)
Method Detail

hasSubClasses

public boolean hasSubClasses()
Description copied from interface: GrailsDomainClass
Returns true if the domain classes has sub classes

Specified by:
hasSubClasses in interface GrailsDomainClass
Returns:
True if it does

getAssociationMap

public Map getAssociationMap()
Retrieves the association map

Specified by:
getAssociationMap in interface GrailsDomainClass
Returns:
The association map

isOwningClass

public boolean isOwningClass(Class domainClass)
Specified by:
isOwningClass in interface GrailsDomainClass
Returns:
True if the specifying domain class is on the owning side of a relationship

getProperties

public GrailsDomainClassProperty[] getProperties()
Description copied from interface: GrailsDomainClass
Returns all of the properties of the domain class

Specified by:
getProperties in interface GrailsDomainClass
Returns:
The domain class properties

getIdentifier

public GrailsDomainClassProperty getIdentifier()
Description copied from interface: GrailsDomainClass
Returns the identifier property

Specified by:
getIdentifier in interface GrailsDomainClass
Returns:
The identifier property

getVersion

public GrailsDomainClassProperty getVersion()
Description copied from interface: GrailsDomainClass
Returns the version property

Specified by:
getVersion in interface GrailsDomainClass
Returns:
The version property

getPersistantProperties

public GrailsDomainClassProperty[] getPersistantProperties()
Deprecated. 

Description copied from interface: GrailsDomainClass
Returns all of the persistant properties of the domain class

Specified by:
getPersistantProperties in interface GrailsDomainClass
Returns:
The domain class' persistant properties
See Also:
GrailsDomainClass.getPersistantProperties()

getPersistentProperties

public GrailsDomainClassProperty[] getPersistentProperties()
Description copied from interface: GrailsDomainClass
Returns all of the persistant properties of the domain class

Specified by:
getPersistentProperties in interface GrailsDomainClass
Returns:
The domain class' persistant properties

getPropertyByName

public GrailsDomainClassProperty getPropertyByName(String name)
Description copied from interface: GrailsDomainClass
Returns the property for the given name

Specified by:
getPropertyByName in interface GrailsDomainClass
Parameters:
name - The property for the name
Returns:
The domain class property for the given name

getFieldName

public String getFieldName(String propertyName)
Description copied from interface: GrailsDomainClass
Returns the field name for the given property name

Specified by:
getFieldName in interface GrailsDomainClass
Returns:
The field representation of the property name

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
Overrides:
getName in class AbstractGrailsClass
Returns:
the logical name

isOneToMany

public boolean isOneToMany(String propertyName)
Description copied from interface: GrailsDomainClass
Returns true if the given property is a one to many relationship

Specified by:
isOneToMany in interface GrailsDomainClass
Parameters:
propertyName - The name of the property
Returns:
A boolean value

isManyToOne

public boolean isManyToOne(String propertyName)
Description copied from interface: GrailsDomainClass
Returns true if the given property is a many to one relationship

Specified by:
isManyToOne in interface GrailsDomainClass
Parameters:
propertyName - The name of the property
Returns:
A boolean value

getPropertyOrStaticPropertyOrFieldValue

protected Object getPropertyOrStaticPropertyOrFieldValue(String name,
                                                         Class type)
Description copied from class: AbstractGrailsClass

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. Standard public bean property (with getter or just public field, using normal introspection)
  2. Public static property with getter method
  3. Public static field

Overrides:
getPropertyOrStaticPropertyOrFieldValue in class AbstractGrailsClass
Returns:
property value or null if no property or static field was found

getRelatedClassType

public Class getRelatedClassType(String propertyName)
Description copied from interface: GrailsDomainClass
Returns the type of the related class of the given property

Specified by:
getRelatedClassType in interface GrailsDomainClass
Parameters:
propertyName - The name of the property
Returns:
The type of the class or null if no relationship exists for the specified property

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
Specified by:
getPropertyName in interface GrailsDomainClass
Overrides:
getPropertyName in class AbstractGrailsClass
Returns:
The property name representation

isBidirectional

public boolean isBidirectional(String propertyName)
Description copied from interface: GrailsDomainClass
Returns true if the given property is a bi-directional relationship

Specified by:
isBidirectional in interface GrailsDomainClass
Parameters:
propertyName - The name of the property
Returns:
A boolean value

getConstrainedProperties

public Map getConstrainedProperties()
Description copied from interface: GrailsDomainClass
Returns a map of constraints applied to this domain class with the keys being the property name and the values being ConstrainedProperty instances

Specified by:
getConstrainedProperties in interface GrailsDomainClass
Returns:
A map of constraints

getValidator

public Validator getValidator()
Description copied from interface: GrailsDomainClass
Retreives the validator for this domain class

Specified by:
getValidator in interface GrailsDomainClass
Returns:
A validator instance or null if none exists

setValidator

public void setValidator(Validator validator)
Description copied from interface: GrailsDomainClass
Sets the validator for this domain class

Specified by:
setValidator in interface GrailsDomainClass
Parameters:
validator - The domain class validator to set

getMappingStrategy

public String getMappingStrategy()
Specified by:
getMappingStrategy in interface GrailsDomainClass
Returns:
The name of the ORM implementation used to map the domain class (default is "GORM")

isRoot

public boolean isRoot()
Description copied from interface: GrailsDomainClass
Whether the class is the root of a heirarchy

Specified by:
isRoot in interface GrailsDomainClass
Returns:
True if it is the root of the heirarchy

getSubClasses

public Set getSubClasses()
Description copied from interface: GrailsDomainClass
Returns the sub-classes for this class if any

Specified by:
getSubClasses in interface GrailsDomainClass
Returns:
A set of sub classes or an empty set if none exist

refreshConstraints

public void refreshConstraints()
Description copied from interface: GrailsDomainClass
Refreshes the constraint defined on a domain class

Specified by:
refreshConstraints in interface GrailsDomainClass

getMappedBy

public Map getMappedBy()
Specified by:
getMappedBy in interface GrailsDomainClass
Returns:
The map that defines association mappings

hasPersistentProperty

public boolean hasPersistentProperty(String propertyName)
Description copied from interface: GrailsDomainClass
Returns true if this domain class has a persistent property for the given name

Specified by:
hasPersistentProperty in interface GrailsDomainClass
Parameters:
propertyName - The property name
Returns:
True if it does

setMappingStrategy

public void setMappingStrategy(String strategy)
Description copied from interface: GrailsDomainClass
Sets the strategy to use for ORM mapping. Default is GORM

Specified by:
setMappingStrategy in interface GrailsDomainClass
Parameters:
strategy - The mapping strategy


Copyright (c) 2005-2009 The Grails project