com.arsdigita.domain
Class DomainObject

java.lang.Object
  extended bycom.arsdigita.domain.DomainObject
Direct Known Subclasses:
BasicAuditTrail, Charset, Document, Host, Locale, MessageCatalog, MimeType, MimeTypeExtension, MimeTypeStatus, ObservableDomainObject, PackageType, PersonName, PostConvertHTML, PreConvertHTML, ResourceType, Role, UserAuthentication, WebApp

public abstract class DomainObject
extends Object

This is the base class that all other persistent classes would extend. It provides methods that delegate to a contained DataObject.

Version:
1.0
See Also:
DataObject

Field Summary
static String versionId
           
 
Constructor Summary
DomainObject(DataObject dataObject)
          Constructor.
DomainObject(ObjectType type)
          Constructor.
DomainObject(OID oid)
          Constructor.
DomainObject(String typeName)
          Constructor.
 
Method Summary
protected  DataObject add(String propertyName, DataObject dataObject)
          Adds to associations with multiplicty > 1.
protected  DataObject add(String propertyName, DomainObject dobj)
          Adds to associations with multiplicty > 1.
 DataObject addToAssociation(DataAssociation da)
          Add the DomainObject to a DataAssociation
protected  void afterDelete()
           
protected  void afterSave()
           
protected  void beforeDelete()
           
protected  void beforeSave()
           
protected  void clear(String propertyName)
          Clears an association with multiplicity > 1.
 void delete()
          Deletes this object.
 void disconnect()
          Disconnects the encapsulated data object from the current transaction.
 boolean equals(Object object)
          Is this domain object equal to another domain object? Default implementation only compares OID (provided it isn't empty).
protected  Object get(String attr)
          Get a property of the DomainObjects DataObject.
protected  String getBaseDataObjectType()
          Returns the base data object type for this domain object class.
 ObjectType getObjectType()
          Returns the type of this persistent object.
 OID getOID()
          Return the OID of this domain object.
 Session getSession()
           
 int hashCode()
          We override the standard hashCode method because we have overridden equals.
protected  void initialize()
          Called from all of the DomainObject constructors to initalize or validate the new domain object or its encapsulated data object.
 boolean isDeleted()
          Returns true if this persistent object has been deleted from the database.
 boolean isDisconnected()
          Returns true if the encapsulated data object has been disconnected from the transaction context.
 boolean isModified()
          Returns true if this persistent object has been modified since it was retrieved.
 boolean isNew()
          Return true if this persistent object is newly created, false otherwise.
 boolean isPropertyModified(String name)
          Returns true if the property specified by name has been modified since this persistent object was retrieved.
 boolean isValid()
          Returns true if this persistent object is in a valid state.
protected  void remove(String propertyName, DataObject dataObject)
          Removes from associations with multiplicity > 1.
protected  void remove(String propertyName, DomainObject dobj)
          Removes from associations with multiplicity > 1.
protected  void remove(String propertyName, OID oid)
          Removes.
 void removeFromAssociation(DataAssociation da)
          Remove the DomainObject from a DataAssociation
 void save()
          Persists any changes made to this object.
protected  void set(String attr, Object value)
          Set a property of the DomainObjects DataObject.
protected static void setAssociation(DataObject dobj, String attr, DomainObject target)
           
protected  void setAssociation(String attr, DomainObject dobj)
          Set an association DomainObjects DataObject.
protected  void specializeDataObject(ObjectType subtype)
          Specializes the encapsulated data object by turning it into a subtype of this object's current type.
protected  void specializeDataObject(String subtypeName)
          Specializes the encapsulated data object by turning it into a subtype of this object's current type.
 String toString()
          Return the OID plus the flags N,M,D,U depending on whether the object is new, modified, deleted, or unknown.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

DomainObject

public DomainObject(String typeName)
Constructor. The contained DataObject is initialized with a new DataObject with an ObjectType specified by the string typeName.

Parameters:
typeName - The name of the ObjectType of the new instance.
See Also:
Session.create(String), DataObject, ObjectType

DomainObject

public DomainObject(ObjectType type)
Constructor. The contained DataObject is initialized with a new DataObject with an ObjectType specified by type.

Parameters:
type - The ObjectType of the new instance.
See Also:
Session.create(ObjectType), DataObject, ObjectType

DomainObject

public DomainObject(OID oid)
             throws DataObjectNotFoundException
Constructor. The contained DataObject is retrieved from the persistent storage mechanism with an OID specified by oid.

Parameters:
oid - The OID for the retrieved DataObject.
Throws:
DataObjectNotFoundException - Thrown if we cannot retrieve a data object for the specified OID
See Also:
Session.retrieve(OID), DataObject, OID

DomainObject

public DomainObject(DataObject dataObject)
Constructor. Creates a new DomainObject instance to encapsulate a given data object.

Parameters:
dataObject - The data object to encapsulate in the new domain object.
See Also:
Session.retrieve(String)
Method Detail

getBaseDataObjectType

protected String getBaseDataObjectType()
Returns the base data object type for this domain object class. Intended to be overrided by subclasses whenever the subclass will only work if their primary data object is of a certain base type.

Returns:
The fully qualified name ("modelName.typeName") of the base data object type for this domain object class, or null if there is no restriction on the data object type for the primary data object encapsulated by this class.

initialize

protected void initialize()
Called from all of the DomainObject constructors to initalize or validate the new domain object or its encapsulated data object. This was introduced in order to support efficient validation of the encapsualted data object's type. If the validation is typically performed in class constructors, then redundant validation is performed in superclass constructors. This validation now occurs here.


getObjectType

public ObjectType getObjectType()
Returns the type of this persistent object.

Returns:
The type of this persistent object.

isNew

public boolean isNew()
Return true if this persistent object is newly created, false otherwise.

Returns:
True if this persistent object is newly created, false otherwise.
See Also:
DataObject.isNew()

getOID

public OID getOID()
Return the OID of this domain object.

Returns:
the OID of this domain object.
See Also:
DataObject.getOID()

isValid

public boolean isValid()
Returns true if this persistent object is in a valid state. An invalid DomainObject usually results from using a data object that was retrieved during a transaction that has been rolled back.

Returns:
true if the object has been modified; false otherwise
See Also:
DataObject.isValid()

isModified

public boolean isModified()
Returns true if this persistent object has been modified since it was retrieved.

Returns:
True if this persistent object has been modified, false otherwise.
See Also:
DataObject.isModified()

isDeleted

public boolean isDeleted()
Returns true if this persistent object has been deleted from the database. This does a database hit to check.

Returns:
True if the object has been deleted

isPropertyModified

public boolean isPropertyModified(String name)
Returns true if the property specified by name has been modified since this persistent object was retrieved.

Parameters:
name - Name of the property on which to check modification status.
Returns:
True if the property specified by name has been modified since this persistent object was retrieved, false otherwise.
See Also:
DataObject.isPropertyModified(String)

save

public final void save()
                throws PersistenceException
Persists any changes made to this object. Note that a data object can be saved without a call to its corresponding domain object's save() method. This means that save() is not guaranteed to be called when saves are cascaded due to associations. For instance, suppose a Folder contains numerous File objects. Adding Files to that Folder and calling Folder.save() will implicitly save all the files without calling the File's DomainObject.save() method. Do not override the save() method under any circumstances. Use beforeSave and afterSave instead. This method is not declared final for backwards compatibility.

Throws:
PersistenceException
See Also:
DataObject.save(), beforeSave(), afterSave()

delete

public void delete()
            throws PersistenceException
Deletes this object.

Throws:
PersistenceException
See Also:
DataObject.delete()

set

protected void set(String attr,
                   Object value)
Set a property of the DomainObjects DataObject. This should only be used inside of a setXXX method.

See Also:
DataObject.set(String, Object)

setAssociation

protected void setAssociation(String attr,
                              DomainObject dobj)
Set an association DomainObjects DataObject. This should only be used inside of a setXXX method.

Specificall, this method should only be used to set associations whose multiplicity is 0..1 or 1..1. If the upper bound of the multiplicity is greater than 1 then the add(String, DataObject) method should be used.

See Also:
DataObject.set(String, Object)

setAssociation

protected static void setAssociation(DataObject dobj,
                                     String attr,
                                     DomainObject target)

removeFromAssociation

public void removeFromAssociation(DataAssociation da)
Remove the DomainObject from a DataAssociation

See Also:
DataAssociation.remove(DataObject)

addToAssociation

public DataObject addToAssociation(DataAssociation da)
Add the DomainObject to a DataAssociation

See Also:
DataAssociation.add(DataObject)

add

protected DataObject add(String propertyName,
                         DataObject dataObject)
Adds to associations with multiplicty > 1. If the multiplicity equals 1 then setAssociation(String, DomainObject) should be used instead.


add

protected DataObject add(String propertyName,
                         DomainObject dobj)
Adds to associations with multiplicty > 1.


remove

protected void remove(String propertyName,
                      DataObject dataObject)
Removes from associations with multiplicity > 1.


remove

protected void remove(String propertyName,
                      DomainObject dobj)
Removes from associations with multiplicity > 1.


remove

protected void remove(String propertyName,
                      OID oid)
Removes.


clear

protected void clear(String propertyName)
Clears an association with multiplicity > 1.


get

protected Object get(String attr)
Get a property of the DomainObjects DataObject. This should only be used inside of a getXXX method.

See Also:
DataObject.get(String)

getSession

public Session getSession()

equals

public boolean equals(Object object)
Is this domain object equal to another domain object? Default implementation only compares OID (provided it isn't empty).

Returns:
true if the two objects have the same OID, unless no OID info exists in which case true if they are at the same memory location (the default .equals).

hashCode

public int hashCode()
We override the standard hashCode method because we have overridden equals. This delegates to OID.hashCode, unless the OID is empty, in which case we delegate to super.hashCode and end up with something based on this object's location in memory.


specializeDataObject

protected void specializeDataObject(ObjectType subtype)
Specializes the encapsulated data object by turning it into a subtype of this object's current type.

Parameters:
subtype - The subtype to which to specialize.
See Also:
DataObject.specialize(ObjectType)

specializeDataObject

protected void specializeDataObject(String subtypeName)
Specializes the encapsulated data object by turning it into a subtype of this object's current type. In addition to the local precondition, also has pre and post conditions of specializeDataObject(ObjectType).

Parameters:
subtypeName - The fully qualified name (e.g. "com.arsdigita.kernel.User") of the subtype to which to specialize
See Also:
DataObject.specialize(String)

toString

public String toString()
Return the OID plus the flags N,M,D,U depending on whether the object is new, modified, deleted, or unknown. Unknown is for objects that have been invalidated.


disconnect

public void disconnect()
Disconnects the encapsulated data object from the current transaction. This allows the object to be used in multiple transactions.

See Also:
isDisconnected()

isDisconnected

public boolean isDisconnected()
Returns true if the encapsulated data object has been disconnected from the transaction context. If true, the object can still be read, but any attempt to update any of the object's attributes will cause an exception to be thrown.

Returns:
true if the object has been disconnected

beforeSave

protected void beforeSave()

afterSave

protected void afterSave()

beforeDelete

protected void beforeDelete()

afterDelete

protected void afterDelete()


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC