1 7 8 package com.sun.corba.se.impl.encoding; 9 10 import org.omg.CORBA.TypeCode ; 11 import org.omg.CORBA.StructMember ; 12 import org.omg.CORBA.UnionMember ; 13 import org.omg.CORBA.ValueMember ; 14 import org.omg.CORBA.TCKind ; 15 import org.omg.CORBA.Any ; 16 import org.omg.CORBA.Principal ; 17 import org.omg.CORBA.CompletionStatus ; 18 19 import org.omg.CORBA.TypeCodePackage.BadKind ; 20 21 import org.omg.CORBA_2_3.portable.InputStream ; 22 import org.omg.CORBA_2_3.portable.OutputStream ; 23 24 import com.sun.corba.se.spi.orb.ORB; 25 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry; 26 import com.sun.corba.se.impl.encoding.MarshalInputStream; 27 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 28 import com.sun.corba.se.impl.encoding.CodeSetConversion; 29 30 import com.sun.corba.se.impl.encoding.CDRInputStream; 31 import com.sun.corba.se.impl.encoding.CDROutputStream; 32 33 import java.util.HashMap ; 34 import java.util.Map ; 35 import java.util.Iterator ; 36 import java.util.List ; 37 import java.util.Collections ; 38 import java.util.ArrayList ; 39 import java.io.IOException ; 40 import java.io.PrintStream ; 41 import java.io.ByteArrayOutputStream ; 42 import java.math.BigDecimal ; 43 import java.math.BigInteger ; 44 import java.nio.ByteBuffer ; 45 46 public final class TypeCodeOutputStream extends EncapsOutputStream 47 { 48 private OutputStream enclosure = null; 49 private Map typeMap = null; 50 private boolean isEncapsulation = false; 51 52 public TypeCodeOutputStream(ORB orb) { 53 super(orb, false); 54 } 55 56 public TypeCodeOutputStream(ORB orb, boolean littleEndian) { 57 super(orb, littleEndian); 58 } 59 60 public org.omg.CORBA.portable.InputStream create_input_stream() 61 { 62 TypeCodeInputStream tcis 64 = new TypeCodeInputStream((ORB)orb(), getByteBuffer(), getIndex(), isLittleEndian(), getGIOPVersion()); 65 return tcis; 70 } 71 72 public void setEnclosingOutputStream(OutputStream enclosure) { 73 this.enclosure = enclosure; 74 } 75 76 88 89 public TypeCodeOutputStream getTopLevelStream() { 90 if (enclosure == null) 91 return this; 92 if (enclosure instanceof TypeCodeOutputStream) 93 return ((TypeCodeOutputStream)enclosure).getTopLevelStream(); 94 return this; 95 } 96 97 public int getTopLevelPosition() { 98 if (enclosure != null && enclosure instanceof TypeCodeOutputStream) { 99 int pos = ((TypeCodeOutputStream)enclosure).getTopLevelPosition() + getPosition(); 100 if (isEncapsulation) pos += 4; 103 return pos; 111 } 112 return getPosition(); 117 } 118 119 public void addIDAtPosition(String id, int position) { 120 if (typeMap == null) 121 typeMap = new HashMap (16); 122 typeMap.put(id, new Integer (position)); 124 } 125 126 public int getPositionForID(String id) { 127 if (typeMap == null) 128 throw wrapper.refTypeIndirType( CompletionStatus.COMPLETED_NO ) ; 129 return ((Integer )typeMap.get(id)).intValue(); 132 } 133 134 public void writeRawBuffer(org.omg.CORBA.portable.OutputStream s, int firstLong) { 135 138 145 s.write_long(firstLong); 152 ByteBuffer byteBuffer = getByteBuffer(); 158 if (byteBuffer.hasArray()) 159 { 160 s.write_octet_array(byteBuffer.array(), 4, getIndex() - 4); 161 } 162 else 163 { 164 byte[] buf = new byte[byteBuffer.limit()]; 169 for (int i = 0; i < buf.length; i++) 170 buf[i] = byteBuffer.get(i); 171 s.write_octet_array(buf, 4, getIndex() - 4); 172 } 173 } 179 180 public TypeCodeOutputStream createEncapsulation(org.omg.CORBA.ORB _orb) { 181 TypeCodeOutputStream encap = new TypeCodeOutputStream((ORB)_orb, isLittleEndian()); 182 encap.setEnclosingOutputStream(this); 183 encap.makeEncapsulation(); 184 return encap; 186 } 187 188 protected void makeEncapsulation() { 189 putEndian(); 191 isEncapsulation = true; 192 } 193 194 public static TypeCodeOutputStream wrapOutputStream(OutputStream os) { 195 boolean littleEndian = ((os instanceof CDROutputStream) ? ((CDROutputStream)os).isLittleEndian() : false); 196 TypeCodeOutputStream tos = new TypeCodeOutputStream((ORB)os.orb(), littleEndian); 197 tos.setEnclosingOutputStream(os); 198 return tos; 200 } 201 202 public int getPosition() { 203 return getIndex(); 204 } 205 206 public int getRealIndex(int index) { 207 int topPos = getTopLevelPosition(); 208 return topPos; 211 } 212 217 public byte[] getTypeCodeBuffer() { 218 ByteBuffer theBuffer = getByteBuffer(); 221 byte[] tcBuffer = new byte[getIndex() - 4]; 223 for (int i = 0; i < tcBuffer.length; i++) 228 tcBuffer[i] = theBuffer.get(i+4); 229 return tcBuffer; 230 } 231 232 public void printTypeMap() { 233 System.out.println("typeMap = {"); 234 Iterator i = typeMap.keySet().iterator(); 235 while (i.hasNext()) { 236 String id = (String )i.next(); 237 Integer pos = (Integer )typeMap.get(id); 238 System.out.println(" key = " + id + ", value = " + pos); 239 } 240 System.out.println("}"); 241 } 242 } 243 | Popular Tags |