com.arsdigita.domain
Class DomainObjectFactory

java.lang.Object
  extended bycom.arsdigita.domain.DomainObjectFactory

public class DomainObjectFactory
extends Object

This is a factory class to support instantiation of an appropriate domain object class from a given data object.

The architecture of the persistence and domain layers intentionally does not impose a simple one-to-one correspondence between data object types and domain object classes. It is possible for multiple domain object classes to encapsulate a given data object. It is also possible that a single domain object class can encapsulate data objects of different types. The primary factory design objectives are:

  1. It should be easy for developers to produce a domain object from a given data object when it cannot be determined at compile time which domain object class should be instantiated.
  2. The process of instantiating a domain object given a data object should be as flexible as possible by delegating to custom code, called a DomainObjectInstantiator, that can make use of any properties of the given data object.
  3. A data object of type X is not supported by the factory unless some DomainObjectInstantiator has been registered with the factory for type X, and even then, it may be possible for the instantiator code to examine other properties of the data object and decide that the given data object is not supported (presumably because there is no sensible way to choose which domain object class should be instantiated for the particular data object).

Version:
1.0
Author:
Oumi Mehrotra
See Also:
DomainObjectInstantiator, DataObject, DomainObject

Field Summary
static String versionId
           
 
Constructor Summary
DomainObjectFactory()
           
 
Method Summary
static DomainObjectInstantiator getInstantiator(ObjectType dataObjectType)
          Get the registered or inherited instantiator for the specified object type.
static DomainObjectInstantiator getInstantiator(String dataObjectType)
          Wrapper around getInstantiator(ObjectType).
static DomainObjectInstantiator getRegisteredInstantiator(ObjectType dataObjectType)
          Get the registered instantiator for the specified object type.
static DomainObjectInstantiator getRegisteredInstantiator(String dataObjectType)
          Wrapper around getRegisteredInstantiator(ObjectType).
static DomainObject newInstance(DataObject dataObject)
          Instantiates a domain object given a data object.
static DomainObject newInstance(OID oid)
          Instantiate a domain object given an OID.
static DomainObjectInstantiator registerInstantiator(ObjectType dataObjectType, DomainObjectInstantiator instantiator)
          Register an instantiator for the data object type specified by dataObjectType.
static DomainObjectInstantiator registerInstantiator(String dataObjectType, DomainObjectInstantiator instantiator)
          Wrapper around registerInstantiator(ObjectType, DomainObjectInstantiator).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

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

DomainObjectFactory

public DomainObjectFactory()
Method Detail

newInstance

public static DomainObject newInstance(DataObject dataObject)
                                throws PersistenceException,
                                       InstantiatorNotFoundException
Instantiates a domain object given a data object.

The process of instantiating the domain object involves delegating to a DomainObjectInstantiator. The instantiator may use any information about the DataObject to produce the appropriate domain object.

The result may be null if there is no instantiator registered for the dataObjectType of the specified dataObject, OR if the registered instantiator does not support instantiation of the specified dataObject.

Parameters:
dataObject - The data object from which to instantiate a domain object.
Returns:
A domain object that encapuslates the given dataObject. Returns null, if called with the null data object parameter. The result may also be null if no domain object could be instantiated for the given data object.
Throws:
InstantiatorNotFoundException - if no Instantiator could be found
PersistenceException
See Also:
DataObject, DomainObject

newInstance

public static DomainObject newInstance(OID oid)
                                throws InstantiatorNotFoundException
Instantiate a domain object given an OID. This method is a wrapper around newInstance(DataObject).

Parameters:
oid - the oid of the data object for which to instantiate a domain object.
Returns:
A domain object that encapuslates the dataObject identified by oid. The result may be null if no domain object could be instantiated for the specified data object.
Throws:
DataObjectNotFoundException - if object could not be retrieved.
InstantiatorNotFoundException
See Also:
newInstance(DataObject), DataObject, DomainObject

registerInstantiator

public static DomainObjectInstantiator registerInstantiator(ObjectType dataObjectType,
                                                            DomainObjectInstantiator instantiator)
Register an instantiator for the data object type specified by dataObjectType. The registered instantiator will be used by newInstance() for data objects whose type is equal to the type specified by dataObjectType. That is, when newInstance(x) is executued, the specified instantiator will be used if the specified dataObjectType is equal to x.getObjectType().

Any object type that does not have an instantiator registered with this factory is not supported by the factory.

If another instantiator was already registered for the specified object type, the previous instantiator is replaced and returned.

Parameters:
dataObjectType - The data object type for which to register the instantiator specified by instantiator
instantiator - The instantiator that will handle data objects of the data object type specified by dataObjectType when newInstance() is called.
Returns:
DomainObjectInstantiator The previous instantiator that was registered with this factory for this object type.
Throws:
InstantiatorRegistryException - if null == dataObjectType
See Also:
registerInstantiator(String, DomainObjectInstantiator), newInstance(DataObject), DataObject, DomainObject

registerInstantiator

public static DomainObjectInstantiator registerInstantiator(String dataObjectType,
                                                            DomainObjectInstantiator instantiator)
Wrapper around registerInstantiator(ObjectType, DomainObjectInstantiator).

Parameters:
dataObjectType - The fully qualified name of the data object type for which to register the specified instantiator. The qualified name is the model name followed by a '.' followed by the object type name (e.g. "com.arsdigita.kernel.Party").
instantiator - The instantiator that will handle data objects of the type specified by typeName when this newInstance() is called.
Returns:
DomainObjectInstantiator The previous instantiator that was registered with this factory for this object type.
Throws:
InstantiatorRegistryException - if the dataObjectType does not exist
See Also:
registerInstantiator(ObjectType, DomainObjectInstantiator)

getRegisteredInstantiator

public static DomainObjectInstantiator getRegisteredInstantiator(ObjectType dataObjectType)
Get the registered instantiator for the specified object type.

Parameters:
dataObjectType - The data object type whose registered instantiator is to be returned
Returns:
The instantiator that is registered for the specified object type.
See Also:
registerInstantiator(ObjectType,DomainObjectInstantiator)

getRegisteredInstantiator

public static DomainObjectInstantiator getRegisteredInstantiator(String dataObjectType)
Wrapper around getRegisteredInstantiator(ObjectType).

Parameters:
dataObjectType - The fully qualified name of the data object type whose registered instantiator is to be returned
Returns:
The instantiator that is registered for the specified object type. The qualified name is the model name followed by a '.' followed by the object type name (e.g. "com.arsdigita.kernel.Party").
See Also:
getRegisteredInstantiator(ObjectType), registerInstantiator(ObjectType,DomainObjectInstantiator)

getInstantiator

public static DomainObjectInstantiator getInstantiator(ObjectType dataObjectType)
Get the registered or inherited instantiator for the specified object type. That is, get the instantiator that is registered for the specified object type or its closest supertype that has a registered instantiator (or null if there is no supertype that has a registered instantiator).

Parameters:
dataObjectType - The data object type whose registered or inherited instantiator is to be returned
Returns:
The registered or inherited instantiator for the specified object type.
See Also:
registerInstantiator(ObjectType,DomainObjectInstantiator)

getInstantiator

public static DomainObjectInstantiator getInstantiator(String dataObjectType)
Wrapper around getInstantiator(ObjectType).

Parameters:
dataObjectType - The fully qualified name of the data object type whose registered or inherited instantiator is to be returned
Returns:
The registered or inherited instantiator for the specified object type. The qualified name is the model name followed by a '.' followed by the object type name (e.g. "com.arsdigita.kernel.Party").
See Also:
getInstantiator(ObjectType), registerInstantiator(ObjectType,DomainObjectInstantiator)


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