KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > demo1 > monolithic > ClientImpl


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): Romain Rouvoy_______________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.demo1.monolithic;
28
29 import org.objectweb.ccm.demo1.*;
30
31 /**
32  * This is the implementation of the OMG IDL3 demo1::Client component type.
33  *
34  * This class inherits from the local CCM_Client interface
35  * generated by the OpenCCM's IDL3 to IDL2 mapping generator.
36  *
37  * This class also implements the java.awt.event.ActionListener to manage
38  * users' interactions on the Swing GUI associated to this component.
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  */

43
44 public class ClientImpl
45      extends org.omg.CORBA.LocalObject JavaDoc
46   implements CCM_Client,
47              org.omg.Components.SessionComponent,
48              java.awt.event.ActionListener JavaDoc
49 {
50     // ==================================================================
51
//
52
// Internal state.
53
//
54
// ==================================================================
55

56     /** The name of the component. */
57     private String JavaDoc name_;
58
59     /** To refer to the GUI frame. */
60     private javax.swing.JFrame JavaDoc frame_;
61
62     /** To refer to the user's input field. */
63     private javax.swing.JTextField JavaDoc text_;
64
65     /** To refer to the component context. */
66     private CCM_Client_Context the_context_;
67
68     // ==================================================================
69
//
70
// Constructor.
71
//
72
// ==================================================================
73

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

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

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

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

104     public void
105     configuration_complete()
106     throws org.omg.Components.InvalidConfiguration
107     {
108         // Checks if the configuration is completed.
109
if(name_ == null)
110             throw new org.omg.Components.InvalidConfiguration();
111
112     // Check if the connection to the server is set.
113
if(the_context_.get_connection_to_server() == null)
114             throw new org.omg.Components.InvalidConfiguration();
115
116         // Instantiating the GUI.
117

118         // Creates a Swing Frame.
119
frame_ = new javax.swing.JFrame JavaDoc(name_ + "'s Client GUI");
120         // Sets its size.
121
frame_.setSize(400, 300);
122
123         // Creates a text field for user's inputs.
124
text_ = new javax.swing.JTextField JavaDoc("", 1);
125
126         // Creates a button to invoke the connected server component.
127
javax.swing.JButton JavaDoc button = new javax.swing.JButton JavaDoc("Print Text");
128         button.addActionListener(this);
129
130         // Constructs and shows the GUI.
131
javax.swing.JPanel JavaDoc panel = new javax.swing.JPanel JavaDoc(
132                                            new java.awt.BorderLayout JavaDoc());
133         frame_.getContentPane().add(panel);
134         panel.add(new javax.swing.JScrollPane JavaDoc(text_),
135                   java.awt.BorderLayout.CENTER);
136         panel.add(button, java.awt.BorderLayout.SOUTH);
137         frame_.pack();
138         frame_.show();
139     }
140         
141     // ==================================================================
142
//
143
// Methods for the OMG IDL org.omg.Components.SessionComponent
144
//
145
// ==================================================================
146

147     /**
148      * Set the session component context.
149      *
150      * @param context The session component context.
151      *
152      * @throw org.omg.Components.CCMException For any problems.
153      */

154     public void
155     set_session_context(org.omg.Components.SessionContext context)
156     throws org.omg.Components.CCMException
157     {
158         the_context_ = (CCM_Client_Context)context;
159     }
160
161     /**
162      * Container callback to signal that the component is activated.
163      *
164      * @throw org.omg.Components.CCMException For any problems.
165      */

166     public void
167     ccm_activate()
168     throws org.omg.Components.CCMException
169     {
170         // Nothing to do currently.
171
}
172
173     /**
174      * Container callback to signal that the component is activated.
175      *
176      * @throw org.omg.Components.CCMException For any problems.
177      */

178     public void
179     ccm_passivate()
180     throws org.omg.Components.CCMException
181     {
182         // Nothing to do currently.
183
}
184
185     /**
186      * Container callback to signal that the component is removed.
187      *
188      * @throw org.omg.Components.CCMException For any problems.
189      */

190     public void
191     ccm_remove()
192     throws org.omg.Components.CCMException
193     {
194         // Release the associated frame.
195
frame_.dispose();
196     frame_ = null;
197     }
198
199     // ==================================================================
200
//
201
// Methods for the OMG IDL demo1::CCM_Client
202
//
203
// ==================================================================
204

205     /**
206      * The mutator method for the attribute name.
207      *
208      * @param n The name.
209      */

210     public void
211     the_name(String JavaDoc n)
212     {
213         name_ = n;
214
215         if (frame_ != null)
216             frame_.setTitle(name_ + "'s Client GUI");
217     }
218
219     /**
220      * The accessor method for the attribute name.
221      *
222      * @return The name.
223      */

224     public String JavaDoc
225     the_name()
226     {
227         return name_;
228     }
229
230     // ==================================================================
231
//
232
// Methods for interface java.awt.event.ActionListener
233
//
234
// ==================================================================
235

236     /**
237      * When the button is selectionned.
238      *
239      * @param e The associate ActionEvent.
240      */

241     public void
242     actionPerformed(java.awt.event.ActionEvent JavaDoc e)
243     {
244         // Obtain the object reference associated to the
245
// 'to_server' receptacle.
246
Display to_server = the_context_.get_connection_to_server();
247
248     // Check if the connection is available.
249
if(to_server == null)
250     {
251         System.err.println("The demo1::Client::to_server receptacle is not set!");
252         return;
253     }
254
255         // Calls the print service.
256
to_server.print(name_ + ":" + text_.getText());
257     }
258 }
259
Popular Tags