1 22 package org.jboss.iiop.rmi.ir; 23 24 import org.omg.CORBA.ValueDef ; 25 import org.omg.CORBA.ValueDefOperations ; 26 import org.omg.CORBA.ValueDefPOATie; 27 import org.omg.CORBA.ValueDefHelper; 28 import org.omg.CORBA.ValueDescription ; 29 import org.omg.CORBA.ValueDescriptionHelper; 30 import org.omg.CORBA.ValueMemberDef ; 31 import org.omg.CORBA.ValueMember ; 32 import org.omg.CORBA.Any ; 33 import org.omg.CORBA.TypeCode ; 34 import org.omg.CORBA.TypeCodePackage.BadKind ; 35 import org.omg.CORBA.TCKind ; 36 import org.omg.CORBA.IRObject ; 37 import org.omg.CORBA.Contained ; 38 import org.omg.CORBA.ContainedPackage.Description; 39 import org.omg.CORBA.DefinitionKind ; 40 import org.omg.CORBA.IDLType ; 41 import org.omg.CORBA.StructMember ; 42 import org.omg.CORBA.UnionMember ; 43 import org.omg.CORBA.ConstantDef ; 44 import org.omg.CORBA.EnumDef ; 45 import org.omg.CORBA.ValueBoxDef ; 46 import org.omg.CORBA.InterfaceDef ; 47 import org.omg.CORBA.InterfaceDefHelper; 48 import org.omg.CORBA.Initializer ; 49 import org.omg.CORBA.StructDef ; 50 import org.omg.CORBA.UnionDef ; 51 import org.omg.CORBA.ModuleDef ; 52 import org.omg.CORBA.AliasDef ; 53 import org.omg.CORBA.NativeDef ; 54 import org.omg.CORBA.OperationDef ; 55 import org.omg.CORBA.OperationMode ; 56 import org.omg.CORBA.ParameterDescription ; 57 import org.omg.CORBA.AttributeDef ; 58 import org.omg.CORBA.AttributeMode ; 59 import org.omg.CORBA.ExceptionDef ; 60 import org.omg.CORBA.OperationDescription ; 61 import org.omg.CORBA.AttributeDescription ; 62 import org.omg.CORBA.BAD_INV_ORDER ; 63 import org.omg.CORBA.VM_NONE ; 64 import org.omg.CORBA.VM_CUSTOM ; 65 import org.omg.CORBA.VM_ABSTRACT ; 66 67 import org.omg.CORBA.ValueDefPackage.FullValueDescription; 68 69 75 class ValueDefImpl 76 extends ContainedImpl 77 implements ValueDefOperations , LocalContainer, LocalContainedIDLType 78 { 79 81 83 85 private static final org.jboss.logging.Logger logger = 86 org.jboss.logging.Logger.getLogger(ValueDefImpl.class); 87 88 90 ValueDefImpl(String id, String name, String version, 91 LocalContainer defined_in, 92 boolean is_abstract, boolean is_custom, 93 String [] supported_interfaces, 94 String [] abstract_base_valuetypes, 95 TypeCode baseValueTypeCode, 96 RepositoryImpl repository) 97 { 98 super(id, name, version, defined_in, 99 DefinitionKind.dk_Value, repository); 100 101 this.is_abstract = is_abstract; 102 this.is_custom = is_custom; 103 this.supported_interfaces = supported_interfaces; 104 this.abstract_base_valuetypes = abstract_base_valuetypes; 105 this.baseValueTypeCode = baseValueTypeCode; 106 this.delegate = new ContainerImplDelegate(this); 107 } 108 109 111 113 public LocalContained _lookup(String search_name) 114 { 115 return delegate._lookup(search_name); 116 } 117 118 public LocalContained[] _contents(DefinitionKind limit_type, 119 boolean exclude_inherited) 120 { 121 return delegate._contents(limit_type, exclude_inherited); 122 } 123 124 public LocalContained[] _lookup_name(String search_name, 125 int levels_to_search, 126 DefinitionKind limit_type, 127 boolean exclude_inherited) 128 { 129 return delegate._lookup_name(search_name, levels_to_search, limit_type, 130 exclude_inherited); 131 } 132 133 public void add(String name, LocalContained contained) 134 throws IRConstructionException 135 { 136 delegate.add(name, contained); 137 } 138 139 141 public IRObject getReference() 142 { 143 if (ref == null) { 144 ref = org.omg.CORBA.ValueDefHelper.narrow( 145 servantToReference(new ValueDefPOATie(this)) ); 146 } 147 return ref; 148 } 149 150 public void allDone() 151 throws IRConstructionException 152 { 153 getReference(); 154 delegate.allDone(); 155 156 logger.debug("ValueDefImpl.allDone(): baseValueTypeCode is " + 157 ((baseValueTypeCode==null) ? "null" : "NOT null") ); 158 if (baseValueTypeCode != null) 159 logger.debug("ValueDefImpl.allDone(): " + 160 "baseValueTypeCode.kind().value()=" + 161 baseValueTypeCode.kind().value() ); 162 if (baseValueTypeCode != null && 163 baseValueTypeCode.kind() != TCKind.tk_null) { 164 try { 165 baseValue = baseValueTypeCode.id(); 166 logger.debug("ValueDefImpl.allDone(): baseValue=\"" 167 + baseValue + "\"."); 168 } catch (BadKind ex) { 169 throw new IRConstructionException( 170 "Bad kind for super-valuetype of " + id()); 171 } 172 Contained c = repository.lookup_id(baseValue); 173 logger.debug("ValueDefImpl.allDone(): c is " + 174 ((c==null) ? "null" : "NOT null") ); 175 base_value_ref = ValueDefHelper.narrow(c); 176 logger.debug("ValueDefImpl.allDone(): base_value_ref is " + 177 ((base_value_ref==null) ? "null" : "NOT null") ); 178 } else 180 baseValue = "IDL:omg.org/CORBA/ValueBase:1.0"; 182 supported_interfaces_ref = new InterfaceDef [supported_interfaces.length]; 184 for (int i = 0; i < supported_interfaces.length; ++i) { 185 InterfaceDef iDef = InterfaceDefHelper.narrow( 186 repository.lookup_id(supported_interfaces[i])); 187 if (iDef == null) 188 throw new IRConstructionException( 189 "ValueDef \"" + id() + "\" unable to resolve " + 190 "reference to implemented interface \"" + 191 supported_interfaces[i] + "\"."); 192 supported_interfaces_ref[i] = iDef; 193 } 194 195 abstract_base_valuetypes_ref = 197 new ValueDef [abstract_base_valuetypes.length]; 198 for (int i = 0; i < abstract_base_valuetypes.length; ++i) { 199 ValueDef vDef = ValueDefHelper.narrow( 200 repository.lookup_id(abstract_base_valuetypes[i])); 201 if (vDef == null) 202 throw new IRConstructionException( 203 "ValueDef \"" + id() + "\" unable to resolve " + 204 "reference to abstract base valuetype \"" + 205 abstract_base_valuetypes[i] + "\"."); 206 abstract_base_valuetypes_ref[i] = vDef; 207 } 208 } 209 210 public void shutdown() 211 { 212 delegate.shutdown(); 213 super.shutdown(); 214 } 215 216 217 219 public Contained lookup(String search_name) 220 { 221 logger.debug("ValueDefImpl.lookup(\"" + search_name + "\") entered."); 222 Contained res = delegate.lookup(search_name); 223 logger.debug("ValueDefImpl.lookup(\"" + search_name + 224 "\") returning " + ((res == null) ? "null" : "non-null") ); 225 return res; 226 } 228 229 public Contained [] contents(DefinitionKind limit_type, 230 boolean exclude_inherited) 231 { 232 logger.debug("ValueDefImpl.contents() entered."); 233 Contained [] res = delegate.contents(limit_type, exclude_inherited); 234 logger.debug("ValueDefImpl.contents() " + res.length + 235 " contained to return."); 236 for (int i = 0; i < res.length; ++i) 237 logger.debug(" ValueDefImpl.contents() [" + i + "]: " + res[i].id()); 238 return res; 239 } 241 242 public Contained [] lookup_name(String search_name, int levels_to_search, 243 DefinitionKind limit_type, 244 boolean exclude_inherited) 245 { 246 return delegate.lookup_name(search_name, levels_to_search, limit_type, 247 exclude_inherited); 248 } 249 250 public org.omg.CORBA.ContainerPackage.Description[] 251 describe_contents(DefinitionKind limit_type, 252 boolean exclude_inherited, 253 int max_returned_objs) 254 { 255 return delegate.describe_contents(limit_type, exclude_inherited, 256 max_returned_objs); 257 } 258 259 public ModuleDef create_module(String id, String name, String version) 260 { 261 return delegate.create_module(id, name, version); 262 } 263 264 public ConstantDef create_constant(String id, String name, String version, 265 IDLType type, Any value) 266 { 267 return delegate.create_constant(id, name, version, type, value); 268 } 269 270 public StructDef create_struct(String id, String name, String version, 271 StructMember [] members) 272 { 273 return delegate.create_struct(id, name, version, members); 274 } 275 276 public UnionDef create_union(String id, String name, String version, 277 IDLType discriminator_type, 278 UnionMember [] members) 279 { 280 return delegate.create_union(id, name, version, discriminator_type, 281 members); 282 } 283 284 public EnumDef create_enum(String id, String name, String version, 285 String [] members) 286 { 287 return delegate.create_enum(id, name, version, members); 288 } 289 290 public AliasDef create_alias(String id, String name, String version, 291 IDLType original_type) 292 { 293 return delegate.create_alias(id, name, version, original_type); 294 } 295 296 public InterfaceDef create_interface(String id, String name, String version, 297 InterfaceDef [] base_interfaces, 298 boolean is_abstract) 299 { 300 return delegate.create_interface(id, name, version, 301 base_interfaces, is_abstract); 302 } 303 304 public ValueDef create_value(String id, String name, String version, 305 boolean is_custom, boolean is_abstract, 306 ValueDef base_value, boolean is_truncatable, 307 ValueDef [] abstract_base_values, 308 InterfaceDef [] supported_interfaces, 309 Initializer [] initializers) 310 { 311 return delegate.create_value(id, name, version, is_custom, is_abstract, 312 base_value, is_truncatable, 313 abstract_base_values, supported_interfaces, 314 initializers); 315 } 316 317 public ValueBoxDef create_value_box(String id, String name, String version, 318 IDLType original_type_def) 319 { 320 return delegate.create_value_box(id, name, version, original_type_def); 321 } 322 323 public ExceptionDef create_exception(String id, String name, String version, 324 StructMember [] members) 325 { 326 return delegate.create_exception(id, name, version, members); 327 } 328 329 public NativeDef create_native(String id, String name, String version) 330 { 331 return delegate.create_native(id, name, version); 332 } 333 334 335 337 public InterfaceDef [] supported_interfaces() 338 { 339 return supported_interfaces_ref; 340 } 341 342 public void supported_interfaces(InterfaceDef [] arg) 343 { 344 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 345 } 346 347 public Initializer [] initializers() 348 { 349 return new Initializer [0]; 352 } 353 354 public void initializers(Initializer [] arg) 355 { 356 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 357 } 358 359 public ValueDef base_value() 360 { 361 logger.debug("ValueDefImpl[" + id + "].base_value() entered."); 362 if (base_value_ref == null) 363 logger.debug("ValueDefImpl[" + id + "].base_value() returning NULL."); 364 else 365 logger.debug("ValueDefImpl[" + id + "].base_value() returning \"" + 366 base_value_ref.id() + "\"."); 367 return base_value_ref; 368 } 369 370 public void base_value(ValueDef arg) 371 { 372 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 373 } 374 375 public ValueDef [] abstract_base_values() 376 { 377 return abstract_base_valuetypes_ref; 378 } 379 380 public void abstract_base_values(ValueDef [] arg) 381 { 382 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 383 } 384 385 public boolean is_abstract() 386 { 387 return is_abstract; 388 } 389 390 public void is_abstract(boolean arg) 391 { 392 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 393 } 394 395 public boolean is_custom() 396 { 397 return is_custom; 398 } 399 400 public void is_custom(boolean arg) 401 { 402 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 403 } 404 405 public boolean is_truncatable() 406 { 407 return false; 408 } 409 410 public void is_truncatable(boolean arg) 411 { 412 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 413 } 414 415 public boolean is_a(String id) 416 { 417 return id().equals(id); 419 } 420 421 public FullValueDescription describe_value() 422 { 423 if (fullValueDescription != null) 424 return fullValueDescription; 425 426 428 OperationDescription [] operations = new OperationDescription [0]; 430 AttributeDescription [] attributes = new AttributeDescription [0]; 431 432 String defined_in_id = "IDL:Global:1.0"; 433 if (defined_in instanceof org.omg.CORBA.ContainedOperations ) 434 defined_in_id = ((org.omg.CORBA.ContainedOperations )defined_in).id(); 435 436 fullValueDescription = new FullValueDescription(name, id, 437 is_abstract, is_custom, 438 defined_in_id, version, 439 operations, attributes, 440 getValueMembers(), 441 new Initializer [0], supported_interfaces, 443 abstract_base_valuetypes, 444 false, 445 baseValue, 446 typeCode); 447 448 return fullValueDescription; 449 } 450 451 public ValueMemberDef create_value_member(String id, String name, 452 String version, IDLType type, 453 short access) 454 { 455 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 456 } 457 458 public AttributeDef create_attribute(String id, String name, String version, 459 IDLType type, AttributeMode mode) 460 { 461 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 462 } 463 464 public OperationDef create_operation(String id, String name, String version, 465 IDLType result, OperationMode mode, 466 ParameterDescription [] params, 467 ExceptionDef [] exceptions, 468 String [] contexts) 469 { 470 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 471 } 472 473 474 476 public TypeCode type() 477 { 478 logger.debug("ValueDefImpl.type() entered."); 479 if (typeCode == null) { 480 short modifier = VM_NONE.value; 481 if (is_custom) 482 modifier = VM_CUSTOM.value; 483 else if (is_abstract) 484 modifier = VM_ABSTRACT.value; 485 486 typeCode = getORB().create_value_tc(id, name, modifier, 487 baseValueTypeCode, 488 getValueMembersForTypeCode()); 489 } 490 logger.debug("ValueDefImpl.type() returning."); 491 return typeCode; 492 } 493 494 495 497 public Description describe() 498 { 499 String defined_in_id = "IR"; 500 501 if (defined_in instanceof org.omg.CORBA.ContainedOperations ) 502 defined_in_id = ((org.omg.CORBA.ContainedOperations )defined_in).id(); 503 504 ValueDescription md = new ValueDescription (name, id, is_abstract, 505 is_custom, 506 defined_in_id, version, 507 supported_interfaces, 508 abstract_base_valuetypes, 509 false, 510 baseValue); 511 512 Any any = getORB().create_any(); 513 514 ValueDescriptionHelper.insert(any, md); 515 516 return new Description (DefinitionKind.dk_Value, any); 517 } 518 519 521 523 525 527 530 private ContainerImplDelegate delegate; 531 532 535 private ValueDef ref = null; 536 537 540 private boolean is_abstract; 541 542 545 private boolean is_custom; 546 547 550 private String [] supported_interfaces; 551 552 555 private InterfaceDef [] supported_interfaces_ref; 556 557 560 private String baseValue; 561 562 565 private TypeCode baseValueTypeCode; 566 567 570 private ValueDef base_value_ref; 571 572 575 private String [] abstract_base_valuetypes; 576 577 580 private ValueDef [] abstract_base_valuetypes_ref; 581 582 585 private TypeCode typeCode; 586 587 590 private ValueMember [] valueMembers; 591 592 595 private FullValueDescription fullValueDescription; 596 597 598 601 private ValueMember [] getValueMembers() 602 { 603 if (valueMembers != null) 604 return valueMembers; 605 606 LocalContained[] c = _contents(DefinitionKind.dk_ValueMember, false); 607 valueMembers = new ValueMember [c.length]; 608 for (int i = 0; i < c.length; ++i) { 609 ValueMemberDefImpl vmdi = (ValueMemberDefImpl)c[i]; 610 611 valueMembers[i] = new ValueMember (vmdi.name(), vmdi.id(), 612 ((LocalContained)vmdi.defined_in).id(), 613 vmdi.version(), 614 vmdi.type(), vmdi.type_def(), 615 vmdi.access()); 616 } 617 618 return valueMembers; 619 } 620 621 624 private ValueMember [] getValueMembersForTypeCode() 625 { 626 LocalContained[] c = _contents(DefinitionKind.dk_ValueMember, false); 627 ValueMember [] vms = new ValueMember [c.length]; 628 for (int i = 0; i < c.length; ++i) { 629 ValueMemberDefImpl vmdi = (ValueMemberDefImpl)c[i]; 630 631 vms[i] = new ValueMember (vmdi.name(), 632 null, null, null, vmdi.type(), 636 null, vmdi.access()); 638 } 639 640 return vms; 641 } 642 643 } 645 | Popular Tags |