KickJava   Java API By Example, From Geeks To Geeks.

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


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::Server component type.
33  *
34  * This class inherits from the local CCM_Server interface
35  * generated by the OpenCCM's IDL3 to IDL2 mapping generator.
36  *
37  * The provided the_service facet is directly implemented
38  * by the component class by implementing the demo3::Service 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 ServerImpl
46      extends org.omg.CORBA.LocalObject JavaDoc
47   implements CCM_Server,
48              CCM_Service,
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_Server_Context the_context_;
68
69     // ==================================================================
70
//
71
// Constructor.
72
//
73
// ==================================================================
74

75     /** The default constructor. */
76     public
77     ServerImpl()
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      * Complete 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 Server 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                                    );
128         frame_.getContentPane().add(panel);
129         panel.add(new javax.swing.JScrollPane JavaDoc(textArea_),
130                   java.awt.BorderLayout.CENTER);
131         frame_.pack();
132         frame_.show();
133     }
134
135     // ==================================================================
136
//
137
// Methods for the OMG IDL org.omg.Components.SessionComponent
138
//
139
// ==================================================================
140

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

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

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

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

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

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

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

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

230     /**
231      * The component must provide the executor object implementing
232      * the the_service Facet.
233      *
234      * @return An executor implementing Service.
235      */

236     public CCM_Service
237     get_the_service()
238     {
239         // Returns the component because it implements the Service facet.
240
return this;
241     }
242
243     // ==================================================================
244
//
245
// Methods for OMG IDL demo3::CCM_Service
246
//
247
// ==================================================================
248

249     /**
250      * The display operation of the demo3::Service interface.
251      *
252      * @param text The text to display.
253      */

254     public void
255     display(String JavaDoc text)
256     {
257         // Puts the text into the text area.
258
textArea_.append(text + "\n");
259
260         // Pushes an event to all connected consumers.
261
the_context_.push_to_consumers( new TextEventImpl(text) );
262     }
263 }
264
265
Popular Tags