org.jbpm.pvm.internal.wire.descriptor
Class ObjectDescriptor

java.lang.Object
  extended by org.jbpm.pvm.internal.util.DefaultObservable
      extended by org.jbpm.pvm.internal.wire.descriptor.AbstractDescriptor
          extended by org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor
All Implemented Interfaces:
java.io.Serializable, Observable, Descriptor
Direct Known Subclasses:
JobExecutorDescriptor

public class ObjectDescriptor
extends AbstractDescriptor

This Descriptor creates and initializes an object. Objects can be instantiated from a constructor or from a method invocation.

The way to create an object is specified one of these methods (see creating objects):

Only one of these methods can be used.

Creating objects

Creating object from a constructor

This method is used when getClassName()!=null && getMethodName()==null.

The construct(WireContext) method creates a new object from a constructor matching the given arguments (specified with setArgDescriptors(List)).

Creating an object from a method invocation

The name of the method to call is specified by the method attribute.

The object returned by construct(WireContext) is the object returned by the method invocation.

Initializing Objects

Auto Wiring

If the auto wiring is enabled for the object (isAutoWireEnabled()==true), the WireContext will try to look for objects with the same name as the fields in the class. If it finds an object with that name, and if it is assignable to the field's type, it is automatically injected, without the need for explicit FieldOperation that specifies the injection in the wiring xml.

If the auto wiring is enabled and the WireContext finds an object with the name of a field, but not assignable to this field, a warning message is generated.

Auto-wiring is disabled by default.

Operations

Field injection or property injection are done after the auto-wiring. For more information, see Operation.

If a field was injected by auto-wiring, its value can be overridden by specifying a FieldOperation or PropertyOperation operation.

Author:
Tom Baeyens, Guillaume Porcher (documentation)
See Also:
Serialized Form

Field Summary
protected  java.util.List<ArgDescriptor> argDescriptors
          map to db as a component
protected  java.lang.String className
           
protected  Expression expression
           
protected  Descriptor factoryDescriptor
          specifies the object on which to invoke the method.
protected  boolean isAutoWireEnabled
          True if autowiring is enabled.
protected  java.lang.String methodName
           
protected  java.util.List<Operation> operations
          list of operations to perform during initialization.
 
Fields inherited from class org.jbpm.pvm.internal.wire.descriptor.AbstractDescriptor
dbid, dbversion, init, INIT_EAGER, INIT_IMMEDIATE, INIT_LAZY, INIT_REQUIRED, name, version
 
Fields inherited from class org.jbpm.pvm.internal.util.DefaultObservable
listeners
 
Fields inherited from interface org.jbpm.pvm.internal.wire.Descriptor
EVENT_CONSTRUCTED, EVENT_CONSTRUCTING, EVENT_INITIALIZING, EVENT_REMOVE, EVENT_SET
 
Constructor Summary
ObjectDescriptor()
           
ObjectDescriptor(java.lang.Class<?> clazz)
           
ObjectDescriptor(java.lang.String className)
           
 
Method Summary
 void addArgDescriptor(ArgDescriptor argDescriptor)
          Adds a argument descriptor to the list of arguments descriptor to used when invoking the specified method.
 void addInjection(java.lang.String fieldName, Descriptor descriptor)
          add a field injection based on a descriptor
 void addOperation(Operation operation)
          Adds an operation to perform during initialization.
 void addPropertyInjection(java.lang.String propertyName, Descriptor valueDescriptor)
          add a property injection based on a descriptor
 void addTypedInjection(java.lang.String fieldName, java.lang.Class<?> type)
          convenience method to add a type based field injection
protected  void autoWire(java.lang.Object object, WireContext wireContext)
          Auto wire object present in the context and the specified object's fields.
 java.lang.Object construct(WireContext wireContext)
          This method constructs a new Object from the ObjectDefinition.
 java.util.List<ArgDescriptor> getArgDescriptors()
           
static java.lang.Object[] getArgs(WireContext wireContext, java.util.List<ArgDescriptor> argDescriptors)
          Creates a list of arguments (objects) from a list of argument descriptors.
 java.lang.String getClassName()
           
 Expression getExpression()
           
 Descriptor getFactoryDescriptor()
           
 java.lang.String getFactoryObjectName()
           
 java.lang.String getMethodName()
           
 java.util.List<Operation> getOperations()
           
 java.lang.Class<?> getType(WireDefinition wireDefinition)
          the type of the produced object or null if that is not available
 void initialize(java.lang.Object object, WireContext wireContext)
          Initializes the specified object.
static java.lang.Object invokeMethod(java.lang.String methodName, java.util.List<ArgDescriptor> argDescriptors, WireContext wireContext, java.lang.Object object, java.lang.Class<?> clazz)
           
 boolean isAutoWireEnabled()
           
 void setArgDescriptors(java.util.List<ArgDescriptor> argDescriptors)
           
 void setAutoWireEnabled(boolean isAutoWireEnabled)
           
 void setClassName(java.lang.String className)
           
 void setExpression(Expression expr)
           
 void setFactoryDescriptor(Descriptor factoryDescriptor)
           
 void setFactoryObjectName(java.lang.String factoryObjectName)
           
 void setMethodName(java.lang.String methodName)
           
 void setOperations(java.util.List<Operation> operations)
           
 
Methods inherited from class org.jbpm.pvm.internal.wire.descriptor.AbstractDescriptor
getDbid, getName, isDelayable, isEagerInit, setInit, setName
 
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, toString, wait, wait, wait
 
Methods inherited from interface org.jbpm.pvm.internal.util.Observable
addListener, addListener, addListener, fire, fire, removeListener
 

Field Detail

className

protected java.lang.String className

expression

protected Expression expression

factoryDescriptor

protected Descriptor factoryDescriptor
specifies the object on which to invoke the method. Either className, objectName or a descriptor has to be specified.


methodName

protected java.lang.String methodName

argDescriptors

protected java.util.List<ArgDescriptor> argDescriptors
map to db as a component


operations

protected java.util.List<Operation> operations
list of operations to perform during initialization.


isAutoWireEnabled

protected boolean isAutoWireEnabled
True if autowiring is enabled.

Constructor Detail

ObjectDescriptor

public ObjectDescriptor()

ObjectDescriptor

public ObjectDescriptor(java.lang.String className)

ObjectDescriptor

public ObjectDescriptor(java.lang.Class<?> clazz)
Method Detail

construct

public java.lang.Object construct(WireContext wireContext)
This method constructs a new Object from the ObjectDefinition. This object will be created from a class constructor or from a method invocation.

Parameters:
wireContext - WireContext in which the object is created. This is also the WireContext where the object will search for other object that may be needed during the initialization phase.
Returns:
the constructed object.
Throws:
WireException - one of the following exception occurred:
  • if the object cannot be created (unable to load the specified class or no matching constructor found)
  • if the invocation of the specified method failed
See Also:
ObjectDescriptor

invokeMethod

public static java.lang.Object invokeMethod(java.lang.String methodName,
                                            java.util.List<ArgDescriptor> argDescriptors,
                                            WireContext wireContext,
                                            java.lang.Object object,
                                            java.lang.Class<?> clazz)
                                     throws java.lang.Exception
Throws:
java.lang.Exception

initialize

public void initialize(java.lang.Object object,
                       WireContext wireContext)
Initializes the specified object. If auto-wiring was set to true, auto-wiring is performed (see autoWire(Object, WireContext)). Fields and properties injections are then performed.

Specified by:
initialize in interface Descriptor
Overrides:
initialize in class AbstractDescriptor
Parameters:
object - object to initialize.
wireContext - the context in which the object will be initialized.

getType

public java.lang.Class<?> getType(WireDefinition wireDefinition)
Description copied from interface: Descriptor
the type of the produced object or null if that is not available

Specified by:
getType in interface Descriptor
Overrides:
getType in class AbstractDescriptor

autoWire

protected void autoWire(java.lang.Object object,
                        WireContext wireContext)
Auto wire object present in the context and the specified object's fields.

Parameters:
object - object on which auto-wiring is performed.
wireContext - context in which the wiring objects are searched.

getArgs

public static java.lang.Object[] getArgs(WireContext wireContext,
                                         java.util.List<ArgDescriptor> argDescriptors)
                                  throws java.lang.Exception
Creates a list of arguments (objects) from a list of argument descriptors.

Parameters:
wireContext - context used to create objects.
argDescriptors - list of argument descriptors.
Returns:
a list of object created from the descriptors.
Throws:
java.lang.Exception

addArgDescriptor

public void addArgDescriptor(ArgDescriptor argDescriptor)
Adds a argument descriptor to the list of arguments descriptor to used when invoking the specified method.

Parameters:
argDescriptor - argument descriptor to add.

addOperation

public void addOperation(Operation operation)
Adds an operation to perform during initialization.

Parameters:
operation - operation to add.

addTypedInjection

public void addTypedInjection(java.lang.String fieldName,
                              java.lang.Class<?> type)
convenience method to add a type based field injection


addInjection

public void addInjection(java.lang.String fieldName,
                         Descriptor descriptor)
add a field injection based on a descriptor


addPropertyInjection

public void addPropertyInjection(java.lang.String propertyName,
                                 Descriptor valueDescriptor)
add a property injection based on a descriptor


getClassName

public java.lang.String getClassName()

setClassName

public void setClassName(java.lang.String className)

getArgDescriptors

public java.util.List<ArgDescriptor> getArgDescriptors()

setArgDescriptors

public void setArgDescriptors(java.util.List<ArgDescriptor> argDescriptors)

getOperations

public java.util.List<Operation> getOperations()

setOperations

public void setOperations(java.util.List<Operation> operations)

getFactoryDescriptor

public Descriptor getFactoryDescriptor()

setFactoryDescriptor

public void setFactoryDescriptor(Descriptor factoryDescriptor)

getFactoryObjectName

public java.lang.String getFactoryObjectName()

setFactoryObjectName

public void setFactoryObjectName(java.lang.String factoryObjectName)

getMethodName

public java.lang.String getMethodName()

setMethodName

public void setMethodName(java.lang.String methodName)

isAutoWireEnabled

public boolean isAutoWireEnabled()

setAutoWireEnabled

public void setAutoWireEnabled(boolean isAutoWireEnabled)

getExpression

public Expression getExpression()

setExpression

public void setExpression(Expression expr)


Copyright © 2010 JBoss Community. All Rights Reserved.