1 26 27 package org.objectweb.openccm.ast.lib; 28 29 30 import org.objectweb.openccm.ast.api.TypeKind; 31 32 33 import org.objectweb.openccm.ast.api.TypeRef; 34 35 36 import org.objectweb.openccm.ast.api.DeclarationKind; 37 38 39 import org.objectweb.openccm.ast.api.Declaration; 40 41 42 import org.objectweb.openccm.ast.api.UnionMemberList; 43 44 45 import org.omg.CORBA.TypeCode ; 46 47 48 import org.omg.CORBA.UnionDef ; 49 import org.omg.CORBA.UnionDefHelper; 50 51 52 import org.omg.CORBA.UnionMember ; 53 54 66 67 public class UnionDeclImpl 68 extends ForwardScopeIDLImpl 69 implements org.objectweb.openccm.ast.api.UnionDecl, 70 IDLTypeWrapper 71 { 72 78 79 private UnionDef union_def_; 80 81 82 private int default_index_; 83 84 85 private TypeRef discriminator_; 86 87 88 private TypeCode tc_discriminator_; 89 90 91 private UnionMemberListImpl members_; 92 93 99 105 protected 106 UnionDeclImpl(Repository rep, ScopeImpl parent) 107 { 108 super(rep, parent); 110 111 union_def_ = null; 113 default_index_ = -1; 114 discriminator_ = null; 115 tc_discriminator_ = null; 116 members_ = new UnionMemberListImpl(); 117 } 118 119 125 130 protected org.omg.CORBA.IDLType 131 getDiscriminatorIDLType() 132 { 133 return ( discriminator_ != null ) ? 134 (((IDLTypeWrapper)discriminator_).getIDLType()) : null; 135 } 136 137 142 protected TypeCode 143 getDiscriminatorTypeCode() 144 { 145 if(tc_discriminator_ == null) 146 { 147 org.omg.CORBA.IDLType type = getDiscriminatorIDLType(); 148 if(type != null) 149 tc_discriminator_ = type.type(); 150 } 151 return tc_discriminator_; 152 } 153 154 159 protected org.omg.CORBA.UnionMember [] 160 getUnionMemberSeq() 161 { 162 TypeCode tc = getDiscriminatorTypeCode(); 163 return (tc != null) ? members_.getUnionMemberSeq(tc) 164 : new org.omg.CORBA.UnionMember [0]; 165 } 166 167 173 178 protected void 179 load(org.omg.CORBA.Contained contained) 180 { 181 union_def_ = UnionDefHelper.narrow(contained); 182 setDiscriminator(getRepository(). 183 getAsTypeRef(union_def_.discriminator_type_def())); 184 try 185 { 186 default_index_ = union_def_.type().default_index(); 187 } 188 catch (org.omg.CORBA.TypeCodePackage.BadKind ex) 189 { 190 throw new org.objectweb.openccm.corba.UserExceptionWrapper(ex); 192 } 193 194 super.load(contained); 197 198 UnionMember [] members = union_def_.members(); 199 for (int i=0; i<members.length; i++) 200 { 201 AnyValueImpl any = new AnyValueImpl(); 202 any.loadAny(members[i].label); 203 members_.addMember(members[i].name, 204 getRepository().getAsTypeRef(members[i].type_def), 205 any); 206 } 207 } 208 209 214 protected void 215 loadAsMapping(org.omg.CORBA.Contained contained) 216 { 217 union_def_ = UnionDefHelper.narrow(contained); 218 setDiscriminator(getRepository(). 219 getAsMappedTypeRef(union_def_.discriminator_type_def())); 220 try 221 { 222 default_index_ = union_def_.type().default_index(); 223 } 224 catch (org.omg.CORBA.TypeCodePackage.BadKind ex) 225 { 226 throw new org.objectweb.openccm.corba.UserExceptionWrapper(ex); 228 } 229 230 super.loadAsMapping(contained); 233 234 UnionMember [] members = union_def_.members(); 235 for (int i=0; i<members.length; i++) 236 { 237 AnyValueImpl any = new AnyValueImpl(); 238 any.loadAny(members[i].label); 239 members_.addMember(members[i].name, 240 getRepository().getAsMappedTypeRef(members[i].type_def), 241 any); 242 } 243 } 244 245 250 protected org.omg.CORBA.Contained 251 getContained() 252 { 253 return union_def_; 254 } 255 256 262 267 protected org.omg.CORBA.Container 268 getContainer() 269 { 270 return union_def_; 271 } 272 273 279 285 288 protected void 289 createContainer() 290 { 291 union_def_ = the_parent_.getContainer(). 293 create_union(getId(), getName(), getVersion(), 294 getDiscriminatorIDLType(), 295 getUnionMemberSeq()); 296 } 297 298 301 protected void 302 completeContainer() 303 { 304 union_def_.discriminator_type_def(getDiscriminatorIDLType()); 305 union_def_.members(getUnionMemberSeq()); 306 } 307 308 314 320 328 public Declaration[] 329 getDependencies() 330 { 331 if (dependencies_!=null) 332 return dependencies_; 333 334 dependencies_ = new Declaration[0]; 335 java.util.List union_depend = new java.util.ArrayList (); 336 Declaration[] depend = null; 337 338 if (getDiscriminator().isDeclaration()) 340 union_depend.add(getDiscriminator()); 341 342 depend = getDiscriminator().getDependencies(); 343 for (int i=0;i<depend.length;i++) 344 union_depend.add(depend[i]); 345 346 org.objectweb.openccm.ast.api.UnionMember[] members = 348 members_.getUnionMembers(); 349 for (int i=0; i<members.length; i++) 350 { 351 TypeRef member_type = members[i].getType(); 352 if (member_type.isDeclaration()) 353 { 354 if ((!containsDecl((Declaration)member_type)) && 355 (union_depend.indexOf(member_type)==-1)) 356 union_depend.add(member_type); 357 } 358 359 depend = member_type.getDependencies(); 360 for (int j=0;j<depend.length;j++) 361 { 362 if ((union_depend.indexOf(depend[j])==-1) && 363 (!containsDecl(depend[j])) && 364 (depend[j]!=this)) 365 union_depend.add(depend[j]); 366 } 367 } 368 369 dependencies_ = (Declaration[])union_depend.toArray(new Declaration[0]); 370 return dependencies_; 371 } 372 373 379 384 public long 385 getDeclKind() 386 { 387 return DeclarationKind.dk_union; 388 } 389 390 396 402 408 413 public TypeKind 414 getTypeKind() 415 { 416 return TypeKind.tk_union; 417 } 418 419 425 430 public void 431 setDiscriminator(TypeRef type) 432 { 433 if(type!=null) 434 { 435 discriminator_ = type; 436 } 437 } 438 439 444 public TypeRef 445 getDiscriminator() 446 { 447 return discriminator_; 448 } 449 450 455 public UnionMemberList 456 getMemberList() 457 { 458 return members_; 459 } 460 461 466 public int 467 getDefaultIndex() 468 { 469 return default_index_; 470 } 471 472 478 483 public org.omg.CORBA.IDLType 484 getIDLType() 485 { 486 return union_def_; 487 } 488 } 489 | Popular Tags |