1 26 27 package org.objectweb.ccm.IDL3; 28 29 37 38 public class UnionDeclImpl 39 extends ForwardScopeImpl 40 implements TypeRef, UnionDecl 41 { 42 48 51 private org.omg.CORBA.UnionDef union_def_; 52 53 56 private int default_index_; 57 58 61 private UnionMembersImpl members_; 62 63 69 74 protected 75 UnionDeclImpl(Repository rep, ScopeImpl parent) 76 { 77 super(rep, parent); 79 80 union_def_ = null; 82 members_ = new UnionMembersImpl(); 83 default_index_ = -1; 84 the_declaration_kind_ = DeclarationKind._dk_union; 85 } 86 87 93 98 protected void 99 load(org.omg.CORBA.Contained contained) 100 { 101 union_def_ = org.omg.CORBA.UnionDefHelper.narrow(contained); 102 setDiscriminator(getRepository().getAsTypeRef(union_def_.discriminator_type_def())); 103 try 104 { 105 default_index_ = union_def_.type().default_index(); 106 } 107 catch (org.omg.CORBA.TypeCodePackage.BadKind e) {} 108 109 org.omg.CORBA.UnionMember [] members = union_def_.members(); 110 111 super.load(contained); 114 115 for (int i=0;i<members.length;i++) 116 { 117 AnyValue any = new AnyValue(); 118 any.loadAny(members[i].label); 119 addMember(members[i].name, 120 getRepository().getAsTypeRef(members[i].type_def), 121 any); 122 } 123 } 124 125 130 protected void 131 loadAsMapping(org.omg.CORBA.Contained contained) 132 { 133 union_def_ = org.omg.CORBA.UnionDefHelper.narrow(contained); 134 setDiscriminator(getRepository().getAsMappedTypeRef(union_def_.discriminator_type_def())); 135 try 136 { 137 default_index_ = union_def_.type().default_index(); 138 } 139 catch (org.omg.CORBA.TypeCodePackage.BadKind e) {} 140 org.omg.CORBA.UnionMember [] members = union_def_.members(); 141 142 super.loadAsMapping(contained); 145 146 for (int i=0;i<members.length;i++) 147 { 148 AnyValue any = new AnyValue(); 149 any.loadAny(members[i].label); 150 addMember(members[i].name, 151 getRepository().getAsMappedTypeRef(members[i].type_def), 152 any); 153 } 154 } 155 156 162 169 public Declaration[] 170 getDependencies() 171 { 172 if (dependencies_!=null) 173 return dependencies_; 174 175 dependencies_ = new Declaration[0]; 176 org.objectweb.ccm.util.Vector union_depend = new org.objectweb.ccm.util.Vector(); 177 Declaration[] depend = null; 178 179 if (getType().isDeclaration()) 181 union_depend.add(getType()); 182 183 depend = getType().getDependencies(); 184 for (int i=0;i<depend.length;i++) 185 union_depend.add(depend[i]); 186 187 188 TypeRef[] member_types = getMembers().getMemberTypes(); 190 191 for (int i=0;i<member_types.length;i++) 192 { 193 if (member_types[i].isDeclaration()) 194 { 195 if ((!containsDecl((Declaration)member_types[i])) && 196 (union_depend.indexOf(member_types[i])==-1)) 197 union_depend.add(member_types[i]); 198 } 199 200 depend = member_types[i].getDependencies(); 201 for (int j=0;j<depend.length;j++) 202 { 203 if ((union_depend.indexOf(depend[j])==-1) && 204 (!containsDecl(depend[j])) && 205 (depend[j]!=this)) 206 union_depend.add(depend[j]); 207 } 208 } 209 210 dependencies_ = (Declaration[])union_depend.toArray(new Declaration[0]); 211 return dependencies_; 212 } 213 214 220 226 231 public org.omg.CORBA.IDLType 232 getIDLType() 233 { 234 return union_def_; 235 } 236 237 240 public int 241 getTypeKind() 242 { 243 return TypeKind._tk_union; 244 } 245 246 252 257 public void 258 setDiscriminator(TypeRef type) 259 { 260 if(type!=null) 261 { 262 type.addRef(); 263 members_.setDiscriminator(type); 264 } 265 } 266 267 274 public void 275 addMember(String name, 276 TypeRef type, 277 AnyValue value) 278 { 279 members_.addMember(name, type, value); 280 } 281 282 285 public TypeRef 286 getType() 287 { 288 return members_.getDiscriminator(); 289 } 290 291 294 public UnionMembers 295 getMembers() 296 { 297 return members_; 298 } 299 300 303 public int 304 getDefaultIndex() 305 { 306 return default_index_; 307 } 308 309 315 318 public void 319 destroy() 320 { 321 members_.destroy(); 322 super.destroy(); 323 } 324 325 330 protected org.omg.CORBA.Contained 331 getContained() 332 { 333 return union_def_; 334 } 335 336 342 347 protected org.omg.CORBA.Container 348 getContainer() 349 { 350 return union_def_; 351 } 352 353 359 362 protected void 363 createContainer() 364 { 365 org.omg.CORBA.IDLType disc = null; 367 if (members_.getDiscriminator()!=null) 368 disc = members_.getDiscriminator().getIDLType(); 369 370 union_def_ = the_parent_.getContainer().create_union(getId(), getName(), getVersion(), 371 disc, 372 members_.getMemberDefs()); 373 } 374 375 378 protected void 379 completeContainer() 380 { 381 union_def_.discriminator_type_def(members_.getDiscriminator().getIDLType()); 382 union_def_.members(members_.getMemberDefs()); 383 } 384 } 385 | Popular Tags |