1 7 8 package com.sun.corba.se.impl.dynamicany; 9 10 import org.omg.CORBA.TypeCode ; 11 import org.omg.CORBA.Any ; 12 import org.omg.CORBA.BAD_OPERATION ; 13 import org.omg.CORBA.TypeCodePackage.BadKind ; 14 import org.omg.CORBA.TypeCodePackage.Bounds ; 15 import org.omg.CORBA.portable.InputStream ; 16 import org.omg.CORBA.portable.OutputStream ; 17 import org.omg.DynamicAny.*; 18 import org.omg.DynamicAny.DynAnyPackage.TypeMismatch ; 19 import org.omg.DynamicAny.DynAnyPackage.InvalidValue ; 20 import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode ; 21 22 import com.sun.corba.se.spi.orb.ORB ; 23 import com.sun.corba.se.spi.logging.CORBALogDomains ; 24 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 25 26 public class DynSequenceImpl extends DynAnyCollectionImpl implements DynSequence 30 { 31 35 private DynSequenceImpl() { 36 this(null, (Any )null, false); 37 } 38 39 protected DynSequenceImpl(ORB orb, Any any, boolean copyValue) { 40 super(orb, any, copyValue); 41 } 42 43 protected DynSequenceImpl(ORB orb, TypeCode typeCode) { 45 super(orb, typeCode); 46 } 47 48 protected boolean initializeComponentsFromAny() { 51 TypeCode typeCode = any.type(); 53 int length; 54 TypeCode contentType = getContentType(); 55 InputStream input; 56 57 try { 58 input = any.create_input_stream(); 59 } catch (BAD_OPERATION e) { 60 return false; 61 } 62 63 length = input.read_long(); 64 components = new DynAny[length]; 65 anys = new Any [length]; 66 67 for (int i=0; i<length; i++) { 68 anys[i] = DynAnyUtil.extractAnyFromStream(contentType, input, orb); 71 try { 72 components[i] = DynAnyUtil.createMostDerivedDynAny(anys[i], orb, false); 74 } catch (InconsistentTypeCode itc) { } 76 } 77 return true; 78 } 79 80 protected boolean initializeComponentsFromTypeCode() { 82 components = new DynAny[0]; 84 anys = new Any [0]; 85 return true; 86 } 87 88 protected boolean initializeAnyFromComponents() { 90 OutputStream out = any.create_output_stream(); 91 out.write_long(components.length); 93 for (int i=0; i<components.length; i++) { 94 if (components[i] instanceof DynAnyImpl) { 95 ((DynAnyImpl)components[i]).writeAny(out); 96 } else { 97 components[i].to_any().write_value(out); 99 } 100 } 101 any.read_value(out.create_input_stream(), any.type()); 102 return true; 103 } 104 105 106 110 public int get_length() { 112 if (status == STATUS_DESTROYED) { 113 throw wrapper.dynAnyDestroyed() ; 114 } 115 return (checkInitComponents() ? components.length : 0); 116 } 117 118 public void set_length(int len) 141 throws org.omg.DynamicAny.DynAnyPackage.InvalidValue 142 { 143 if (status == STATUS_DESTROYED) { 144 throw wrapper.dynAnyDestroyed() ; 145 } 146 int bound = getBound(); 147 if (bound > 0 && len > bound) { 148 throw new InvalidValue (); 149 } 150 151 checkInitComponents(); 152 153 int oldLength = components.length; 154 if (len > oldLength) { 155 DynAny[] newComponents = new DynAny[len]; 157 Any [] newAnys = new Any [len]; 158 System.arraycopy(components, 0, newComponents, 0, oldLength); 159 System.arraycopy(anys, 0, newAnys, 0, oldLength); 160 components = newComponents; 161 anys = newAnys; 162 163 TypeCode contentType = getContentType(); 165 for (int i=oldLength; i<len; i++) { 166 createDefaultComponentAt(i, contentType); 167 } 168 169 if (index == NO_INDEX) 172 index = oldLength; 173 } else if (len < oldLength) { 174 DynAny[] newComponents = new DynAny[len]; 176 Any [] newAnys = new Any [len]; 177 System.arraycopy(components, 0, newComponents, 0, len); 178 System.arraycopy(anys, 0, newAnys, 0, len); 179 components = newComponents; 186 anys = newAnys; 187 188 if (len == 0 || index >= len) { 195 index = NO_INDEX; 196 } 197 } else { 198 if (index == NO_INDEX && len > 0) { 201 index = 0; 202 } 203 } 204 } 205 206 219 220 224 protected void checkValue(Object [] value) 225 throws org.omg.DynamicAny.DynAnyPackage.InvalidValue 226 { 227 if (value == null || value.length == 0) { 228 clearData(); 229 index = NO_INDEX; 230 return; 231 } else { 232 index = 0; 233 } 234 int bound = getBound(); 235 if (bound > 0 && value.length > bound) { 236 throw new InvalidValue (); 237 } 238 } 239 } 240 | Popular Tags |