org.jbpm.wire.binding
Class ObjectBinding

java.lang.Object
  extended by org.jbpm.wire.binding.ObjectBinding
All Implemented Interfaces:
Binding

public class ObjectBinding
extends java.lang.Object
implements Binding

This Binding specifies a ObjectDescriptor (to create an object).

Objects can be instantiated from a constructor or from a method invocation.

An object descriptor is defined by a <object> element.

This element can have an attribute "name", which specifies the name of the created object in the WireContext.

This element can have an attribute "auto-wire", which specifies if auto-wire is enabled (see Auto Wiring)

The method to create the object is specified with one of these methods (see creating objects):

Only one of these methods can be used.

The method attribute specifies a method to call on the object. If the method is called on a previously created object, the access to this object is specified by the "factory" element or attribute. If the method is static, the class is specified by the "class" attribute. The arguments are taken from the <arg> children elements.

Creating objects

Creating object from a constructor

This method uses the "class" attribute.

The constructor is specified by the <constructor> element. It contains a list of <arg> elements, which are the arguments to give to the constructor.

the method attribute must not be used if the <constructor> element is specified.

Example
Consider the following class:
 public class Foo {
   String bar;
   public Foo(String text) {
     bar = text;
   }
 }
The following Xml declaration will create an object 'o' of class 'Foo'. The object will be constructed by calling new Foo("hello").
<objects>
   <object name='o' class='Foo'>
     <constructor>
       <arg>
        <string value='hello' />
       </arg>
     </constructor>
   </object>
 </objects>

Creating an object from a method invocation

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

The object constructed by the resulting ObjectDescriptor is the object returned by the call to the specified method.

Initializing Objects

Auto Wiring

If the auto wiring is enabled for the object (the attribute "auto-wire" is set to "true", "enabled" or "on"), 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 <field> tag 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 (if no auto-wire attribute is found, a default value "auto-wire=disabled" is used).

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 <field> or <property> operation.

Known Xml tags to specify an Operation:

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

Constructor Summary
ObjectBinding()
           
 
Method Summary
 java.lang.Object parse(org.w3c.dom.Element element, Parse parse, Parser parser)
          translates the given element into a domain model java object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectBinding

public ObjectBinding()
Method Detail

parse

public java.lang.Object parse(org.w3c.dom.Element element,
                              Parse parse,
                              Parser parser)
Description copied from interface: Binding
translates the given element into a domain model java object. Use the parse to report problems.

Specified by:
parse in interface Binding
Returns:
the domain model java object.
See Also:
Parser