1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 37 public class SegmentedIdCodec 38 { 39 static final private String _class_name = "SegmentedIdCodec"; 41 private ORBService _orb_service; 42 private org.omg.IOP.Codec _iiop12codec; 43 44 public 46 SegmentedIdCodec(ORBService orbs) 47 { 48 _orb_service = orbs; 50 51 org.omg.CORBA.Object obj = _orb_service.resolve_initial_references("CodecFactory"); 53 org.omg.IOP.CodecFactory fact = org.omg.IOP.CodecFactoryHelper.narrow(obj); 54 org.omg.IOP.Encoding enc12 = new org.omg.IOP.Encoding (); 55 enc12.format = org.omg.IOP.ENCODING_CDR_ENCAPS.value; 56 enc12.major_version = (byte)1; 57 enc12.minor_version = (byte)2; 58 59 try { 60 _iiop12codec = fact.create_codec(enc12); 61 } catch (org.omg.IOP.CodecFactoryPackage.UnknownEncoding ex) { 62 final String opname = "SegmentedIdCodec"; 63 TheLogger.error(_class_name, opname, "FAILED (IIOP 1.2 no supported)", ex); 64 } 65 } 66 67 71 final public byte[] 72 encode(SegmentedId sid) 73 { 74 final String opname = "encode"; 75 76 org.omg.CORBA.Any any_id = _orb_service.create_any(); 78 SegmentedIdHelper.insert(any_id, sid); 79 byte[] id = null; 80 try { 81 id = _iiop12codec.encode_value(any_id); 82 } catch (org.omg.IOP.CodecPackage.InvalidTypeForEncoding ex) { 83 TheLogger.error(_class_name, opname, "FAILED (invalid type)", ex); 85 return null; 86 } catch (Throwable ex) { 87 TheLogger.debug(_class_name, opname, "FAILED", ex); 88 return null; 89 } 90 91 return id; 92 } 93 94 final public SegmentedId 95 decode(byte[] id) 96 { 97 final String opname = "decode"; 98 99 org.omg.CORBA.Any any_id = _orb_service.create_any(); 101 try { 102 any_id = _iiop12codec.decode_value(id, SegmentedIdHelper.type()); 103 } catch (org.omg.IOP.CodecPackage.FormatMismatch ex) { 104 TheLogger.debug(_class_name, opname, "IGNORE", ex); 106 return null; 107 } catch (org.omg.IOP.CodecPackage.TypeMismatch ex) { 108 TheLogger.error(_class_name, opname, "FAILED (wrong type)", ex); 110 return null; 111 } catch (Throwable ex) { 112 TheLogger.debug(_class_name, opname, "FAILED", ex); 113 return null; 114 } 115 116 SegmentedId mid = SegmentedIdHelper.extract(any_id); 118 119 return mid; 120 } 121 } 122 | Popular Tags |