1 26 27 package org.objectweb.openccm.ir3; 28 29 import org.omg.CORBA.*; 31 32 40 41 abstract public class Container_impl 42 extends Contained_impl 43 implements ContainerOperations 44 { 45 51 54 protected java.util.List contained_elements_; 55 56 59 protected java.util.List contained_with_mappings_; 60 61 65 protected boolean mapping_started_; 66 67 73 76 public 77 Container_impl(IFR ifr, 78 Container_impl container) 79 { 80 super(ifr, container); 82 83 contained_elements_ = new java.util.ArrayList (); 85 contained_with_mappings_ = new java.util.ArrayList (); 86 mapping_started_ = false; 87 } 88 89 95 98 protected Contained_impl[] 99 getContainedElements() 100 { 101 if (!getIFR().getRepository().isIDL2Repository()) 102 return (Contained_impl[])contained_elements_.toArray(new Contained_impl[0]); 103 else 104 return (Contained_impl[])contained_with_mappings_.toArray(new Contained_impl[0]); 105 } 106 107 108 111 protected void 112 addContained(Contained_impl contained) 113 { 114 if (!checkDefinitionKind(contained.def_kind())) 116 throw exceptionInvalidContainer(); 117 118 if (!mapping_started_) 119 contained_elements_.add(contained); 120 121 contained_with_mappings_.add(contained); 122 } 123 124 130 133 static public Contained[] 134 toContainedSeq(java.util.List list) 135 { 136 Contained[] result = new Contained[list.size()]; 137 for(int i=0; i<result.length; i++) 138 { 139 result[i] = ((Contained_impl)list.get(i)).asContained(); 140 } 141 return result; 142 } 143 144 150 153 protected void 154 cutDependencies() 155 { 156 while(contained_with_mappings_.size() != 0) 158 { 159 ((Contained_impl) contained_with_mappings_.get(contained_with_mappings_.size() -1)).destroy(); 160 } 161 162 super.cutDependencies(); 164 } 165 166 172 175 public Container 176 asContainer() 177 { 178 return ContainerHelper.narrow(asObject()); 179 } 180 181 184 public boolean 185 checkDefinitionKind(DefinitionKind def_kind) 186 { 187 return true; 189 } 190 191 194 public void 195 addContained(Contained_impl contained, 196 String id, 197 String name, 198 String version) 199 { 200 contained.name(name); 201 contained.id(id); 202 contained.version(version); 203 addContained(contained); 204 } 205 206 209 public void 210 removeContained(Contained_impl contained) 211 { 212 contained_elements_.remove(contained); 213 contained_with_mappings_.remove(contained); 214 } 215 216 219 public java.util.List 220 selectNamedContained(java.util.List selection, 221 String search_name, 222 int levels_to_search, 223 DefinitionKind limit_type, 224 boolean exclude_inherited) 225 { 226 if(levels_to_search == 0) return selection; 227 levels_to_search --; 228 229 Contained_impl[] containeds = getContainedElements(); 231 for (int i=0;i<containeds.length;i++) 232 { 233 Contained_impl contained = containeds[i]; 234 235 if ( (limit_type == DefinitionKind.dk_all) 236 || (limit_type == contained.def_kind()) ) 237 { 238 if ((getIFR().getRepository().isIDL2Repository()) && 239 (contained.def_kind()!=DefinitionKind.dk_Consumes) && 240 (contained.def_kind()!=DefinitionKind.dk_Emits) && 241 (contained.def_kind()!=DefinitionKind.dk_Publishes) && 242 (contained.def_kind()!=DefinitionKind.dk_Provides) && 243 (contained.def_kind()!=DefinitionKind.dk_Uses) && 244 (contained.def_kind()!=DefinitionKind.dk_Factory) && 245 (contained.def_kind()!=DefinitionKind.dk_Finder) && 246 (contained.def_kind()!=DefinitionKind.dk_Event) && 247 (contained.def_kind()!=DefinitionKind.dk_Component) && 248 (contained.def_kind()!=DefinitionKind.dk_Home) && 249 (search_name.equals(contained.name()))) 250 selection.add(contained); 251 else if ((!getIFR().getRepository().isIDL2Repository()) && 252 (search_name.equals(contained.name()))) 253 selection.add(contained); 254 } 255 256 if(levels_to_search != 0) 257 { 258 Container_impl container = (Container_impl)contained; 259 if(container != null) 260 { 261 container.selectNamedContained(selection, 262 search_name, 263 levels_to_search, 264 limit_type, 265 exclude_inherited); 266 } 267 } 268 } 269 270 return selection; 271 } 272 273 276 public java.util.List 277 selectContained(java.util.List selection, 278 DefinitionKind limit_type, 279 boolean exclude_inherited) 280 { 281 Contained_impl[] containeds = getContainedElements(); 283 for (int i=0;i<containeds.length;i++) 284 { 285 Contained_impl contained = containeds[i]; 286 287 if ( (limit_type == DefinitionKind.dk_all) 288 || (limit_type == contained.def_kind()) ) 289 { 290 selection.add(contained); 291 } 292 } 293 294 return selection; 295 } 296 297 300 public AttributeDescription[] 301 getAttrDescriptionSeq() 302 { 303 java.util.List selection = new java.util.ArrayList (); 304 305 selectContained(selection, DefinitionKind.dk_Attribute, false); 308 309 AttributeDescription[] result = 310 new AttributeDescription[selection.size()]; 311 312 for(int i=0; i<selection.size(); i++) 313 result[i] = ((AttributeDef_impl)selection.get(i)) 314 .getAttributeDescription(); 315 316 return result; 317 } 318 319 322 public ExtAttributeDescription[] 323 getExtAttrDescriptionSeq() 324 { 325 java.util.List selection = new java.util.ArrayList (); 326 327 selectContained(selection, DefinitionKind.dk_Attribute, false); 330 331 ExtAttributeDescription[] result = 332 new ExtAttributeDescription[selection.size()]; 333 334 for(int i=0; i<selection.size(); i++) 335 result[i] = ((ExtAttributeDef_impl)selection.get(i)) 336 .getExtAttributeDescription(); 337 338 return result; 339 } 340 341 344 public OperationDescription[] 345 getOpDescriptionSeq() 346 { 347 java.util.List selection = new java.util.ArrayList (); 348 349 selectContained(selection, DefinitionKind.dk_Operation, false); 352 353 OperationDescription[] result = 354 new OperationDescription[selection.size()]; 355 356 for(int i=0; i<selection.size(); i++) 357 result[i] = ((OperationDef_impl)selection.get(i)) 358 .getOperationDescription(); 359 360 return result; 361 } 362 363 366 public void 367 checkName(String name, 368 boolean exclude_inherited, 369 boolean in_inherited) 370 { 371 Contained_impl[] containeds = getContainedElements(); 373 for (int i=0;i<containeds.length;i++) 374 { 375 Contained_impl contained = containeds[i]; 376 377 DefinitionKind dk = contained.def_kind(); 378 379 if (in_inherited && ( (dk == DefinitionKind.dk_Constant) 380 || (dk == DefinitionKind.dk_Exception) 381 || (dk == DefinitionKind.dk_Alias) 382 || (dk == DefinitionKind.dk_Struct) 383 || (dk == DefinitionKind.dk_Union) 384 || (dk == DefinitionKind.dk_Enum) 385 || (dk == DefinitionKind.dk_Native) 386 )) 387 continue; 388 389 boolean found = name.equalsIgnoreCase(contained.name()); 390 391 if(!found && dk == DefinitionKind.dk_Enum) 392 { 393 String [] members = ((EnumDef_impl)contained).members(); 394 for(int j=0; j<members.length; j++) 395 { 396 if(name.equalsIgnoreCase(members[j])) 397 { 398 found = true; 399 break; 400 } 401 } 402 } 403 404 if(found) 405 { 406 if(in_inherited) 407 throw exceptionNameClashInInheritedContext(name); 408 else 409 throw exceptionNameAlreadyUsed(name); 410 } 411 } 412 } 413 414 420 426 429 public Contained 430 lookup(String search_name) 431 { 432 if(search_name.startsWith("::")) 434 return getIFR().getRepository().lookup(search_name); 435 436 int index = search_name.indexOf("::"); 437 String s1 = null; 438 String s2 = null; 439 440 if (index == -1) { 441 s1 = search_name; 442 } else { 443 s1 = search_name.substring(0,index); 444 s2 = search_name.substring(index+2); 445 } 446 447 Contained_impl[] containeds = getContainedElements(); 449 for (int i=0;i<containeds.length;i++) 450 { 451 Contained_impl contained = containeds[i]; 452 453 if (s1.equals(contained.name())) { 454 if (s2 == null) { 455 return contained.asContained(); 456 } else { 457 Container_impl container = (Container_impl)contained; 458 if (container == null) { 459 return null; 460 } else { 461 return container.lookup(s2); 462 } 463 } 464 } 465 } 466 467 return null; 468 } 469 470 473 public Contained[] 474 contents(DefinitionKind limit_type, 475 boolean exclude_inherited) 476 { 477 java.util.List selection = new java.util.ArrayList (); 478 479 selectContained(selection, limit_type, exclude_inherited); 480 481 return toContainedSeq(selection); 482 } 483 484 487 public Contained[] 488 lookup_name(String search_name, 489 int levels_to_search, 490 DefinitionKind limit_type, 491 boolean exclude_inherited) 492 { 493 java.util.List selection = new java.util.ArrayList (); 494 495 selectNamedContained(selection, search_name, levels_to_search, 496 limit_type, exclude_inherited); 497 498 return toContainedSeq(selection); 499 } 500 501 504 public org.omg.CORBA.ContainerPackage.Description[] 505 describe_contents(DefinitionKind limit_type, 506 boolean exclude_inherited, 507 int max_returned_objs) 508 { 509 java.util.List selection = new java.util.ArrayList (); 510 selectContained(selection, limit_type, exclude_inherited); 511 512 int len = selection.size(); 513 if(max_returned_objs >= 0 && len > max_returned_objs) 514 len = max_returned_objs; 515 516 org.omg.CORBA.ContainerPackage.Description[] result = 517 new org.omg.CORBA.ContainerPackage.Description[len]; 518 519 for(int i=0; i<len; i++) 520 { 521 Contained_impl contained = (Contained_impl)selection.get(i); 522 523 org.omg.CORBA.ContainerPackage.Description tmp = 524 new org.omg.CORBA.ContainerPackage.Description(); 525 526 tmp.contained_object = contained.asContained(); 527 tmp.kind = contained.def_kind(); 528 tmp.value = org.objectweb.openccm.corba.TheORB.create_any(); 529 contained.setDescriptionValue(tmp.value); 530 531 result[i] = tmp; 532 } 533 534 return result; 535 } 536 537 540 public ModuleDef 541 create_module(String id, 542 String name, 543 String version) 544 { 545 ModuleDef_impl module = new ModuleDef_impl(getIFR(), this); 546 547 try 548 { 549 addContained(module, id, name, version); 550 } 551 catch(SystemException exc) 552 { 553 module.destroy(); 554 throw exc; 555 } 556 557 return module.asModuleDef(); 558 } 559 560 563 public ConstantDef 564 create_constant(String id, 565 String name, 566 String version, 567 IDLType type, 568 Any value) 569 { 570 ConstantDef_impl constant = new ConstantDef_impl(getIFR(), this); 571 572 try 573 { 574 addContained(constant, id, name, version); 575 constant.type_def(type); 576 constant.value(value); 577 } 578 catch(SystemException exc) 579 { 580 constant.destroy(); 581 throw exc; 582 } 583 584 return constant.asConstantDef(); 585 } 586 587 590 public StructDef 591 create_struct(String id, 592 String name, 593 String version, 594 StructMember[] members) 595 { 596 StructDef_impl struct = new StructDef_impl(getIFR(), this); 597 598 try 599 { 600 addContained(struct, id, name, version); 601 struct.members(members); 602 } 603 catch(SystemException exc) 604 { 605 struct.destroy(); 606 throw exc; 607 } 608 609 return struct.asStructDef(); 610 } 611 612 615 public UnionDef 616 create_union(String id, 617 String name, 618 String version, 619 IDLType discriminator_type, 620 UnionMember[] members) 621 { 622 UnionDef_impl union = new UnionDef_impl(getIFR(), this); 623 624 try 625 { 626 addContained(union, id, name, version); 627 union.discriminator_type_def(discriminator_type); 628 union.members(members); 629 } 630 catch(SystemException exc) 631 { 632 union.destroy(); 633 throw exc; 634 } 635 636 return union.asUnionDef(); 637 } 638 639 642 public EnumDef 643 create_enum(String id, 644 String name, 645 String version, 646 String [] members) 647 { 648 EnumDef_impl enumDef = new EnumDef_impl(getIFR(), this); 649 650 try 651 { 652 addContained(enumDef, id, name, version); 653 enumDef.members(members); 654 } 655 catch(SystemException exc) 656 { 657 enumDef.destroy(); 658 throw exc; 659 } 660 661 return enumDef.asEnumDef(); 662 } 663 664 667 public AliasDef 668 create_alias(String id, 669 String name, 670 String version, 671 IDLType original_type) 672 { 673 AliasDef_impl alias = new AliasDef_impl(getIFR(), this); 674 675 try 676 { 677 addContained(alias, id, name, version); 678 alias.original_type_def(original_type); 679 } 680 catch(SystemException exc) 681 { 682 alias.destroy(); 683 throw exc; 684 } 685 686 return alias.asAliasDef(); 687 } 688 689 692 public InterfaceDef 693 create_interface(String id, 694 String name, 695 String version, 696 InterfaceDef[] base_interfaces) 697 { 698 InterfaceDef_impl itf = new InterfaceDef_impl(getIFR(), this); 699 700 try 701 { 702 addContained(itf, id, name, version); 703 itf.base_interfaces(base_interfaces); 704 } 705 catch(SystemException exc) 706 { 707 itf.destroy(); 708 throw exc; 709 } 710 711 return itf.asInterfaceDef(); 712 } 713 714 717 public AbstractInterfaceDef 718 create_abstract_interface(String id, 719 String name, 720 String version, 721 AbstractInterfaceDef[] base_interfaces) 722 { 723 AbstractInterfaceDef_impl itf = 724 new AbstractInterfaceDef_impl(getIFR(), this); 725 726 try 727 { 728 addContained(itf, id, name, version); 729 itf.base_interfaces(base_interfaces); 730 } 731 catch(SystemException exc) 732 { 733 itf.destroy(); 734 throw exc; 735 } 736 737 return itf.asAbstractInterfaceDef(); 738 } 739 740 743 public LocalInterfaceDef 744 create_local_interface(String id, 745 String name, 746 String version, 747 InterfaceDef[] base_interfaces) 748 { 749 LocalInterfaceDef_impl itf = 750 new LocalInterfaceDef_impl(getIFR(), this); 751 752 try 753 { 754 addContained(itf, id, name, version); 755 itf.base_interfaces(base_interfaces); 756 } 757 catch(SystemException exc) 758 { 759 itf.destroy(); 760 throw exc; 761 } 762 763 return itf.asLocalInterfaceDef(); 764 } 765 766 769 public ValueDef 770 create_value(String id, 771 String name, 772 String version, 773 boolean is_custom, 774 boolean is_abstract, 775 ValueDef base_value, 776 boolean is_truncatable, 777 ValueDef[] abstract_base_values, 778 InterfaceDef[] supported_interfaces, 779 Initializer[] initializers) 780 { 781 ValueDef_impl value = new ValueDef_impl(getIFR(), this); 782 783 try 784 { 785 addContained(value, id, name, version); 786 value.is_custom(is_custom); 787 value.is_abstract(is_abstract); 788 value.base_value(base_value); 789 value.is_truncatable(is_truncatable); 790 value.abstract_base_values(abstract_base_values); 791 value.supported_interfaces(supported_interfaces); 792 value.initializers(initializers); 793 } 794 catch(SystemException exc) 795 { 796 value.destroy(); 797 throw exc; 798 } 799 800 return value.asValueDef(); 801 } 802 803 806 public ValueBoxDef 807 create_value_box(String id, 808 String name, 809 String version, 810 IDLType original_type_def) 811 { 812 ValueBoxDef_impl value_box = new ValueBoxDef_impl(getIFR(), this); 813 814 try 815 { 816 addContained(value_box, id, name, version); 817 value_box.original_type_def(original_type_def); 818 } 819 catch(SystemException exc) 820 { 821 value_box.destroy(); 822 throw exc; 823 } 824 825 return value_box.asValueBoxDef(); 826 } 827 828 831 public ExceptionDef 832 create_exception(String id, 833 String name, 834 String version, 835 StructMember[] members) 836 { 837 ExceptionDef_impl e = new ExceptionDef_impl(getIFR(), this); 838 839 try 840 { 841 addContained(e, id, name, version); 842 e.members(members); 843 } 844 catch(SystemException exc) 845 { 846 e.destroy(); 847 throw exc; 848 } 849 850 return e.asExceptionDef(); 851 } 852 853 856 public NativeDef 857 create_native(String id, 858 String name, 859 String version) 860 { 861 NativeDef_impl n = new NativeDef_impl(getIFR(), this); 862 863 try 864 { 865 addContained(n, id, name, version); 866 } 867 catch(SystemException exc) 868 { 869 n.destroy(); 870 throw exc; 871 } 872 873 return n.asNativeDef(); 874 } 875 876 879 public ExtValueDef 880 create_ext_value(String id, 881 String name, 882 String version, 883 boolean is_custom, 884 boolean is_abstract, 885 ValueDef base_value, 886 boolean is_truncatable, 887 ValueDef[] abstract_base_values, 888 InterfaceDef[] supported_interfaces, 889 ExtInitializer[] initializers) 890 { 891 ExtValueDef_impl value = new ExtValueDef_impl(getIFR(), this); 892 893 try 894 { 895 addContained(value, id, name, version); 896 value.is_custom(is_custom); 897 value.is_abstract(is_abstract); 898 value.base_value(base_value); 899 value.is_truncatable(is_truncatable); 900 value.abstract_base_values(abstract_base_values); 901 value.supported_interfaces(supported_interfaces); 902 value.ext_initializers(initializers); 903 } 904 catch(SystemException exc) 905 { 906 value.destroy(); 907 throw exc; 908 } 909 910 return value.asExtValueDef(); 911 } 912 913 916 public ExtInterfaceDef 917 create_ext_interface(String id, 918 String name, 919 String version, 920 InterfaceDef[] base_interfaces) 921 { 922 ExtInterfaceDef_impl itf = new ExtInterfaceDef_impl(getIFR(), this); 923 924 try 925 { 926 addContained(itf, id, name, version); 927 itf.base_interfaces(base_interfaces); 928 } 929 catch(SystemException exc) 930 { 931 itf.destroy(); 932 throw exc; 933 } 934 935 return itf.asExtInterfaceDef(); 936 } 937 938 941 public ExtAbstractInterfaceDef 942 create_ext_abstract_interface(String id, 943 String name, 944 String version, 945 AbstractInterfaceDef[] base_interfaces) 946 { 947 ExtAbstractInterfaceDef_impl itf = 948 new ExtAbstractInterfaceDef_impl(getIFR(), this); 949 950 try 951 { 952 addContained(itf, id, name, version); 953 itf.base_interfaces(base_interfaces); 954 } 955 catch(SystemException exc) 956 { 957 itf.destroy(); 958 throw exc; 959 } 960 961 return itf.asExtAbstractInterfaceDef(); 962 } 963 964 967 public ExtLocalInterfaceDef 968 create_ext_local_interface(String id, 969 String name, 970 String version, 971 InterfaceDef[] base_interfaces) 972 { 973 ExtLocalInterfaceDef_impl itf = 974 new ExtLocalInterfaceDef_impl(getIFR(), this); 975 976 try 977 { 978 addContained(itf, id, name, version); 979 itf.base_interfaces(base_interfaces); 980 } 981 catch(SystemException exc) 982 { 983 itf.destroy(); 984 throw exc; 985 } 986 987 return itf.asExtLocalInterfaceDef(); 988 } 989 } 990 | Popular Tags |