KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > demo3 > monolithic > ConsumerImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Mathieu Vadet.
23 Contributor(s): Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.demo3.monolithic;
28
29 import org.objectweb.ccm.demo3.*;
30
31 /**
32  * This is the implementation of the OMG IDL3 demo3::Consumer component type.
33  *
34  * This class inherits from the local CCM_Consumer interface
35  * generated by the OpenCCM's IDL3 to IDL2 mapping generator.
36  *
37  * The from_servers event sink is directly implemented
38  * by the component class by implementing the demo3::EventConsumer interface.
39  *
40  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</A>
41  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</A>
42  * <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</A>
43  */

44
45 public class ConsumerImpl
46      extends org.omg.CORBA.LocalObject JavaDoc
47   implements CCM_Consumer,
48              CCM_TextEventConsumer,
49              org.omg.Components.SessionComponent
50 {
51     // ==================================================================
52
//
53
// Internal state.
54
//
55
// ==================================================================
56

57     /** The name of the component. */
58     private String JavaDoc name_;
59
60     /** To refer to the GUI frame. */
61     private javax.swing.JFrame JavaDoc frame_;
62
63     /** To refer to the GUI user output area. */
64     private javax.swing.JTextArea JavaDoc textArea_;
65
66     /** To refer to the component context. */
67     private CCM_Consumer_Context the_context_;
68
69     // ==================================================================
70
//
71
// Constructor.
72
//
73
// ==================================================================
74

75     /** The default constructor. */
76     public
77     ConsumerImpl()
78     {
79     }
80
81     // ==================================================================
82
//
83
// Internal methods.
84
//
85
// ==================================================================
86

87     // ==================================================================
88
//
89
// Public methods.
90
//
91
// ==================================================================
92

93     // ==================================================================
94
//
95
// Methods for OMG IDL Components::EnterpriseComponent
96
//
97
// ==================================================================
98

99     /**
100      * Completes the component configuration.
101      *
102      * @exception org.omg.Components.InvalidConfiguration
103      * Thrown if the configuration is invalid.
104      */

105     public void
106     configuration_complete()
107     throws org.omg.Components.InvalidConfiguration
108     {
109         // Checks if the configuration is not completed.
110
if(name_ == null)
111             throw new org.omg.Components.InvalidConfiguration();
112
113         // Instantiating the GUI.
114

115         // Creates a Swing Frame.
116
frame_ = new javax.swing.JFrame JavaDoc(name_ + "'s Consumer GUI");
117         // Sets its size.
118
frame_.setSize(400, 300);
119
120         // Creates a text area for displaying inputs.
121
textArea_ = new javax.swing.JTextArea JavaDoc(40, 20);
122         textArea_.setEditable(false);
123
124         // Constructs and shows the GUI.
125
javax.swing.JPanel JavaDoc panel = new javax.swing.JPanel JavaDoc(
126                                         new java.awt.BorderLayout JavaDoc());
127         frame_.getContentPane().add(panel);
128         panel.add(new javax.swing.JScrollPane JavaDoc(textArea_),
129                   java.awt.BorderLayout.CENTER);
130         frame_.pack();
131         frame_.show();
132     }
133
134     // ==================================================================
135
//
136
// Methods for the OMG IDL org.omg.Components.SessionComponent
137
//
138
// ==================================================================
139

140     /**
141      * Set the session component context.
142      *
143      * @param context The session component context.
144      *
145      * @throw org.omg.Components.CCMException For any problems.
146      */

147     public void
148     set_session_context(org.omg.Components.SessionContext context)
149     throws org.omg.Components.CCMException
150     {
151         the_context_ = (CCM_Consumer_Context)context;
152     }
153
154     /**
155      * Container callback to signal that the component is activated.
156      *
157      * @throw org.omg.Components.CCMException For any problems.
158      */

159     public void
160     ccm_activate()
161     throws org.omg.Components.CCMException
162     {
163         // Nothing to do currently.
164
}
165
166     /**
167      * Container callback to signal that the component is activated.
168      *
169      * @throw org.omg.Components.CCMException For any problems.
170      */

171     public void
172     ccm_passivate()
173     throws org.omg.Components.CCMException
174     {
175         // Nothing to do currently.
176
}
177
178     /**
179      * Container callback to signal that the component is removed.
180      *
181      * @throw org.omg.Components.CCMException For any problems.
182      */

183     public void
184     ccm_remove()
185     throws org.omg.Components.CCMException
186     {
187         // Release the associated frame.
188
frame_.dispose();
189         frame_ = null;
190     }
191
192     // ==================================================================
193
//
194
// Methods for OMG IDL demo3::CCM_NamedComponent_Executor
195
//
196
// ==================================================================
197

198     /**
199      * The mutator method for the attribute name.
200      *
201      * @param n The name.
202      */

203     public void
204     name(String JavaDoc n)
205     {
206         name_ = n;
207
208         if (frame_ != null)
209             frame_.setTitle(name_ + "'s Consumer GUI");
210     }
211
212     /**
213      * The accessor method for the attribute name.
214      *
215      * @return The name.
216      */

217     public String JavaDoc
218     name()
219     {
220         return name_;
221     }
222
223     // ==================================================================
224
//
225
// Methods for OMG IDL demo3::CCM_Consumer
226
//
227
// ==================================================================
228

229     /**
230      * To receive demo3::Event events published by demo3::Server components.
231      *
232      * @param event The received event.
233      */

234     public void
235     push_from_servers(TextEvent event)
236     {
237         push(event);
238     }
239
240
241     // ==================================================================
242
//
243
// Methods for OMG IDL demo3::CCM_TextEventConsumer
244
//
245
// ==================================================================
246

247     /**
248      * To receive demo3::Event events published by demo3::Server components.
249      *
250      * @param event The received event.
251      */

252     public void
253     push(TextEvent event)
254     {
255         // Put the text into the text area.
256
textArea_.append(event.text + "\n");
257     }
258 }
259
260
Popular Tags