KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > demo3 > 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): 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::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  * <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</A>
43  */

44
45 public class ClientImpl
46      extends org.omg.CORBA.LocalObject JavaDoc
47   implements CCM_Client,
48              org.omg.Components.SessionComponent,
49              java.awt.event.ActionListener JavaDoc
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 input field. */
64     private javax.swing.JTextField JavaDoc text_;
65
66     /** To refer to the component context. */
67     private CCM_Client_Context the_context_;
68
69     // ==================================================================
70
//
71
// Constructor.
72
//
73
// ==================================================================
74

75     /** The default constructor. */
76     public
77     ClientImpl()
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 completed.
110
if(name_ == null)
111             throw new org.omg.Components.InvalidConfiguration();
112
113         // Check if the connection to the server is set.
114
if(the_context_.get_connection_the_service() == null)
115             throw new org.omg.Components.InvalidConfiguration();
116
117         // Instantiating the GUI.
118

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

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

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

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

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

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

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

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

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

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

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