KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > core > component > lifecycle > test > TestComponentImpl


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.core.component.lifecycle.test;
19
20 import org.sape.carbon.core.component.Component;
21 import org.sape.carbon.core.component.ComponentConfiguration;
22 import org.sape.carbon.core.component.lifecycle.ComponentLifecycle;
23
24
25 /**
26  * A simple Component that provides only Lifecycle methods
27  *
28  * Copyright 2002 Sapient
29  * @since carbon 1.0
30  * @author Chris Herron, Febuary 2002
31  * @version $Revision: 1.11 $($Author: dvoet $ / $Date: 2003/05/05 21:21:13 $)
32  */

33 public class TestComponentImpl implements TestComponent, ComponentLifecycle {
34
35     TestListener listener;
36
37     Component thisComponent;
38
39     /** Creates a new TestComponentImpl */
40     public TestComponentImpl() {
41         this.listener = null;
42     }
43
44     /** Creates a new TestComponentImpl */
45     public TestComponentImpl(TestListener listener) {
46         this.listener = listener;
47     }
48
49     /**
50      * Suspend the component. This is an opportunity to 'pause' any ongoing
51      * work". Prior to calling this method, the container will block requests
52      * for service to the component.
53      */

54     public void suspend() {
55         if (this.listener != null) {
56             this.listener.suspendCalled();
57         }
58     }
59
60     /**
61      * Destroy the component. Called when the Component is already Stopped.
62      */

63     public void destroy() {
64         if (this.listener != null) {
65             this.listener.destroyCalled();
66         }
67     }
68
69     /**
70      * Initialize the component. Called immediately after the Component's
71      * constructor. On return, the container may start the component.
72      */

73     public void initialize(Component thisComponent) {
74         this.thisComponent = thisComponent;
75
76         if (this.listener != null) {
77             this.listener.initializeCalled();
78         }
79     }
80
81     /**
82      * Resume the component. This implies "picking-up where you left off".
83      * On return of this method, the container will resume forwarding service
84      * requests to the component.
85      */

86     public void resume() {
87         if (this.listener != null) {
88             this.listener.resumeCalled();
89         }
90     }
91
92     /**
93      * Configure the component. This is preceded and followed by the suspend and
94      * resume operations if they are available on the component.
95      */

96     public void configure(ComponentConfiguration configuration) {
97         if (this.listener != null) {
98             this.listener.configureCalled();
99         }
100     }
101
102     /**
103      * Stop the component. Prior to entry, the container will cease forwarding
104      * requests for service to the component. This is an opportunity to cleanly
105      * complete or abort any outstanding work. For example, a set of worker
106      * threads could be killed off, or a queue set to drain.
107      */

108     public void stop() {
109         if (this.listener != null) {
110             this.listener.stopCalled();
111         }
112     }
113
114     /**
115      * Start the component. On return, the container will begin fowarding
116      * requests to the component. This may be an opportunity to dispatch
117      * worker threads.
118      */

119     public void start() {
120         if (this.listener != null) {
121             this.listener.startCalled();
122         }
123     }
124
125     /**
126      * @see TestComponent#doSomething()
127      */

128     public void doSomething() {
129     }
130
131     public Component getThisComponent() {
132         return this.thisComponent;
133     }
134
135 }
136
Popular Tags