|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.domain.DomainObjectInstantiator
com.arsdigita.kernel.ACSObjectInstantiator
Defines the instantiator that should be
registered with DomainObjectFactory for the ACSObject data object type.
It always delegates domain object instantiation to another instantiator
based on the objectType
property of the given dataObject.
As an example of how subtypes of ACSObject can make use of ACSObjectInstantiator, here is a modified snippet of code from com.arsdigita.kernel.Initializer:
DomainObjectInstantiator instantiator = new ACSObjectInstantiator() { public DomainObject doNewInstance(DataObject dataObject) { return new Group(dataObject); } }; DomainObjectFactory.registerInstantiator("com.arsdigita.kernel.Group", instantiator);This initializer will work even if Group is extended. For example, suppose we add data object type FooGroup and domain object class FooGroup, and register an instantiator for FooGroup in a similar manner as the example code above. Further suppose we retrieve a FooGroup data object as type Group instead of FooGroup:
// create a FooGroup FooGroup fooGroup = new FooGroup(123); fooGroup.save(); // retrieve group with id 123, which happens to be a FooGroup. DataObject groupData = Session.retrieve(new OID("com.arsdigita.kernel.Group", 123)); // produce a domain object that encapsulates group 123. DomainObject group = DomainObjectFactory.newInstance(groupData);What domain class was instantiated by the factory:
Group
or FooGroup
? The answer is FooGroup.
What happens is the factory looks at groupData
's object type,
which is Group
. The factory looks up the registered
instantiator for Group
, and then calls
resolveInstantiator(groupData). resolveInstantiator()
was
inherited from ACSObjectInstantiator, so it "knows" to look at the
objectType
property of groupData
and delegate
to whatever instantiator is registered for that type. In this example,
the call to resolveInstantiator returns the FooGroup
instantiator. The factory again calls resolveInstantiator()
on the FooGroup
instantiator, and this time the same
instantiator is returned. So the factory calls doNewInstance
on the FooGroup
instantiator, which contains a hardcoded call
to the constructor for FooGroup
.
DomainObjectInstantiator
,
DomainObjectFactory
,
DomainObject
,
DataObject
,
ACSObject
Field Summary | |
protected boolean |
m_useReflectionForSubtypes
|
static String |
versionId
|
Constructor Summary | |
ACSObjectInstantiator()
|
Method Summary | |
protected DomainObject |
doNewInstance(DataObject dataObject)
UNSUPPORTED--Given a data object, constructs a DomainObject. |
DomainObjectInstantiator |
resolveInstantiator(DataObject dataObject)
Returns the instantiator that is registered with DomainObjectFactory for the object type identified by the specified data object's objectType property. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String versionId
protected boolean m_useReflectionForSubtypes
Constructor Detail |
public ACSObjectInstantiator()
Method Detail |
public DomainObjectInstantiator resolveInstantiator(DataObject dataObject)
objectType
property.
The returned instantiator will be used by the DomainObjectFactory in place of this.
This method also specializes the DataObject to the object type
identified by the data object's objectType
property.
The specialization happens to "prepare" the data object for processing
by the instantiator that was registered with the factory for the
specific data object type. This instantiator should be able to assume that
it will be given a data object of the type for which the instantiator
was registered.
resolveInstantiator
in class DomainObjectInstantiator
dataObject
- the data object for which to find a
DomainObjectInstantiator
DataObject.specialize(ObjectType)
,
DomainObjectInstantiator
,
DomainObjectFactory
protected DomainObject doNewInstance(DataObject dataObject)
This instantiator is primarily intended to be registered for the
ACSObject
data object type, which is abstract. Every
ACSObject data object should have a more specific object type
(identified by the objectType
property), so
resolveInstantiator() would have returned a different instantiator
to delegate to. Therefore, this method should never be called by
the factory unless someone registered this instantiator for a
concrete object type.
Note that it is okay to register this instantiator for an object type that is abstract and is a subtype of ACSObject. For example, an ACSObjectInstantiator is registered for the Party object type.
doNewInstance
in class DomainObjectInstantiator
dataObject
- the data object from which to construct a domain
object
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |