001 package controlEvents;
002
003 import com.bea.control.*;
004 import java.util.Date;
005 import java.util.Calendar;
006
007 /**
008 * The LifeCycle control simply illustrates the events that occur
009 * in the life of a Java control. As the client uses this control --
010 * acquiring it, calling its method, releasing it -- each of these
011 * events is reported to the WebLogic Server console window.
012 *
013 * @jcs:jc-jar palette-priority="7" label="LifeCycle"
014 * version="1.0"
015 * icon-16="/images/buffer_16.gif"
016 * icon-32="/images/buffer_32.gif"
017 * group-name="Feature Sample Controls"
018 * description="Illustrates Context life cycle events"
019 * @editor-info:code-gen control-interface="true"
020 */
021 public class LifeCycleImpl implements LifeCycle, com.bea.control.ControlSource
022 {
023 /**
024 * @jc:timer timeout="5 seconds"
025 * @common:control
026 */
027 private TimerControl delayTimer;
028
029 public Callback callback;
030
031 long m_currentTime;
032 StringBuffer m_cycleMessages = new StringBuffer();
033 Calendar m_calendar;
034
035 /**
036 * @common:context
037 */
038 com.bea.control.ControlContext context;
039
040 /**
041 * The startMeUp method provides a place for clients to start using this
042 * control.
043 *
044 * @common:operation
045 */
046 public void startMeUp()
047 {
048 String message = "LifeCycle: context.startMeUp method is called. \n";
049 System.out.println(message);
050 m_cycleMessages.append(message);
051 }
052
053 /*
054 * The onCreate callback is received when the control is created by
055 * the container. onCreate is a good place to acquire resources that
056 * may be needed by the control.
057 */
058 public void context_onCreate() {
059 delayTimer.start();
060 String message = "LifeCycle: context_onCreate received. Timer started. \n";
061
062 System.out.println(message);
063 m_cycleMessages.append(message);
064 }
065
066 /*
067 * onAcquire is received when a control operation is about to start.
068 */
069 public void context_onAcquire() {
070 String message = "LifeCycle: context_onAcquire received. \n";
071 System.out.println(message);
072 m_cycleMessages.append(message);
073 }
074
075 /*
076 * onReset is implemented to let the container know that this
077 * instance can be re-used after a call to onReset().
078 */
079 public void context_onReset() {
080 String message = "LifeCycle: context_onReset received. \n";
081 System.out.println(message);
082 m_cycleMessages.append(message);
083 }
084
085 /*
086 * onRelease is received with a control operation has finished.
087 */
088 public void context_onRelease() {
089 String message = "LifeCycle: context_onRelease received. \n";
090 System.out.println(message);
091 m_cycleMessages.append(message);
092 }
093
094
095 /*
096 * onException is received in the event of an unhandled exception.
097 * It provides a place to do clean up and notify the client
098 * of the error.
099 */
100 public void context_onException(Exception e, String methodName,
101 Object[] methodArgs)
102 {
103 throw new ControlException("Exception at: " + methodName, e);
104 }
105
106
107 public void delayTimer_onTimeout(long arg0)
108 {
109 String message = "LifeCycle: delayTimer_onTimeout received. " +
110 "onDone about to be invoked. \n";
111 System.out.println(message);
112 callback.onDone(m_cycleMessages.toString());
113 }
114 }
|