KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > logservice > LogServerImpl


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.corba.logservice;
31
32 import org.objectweb.corba.runtime.*;
33
34 /**
35  ** <p>.</p>
36  **/

37 public class LogServerImpl
38 extends org.omg.CORBA.LocalObject JavaDoc
39 implements Servant, LogServerOperations
40 {
41     // system component
42
static private String JavaDoc _class_name = "LogServerImpl";
43
44     // servant
45
static final private String JavaDoc _type_id = LogServerHelper.id();
46
47     // log server
48
private javax.swing.JFrame JavaDoc _frame;
49     private javax.swing.JTextArea JavaDoc _text_error;
50     private javax.swing.JTextArea JavaDoc _text_warn;
51     private javax.swing.JTextArea JavaDoc _text_info;
52     private javax.swing.JTextArea JavaDoc _text_debug;
53
54     // default constructor
55
protected
56     LogServerImpl()
57     {
58         // log server
59
_frame = null;
60         _text_error = null;
61         _text_warn = null;
62         _text_info = null;
63         _text_debug = null;
64     }
65
66     //
67
// Entry point
68
//
69

70     static public Servant
71     create_servant()
72     {
73         return new LogServerImpl();
74     }
75
76     //
77
// internal operations
78
//
79

80     private void
81     initializeGUI()
82     {
83         // text areas for displaying events
84
_text_error = new javax.swing.JTextArea JavaDoc(20, 25);
85         _text_error.setEditable(false);
86         javax.swing.JScrollPane JavaDoc scroll_err = new javax.swing.JScrollPane JavaDoc(_text_error);
87         javax.swing.JLabel JavaDoc label_err = new javax.swing.JLabel JavaDoc("ERRORS");
88
89         _text_warn = new javax.swing.JTextArea JavaDoc(20, 25);
90         _text_warn.setEditable(false);
91         javax.swing.JScrollPane JavaDoc scroll_warn = new javax.swing.JScrollPane JavaDoc(_text_warn);
92         javax.swing.JLabel JavaDoc label_warn = new javax.swing.JLabel JavaDoc("WARNINGS");
93
94         _text_info = new javax.swing.JTextArea JavaDoc(20, 25);
95         _text_info.setEditable(false);
96         javax.swing.JScrollPane JavaDoc scroll_info = new javax.swing.JScrollPane JavaDoc(_text_info);
97         javax.swing.JLabel JavaDoc label_info = new javax.swing.JLabel JavaDoc("INFOS");
98
99         _text_debug = new javax.swing.JTextArea JavaDoc(20, 25);
100         _text_debug.setEditable(false);
101         javax.swing.JScrollPane JavaDoc scroll_debug = new javax.swing.JScrollPane JavaDoc(_text_debug);
102         javax.swing.JLabel JavaDoc label_debug = new javax.swing.JLabel JavaDoc("DEBUG");
103
104         // boxes
105
javax.swing.Box JavaDoc mbox = javax.swing.Box.createHorizontalBox();
106         javax.swing.Box JavaDoc lbox = javax.swing.Box.createVerticalBox();
107         //lbox.setSize(new java.awt.Dimension(250, 600));
108
javax.swing.Box JavaDoc rbox = javax.swing.Box.createVerticalBox();
109         //rbox.setSize(new java.awt.Dimension(250, 600));
110
mbox.add(lbox);
111         mbox.add(rbox);
112         lbox.add(label_err);
113         lbox.add(scroll_err);
114         lbox.add(label_warn);
115         lbox.add(scroll_warn);
116         rbox.add(label_info);
117         rbox.add(scroll_info);
118         rbox.add(label_debug);
119         rbox.add(scroll_debug);
120
121         // frame
122
_frame = new javax.swing.JFrame JavaDoc("LogServer GUI");
123         _frame.getContentPane().add(mbox);
124         _frame.pack();
125         _frame.show();
126     }
127
128     //
129
// IDL:org/objectweb/corba/runtime/SystemComponent:1.0
130
//
131

132     final public void
133     system_configuration_complete(SystemConfiguration cfg)
134     {
135         //
136
initializeGUI();
137     }
138
139     final public void
140     destroy()
141     {
142         // TODO
143
}
144
145     //
146
// IDL:org/objectweb/corba/runtime/Servant:1.0
147
//
148

149     final public String JavaDoc
150     type_id()
151     {
152         return _type_id;
153     }
154
155     final public org.omg.PortableServer.Servant JavaDoc
156     as_native_servant()
157     {
158         return new LogServerPOATie(this);
159     }
160
161     //
162
// IDL:org/objectweb/corba/logservice/LogServer:1.0
163
//
164

165     final public void
166     log_event(LogEvent evt)
167     {
168         javax.swing.JTextArea JavaDoc area = null;
169         if (evt.level==org.objectweb.corba.logservice.ERROR_LEVEL.value) {
170             area = _text_error;
171         } else if (evt.level==org.objectweb.corba.logservice.WARN_LEVEL.value) {
172             area = _text_warn;
173         } else if (evt.level==org.objectweb.corba.logservice.INFO_LEVEL.value) {
174             area = _text_info;
175         } else if (evt.level==org.objectweb.corba.logservice.DEBUG_LEVEL.value) {
176             area = _text_debug;
177         }
178
179         // System.err.println("### "+msg);
180

181         area.append("[new message] \n");
182         if (evt.message.interception_point.length()!=0) {
183             area.append(" IP: "+evt.message.interception_point+"\n");
184         }
185         area.append(" timesptamp: "+evt.message.timestamp+"\n");
186         area.append(" operation: "+evt.message.operation_name+"\n");
187         if (evt.message.sender_id.length()!=0) {
188             area.append(" sender: "+evt.message.sender_id+"\n");
189         }
190         if (evt.message.receiver_id.length()!=0) {
191             area.append(" receiver: "+evt.message.receiver_id+"\n");
192         }
193         if (evt.message.data.length()!=0) {
194             area.append(" data: "+evt.message.data+"\n");
195         }
196     }
197
198     final public void
199     log_events(LogEvent[] evts)
200     {
201         for (int i=0;i<evts.length;i++) {
202             log_event(evts[i]);
203         }
204     }
205 }
206
Popular Tags