EventRaiserImpl.jcs Sample

This topic inludes the source code for the EventRaiserImpl.jcs Sample.

Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/ExtensionDevKit/ControlDevKit/ControlFeatures/controlEvents/

Sample Source Code


01 package controlEvents; 
02 
03 import com.bea.control.*;
04 
05 /**
06  * EventRaiser illustrates how you can pass a callback 
07  * from a nested control through to a client. EventRaiser nests
08  * a Timer control. When that Timer fires its onTimeout, that
09  * callback is simply sent directly to the client through a
10  * callback that EventRaiser exposes. 
11  
12  * @jcs:jc-jar label="EventRaiser"
13  *          version="1.0" 
14  *          icon-16="/images/buffer_16.gif" 
15  *          icon-32="/images/buffer_32.gif" 
16  *          group-name="Feature Sample Controls" 
17  *          description="Starts a timer and calls raiseEvent to callback its container"
18  *          palette-priority="7" 
19  */
20 public class EventRaiserImpl implements EventRaiser, com.bea.control.ControlSource
21 {
22     /**
23      * @jc:timer timeout="5 seconds"
24      * @common:control
25      */
26     private TimerControl backEndTimer;
27 
28     /**
29      * @common:context
30      */
31     com.bea.control.ControlContext context;
32 
33     /**
34      * The startTimer method provides a way for EventRaiser's
35      * clients to start its Timer.
36      
37      * @common:operation
38      */
39     public void startTimer()
40     {
41         backEndTimer.start();
42     }
43 
44     /* 
45      * This is the handler for the Timer control's onTimeout
46      * callback. When that callback is received, it is sent directly
47      * to EventRaiser's client.
48      */
49     public void backEndTimer_onTimeout(long arg0)
50     {
51         try{
52             /* 
53              * The raiseEvent method tells WebLogic Server to 
54              * forward the onTimeout callback to an EventRaiser
55              * callback *that has the same name*.
56              */
57             context.raiseEvent();
58         catch (Exception e){
59             throw new ControlException("EventRaiser exception.", e);
60         }
61     }
62  
63