1 7 8 package com.sun.corba.se.impl.dynamicany; 9 10 import org.omg.CORBA.TypeCode ; 11 import org.omg.CORBA.TCKind ; 12 import org.omg.CORBA.Any ; 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.DynamicAny.*; 17 import org.omg.DynamicAny.DynAnyPackage.TypeMismatch ; 18 import org.omg.DynamicAny.DynAnyPackage.InvalidValue ; 19 import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode ; 20 21 import com.sun.corba.se.spi.orb.ORB ; 22 import com.sun.corba.se.spi.logging.CORBALogDomains ; 23 import com.sun.corba.se.impl.logging.ORBUtilSystemException ; 24 25 abstract class DynAnyComplexImpl extends DynAnyConstructedImpl 26 { 27 31 String [] names = null; 32 NameValuePair[] nameValuePairs = null; 35 NameDynAnyPair[] nameDynAnyPairs = null; 36 37 41 private DynAnyComplexImpl() { 42 this(null, (Any )null, false); 43 } 44 45 protected DynAnyComplexImpl(ORB orb, Any any, boolean copyValue) { 46 super(orb, any, copyValue); 48 } 51 52 protected DynAnyComplexImpl(ORB orb, TypeCode typeCode) { 53 super(orb, typeCode); 55 index = 0; 59 } 60 61 65 82 83 87 public String current_member_name () 88 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch , 89 org.omg.DynamicAny.DynAnyPackage.InvalidValue 90 { 91 if (status == STATUS_DESTROYED) { 92 throw wrapper.dynAnyDestroyed() ; 93 } 94 if( ! checkInitComponents() || index < 0 || index >= names.length) { 95 throw new InvalidValue (); 96 } 97 return names[index]; 98 } 99 100 public TCKind current_member_kind () 101 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch , 102 org.omg.DynamicAny.DynAnyPackage.InvalidValue 103 { 104 if (status == STATUS_DESTROYED) { 105 throw wrapper.dynAnyDestroyed() ; 106 } 107 if( ! checkInitComponents() || index < 0 || index >= components.length) { 108 throw new InvalidValue (); 109 } 110 return components[index].type().kind(); 111 } 112 113 public void set_members (org.omg.DynamicAny.NameValuePair [] value) 115 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch , 116 org.omg.DynamicAny.DynAnyPackage.InvalidValue 117 { 118 if (status == STATUS_DESTROYED) { 119 throw wrapper.dynAnyDestroyed() ; 120 } 121 if (value == null || value.length == 0) { 122 clearData(); 123 return; 124 } 125 126 Any memberAny; 127 DynAny memberDynAny = null; 128 String memberName; 129 TypeCode expectedTypeCode = any.type(); 131 132 int expectedMemberCount = 0; 133 try { 134 expectedMemberCount = expectedTypeCode.member_count(); 135 } catch (BadKind badKind) { } 137 if (expectedMemberCount != value.length) { 138 clearData(); 139 throw new InvalidValue (); 140 } 141 142 allocComponents(value); 143 144 for (int i=0; i<value.length; i++) { 145 if (value[i] != null) { 146 memberName = value[i].id; 147 String expectedMemberName = null; 148 try { 149 expectedMemberName = expectedTypeCode.member_name(i); 150 } catch (BadKind badKind) { } catch (Bounds bounds) { } 153 if ( ! (expectedMemberName.equals(memberName) || memberName.equals(""))) { 154 clearData(); 155 throw new TypeMismatch (); 157 } 158 memberAny = value[i].value; 159 TypeCode expectedMemberType = null; 160 try { 161 expectedMemberType = expectedTypeCode.member_type(i); 162 } catch (BadKind badKind) { } catch (Bounds bounds) { } 165 if (! expectedMemberType.equal(memberAny.type())) { 166 clearData(); 167 throw new TypeMismatch (); 169 } 170 try { 171 memberDynAny = DynAnyUtil.createMostDerivedDynAny(memberAny, orb, false); 173 } catch (InconsistentTypeCode itc) { 174 throw new InvalidValue (); 175 } 176 addComponent(i, memberName, memberAny, memberDynAny); 177 } else { 178 clearData(); 179 throw new InvalidValue (); 181 } 182 } 183 index = (value.length == 0 ? NO_INDEX : 0); 184 representations = REPRESENTATION_COMPONENTS; 185 } 186 187 public void set_members_as_dyn_any (org.omg.DynamicAny.NameDynAnyPair [] value) 189 throws org.omg.DynamicAny.DynAnyPackage.TypeMismatch , 190 org.omg.DynamicAny.DynAnyPackage.InvalidValue 191 { 192 if (status == STATUS_DESTROYED) { 193 throw wrapper.dynAnyDestroyed() ; 194 } 195 if (value == null || value.length == 0) { 196 clearData(); 197 return; 198 } 199 200 Any memberAny; 201 DynAny memberDynAny; 202 String memberName; 203 TypeCode expectedTypeCode = any.type(); 205 206 int expectedMemberCount = 0; 207 try { 208 expectedMemberCount = expectedTypeCode.member_count(); 209 } catch (BadKind badKind) { } 211 if (expectedMemberCount != value.length) { 212 clearData(); 213 throw new InvalidValue (); 214 } 215 216 allocComponents(value); 217 218 for (int i=0; i<value.length; i++) { 219 if (value[i] != null) { 220 memberName = value[i].id; 221 String expectedMemberName = null; 222 try { 223 expectedMemberName = expectedTypeCode.member_name(i); 224 } catch (BadKind badKind) { } catch (Bounds bounds) { } 227 if ( ! (expectedMemberName.equals(memberName) || memberName.equals(""))) { 228 clearData(); 229 throw new TypeMismatch (); 231 } 232 memberDynAny = value[i].value; 233 memberAny = getAny(memberDynAny); 234 TypeCode expectedMemberType = null; 235 try { 236 expectedMemberType = expectedTypeCode.member_type(i); 237 } catch (BadKind badKind) { } catch (Bounds bounds) { } 240 if (! expectedMemberType.equal(memberAny.type())) { 241 clearData(); 242 throw new TypeMismatch (); 244 } 245 246 addComponent(i, memberName, memberAny, memberDynAny); 247 } else { 248 clearData(); 249 throw new InvalidValue (); 251 } 252 } 253 index = (value.length == 0 ? NO_INDEX : 0); 254 representations = REPRESENTATION_COMPONENTS; 255 } 256 257 261 private void allocComponents(int length) { 262 components = new DynAny[length]; 263 names = new String [length]; 264 nameValuePairs = new NameValuePair[length]; 265 nameDynAnyPairs = new NameDynAnyPair[length]; 266 for (int i=0; i<length; i++) { 267 nameValuePairs[i] = new NameValuePair(); 268 nameDynAnyPairs[i] = new NameDynAnyPair(); 269 } 270 } 271 272 private void allocComponents(org.omg.DynamicAny.NameValuePair [] value) { 273 components = new DynAny[value.length]; 274 names = new String [value.length]; 275 nameValuePairs = value; 276 nameDynAnyPairs = new NameDynAnyPair[value.length]; 277 for (int i=0; i<value.length; i++) { 278 nameDynAnyPairs[i] = new NameDynAnyPair(); 279 } 280 } 281 282 private void allocComponents(org.omg.DynamicAny.NameDynAnyPair [] value) { 283 components = new DynAny[value.length]; 284 names = new String [value.length]; 285 nameValuePairs = new NameValuePair[value.length]; 286 for (int i=0; i<value.length; i++) { 287 nameValuePairs[i] = new NameValuePair(); 288 } 289 nameDynAnyPairs = value; 290 } 291 292 private void addComponent(int i, String memberName, Any memberAny, DynAny memberDynAny) { 293 components[i] = memberDynAny; 294 names[i] = (memberName != null ? memberName : ""); 295 nameValuePairs[i].id = memberName; 296 nameValuePairs[i].value = memberAny; 297 nameDynAnyPairs[i].id = memberName; 298 nameDynAnyPairs[i].value = memberDynAny; 299 if (memberDynAny instanceof DynAnyImpl) 300 ((DynAnyImpl)memberDynAny).setStatus(STATUS_UNDESTROYABLE); 301 } 302 303 protected boolean initializeComponentsFromAny() { 306 TypeCode typeCode = any.type(); 308 TypeCode memberType = null; 309 Any memberAny; 310 DynAny memberDynAny = null; 311 String memberName = null; 312 int length = 0; 313 314 try { 315 length = typeCode.member_count(); 316 } catch (BadKind badKind) { } 318 319 InputStream input = any.create_input_stream(); 320 321 allocComponents(length); 322 323 for (int i=0; i<length; i++) { 324 try { 325 memberName = typeCode.member_name(i); 326 memberType = typeCode.member_type(i); 327 } catch (BadKind badKind) { } catch (Bounds bounds) { } 330 memberAny = DynAnyUtil.extractAnyFromStream(memberType, input, orb); 331 try { 332 memberDynAny = DynAnyUtil.createMostDerivedDynAny(memberAny, orb, false); 334 } catch (InconsistentTypeCode itc) { } 339 addComponent(i, memberName, memberAny, memberDynAny); 340 } 341 return true; 342 } 343 344 protected boolean initializeComponentsFromTypeCode() { 349 TypeCode typeCode = any.type(); 351 TypeCode memberType = null; 352 Any memberAny; 353 DynAny memberDynAny = null; 354 String memberName; 355 int length = 0; 356 357 try { 358 length = typeCode.member_count(); 359 } catch (BadKind badKind) { } 361 362 allocComponents(length); 363 364 for (int i=0; i<length; i++) { 365 memberName = null; 366 try { 367 memberName = typeCode.member_name(i); 368 memberType = typeCode.member_type(i); 369 } catch (BadKind badKind) { } catch (Bounds bounds) { } 372 try { 373 memberDynAny = DynAnyUtil.createMostDerivedDynAny(memberType, orb); 374 385 } catch (InconsistentTypeCode itc) { } 387 memberAny = getAny(memberDynAny); 389 addComponent(i, memberName, memberAny, memberDynAny); 390 } 391 return true; 392 } 393 394 protected void clearData() { 398 super.clearData(); 399 names = null; 400 nameValuePairs = null; 401 nameDynAnyPairs = null; 402 } 403 } 404 | Popular Tags |