1 21 package org.jacorb.orb.portableInterceptor; 22 23 import org.omg.IOP.CodecPackage.*; 24 import org.omg.IOP.CodecFactoryPackage.UnknownEncoding ; 25 import org.omg.IOP.Codec ; 26 import org.omg.IOP.Encoding ; 27 import org.omg.IOP.ENCODING_CDR_ENCAPS ; 28 import org.omg.CORBA.*; 29 30 import org.jacorb.orb.CDRInputStream; 31 import org.jacorb.orb.CDROutputStream; 32 33 42 43 public class CodecImpl 44 extends org.omg.CORBA.LocalObject 45 implements Codec 46 { 47 private ORB orb = null; 48 int giopMinor = 0; 49 50 public CodecImpl(ORB orb, Encoding enc) 51 throws UnknownEncoding 52 { 53 if (enc.format != ENCODING_CDR_ENCAPS.value) 54 throw new UnknownEncoding (); 55 56 if (enc.major_version != 1 || enc.minor_version > 2 ) 57 throw new UnknownEncoding (); 58 59 this.orb = orb; 60 this.giopMinor = (int)enc.minor_version; 61 } 62 63 65 public Any decode(byte[] data) 66 throws FormatMismatch 67 { 68 CDRInputStream in = new CDRInputStream(orb, data); 69 in.setGIOPMinor( giopMinor ); 70 71 in.openEncapsulatedArray(); 72 Any result = in.read_any(); 73 74 77 return result; 78 } 79 80 81 public Any decode_value(byte[] data, TypeCode tc) 82 throws FormatMismatch, TypeMismatch 83 { 84 CDRInputStream in = new CDRInputStream(orb, data); 85 in.setGIOPMinor( giopMinor ); 86 87 in.openEncapsulatedArray(); 88 Any result = orb.create_any(); 89 result.read_value(in, tc); 90 91 94 return result; 95 } 96 97 public byte[] encode(Any data) 98 throws InvalidTypeForEncoding 99 { 100 CDROutputStream out = new CDROutputStream(orb); 101 out.setGIOPMinor( giopMinor ); 102 103 out.beginEncapsulatedArray(); 104 out.write_any(data); 105 106 117 118 122 byte[] result = out.getBufferCopy(); 123 out.close(); 124 125 return result; 126 } 127 128 public byte[] encode_value(Any data) 129 throws InvalidTypeForEncoding 130 { 131 CDROutputStream out = new CDROutputStream(orb); 132 out.setGIOPMinor( giopMinor ); 133 134 out.beginEncapsulatedArray(); 135 data.write_value(out); 136 137 149 150 154 byte[] result = out.getBufferCopy(); 155 out.close(); 156 157 return result; 158 } 159 160 } | Popular Tags |