KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > demo2 > 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): Romain Rouvoy, Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.ccm.demo2.monolithic;
28
29 import org.objectweb.ccm.demo2.*;
30
31 /**
32  * This is the implementation of the OMG IDL3 demo2::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  * This class also implements the demo2::Food event sink interface
38  * to consume Food events.
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 ConsumerImpl
45      extends org.omg.CORBA.LocalObject JavaDoc
46   implements CCM_Consumer,
47              CCM_FoodConsumer,
48              org.omg.Components.SessionComponent
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 GUI output area. */
63     private javax.swing.JTextArea JavaDoc textArea_;
64
65     /** To refer to the component context. */
66     private CCM_Consumer_Context the_context_;
67
68     // ==================================================================
69
//
70
// Constructor.
71
//
72
// ==================================================================
73

74     /** The default constructor. */
75     public
76     ConsumerImpl()
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 not completed.
109
if(name_ == null)
110             throw new org.omg.Components.InvalidConfiguration();
111
112         // Instantiating the GUI.
113

114         // Creates a Swing Frame.
115
frame_ = new javax.swing.JFrame JavaDoc(name_ + "'s Consumer GUI");
116         // Sets its size.
117
frame_.setSize(400, 300);
118
119         // Creates a text area for displaying inputs.
120
textArea_ = new javax.swing.JTextArea JavaDoc(40, 20);
121         textArea_.setEditable(false);
122
123         // Constructs and shows the GUI.
124
javax.swing.JPanel JavaDoc panel = new javax.swing.JPanel JavaDoc(
125                                        new java.awt.BorderLayout JavaDoc()
126                                    );
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 demo2::CCM_Consumer
195
//
196
// ==================================================================
197

198     /**
199      * Implementation of the OMG IDL demo2::FoodConsumer::push operation.
200      *
201      * @param event The received event.
202      */

203     public void
204     push_eat(Food event)
205     {
206         push(event);
207     }
208
209     /**
210      * The mutator method for the attribute name.
211      *
212      * @param n The name.
213      */

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

228     public String JavaDoc
229     name()
230     {
231         return name_;
232     }
233
234     // ==================================================================
235
//
236
// Methods for the OMG IDL demo2::CCM_FoodConsumer interface.
237
//
238
// ==================================================================
239

240     /**
241      * Implementation of the OMG IDL demo2::FoodConsumer::push operation.
242      *
243      * @param event The received event.
244      */

245     public void
246     push(Food event)
247     {
248         // Puts the food type into the text area.
249
textArea_.append("Receive Food(" + event.type + ")\n");
250     }
251 }
252
253
254
Popular Tags