1 28 29 30 package org.objectweb.corba.logservice; 31 32 import org.objectweb.corba.runtime.*; 33 34 41 public class LogCRIImpl 42 extends org.omg.CORBA.LocalObject 43 implements org.omg.PortableInterceptor.ClientRequestInterceptor 44 { 45 private org.omg.IOP.Codec _codec; 47 private int _slot_id; 48 49 public 50 LogCRIImpl(org.omg.IOP.Codec codec, 51 int slotid) 52 { 53 _codec = codec; 54 _slot_id = slotid; 55 } 56 57 61 private org.omg.PortableInterceptor.Current 62 getPICurrent() 63 { 64 org.omg.CORBA.Object obj = null; 65 org.omg.PortableInterceptor.Current current = null; 66 org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(); 67 try { 68 obj = orb.resolve_initial_references("PICurrent"); 69 } catch (org.omg.CORBA.ORBPackage.InvalidName ex) { 70 } catch (Exception ex) { 71 System.err.println("!!! LogCRIImpl::getPICurrent exception caught: "+ex.getMessage()); 72 } catch (Error err) { 73 System.err.println("!!! LogCRIImpl::getPICurrent error caught: "+err.getMessage()); 74 } 75 76 return org.omg.PortableInterceptor.CurrentHelper.narrow(obj); 77 } 78 79 private void 80 setIdInServiceContext(org.omg.PortableInterceptor.ClientRequestInfo info) 81 { 82 org.omg.CORBA.Any cid = null; 84 try { 85 cid = info.get_slot(_slot_id); 86 } catch (org.omg.PortableInterceptor.InvalidSlot ex) { 87 System.err.println("!!! LogCRIImpl::setIdInServiceContext: invalid slot"); 88 } 89 90 if ((cid==null) || (cid.type().kind()==org.omg.CORBA.TCKind.tk_null)) { 91 System.err.println("!!! LogCRIImpl::setIdInServiceContext: slot has no value"); 92 return ; 93 } 94 95 org.omg.IOP.ServiceContext sctx = new org.omg.IOP.ServiceContext (); 97 sctx.context_id = LOG_IOP_SERVICE_ID.value; 98 try { 99 sctx.context_data = _codec.encode(cid); 100 } catch (org.omg.IOP.CodecPackage.InvalidTypeForEncoding ex) { 101 System.err.println("!!! LogCRIImpl::setIdInServiceContext: invalid type for encoding in service context"); 102 } 103 104 info.add_request_service_context(sctx, true); 105 } 106 107 private void 108 getIdFromServiceContext(org.omg.PortableInterceptor.ClientRequestInfo info) 109 { 110 org.omg.IOP.ServiceContext sctx = null; 112 try { 113 sctx = info.get_reply_service_context(LOG_IOP_SERVICE_ID.value); 114 } catch (org.omg.CORBA.SystemException ex) { 115 System.err.println("!!! LogCRIImpl::getIdFromServiceContext: Service context not found"); 116 } 117 118 if (sctx==null) { 119 System.err.println("!!! LogCRIImpl::getIdFromServiceContext: Service context not found"); 120 return ; 121 } 122 123 org.omg.CORBA.Any cid = null; 125 try { 126 cid = _codec.decode(sctx.context_data); 127 } catch (org.omg.IOP.CodecPackage.FormatMismatch ex) { 128 } 129 130 try { 132 getPICurrent().set_slot(_slot_id, cid); 133 } catch (org.omg.PortableInterceptor.InvalidSlot ex) { 134 } 135 } 136 137 141 final public String 142 name() 143 { 144 return "LogCRIImpl"; 145 } 146 147 final public void 148 destroy() 149 { 150 } 151 152 156 final public void 157 send_request(org.omg.PortableInterceptor.ClientRequestInfo info) 158 throws org.omg.PortableInterceptor.ForwardRequest 159 { 160 System.err.println("### LogCRIImpl::send_request called on operation: "+info.operation()); 161 setIdInServiceContext(info); 163 } 164 165 final public void 166 send_poll(org.omg.PortableInterceptor.ClientRequestInfo info) 167 { 168 System.err.println("### LogCRIImpl::send_poll called on operation: "+info.operation()); 169 setIdInServiceContext(info); 171 } 172 173 final public void 174 receive_reply(org.omg.PortableInterceptor.ClientRequestInfo info) 175 { 176 System.err.println("### LogCRIImpl::receive_reply called on operation: "+info.operation()); 177 getIdFromServiceContext(info); 179 } 180 181 final public void 182 receive_exception(org.omg.PortableInterceptor.ClientRequestInfo info) 183 throws org.omg.PortableInterceptor.ForwardRequest 184 { 185 System.err.println("### LogCRIImpl::receive_exception called on operation: "+info.operation()); 186 getIdFromServiceContext(info); 188 } 189 190 final public void 191 receive_other(org.omg.PortableInterceptor.ClientRequestInfo info) 192 throws org.omg.PortableInterceptor.ForwardRequest 193 { 194 System.err.println("### LogCRIImpl::receive_other called on operation: "+info.operation()); 195 getIdFromServiceContext(info); 197 } 198 } 199 | Popular Tags |