org.jbpm.wire.binding
Class SubscribeBinding

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

public class SubscribeBinding
extends java.lang.Object
implements Binding

This Binding specifies a SubscribeOperation (subscription to an Observable object).

XML declaration

A subscription is defined by a <subscribe> xml element.

Context attribute

This element can have a "context" attribute. The value of this attribute should be the name of a WireContext in the object's environment. This WireContext will be used to find the Observable to listen. If this attribute is not present, the object's WireContext will be used.

Event attribute

This element can have a "event" or "events" attribute. The value of this attribute specifies the list of events name that should be observed. Other events are filtered. If this attribute if not present, all events are observed.

Object attribute

This element can have a "object" or "objects" attribute. The value of this attribute specifies the list of objects that should be observed. If this attribute if not present, the WireContext specified by the "context" attribute is observed.

To attribute

This element can have a "to" attribute. If this attribute is set to "wire-events", the object will listen to the events fired by the descriptor of the target object. Otherwise, it will listen to the events fired by the target object (which must be an instance of Observable).

Method attribute

This element can have a "method" attribute.

If this attribute is not present, this operation must be applied to a Listener object.

If this attribute is present, the specified method will be invoked each time the specified events are received. Arguments given to the method invocation are specified in the <arg> child elements of the <subscribe> element. For more information on how to declare arguments, see ArgDescriptor.

Examples

Observing a WireContext

 <objects>
   <object name='o' class='Listener'>
     <subscribe context='contextName' />
   </object>
 </objects>
In this example, the object 'o' will observe all events of the WireContext named 'contextName'.

Observing objects.

 <objects>
   <object name='l' class='Listener'>
     <subscribe objects='a, c' />
   </object>
   <object name='a' class='Observable' />
   <object name='b' class='Observable' />
   <object name='c' class='Observable' />
 </objects>
In this example, the object 'l' will observe all events from 'a' and 'c', but not events fired by 'b'.

Observing events.

 <objects>
   <object name='l' class='Listener'>
     <subscribe object='a' event='start'/>
   </object>
   <object name='a' class='Observable' />
 </objects>
In this example, the object 'l' will observe the 'start' event from 'a', but not other events (for example a 'stop' event won't be observed).

Invoking a method on event reception

Consider the following class:
 public class Foo {
   void logEvent(String name) {
    System.out.println("Object " + name  + " sent an event.");
   }
 }
With the following definition:
 <objects>
   <object name='l' class='Foo'>
     <subscribe object='a' method='logEvent' >
        <arg>
          <string value='a'/>
        </arg>
     </subscribe>
     <subscribe object='b' method='logEvent' >
        <arg>
          <string value='b'/>
        </arg>
     </subscribe>
   </object>
   <object name='a' class='Observable' />
   <object name='b' class='Observable' />
 </objects>
When 'a' fires an event, logEvent("a") will be invoked; when 'b' fires an event, logEvent("b") will be invoked.

Author:
Tom Baeyens, Guillaume Porcher (documentation)

Constructor Summary
SubscribeBinding()
           
 
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

SubscribeBinding

public SubscribeBinding()
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