org.nakedobjects.runtime.persistence.objectfactory
Class ObjectFactoryAbstract

java.lang.Object
  extended by org.nakedobjects.runtime.persistence.objectfactory.ObjectFactoryAbstract
All Implemented Interfaces:
Component, SessionScopedComponent, ObjectFactory
Direct Known Subclasses:
ObjectFactoryBasic

public abstract class ObjectFactoryAbstract
extends java.lang.Object
implements ObjectFactory

Abstract adapter for ObjectFactory.

Implementation note: rather than use the *Aware interfaces, we instead look up dependencies from the NakedObjectsContext. This is necessary, for the PersistenceSession at least, because class enhancers may hold a reference to the factory as part of the generated bytecode. Since the PersistenceSession could change over the lifetime of the instance (eg when using the InMemoryObjectStore), we must always look the PersistenceSession from the NakedObjectsContext. The same applies to the ServicesInjector.

In theory it would be possible to cache the SpecificationLoader and inject using SpecificationLoaderAware, but since we are already using the NakedObjectsContext, decided instead to use the same approach throughout.


Nested Class Summary
static class ObjectFactoryAbstract.Mode
           
 
Constructor Summary
ObjectFactoryAbstract()
           
ObjectFactoryAbstract(ObjectFactoryAbstract.Mode mode)
           
 
Method Summary
 void close()
          Default implementation does nothing.
protected abstract
<T> T
doInstantiate(java.lang.Class<T> cls)
          Hook method for subclasses to override.
protected  PersistenceSession getPersistenceSession()
           
protected  ServicesInjector getServicesInjector()
           
protected  SpecificationLoader getSpecificationLoader()
           
<T> T
instantiate(java.lang.Class<T> cls)
          Should instantiate the object, and in addition initialize the domain object (for example, inject any services and repositories into it).
 void open()
          Default implementation does nothing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectFactoryAbstract

public ObjectFactoryAbstract()

ObjectFactoryAbstract

public ObjectFactoryAbstract(ObjectFactoryAbstract.Mode mode)
Method Detail

instantiate

public <T> T instantiate(java.lang.Class<T> cls)
              throws ObjectInstantiationException
Description copied from interface: ObjectFactory
Should instantiate the object, and in addition initialize the domain object (for example, inject any services and repositories into it).

Specified by:
instantiate in interface ObjectFactory
Throws:
ObjectInstantiationException

open

public void open()
Default implementation does nothing.

Specified by:
open in interface SessionScopedComponent

close

public void close()
Default implementation does nothing.

Specified by:
close in interface SessionScopedComponent

doInstantiate

protected abstract <T> T doInstantiate(java.lang.Class<T> cls)
                            throws ObjectInstantiationException
Hook method for subclasses to override.

Throws:
ObjectInstantiationException

getSpecificationLoader

protected SpecificationLoader getSpecificationLoader()

getPersistenceSession

protected PersistenceSession getPersistenceSession()

getServicesInjector

protected ServicesInjector getServicesInjector()


Copyright © 2001-2009 Naked Objects Group Ltd.. All Rights Reserved.