The Timer Xbean

Function

The timer is a source and a sink Xbean that records the time when it receives a DOM document and passes the document on to its listener. 

Bean Properties

startTime A readonly property whose value is the time that the last document was received. The time is expressed in milliseconds as returned by the Java System method currentTimeMillis().
elapsedTime A readonly property whose value is the number of milliseconds that have elapsed since the document was received. More precisely it is the current time as returned by the Java System method currentTimeMillis() minus the value of the startTime property.
DOMListener As with all source Xbeans, the DOMListener property is the next Xbean in the channel. The DOMListener receives the DOM processed by this Xbean.

Usage

The timer Xbean is in the org.xbeans.utilities package. The package can be imported into Java source code as follows:

import org.xbeans.utilties.TimerBean;

Creating a timer Xbean is accomplished by instantiating the class:

TimerBean timer = new TimerBean();

Note that if you are using a Java Bean design tools found in many Java Integrated Development Environments, the above code is generated automatically when you drag and drop a timer Xbean into your application.

After creating the timer Xbean, you need to get a DOM document by registering it with the previous Xbean in the channel.

previousXbean.setDOMListener(timer);

To pass the document on to the next Xbean, you simply register the next Xbean to be the DOM Listener.

timer.setDOMListener(nextXbean);

Again, if you are using a Java Bean design tool, the above calls setting properties may be automatically generated for you.

By placing a timer in a channel, it is possible to track the amount of time that has elapsed to process the chain. At any point, simply call:

timer.getElapsedTime();

Source files

source/org/xbeans/utilities/TimerBean.java
source/org/xbeans/utilities/TimerBeanBeanInfo.java