org.codehaus.groovy.grails.commons
Class DefaultGrailsDomainClassProperty

java.lang.Object
  extended by org.codehaus.groovy.grails.commons.DefaultGrailsDomainClassProperty
All Implemented Interfaces:
GrailsDomainClassProperty

public class DefaultGrailsDomainClassProperty
extends Object
implements GrailsDomainClassProperty

A class that represents a property of a domain class and contains meta information about the properties relationships, naming conventions and type

Since:
0.1 Created: 05-Jul-2005
Author:
Graeme Rocher

Field Summary
 
Fields inherited from interface org.codehaus.groovy.grails.commons.GrailsDomainClassProperty
BELONGS_TO, CLASS, CONSTRAINTS, DATE_CREATED, EMBEDDED, EVANESCENT, FETCH_EAGER, FETCH_LAZY, FETCH_MODE, HAS_MANY, IDENTITY, LAST_UPDATED, MAPPED_BY, MAPPING, MAPPING_STRATEGY, META_CLASS, RELATES_TO_MANY, SORT, TRANSIENT, VERSION
 
Constructor Summary
DefaultGrailsDomainClassProperty(GrailsDomainClass domainClass, PropertyDescriptor descriptor)
           
 
Method Summary
 boolean equals(Object o)
          Overriddent equals to take into account inherited properties e.g. childClass.propertyName is equal to parentClass.propertyName if the types match and childClass.property.isInherited
 GrailsDomainClass getComponent()
          If #isEmbedded returns true then this method can be called to obtain a reference to the embedded component, which implements the GrailsDomainClass interface
 GrailsDomainClass getDomainClass()
          Returns the parent domain class of the property instance
 int getFetchMode()
          Returns the configured fetch mode for the property
 String getFieldName()
          Returns the domain field name for this property
 String getName()
          Returns the name of the property
 String getNaturalName()
           
 GrailsDomainClassProperty getOtherSide()
          Returns the other side of a bidirectional association
 GrailsDomainClass getReferencedDomainClass()
          Returns the GrailsDomainClass of a relationship property or null if the property is not a relationship property
 String getReferencedPropertyName()
          Retrieves the name of property referenced by this property if it is an association and is known, otherwise null
 Class getReferencedPropertyType()
          Returns the referenced property type.
 Class getType()
          Returns the type for the domain class
 String getTypePropertyName()
          Returns the class type as a property name representation
 boolean isAssociation()
          Returns true if this property is a relationship property
 boolean isBasicCollectionType()
          Return whether this is a collection of basic types like String, Integer etc.
 boolean isBidirectional()
          Returns true if the property is a bi-directional relationship
 boolean isCircular()
          Whether the relationship is cirucular
 boolean isEmbedded()
          Returns true if this propert is an embedded component
 boolean isEnum()
          Returns true if this properties type is an enum
 boolean isIdentity()
          Returns true of the property is an identifier
 boolean isInherited()
          Whether the property is inherited from a super class
 boolean isManyToMany()
          Returns true if the property is a many-to-many relationship
 boolean isManyToOne()
          Returns true if the property is a many-to-one relationship
 boolean isOneToMany()
          Returns true if the property is a one-to-many relationship
 boolean isOneToOne()
          Returns true if the property is a one-to-one relationship
 boolean isOptional()
          Returns true if the property is required
 boolean isOwningSide()
          Whether this side of the association is the "owning" side
 boolean isPersistent()
          Returns true if the domain class property is a persistent property
 void setBasicCollectionType(boolean b)
           
protected  void setBidirectional(boolean bidirectional)
          Sets whether the relationship is bidirectional or not
 void setEmbedded(boolean isEmbedded)
           
protected  void setManyToMany(boolean manyToMany)
           
protected  void setManyToOne(boolean manyToOne)
           
protected  void setOneToMany(boolean oneToMany)
           
protected  void setOneToOne(boolean oneToOne)
           
 void setOtherSide(GrailsDomainClassProperty property)
          Sets the other side of an associative property
 void setOwningSide(boolean b)
           
protected  void setPersistant(boolean persistant)
           
 void setReferencedDomainClass(GrailsDomainClass referencedDomainClass)
          Sets the references domain class on the property
protected  void setReferencedPropertyType(Class referencedPropertyType)
          Sets the referenced property type of this property
 void setReferencePropertyName(String name)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultGrailsDomainClassProperty

public DefaultGrailsDomainClassProperty(GrailsDomainClass domainClass,
                                        PropertyDescriptor descriptor)
Method Detail

getName

public String getName()
Description copied from interface: GrailsDomainClassProperty
Returns the name of the property

Specified by:
getName in interface GrailsDomainClassProperty
Returns:
The property name

getType

public Class getType()
Description copied from interface: GrailsDomainClassProperty
Returns the type for the domain class

Specified by:
getType in interface GrailsDomainClassProperty
Returns:
The property type

isPersistent

public boolean isPersistent()
Description copied from interface: GrailsDomainClassProperty
Returns true if the domain class property is a persistent property

Specified by:
isPersistent in interface GrailsDomainClassProperty
Returns:
Whether the property is persistent

isOptional

public boolean isOptional()
Description copied from interface: GrailsDomainClassProperty
Returns true if the property is required

Specified by:
isOptional in interface GrailsDomainClassProperty
Returns:
Whether the property is optional

isIdentity

public boolean isIdentity()
Description copied from interface: GrailsDomainClassProperty
Returns true of the property is an identifier

Specified by:
isIdentity in interface GrailsDomainClassProperty
Returns:
Whether the property is the identifier

isOneToMany

public boolean isOneToMany()
Description copied from interface: GrailsDomainClassProperty
Returns true if the property is a one-to-many relationship

Specified by:
isOneToMany in interface GrailsDomainClassProperty
Returns:
Whether it is a oneToMany

isManyToOne

public boolean isManyToOne()
Description copied from interface: GrailsDomainClassProperty
Returns true if the property is a many-to-one relationship

Specified by:
isManyToOne in interface GrailsDomainClassProperty
Returns:
Whether it is a manyToOne

getFieldName

public String getFieldName()
Description copied from interface: GrailsDomainClassProperty
Returns the domain field name for this property

Specified by:
getFieldName in interface GrailsDomainClassProperty

isOneToOne

public boolean isOneToOne()
Description copied from interface: GrailsDomainClassProperty
Returns true if the property is a one-to-one relationship

Specified by:
isOneToOne in interface GrailsDomainClassProperty
Returns:
True if it is a one-to-one relationship

getDomainClass

public GrailsDomainClass getDomainClass()
Description copied from interface: GrailsDomainClassProperty
Returns the parent domain class of the property instance

Specified by:
getDomainClass in interface GrailsDomainClassProperty
Returns:
The parent domain class

isManyToMany

public boolean isManyToMany()
Description copied from interface: GrailsDomainClassProperty
Returns true if the property is a many-to-many relationship

Specified by:
isManyToMany in interface GrailsDomainClassProperty
Returns:
True if it is a manyToMany

setManyToMany

protected void setManyToMany(boolean manyToMany)
Parameters:
manyToMany - The manyToMany to set.

setOneToMany

protected void setOneToMany(boolean oneToMany)
Parameters:
oneToMany - The oneToMany to set.

setManyToOne

protected void setManyToOne(boolean manyToOne)
Parameters:
manyToOne - The manyToOne to set.

setOneToOne

protected void setOneToOne(boolean oneToOne)
Parameters:
oneToOne - The oneToOne to set.

setPersistant

protected void setPersistant(boolean persistant)
Parameters:
persistant - The persistant to set.

setBidirectional

protected void setBidirectional(boolean bidirectional)
Sets whether the relationship is bidirectional or not


getTypePropertyName

public String getTypePropertyName()
Description copied from interface: GrailsDomainClassProperty
Returns the class type as a property name representation

Specified by:
getTypePropertyName in interface GrailsDomainClassProperty
Returns:
The property name representation

getReferencedPropertyType

public Class getReferencedPropertyType()
Description copied from interface: GrailsDomainClassProperty

Returns the referenced property type. This differs from getType() in that in the case of an Association it will return the type of the elements contained within the Collection, otherwise it will delegate to getType();

Specified by:
getReferencedPropertyType in interface GrailsDomainClassProperty
Returns:
The referenced type

isBidirectional

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

Specified by:
isBidirectional in interface GrailsDomainClassProperty
Returns:
A boolean value

setReferencedPropertyType

protected void setReferencedPropertyType(Class referencedPropertyType)
Sets the referenced property type of this property


getReferencedDomainClass

public GrailsDomainClass getReferencedDomainClass()
Description copied from interface: GrailsDomainClassProperty
Returns the GrailsDomainClass of a relationship property or null if the property is not a relationship property

Specified by:
getReferencedDomainClass in interface GrailsDomainClassProperty
Returns:
The GrailsDomainClass

setReferencedDomainClass

public void setReferencedDomainClass(GrailsDomainClass referencedDomainClass)
Description copied from interface: GrailsDomainClassProperty
Sets the references domain class on the property

Specified by:
setReferencedDomainClass in interface GrailsDomainClassProperty

isAssociation

public boolean isAssociation()
Description copied from interface: GrailsDomainClassProperty
Returns true if this property is a relationship property

Specified by:
isAssociation in interface GrailsDomainClassProperty
Returns:
True if it is an associative property

isEnum

public boolean isEnum()
Description copied from interface: GrailsDomainClassProperty
Returns true if this properties type is an enum

Specified by:
isEnum in interface GrailsDomainClassProperty
Returns:
True if it is

getNaturalName

public String getNaturalName()
Specified by:
getNaturalName in interface GrailsDomainClassProperty
Returns:
The natural name representation of the property (eg. 'lastName' becomes 'Last Name'

toString

public String toString()
Overrides:
toString in class Object

getOtherSide

public GrailsDomainClassProperty getOtherSide()
Description copied from interface: GrailsDomainClassProperty

Returns the other side of a bidirectional association

Specified by:
getOtherSide in interface GrailsDomainClassProperty
Returns:
The other side of the relationship or null if not known

setOtherSide

public void setOtherSide(GrailsDomainClassProperty property)
Description copied from interface: GrailsDomainClassProperty
Sets the other side of an associative property

Specified by:
setOtherSide in interface GrailsDomainClassProperty

isInherited

public boolean isInherited()
Description copied from interface: GrailsDomainClassProperty
Whether the property is inherited from a super class

Specified by:
isInherited in interface GrailsDomainClassProperty
Returns:
True if its inherited

getFetchMode

public int getFetchMode()
Description copied from interface: GrailsDomainClassProperty
Returns the configured fetch mode for the property

Specified by:
getFetchMode in interface GrailsDomainClassProperty

isOwningSide

public boolean isOwningSide()
Description copied from interface: GrailsDomainClassProperty
Whether this side of the association is the "owning" side

Specified by:
isOwningSide in interface GrailsDomainClassProperty
Returns:
True if it is the owning side

setOwningSide

public void setOwningSide(boolean b)
Specified by:
setOwningSide in interface GrailsDomainClassProperty

isCircular

public boolean isCircular()
Description copied from interface: GrailsDomainClassProperty
Whether the relationship is cirucular

Specified by:
isCircular in interface GrailsDomainClassProperty
Returns:
True if it is

setReferencePropertyName

public void setReferencePropertyName(String name)

getReferencedPropertyName

public String getReferencedPropertyName()
Description copied from interface: GrailsDomainClassProperty
Retrieves the name of property referenced by this property if it is an association and is known, otherwise null

Specified by:
getReferencedPropertyName in interface GrailsDomainClassProperty
Returns:
The name of the prop

isEmbedded

public boolean isEmbedded()
Description copied from interface: GrailsDomainClassProperty
Returns true if this propert is an embedded component

Specified by:
isEmbedded in interface GrailsDomainClassProperty
Returns:
True if it is, false otherwise

getComponent

public GrailsDomainClass getComponent()
Description copied from interface: GrailsDomainClassProperty
If #isEmbedded returns true then this method can be called to obtain a reference to the embedded component, which implements the GrailsDomainClass interface

Specified by:
getComponent in interface GrailsDomainClassProperty
Returns:
The component or null if it is not an embedded component
See Also:
GrailsDomainClass, GrailsDomainClassProperty.isEmbedded()

setEmbedded

public void setEmbedded(boolean isEmbedded)

equals

public boolean equals(Object o)
Overriddent equals to take into account inherited properties e.g. childClass.propertyName is equal to parentClass.propertyName if the types match and childClass.property.isInherited

Overrides:
equals in class Object
Parameters:
o - the Object to compare this property to
Returns:
boolean indicating equality of the two objects

setBasicCollectionType

public void setBasicCollectionType(boolean b)

isBasicCollectionType

public boolean isBasicCollectionType()
Description copied from interface: GrailsDomainClassProperty
Return whether this is a collection of basic types like String, Integer etc.

Specified by:
isBasicCollectionType in interface GrailsDomainClassProperty
Returns:
True if it is a collection of basic types


Copyright (c) 2005-2009 The Grails project