KickJava   Java API By Example, From Geeks To Geeks.

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

44
45 public class ConsumerImpl
46      extends org.objectweb.ccm.demo2.ConsumerSessionComposition.ComponentImpl
47 {
48     // ==================================================================
49
//
50
// Internal state.
51
//
52
// ==================================================================
53

54     /** The name of the component. */
55     private String JavaDoc name_;
56
57     /** To refer to the GUI frame. */
58     private javax.swing.JFrame JavaDoc frame_;
59
60     /** To refer to the GUI output area. */
61     private javax.swing.JTextArea JavaDoc textArea_;
62
63     // ==================================================================
64
//
65
// Constructor.
66
//
67
// ==================================================================
68

69     /** The default constructor. */
70     public
71     ConsumerImpl()
72     {
73     }
74
75     // ==================================================================
76
//
77
// Internal methods.
78
//
79
// ==================================================================
80

81     // ==================================================================
82
//
83
// Public methods.
84
//
85
// ==================================================================
86

87     // ==================================================================
88
//
89
// Methods for OMG IDL Components::EnterpriseComponent
90
//
91
// ==================================================================
92

93     /**
94      * Complete the component configuration.
95      *
96      * @exception org.omg.Components.InvalidConfiguration
97      * Thrown if the configuration is invalid.
98      */

99     public void
100     configuration_complete ()
101     throws org.omg.Components.InvalidConfiguration
102     {
103         // Checks if the configuration is not completed.
104
if(name_ == null)
105             throw new org.omg.Components.InvalidConfiguration();
106
107         // Instantiating the GUI.
108

109         // Creates a Swing Frame.
110
frame_ = new javax.swing.JFrame JavaDoc(name_ + "'s Consumer GUI");
111         // Sets its size.
112
frame_.setSize(400, 300);
113
114         // Creates a text area for displaying inputs.
115
textArea_ = new javax.swing.JTextArea JavaDoc(40, 20);
116         textArea_.setEditable(false);
117
118         // Constructs and shows the GUI.
119
javax.swing.JPanel JavaDoc panel = new javax.swing.JPanel JavaDoc(
120                                        new java.awt.BorderLayout JavaDoc()
121                                    );
122         frame_.getContentPane().add(panel);
123         panel.add(new javax.swing.JScrollPane JavaDoc(textArea_),
124                   java.awt.BorderLayout.CENTER);
125         frame_.pack();
126         frame_.show();
127     }
128
129     // ==================================================================
130
//
131
// Methods for the OMG IDL org.omg.Components.SessionComponent
132
//
133
// ==================================================================
134

135     /**
136      * Container callback to signal that the component is removed.
137      *
138      * @throw org.omg.Components.CCMException For any problems.
139      */

140     public void
141     ccm_remove()
142     throws org.omg.Components.CCMException
143     {
144         // Release the associated frame.
145
frame_.dispose();
146         frame_ = null;
147     }
148
149     // ==================================================================
150
//
151
// Methods for OMG IDL demo2::CCM_Consumer
152
//
153
// ==================================================================
154

155     /**
156      * The mutator method for the attribute name.
157      *
158      * @param n The name.
159      */

160     public void
161     name(String JavaDoc n)
162     {
163         name_ = n;
164
165         if (frame_ != null)
166             frame_.setTitle(name_ + "'s Consumer GUI");
167     }
168
169     /**
170      * The accessor method for the attribute name.
171      *
172      * @return The name.
173      */

174     public String JavaDoc
175     name()
176     {
177         return name_;
178     }
179
180     // ==================================================================
181
//
182
// Methods for the OMG IDL demo2::CCM_FoodConsumer interface.
183
//
184
// ==================================================================
185

186     /**
187      * Implementation of the OMG IDL demo2::FoodConsumer::push operation.
188      *
189      * @param event The received event.
190      */

191     public void
192     push(Food event)
193     {
194         // Puts the food type into the text area.
195
textArea_.append("Receive Food(" + event.type + ")\n");
196     }
197 }
198
199
200
Popular Tags