KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > chat > 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): Areski Flissi.
23 Contributor(s):
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.chat.monolithic;
28
29 import org.objectweb.ccm.chat.*;
30
31 /**
32  * This is the implementation of the OMG IDL3 chat::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 chat::Service interface.
39  *
40  * @author <a HREF="mailto:Areski.Flissi@lifl.fr">Areski Flissi</A>
41  */

42
43 public class ServerImpl
44      extends org.omg.CORBA.LocalObject JavaDoc
45   implements CCM_Server,
46              CCM_Service,
47              org.omg.Components.SessionComponent
48 {
49     // ==================================================================
50
//
51
// Internal state.
52
//
53
// ==================================================================
54

55     /** The name of the component. */
56     private String JavaDoc name_;
57
58     /** To refer to the GUI frame. */
59     private java.awt.Frame JavaDoc frame_;
60     /** To refer to the GUI user output area. */
61     private java.awt.TextArea JavaDoc textArea_;
62
63     /** To refer to the component context. */
64     private CCM_Server_Context the_context_;
65
66     // ==================================================================
67
//
68
// Constructor.
69
//
70
// ==================================================================
71

72     /** The default constructor. */
73     public
74     ServerImpl()
75     {
76     }
77
78     // ==================================================================
79
//
80
// Internal methods.
81
//
82
// ==================================================================
83

84     // ==================================================================
85
//
86
// Public methods.
87
//
88
// ==================================================================
89

90     // ==================================================================
91
//
92
// Methods for OMG IDL Components::EnterpriseComponent
93
//
94
// ==================================================================
95

96     /**
97      * Complete the component configuration.
98      *
99      * @exception org.omg.Components.InvalidConfiguration
100      * Thrown if the configuration is invalid.
101      */

102     public void
103     configuration_complete()
104     throws org.omg.Components.InvalidConfiguration
105     {
106         // Checks if the configuration is not completed.
107
if(name_ == null)
108             throw new org.omg.Components.InvalidConfiguration();
109
110         System.out.println("================================");
111         System.out.println("Welcome to OpenCCM's Chat server");
112         System.out.println("================================");
113     }
114
115     // ==================================================================
116
//
117
// Methods for the OMG IDL org.omg.Components.SessionComponent
118
//
119
// ==================================================================
120

121     /**
122      * Set the session component context.
123      *
124      * @param context The session component context.
125      *
126      * @throw org.omg.Components.CCMException For any problems.
127      */

128     public void
129     set_session_context(org.omg.Components.SessionContext context)
130     throws org.omg.Components.CCMException
131     {
132         the_context_ = (CCM_Server_Context)context;
133     }
134
135     /**
136      * Container callback to signal that the component is activated.
137      *
138      * @throw org.omg.Components.CCMException For any problems.
139      */

140     public void
141     ccm_activate()
142     throws org.omg.Components.CCMException
143     {
144         // Nothing to do currently.
145
}
146
147     /**
148      * Container callback to signal that the component is activated.
149      *
150      * @throw org.omg.Components.CCMException For any problems.
151      */

152     public void
153     ccm_passivate()
154     throws org.omg.Components.CCMException
155     {
156         // Nothing to do currently.
157
}
158
159     /**
160      * Container callback to signal that the component is removed.
161      *
162      * @throw org.omg.Components.CCMException For any problems.
163      */

164     public void
165     ccm_remove()
166     throws org.omg.Components.CCMException
167     {
168         // Release the associated frame.
169
frame_.dispose();
170         frame_ = null;
171     }
172
173     // ==================================================================
174
//
175
// Methods for OMG IDL chat::CCM_NamedComponent_Executor
176
//
177
// ==================================================================
178

179     /**
180      * The mutator method for the attribute name.
181      *
182      * @param n The name.
183      */

184     public void
185     name(String JavaDoc n)
186     {
187         name_ = n;
188
189         if (frame_ != null)
190             frame_.setTitle(name_ + "'s Server GUI");
191     }
192
193     /**
194      * The accessor method for the attribute name.
195      *
196      * @return The name.
197      */

198     public String JavaDoc
199     name()
200     {
201         return name_;
202     }
203
204     // ==================================================================
205
//
206
// Methods for OMG IDL chat::CCM_Server
207
//
208
// ==================================================================
209

210     /**
211      * The component must provide the executor object implementing
212      * the the_service Facet.
213      *
214      * @return An executor implementing Service.
215      */

216     public CCM_Service
217     get_the_service()
218     {
219         // Returns the component because it implements the Service facet.
220
return this;
221     }
222
223     // ==================================================================
224
//
225
// Methods for OMG IDL chat::CCM_Service
226
//
227
// ==================================================================
228

229     /**
230      * The display operation of the chat::Service interface.
231      *
232      * @param text The text to display.
233      */

234     public void
235     display(String JavaDoc text)
236     {
237         // Puts the text into the text area.
238
//textArea_.append(text + "\n");
239
System.out.println(text);
240         // Pushes an event to all connected consumers.
241
the_context_.push_to_consumers( new TextEventImpl(text) );
242     }
243 }
244
245
Popular Tags