KickJava   Java API By Example, From Geeks To Geeks.

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


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-aware implementation of the OMG IDL3 <tt>Server</tt> component type
34  ** which uses the simple log service.
35  **/

36 public class ServerWithLogImpl
37 extends Server_MainSegBase
38 implements java.io.Serializable JavaDoc,
39            org.coach.ECM.ECMExecutor,
40            org.objectweb.ccm.logservice.LogCallback
41 {
42     // server
43
private String JavaDoc _name;
44     private javax.swing.JFrame JavaDoc _frame;
45     private javax.swing.JTextArea JavaDoc _text;
46
47     public
48     ServerWithLogImpl()
49     {
50         // server
51
_name = null;
52         _frame = null;
53         _text = null;
54     }
55
56     //
57
// overriden operations
58
//
59

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

83     final public void
84     ccm_activate()
85     throws org.omg.Components.CCMException
86     {
87         // show the frame if hidden
88
if ((_frame!=null) && (!_frame.isShowing())){
89             _frame.show();
90         }
91     }
92
93     final public void
94     ccm_passivate()
95     throws org.omg.Components.CCMException
96     {
97         // hide the frame and clear the text field
98
_frame.hide();
99         _text.setText(null);
100     }
101
102     final public void
103     ccm_remove()
104     throws org.omg.Components.CCMException
105     {
106         // Release the associated frame.
107
_frame.dispose();
108         _frame = null;
109     }
110
111     //
112
// IDL:coach.org/ECM/ECMExecutor:1.0
113
//
114

115     final public org.omg.CORBA.Object JavaDoc
116     get_service_callback(String JavaDoc sid, String JavaDoc cid)
117     throws org.coach.ECM.UnknownService,
118            org.coach.ECM.UnknownServiceCallback
119     {
120         if (!sid.equals(org.objectweb.ccm.logservice.LOG_SERVICE_ID.value)) {
121             throw new org.coach.ECM.UnknownService();
122         }
123
124         if (!cid.equals(org.objectweb.ccm.logservice.LOG_SERVICE_CALLBACK_ID.value)) {
125             throw new org.coach.ECM.UnknownServiceCallback();
126         }
127
128         return this;
129     }
130
131     //
132
// IDL:objectweb.org/ccm/logservice/LogCallback:1.0
133
//
134

135     final public String JavaDoc
136     get_identity()
137     {
138         return "Server:"+name();
139     }
140
141     //
142
// IDL:objectweb.org/ccm/logdemo/CCM_Display:1.0
143
//
144

145     final public void
146     print(Message msg)
147     {
148         // add content to the text field
149
_text.append("["+msg.header+"] "+msg.content + "\n");
150
151         // use the log service internal interface to send a log event.
152
try {
153             // get ECMContext
154
org.coach.ECM.ECMContext ctx = getECMContext();
155             org.objectweb.ccm.logservice.LogInternal internal = null;
156
157             // may raise UnknownService or UnknownServiceInternal exceptions if the service is not installed
158
// or if the particular internal was not registered by the service
159
Object JavaDoc obj = ctx.get_service_internal(org.objectweb.ccm.logservice.LOG_SERVICE_ID.value,
160                                                   org.objectweb.ccm.logservice.LOG_SERVICE_INTERNAL_ID.value);
161
162             // should not fail
163
internal = (org.objectweb.ccm.logservice.LogInternal)obj;
164
165             // build a log event with INFO_LEVEL
166
org.objectweb.corba.logservice.LogEvent evt = new org.objectweb.corba.logservice.LogEvent();
167             evt.level = org.objectweb.corba.logservice.DEBUG_LEVEL.value;
168             org.objectweb.corba.logservice.MessageContent content = new org.objectweb.corba.logservice.MessageContent();
169             java.util.Calendar JavaDoc cal = java.util.Calendar.getInstance();
170             content.timestamp = java.lang.Long.toString(cal.getTimeInMillis());
171             content.interception_point = "";
172             content.operation_name = "print";
173             content.sender_id = "";
174             content.receiver_id = get_identity();
175             content.data = "["+msg.header+"] "+msg.content;
176             evt.message = content;
177             // send
178
internal.log_event(evt);
179         } catch (Exception JavaDoc ex) {
180             ex.printStackTrace();
181         }
182     }
183
184     //
185
// IDL:objectweb.org/ccm/logdemo/Server:1.0
186
//
187

188     final public void
189     name(String JavaDoc n)
190     {
191         _name = n;
192
193         if (_frame!=null) {
194             _frame.setTitle(_name+" GUI");
195         }
196     }
197
198     final public String JavaDoc
199     name()
200     {
201         return _name;
202     }
203 }
204
205
206
Popular Tags