KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > logdemo > AsyncServerImpl


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@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): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ccm.logdemo;
31
32 /**
33  ** This is the ECM-unaware (and CCM standard) implementation of the OMG IDL3
34  ** <tt>AsyncServer</tt> component type.
35  **/

36 public class AsyncServerImpl
37 extends AsyncServer_MainSegBase
38 {
39     // server
40
private String JavaDoc _name;
41     private javax.swing.JFrame JavaDoc _frame;
42     private javax.swing.JTextArea JavaDoc _text;
43
44     public
45     AsyncServerImpl()
46     {
47         // server
48
_name = null;
49         _frame = null;
50         _text = null;
51     }
52
53     //
54
// overriden operations
55
//
56

57     final public void
58     configuration_complete()
59     throws org.omg.Components.InvalidConfiguration
60     {
61         // create a GUI
62
// CENTER: text field to display client inputs
63
_text = new javax.swing.JTextArea JavaDoc(40, 20);
64         _text.setEditable(false);
65
66         // MAIN panel
67
javax.swing.JPanel JavaDoc panel = new javax.swing.JPanel JavaDoc(new java.awt.BorderLayout JavaDoc());
68         panel.add(new javax.swing.JScrollPane JavaDoc(_text), java.awt.BorderLayout.CENTER);
69         _frame = new javax.swing.JFrame JavaDoc(_name + " GUI");
70         _frame.setSize(400, 300);
71         _frame.getContentPane().add(panel);
72         _frame.pack();
73         _frame.show();
74     }
75
76     //
77
// IDL:omg.org/Components/SessionComponent:1.0
78
//
79

80     final public void
81     ccm_activate()
82     throws org.omg.Components.CCMException
83     {
84         // NOTE: TODO: should be done externally using the CSD info
85
// register value factory
86
getCCM2Context().register_valuefactory(AsyncMessageHelper.id(), new AsyncMessageFactoryImpl());
87
88         // show the frame if hidden
89
if ((_frame!=null) && (!_frame.isShowing())){
90             _frame.show();
91         }
92     }
93
94     final public void
95     ccm_passivate()
96     throws org.omg.Components.CCMException
97     {
98         // hide the frame and clear the text field
99
_text.setText(null);
100         _frame.hide();
101     }
102
103     final public void
104     ccm_remove()
105     throws org.omg.Components.CCMException
106     {
107         // Release the associated frame.
108
_frame.dispose();
109         _frame = null;
110     }
111
112     //
113
// IDL:org.omg/Components/EventConsumerBase:1.0
114
//
115

116     final public void
117     push_event(org.omg.Components.EventBase evt)
118     throws org.omg.Components.BadEventType
119     {
120         if (evt instanceof AsyncMessage) {
121             push_AsyncMessage((AsyncMessage)evt);
122             return ;
123         }
124
125         throw new org.omg.Components.BadEventType();
126     }
127
128     //
129
// IDL:objectweb.org/ccm/logdemo/MessageConsumer:1.0
130
//
131

132     final public void
133     push_AsyncMessage(AsyncMessage amsg)
134     {
135         // add content to the text field
136
_text.append("["+amsg.msg.header+"] "+amsg.msg.content + "\n");
137     }
138
139     //
140
// IDL:objectweb.org/ccm/logdemo/AsyncServer:1.0
141
//
142

143     final public void
144     name(String JavaDoc n)
145     {
146         _name = n;
147
148         if (_frame!=null) {
149             _frame.setTitle(_name+" GUI");
150         }
151     }
152
153     final public String JavaDoc
154     name()
155     {
156         return _name;
157     }
158 }
159
Popular Tags