1 28 29 30 package org.objectweb.ccm.logdemo; 31 32 36 public class AsyncServerWithLogImpl 37 extends AsyncServer_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 AsyncServerWithLogImpl() 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 getCCM2Context().register_valuefactory(AsyncMessageHelper.id(), new AsyncMessageFactoryImpl()); 90 91 if ((_frame!=null) && (!_frame.isShowing())){ 93 _frame.show(); 94 } 95 } 96 97 final public void 98 ccm_passivate() 99 throws org.omg.Components.CCMException 100 { 101 _frame.hide(); 103 _text.setText(null); 104 } 105 106 final public void 107 ccm_remove() 108 throws org.omg.Components.CCMException 109 { 110 _frame.dispose(); 112 _frame = null; 113 } 114 115 119 final public org.omg.CORBA.Object 120 get_service_callback(String sid, String cid) 121 throws org.coach.ECM.UnknownService, 122 org.coach.ECM.UnknownServiceCallback 123 { 124 if (!sid.equals(org.objectweb.ccm.logservice.LOG_SERVICE_ID.value)) { 125 throw new org.coach.ECM.UnknownService(); 126 } 127 128 if (!cid.equals(org.objectweb.ccm.logservice.LOG_SERVICE_CALLBACK_ID.value)) { 129 throw new org.coach.ECM.UnknownServiceCallback(); 130 } 131 132 return this; 133 } 134 135 139 final public String 140 get_identity() 141 { 142 return "Server:"+name(); 143 } 144 145 149 final public void 150 push_event(org.omg.Components.EventBase evt) 151 throws org.omg.Components.BadEventType 152 { 153 if (evt instanceof AsyncMessage) { 154 push_AsyncMessage((AsyncMessage)evt); 155 return ; 156 } 157 158 throw new org.omg.Components.BadEventType(); 159 } 160 161 165 final public void 166 push_AsyncMessage(AsyncMessage amsg) 167 { 168 _text.append("["+amsg.msg.header+"] "+amsg.msg.content + "\n"); 170 171 try { 173 org.coach.ECM.ECMContext ctx = getECMContext(); 175 org.objectweb.ccm.logservice.LogInternal internal = null; 176 177 Object obj = ctx.get_service_internal(org.objectweb.ccm.logservice.LOG_SERVICE_ID.value, 180 org.objectweb.ccm.logservice.LOG_SERVICE_INTERNAL_ID.value); 181 182 internal = (org.objectweb.ccm.logservice.LogInternal)obj; 184 185 org.objectweb.corba.logservice.LogEvent evt = new org.objectweb.corba.logservice.LogEvent(); 187 evt.level = org.objectweb.corba.logservice.DEBUG_LEVEL.value; 188 org.objectweb.corba.logservice.MessageContent content = new org.objectweb.corba.logservice.MessageContent(); 189 java.util.Calendar cal = java.util.Calendar.getInstance(); 190 content.timestamp = java.lang.Long.toString(cal.getTimeInMillis()); 191 content.interception_point = ""; 192 content.operation_name = "push_AsyncMessage"; 193 content.sender_id = ""; 194 content.receiver_id = get_identity(); 195 content.data = "["+amsg.msg.header+"] "+amsg.msg.content; 196 evt.message = content; 197 internal.log_event(evt); 199 } catch (Exception ex) { 200 ex.printStackTrace(); 201 } 202 } 203 204 208 final public void 209 name(String n) 210 { 211 _name = n; 212 213 if (_frame!=null) { 214 _frame.setTitle(_name+" GUI"); 215 } 216 } 217 218 final public String 219 name() 220 { 221 return _name; 222 } 223 } 224 | Popular Tags |