1 7 8 package com.sun.corba.se.impl.encoding; 9 10 import java.util.HashMap ; 11 import java.util.Map ; 12 import java.util.Iterator ; 13 import java.util.List ; 14 import java.util.Collections ; 15 import java.util.ArrayList ; 16 import java.io.IOException ; 17 import java.io.PrintStream ; 18 import java.io.ByteArrayOutputStream ; 19 import java.math.BigDecimal ; 20 import java.math.BigInteger ; 21 import java.nio.ByteBuffer ; 22 23 import org.omg.CORBA.TypeCode ; 24 import org.omg.CORBA.StructMember ; 25 import org.omg.CORBA.UnionMember ; 26 import org.omg.CORBA.ValueMember ; 27 import org.omg.CORBA.TCKind ; 28 import org.omg.CORBA.Any ; 29 import org.omg.CORBA.Principal ; 30 import org.omg.CORBA.BAD_TYPECODE ; 31 import org.omg.CORBA.BAD_PARAM ; 32 import org.omg.CORBA.BAD_OPERATION ; 33 import org.omg.CORBA.INTERNAL ; 34 import org.omg.CORBA.MARSHAL ; 35 36 import org.omg.CORBA.TypeCodePackage.BadKind ; 37 38 import org.omg.CORBA_2_3.portable.InputStream ; 39 import org.omg.CORBA_2_3.portable.OutputStream ; 40 41 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 42 import com.sun.corba.se.impl.corba.TypeCodeImpl; 43 import com.sun.corba.se.spi.orb.ORB; 44 import com.sun.corba.se.impl.encoding.CodeSetConversion; 45 import com.sun.corba.se.impl.encoding.CDRInputStream; 46 import com.sun.corba.se.impl.encoding.CDROutputStream; 47 import com.sun.corba.se.impl.encoding.MarshalInputStream; 48 49 public class TypeCodeInputStream extends EncapsInputStream implements TypeCodeReader 50 { 51 private Map typeMap = null; 52 private InputStream enclosure = null; 53 private boolean isEncapsulation = false; 54 55 public TypeCodeInputStream(org.omg.CORBA.ORB orb, byte[] data, int size) { 56 super(orb, data, size); 57 } 58 59 public TypeCodeInputStream(org.omg.CORBA.ORB orb, 60 byte[] data, 61 int size, 62 boolean littleEndian, 63 GIOPVersion version) { 64 super(orb, data, size, littleEndian, version); 65 } 66 67 public TypeCodeInputStream(org.omg.CORBA.ORB orb, 68 ByteBuffer byteBuffer, 69 int size, 70 boolean littleEndian, 71 GIOPVersion version) { 72 super(orb, byteBuffer, size, littleEndian, version); 73 } 74 75 public void addTypeCodeAtPosition(TypeCodeImpl tc, int position) { 76 if (typeMap == null) { 77 typeMap = new HashMap (16); 79 } 80 typeMap.put(new Integer (position), tc); 82 } 83 84 public TypeCodeImpl getTypeCodeAtPosition(int position) { 85 if (typeMap == null) 86 return null; 87 return (TypeCodeImpl)typeMap.get(new Integer (position)); 92 } 93 94 public void setEnclosingInputStream(InputStream enclosure) { 95 this.enclosure = enclosure; 96 } 97 98 public TypeCodeReader getTopLevelStream() { 99 if (enclosure == null) 100 return this; 101 if (enclosure instanceof TypeCodeReader) 102 return ((TypeCodeReader)enclosure).getTopLevelStream(); 103 return this; 104 } 105 106 public int getTopLevelPosition() { 107 if (enclosure != null && enclosure instanceof TypeCodeReader) { 108 int topPos = ((TypeCodeReader)enclosure).getTopLevelPosition(); 112 int pos = topPos - getBufferLength() + getPosition(); 115 return pos; 122 } 123 return getPosition(); 128 } 129 130 public static TypeCodeInputStream readEncapsulation(InputStream is, org.omg.CORBA.ORB _orb) { 131 TypeCodeInputStream encap; 133 134 int encapLength = is.read_long(); 135 136 byte[] encapBuffer = new byte[encapLength]; 138 is.read_octet_array(encapBuffer, 0, encapBuffer.length); 139 140 if (is instanceof CDRInputStream) { 142 encap = new TypeCodeInputStream((ORB)_orb, encapBuffer, encapBuffer.length, 143 ((CDRInputStream)is).isLittleEndian(), 144 ((CDRInputStream)is).getGIOPVersion()); 145 } else { 146 encap = new TypeCodeInputStream((ORB)_orb, encapBuffer, encapBuffer.length); 147 } 148 encap.setEnclosingInputStream(is); 149 encap.makeEncapsulation(); 150 return encap; 155 } 156 157 protected void makeEncapsulation() { 158 consumeEndian(); 160 isEncapsulation = true; 161 } 162 163 public void printTypeMap() { 164 System.out.println("typeMap = {"); 165 Iterator i = typeMap.keySet().iterator(); 166 while (i.hasNext()) { 167 Integer pos = (Integer )i.next(); 168 TypeCodeImpl tci = (TypeCodeImpl)typeMap.get(pos); 169 System.out.println(" key = " + pos.intValue() + ", value = " + tci.description()); 170 } 171 System.out.println("}"); 172 } 173 } 174 | Popular Tags |