1 28 29 30 package org.objectweb.ccm.logdemo; 31 32 36 public class ServerWithLogImpl 37 extends Server_MainSegBase 38 implements java.io.Serializable , 39 org.coach.ECM.ECMExecutor, 40 org.objectweb.ccm.logservice.LogCallback 41 { 42 private String _name; 44 private javax.swing.JFrame _frame; 45 private javax.swing.JTextArea _text; 46 47 public 48 ServerWithLogImpl() 49 { 50 _name = null; 52 _frame = null; 53 _text = null; 54 } 55 56 60 final public void 61 configuration_complete() 62 throws org.omg.Components.InvalidConfiguration 63 { 64 _text = new javax.swing.JTextArea (40, 20); 67 _text.setEditable(false); 68 69 javax.swing.JPanel panel = new javax.swing.JPanel (new java.awt.BorderLayout ()); 71 panel.add(new javax.swing.JScrollPane (_text), java.awt.BorderLayout.CENTER); 72 _frame = new javax.swing.JFrame (_name + " GUI"); 73 _frame.setSize(400, 300); 74 _frame.getContentPane().add(panel); 75 _frame.pack(); 76 _frame.show(); 77 } 78 79 83 final public void 84 ccm_activate() 85 throws org.omg.Components.CCMException 86 { 87 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 _frame.hide(); 99 _text.setText(null); 100 } 101 102 final public void 103 ccm_remove() 104 throws org.omg.Components.CCMException 105 { 106 _frame.dispose(); 108 _frame = null; 109 } 110 111 115 final public org.omg.CORBA.Object 116 get_service_callback(String sid, String 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 135 final public String 136 get_identity() 137 { 138 return "Server:"+name(); 139 } 140 141 145 final public void 146 print(Message msg) 147 { 148 _text.append("["+msg.header+"] "+msg.content + "\n"); 150 151 try { 153 org.coach.ECM.ECMContext ctx = getECMContext(); 155 org.objectweb.ccm.logservice.LogInternal internal = null; 156 157 Object 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 internal = (org.objectweb.ccm.logservice.LogInternal)obj; 164 165 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 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 internal.log_event(evt); 179 } catch (Exception ex) { 180 ex.printStackTrace(); 181 } 182 } 183 184 188 final public void 189 name(String n) 190 { 191 _name = n; 192 193 if (_frame!=null) { 194 _frame.setTitle(_name+" GUI"); 195 } 196 } 197 198 final public String 199 name() 200 { 201 return _name; 202 } 203 } 204 205 206 | Popular Tags |