com.arsdigita.domain
Class DomainObjectInstantiator
java.lang.Object
com.arsdigita.domain.DomainObjectInstantiator
- Direct Known Subclasses:
- ACSObjectInstantiator, ReflectionInstantiator
- public abstract class DomainObjectInstantiator
- extends Object
This abstract class provides an interface for DomainObjectFactory to
use in order to delegate the job of instantiating a domain object
from a data object to custom code.
Whenever a developer adds a new data object type, if they want
the DomainObjectFactory to support the new data object type, then
they must register a DomainObjectInstantiator for the new type
using DomainObjectFactory.registerInstantiator().
An instantiator is responsible for producing a DomainObject given
DataObject foo if the instantiator was registered for
foo's object type.
The task of producing a DomainObject generally involves 2 parts:
- optionally delegating to another instantiator based on properties
of the given DataObject, and
- instantiating a DomainObject if no further delegation should occur.
Typically, the logic for delegating to another instantiator is the
same for all data object types with a common base type (e.g. ACSObject).
For this reason, the task of producing a DomainObject is broken into
two methods that can be overrided independently. The method
resolveInstantiator()
examines the given DataObject and
returns a delegate instantiator. The method doNewInstance() performs
the last step of producing a data object, generally assuming that
no futher delegation is necessary. Typically the instantiator for
a base object type (e.g. ACSObjectInstantiator) will provide an
implementation of resolveInstantiator()
that will work
for extended types as well, so an extended type's instantiator need
only override doInstantiate() (usually with only one line of code
to instantiate a DomainObject class for the data object type in
question).
- Version:
- 1.0
- Author:
- Oumi Mehrotra
- See Also:
ACSObjectInstantiator
,
DomainObjectFactory
,
DomainObject
,
DataObject
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
versionId
public static final String versionId
- See Also:
- Constant Field Values
DomainObjectInstantiator
public DomainObjectInstantiator()
resolveInstantiator
public DomainObjectInstantiator resolveInstantiator(DataObject dataObject)
- Return a delegated instantiator. Called from
DomainObjectFactory.newInstance(). If the returned instantiator
is
this
, then the factory will call
this.doNewInstance()
. Otherwise, the factory will
again call resolveInstantiator() on the returned instantiator,
repeating the process until finally an instantiator's
resolveInstantiator() method returns itself.
- Parameters:
dataObject
- The data object for which to find a
DomainObjectInstantiator.
- Returns:
- A domain object for this data object.
doNewInstance
protected abstract DomainObject doNewInstance(DataObject dataObject)
- Construct a DomainObject given a data object. Called from
DomainObjectFactory.newInstance() as the last step of
instantiation.
- Parameters:
dataObject
- The data object from which to construct a domain
object.
- Returns:
- A domain object for this data object.
Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC