|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jbpm.pvm.internal.util.DefaultObservable
org.jbpm.pvm.internal.wire.WireContext
public class WireContext
object factory that creates, initializes, wires and caches objects
based on descriptors (aka IoC container).
As input, a WireContext takes a WireDefinition. The WireDefinition contains
named Descriptors that know how to create objects and wire them together.
Each object has a name. The WireContext will maintain a cache (map) of the created
objects. So that upon subsequent requests, the same object can be given from the cache.

A WireContext is used often in combination with EnvironmentImpl to
decouple the processDefinition virtual machine from its environment. In the
ProcessEngineImpl, both the process-engine context and
the environment contexts are WireContexts. The PVM will use the persistence service,
asynchronous message service, timer service and other services through specified
abstractions in the environment.
Another usage of the WireContext is construction and configuration of user
code objects in a persistable way. ActivityBehaviours and ExternalActivityBehaviour
and other user code can be instantiated with a WireContext. That way, they can
be persisted in a fixed schema.
Each ProcessElementImpl has configuration properties.
Consider this extra metadata that can be associated to elements in a processDefinition definition.
In that respect, it's somewhat similar to what annotations are in Java. Because of the wire
persistence, all these configuration properties fit into the same process model and in its
database schema.
Mostly often, Descriptors and WireContext's are not used
directly. Instead, the wire XML is used in a configuration file.
The wire XML parser contains the documentation on
the XML grammer. The WireParser will produce a WireDefinition
with a bunch of Descriptors in it.
Objects are build in 2 phases: construction and initialization. The motivation for splitting these phases is to resolve many of the circular dependencies. Imagine 2 objects that have a bidirectional reference. By splitting the construction from the initialization phase, the objects can both be constructed first, and then during initialization, they will be injected into each other.
Construction of the object is all that needs to be done until a reference to the object is available.
In the case of dynamically created
objects (ObjectDescriptor), the simplest case this is
accomplished with a constructor. But also static or non-static factory
methods can be used to obtain a reference to an object.
In case of immutable objects, the descriptor can just provide a reference to a singleton object.
Initialization is optional and it is comprised of everything that needs
to be done with an object after a reference to the object is available.
AbstractDescriptor contains an empty default initialization method.
For objects ObjectDescriptors, this means that a a
sequence of Operations can be applied to the object. Following
operations implementations are already available and can be applied to
an object during initialization:
FieldOperation: injects another object into a fieldPropertyOperation: injects another object with a setter method.InvokeOperation: invokes a method.SubscribeOperation: subscribes to an observable.When an environment is injected into a WireContext, lookup of all referenced object names will be done first in this WireContext, but if the object name is not defined there, the environment will be searched in the environment's default search order.
Several objects will fire events to which can be subscribed:
The WireContext itself fires the EVENT_OPEN and EVENT_OPEN
events.
The Descriptors will fire the events Descriptor.EVENT_CONSTRUCTING,
Descriptor.EVENT_INITIALIZING, Descriptor.EVENT_CONSTRUCTED,
Descriptor.EVENT_SET and Descriptor.EVENT_REMOVE.
And last but not least, the objects created by the WireContext can be
Observable themselves.
By default, all objects in a WireContext are lazily constructued and initialized. Eager initialization is specified on a named object and it means that the object is constructed and initialized during construction of the WireContext. You an only specify eager initialization when the object has a name.
The initialization can be specified with the AbstractDescriptor.setInit(char) method.
init parameter is one of :
AbstractDescriptor.INIT_LAZY: for lazy creation and delayed initializationAbstractDescriptor.INIT_REQUIRED: for lazy creation and immediate initializationAbstractDescriptor.INIT_EAGER: for eager creation and delayed initializationAbstractDescriptor.INIT_IMMEDIATE: for eager creation and immediate initialization
| Field Summary | |
|---|---|
static java.lang.String |
EVENT_CLOSE
is fired when the wiring environment is being closed. |
static java.lang.String |
EVENT_OPEN
is fired when a new wiring environment is being opened. |
protected java.lang.String |
name
|
protected WireDefinition |
wireDefinition
|
| Fields inherited from class org.jbpm.pvm.internal.util.DefaultObservable |
|---|
listeners |
| Fields inherited from interface org.jbpm.pvm.internal.env.Context |
|---|
CONTEXTNAME_EXECUTION, CONTEXTNAME_JOB, CONTEXTNAME_PROCESS_ENGINE, CONTEXTNAME_TASK, CONTEXTNAME_TRANSACTION |
| Constructor Summary | |
|---|---|
WireContext()
|
|
WireContext(WireDefinition wireDefinition)
|
|
WireContext(WireDefinition wireDefinition,
java.lang.String name)
when this Context is used in an EnvironmentImpl, it
needs a name. |
|
WireContext(WireDefinition wireDefinition,
java.lang.String name,
boolean delayCreate)
allows for postponing the creation of this wire context. |
|
| Method Summary | ||
|---|---|---|
protected void |
addException(Descriptor descriptor,
java.lang.Exception exception)
|
|
void |
clear()
clears the cache. |
|
void |
close()
fires the close event then removes the listeners, and cleans up the constructed objects of the context (cleans up the object in the cache and the object in construction). |
|
void |
create()
initializes the eager objects and then fires the create event. |
|
static java.lang.Object |
create(Descriptor descriptor)
convenience method that wires the object for a given descriptor. |
|
java.lang.Object |
create(Descriptor descriptor,
boolean isDelayable)
creates a new object for the given descriptor. |
|
static java.lang.Object |
create(Descriptor descriptor,
ScopeInstanceImpl scopeInstance)
|
|
protected java.lang.Object |
create(java.lang.String objectName,
boolean isDelayable)
creates a new object for the given objectName as defined in the wireDefinition. |
|
protected void |
fireObjectEvent(java.lang.String eventName,
java.lang.String objectName,
java.lang.Object object)
fires a WireObjectEventInfo. |
|
|
get(java.lang.Class<T> type)
searches for the first descriptor that defines an object of the given type. |
|
java.lang.Object |
get(java.lang.String objectName)
retrieves the object for the given objectName, ensuring it is constructed and initialized. |
|
java.lang.Object |
get(java.lang.String objectName,
boolean isDelayable)
gets the object having the name objectName in this context. |
|
java.lang.String |
getName()
|
|
ScopeInstanceImpl |
getScopeInstance()
|
|
WireDefinition |
getWireDefinition()
|
|
boolean |
has(java.lang.String objectName)
checks if the given objectName is defined, either by means of a descriptor or by an explicit set(String, Object). |
|
boolean |
hasCached(java.lang.String objectName)
checks if the given objectName is available in the cache, which means it already has been constructed from a wire definition or it has been set(String, Object)
explicitely. |
|
protected boolean |
hasException(java.lang.String objectName)
|
|
java.util.Set<java.lang.String> |
keys()
the list of object names defined in this context. |
|
java.lang.Object |
remove(java.lang.String objectName)
removes an object from the context and fires the remove event. |
|
java.lang.Object |
set(java.lang.String objectName,
java.lang.Object object)
adds an object to this context, which means storing it in the cache. |
|
void |
setScopeInstance(ScopeInstanceImpl scopeInstance)
|
|
void |
setWireDefinition(WireDefinition wireDefinition)
|
|
java.lang.String |
toString()
|
|
| Methods inherited from class org.jbpm.pvm.internal.util.DefaultObservable |
|---|
addListener, addListener, addListener, fire, fire, getListeners, removeListener |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String EVENT_OPEN
public static final java.lang.String EVENT_CLOSE
protected java.lang.String name
protected WireDefinition wireDefinition
| Constructor Detail |
|---|
public WireContext()
public WireContext(WireDefinition wireDefinition)
public WireContext(WireDefinition wireDefinition,
java.lang.String name)
Context is used in an EnvironmentImpl, it
needs a name.
public WireContext(WireDefinition wireDefinition,
java.lang.String name,
boolean delayCreate)
delayCreate - specifies if creation should be postponed till #createTime() is called explicitly.
If delayCreate is set to false, creation is done as part of the constructor. If delayCreate is
set to true, the #createTime() method needs to be called explicitly by the client after
construction is complete. The use case is creation of environment where the transactionName needs to be
set and the scope needs to be added to the environment before the creation of this wire scope is done.ProcessEngineImpl.openEnvironment()| Method Detail |
|---|
public static java.lang.Object create(Descriptor descriptor,
ScopeInstanceImpl scopeInstance)
public static java.lang.Object create(Descriptor descriptor)
public void create()
delayCreate is true
in #WireContext(WireDefinition, String, EnvironmentImpl, boolean).
public java.lang.String toString()
toString in class java.lang.Objectpublic java.util.Set<java.lang.String> keys()
wireDefinition and the objects that
are just set(String, Object). If there are no keys, an empty set will
be returned.
keys in interface Contextpublic boolean has(java.lang.String objectName)
set(String, Object).
has in interface Contextpublic java.lang.Object get(java.lang.String objectName)
get in interface Context
public java.lang.Object set(java.lang.String objectName,
java.lang.Object object)
WireDefinition. If an object is set under a certain objectName that also is associated with
a descriptor, the object provided in this set invocation will be delivered upon subsequent get(String)
requests.
set in interface Contextcache
WireException - when the objectName is nullpublic java.lang.Object remove(java.lang.String objectName)
public void clear()
cache.
public void close()
close in interface ClosableEVENT_CLOSE
public java.lang.Object get(java.lang.String objectName,
boolean isDelayable)
objectName in this context.
isDelayable - indicates wether initialization is delayable. When isDelayable is set to false
the returned object will be constructed and initialized. When isDelayable is set to true, the returned
object will be constructed, but not necessarily initialized.
WireException - if a circular dependency was found during the object creation.
protected java.lang.Object create(java.lang.String objectName,
boolean isDelayable)
wireDefinition.
isDelayable - indicates wether initialization is delayable. When isDelayable is set to false
the returned object will be constructed and initialized. When isDelayable is set to true, the returned
object will be constructed, but not necessarily initialized.
public java.lang.Object create(Descriptor descriptor,
boolean isDelayable)
isDelayable - indicates wether initialization is delayable. When isDelayable is set to false
the returned object will be constructed and initialized. When isDelayable is set to true, the returned
object will be constructed, but not necessarily initialized.public boolean hasCached(java.lang.String objectName)
set(String, Object)
explicitely.
protected void fireObjectEvent(java.lang.String eventName,
java.lang.String objectName,
java.lang.Object object)
WireObjectEventInfo.
public <T> T get(java.lang.Class<T> type)
| ObjectDescriptor | object | | HibernatePersistenceServiceDescriptor | business-calendar | | TransactionDescriptor | transaction | | PropertiesDescriptor | properties | | BusinessCalendarDescriptor | business-calendar |
get in interface Contextprotected boolean hasException(java.lang.String objectName)
protected void addException(Descriptor descriptor,
java.lang.Exception exception)
public java.lang.String getName()
getName in interface Contextpublic WireDefinition getWireDefinition()
public void setWireDefinition(WireDefinition wireDefinition)
public ScopeInstanceImpl getScopeInstance()
public void setScopeInstance(ScopeInstanceImpl scopeInstance)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||