1 26 27 package org.objectweb.ccm.IDL3; 28 29 37 38 public class ValueDeclImpl 39 extends ForwardScopeImpl 40 implements ValueRef, ValueDecl 41 { 42 48 51 protected org.omg.CORBA.ExtValueDef ext_value_def_; 52 53 56 protected boolean is_custom_; 57 58 61 protected boolean is_abstract_; 62 63 66 protected ValueDeclImpl base_value_; 67 68 71 protected boolean is_truncatable_; 72 73 76 protected org.objectweb.ccm.util.Vector abstract_base_values_; 77 78 81 protected org.objectweb.ccm.util.Vector supported_interfaces_; 82 83 86 protected org.objectweb.ccm.util.Vector initializers_; 87 88 94 99 public 100 ValueDeclImpl(Repository rep, ScopeImpl parent) 101 { 102 super(rep, parent); 104 105 ext_value_def_ = null; 107 is_custom_ = false; 108 is_abstract_ = false; 109 base_value_ = null; 110 is_truncatable_ = false; 111 abstract_base_values_ = new org.objectweb.ccm.util.Vector(); 112 supported_interfaces_ = new org.objectweb.ccm.util.Vector(); 113 initializers_ = new org.objectweb.ccm.util.Vector(); 114 the_declaration_kind_ = DeclarationKind._dk_value; 115 } 116 117 123 128 protected org.omg.CORBA.ExtValueDef 129 getBaseValueDef() 130 { 131 return (base_value_ != null) 132 ? (base_value_.getExtValueDef()) : null; 133 } 134 135 140 protected void 141 load(org.omg.CORBA.Contained contained) 142 { 143 ext_value_def_ = org.omg.CORBA.ExtValueDefHelper.narrow(contained); 144 is_custom_ = ext_value_def_.is_custom(); 145 is_abstract_ = ext_value_def_.is_abstract(); 146 is_truncatable_ = ext_value_def_.is_truncatable(); 147 if (ext_value_def_.base_value()!=null) 148 setBaseValue((ValueRef)getRepository().lookupId(ext_value_def_.base_value().id())); 149 150 org.omg.CORBA.ValueDef [] abstract_base_values = ext_value_def_.abstract_base_values(); 151 org.omg.CORBA.InterfaceDef [] supported_interfaces = ext_value_def_.supported_interfaces(); 152 org.omg.CORBA.ExtInitializer[] initializers = ext_value_def_.ext_initializers(); 153 154 super.load(contained); 157 158 for (int i=0;i<abstract_base_values.length;i++) 159 addAbstractValue( 160 (ValueRef)getRepository().lookupId(abstract_base_values[i].id())); 161 162 for (int i=0;i<supported_interfaces.length;i++) 163 addInterface( 164 (InterfaceRef)getRepository().lookupId(supported_interfaces[i].id())); 165 166 Initializer initializer; 167 for (int i=0;i<initializers.length;i++) 168 { 169 initializer = startInitializer(initializers[i].name); 170 initializers_.add(initializer); 171 org.omg.CORBA.StructMember [] params = initializers[i].members; 172 for (int j=0;j<params.length;j++) 173 { 174 initializer.addInParam(params[j].name, 175 getRepository().getAsTypeRef(params[j].type_def)); 176 } 177 } 178 } 179 180 185 protected void 186 loadAsMapping(org.omg.CORBA.Contained contained) 187 { 188 ext_value_def_ = org.omg.CORBA.ExtValueDefHelper.narrow(contained); 189 is_custom_ = ext_value_def_.is_custom(); 190 is_abstract_ = ext_value_def_.is_abstract(); 191 is_truncatable_ = ext_value_def_.is_truncatable(); 192 if (ext_value_def_.base_value()!=null) 193 setBaseValue((ValueRef)getRepository().lookupMappedId(ext_value_def_.base_value().id())); 194 195 org.omg.CORBA.ValueDef [] abstract_base_values = ext_value_def_.abstract_base_values(); 196 org.omg.CORBA.InterfaceDef [] supported_interfaces = ext_value_def_.supported_interfaces(); 197 org.omg.CORBA.ExtInitializer[] initializers = ext_value_def_.ext_initializers(); 198 199 super.loadAsMapping(contained); 202 203 for (int i=0;i<abstract_base_values.length;i++) 204 addAbstractValue( 205 (ValueRef)getRepository().lookupMappedId(abstract_base_values[i].id())); 206 207 for (int i=0;i<supported_interfaces.length;i++) 208 addInterface( 209 (InterfaceRef)getRepository().lookupMappedId(supported_interfaces[i].id())); 210 211 Initializer initializer; 212 for (int i=0;i<initializers.length;i++) 213 { 214 initializer = startInitializer(initializers[i].name); 215 initializers_.add(initializer); 216 org.omg.CORBA.StructMember [] params = initializers[i].members; 217 for (int j=0;j<params.length;j++) 218 { 219 initializer.addInParam(params[j].name, 220 getRepository().getAsMappedTypeRef(params[j].type_def)); 221 } 222 } 223 } 224 225 231 242 public Declaration 243 find(String name) 244 { 245 Declaration decl = super.find(name); 247 if(decl != null) return decl; 249 250 if(base_value_ != null) 252 { 253 decl = base_value_.find(name); 254 if(decl != null) return decl; 256 } 257 258 for(int i=0; i<abstract_base_values_.size(); i++) 260 { 261 decl = ((ValueDeclImpl)(abstract_base_values_.get(i))).find(name); 262 if(decl != null) return decl; 264 } 265 266 for(int i=0; i<supported_interfaces_.size(); i++) 268 { 269 decl = ((InterfaceDeclImpl)(supported_interfaces_.get(i))).find(name); 270 if(decl != null) return decl; 272 } 273 274 return null; 276 } 277 278 285 public Declaration[] 286 getDependencies() 287 { 288 if (dependencies_!=null) 289 return dependencies_; 290 291 dependencies_ = new Declaration[0]; 292 org.objectweb.ccm.util.Vector value_depend = new org.objectweb.ccm.util.Vector(); 293 Declaration[] depend = null; 294 295 if (getBaseValue()!=null) 297 { 298 value_depend.add(getBaseValue()); 299 depend = getBaseValue().getDependencies(); 300 for (int j=0;j<depend.length;j++) 301 { 302 if (depend[j]!=this) 303 value_depend.add(depend[j]); 304 } 305 } 306 307 ValueDecl[] abs = getAbstractValues(); 309 for (int i=0;i<abs.length;i++) 310 { 311 value_depend.add(abs[i]); 312 depend = abs[i].getDependencies(); 313 for (int j=0;j<depend.length;j++) 314 { 315 if ((depend[j]!=this) && 316 (value_depend.indexOf(depend[j])==-1)) 317 value_depend.add(depend[j]); 318 } 319 } 320 321 InterfaceDecl[] supp = getSupportedInterfaces(); 323 for (int i=0;i<supp.length;i++) 324 { 325 value_depend.add(supp[i]); 326 depend = supp[i].getDependencies(); 327 for (int j=0;j<depend.length;j++) 328 { 329 if ((depend[j]!=this) && 330 (value_depend.indexOf(depend[j])==-1)) 331 value_depend.add(depend[j]); 332 } 333 } 334 335 Initializer[] inits = getInitializers(); 337 for (int i=0;i<inits.length;i++) 338 { 339 TypeRef[] param_types = inits[i].getParameters().getParamTypes(); 340 for (int j=0;j<param_types.length;j++) 341 { 342 depend = param_types[j].getDependencies(); 343 for (int k=0;k<depend.length;k++) 344 { 345 if ((!containsDecl(depend[k])) && 346 (depend[k]!=this) && 347 (value_depend.indexOf(depend[k])==-1)) 348 value_depend.add(depend[k]); 349 } 350 } 351 } 352 353 Declaration[] decls = getContents(true, org.objectweb.ccm.IDL3.DeclarationKind._dk_all); 355 for (int i=0;i<decls.length;i++) 356 { 357 depend = decls[i].getDependencies(); 358 for (int j=0;j<depend.length;j++) 359 { 360 if ((!containsDecl(depend[j])) && 361 (depend[j]!=this) && 362 (value_depend.indexOf(depend[j])==-1)) 363 value_depend.add(depend[j]); 364 } 365 } 366 367 dependencies_ = (Declaration[])value_depend.toArray(new Declaration[0]); 368 return dependencies_; 369 } 370 371 377 383 388 public org.omg.CORBA.IDLType 389 getIDLType() 390 { 391 return ext_value_def_; 392 } 393 394 397 public int 398 getTypeKind() 399 { 400 return TypeKind._tk_value; 401 } 402 403 409 414 public org.omg.CORBA.ExtValueDef 415 getExtValueDef() 416 { 417 return ext_value_def_; 418 } 419 420 425 public org.omg.CORBA.ValueDef 426 getValueDef() 427 { 428 return ext_value_def_; 429 } 430 431 437 440 public void 441 setCustom() 442 { 443 is_custom_ = true; 444 } 445 446 449 public void 450 setAbstract() 451 { 452 is_abstract_ = true; 453 } 454 455 458 public void 459 setTruncatable() 460 { 461 is_truncatable_ = true; 462 } 463 464 469 public void 470 setBaseValue(ValueRef value) 471 { 472 if(value != null) 473 { 474 base_value_ = (ValueDeclImpl)value; 475 base_value_.addRef(); 476 } 477 } 478 479 484 public void 485 addInitializer(Initializer init) 486 { 487 initializers_.add(init); 488 } 489 490 495 public void 496 addAbstractValue(ValueRef value) 497 { 498 if(value != null) 499 { 500 value.addRef(); 501 abstract_base_values_.add(value); 502 } 503 } 504 505 510 public void 511 addInterface(InterfaceRef itf) 512 { 513 if(itf != null) 514 { 515 itf.addRef(); 516 supported_interfaces_.add(itf); 517 } 518 } 519 520 526 529 public boolean 530 isCustom() 531 { 532 return is_custom_; 533 } 534 535 538 public boolean 539 isAbstract() 540 { 541 return is_abstract_; 542 } 543 544 547 public boolean 548 isTruncatable() 549 { 550 return is_truncatable_; 551 } 552 553 556 public boolean 557 isPrimaryKey() 558 { 559 boolean is_pk = false; 560 ValueDecl[] abs = getAbstractValues(); 561 for (int i=0;i<abs.length;i++) 562 { 563 if (abs[i].getAbsoluteName().equals("::Components::PrimaryKeyBase")) 564 return true; 565 566 is_pk = abs[i].isPrimaryKey(); 567 if (is_pk) 568 return true; 569 } 570 571 if (getBaseValue()!=null) 572 is_pk = getBaseValue().isPrimaryKey(); 573 574 return is_pk; 575 } 576 577 580 public ValueDecl 581 getBaseValue() 582 { 583 return base_value_; 584 } 585 586 589 public ValueDecl[] 590 getAbstractValues() 591 { 592 ValueDecl[] result = new ValueDecl[abstract_base_values_.size()]; 593 for (int i=0;i<result.length;i++) 594 { 595 result[i] = (ValueDecl)abstract_base_values_.get(i); 596 } 597 return result; 598 } 599 600 603 public InterfaceDecl[] 604 getSupportedInterfaces() 605 { 606 InterfaceDecl[] result = new InterfaceDecl[supported_interfaces_.size()]; 607 for (int i=0;i<result.length;i++) 608 { 609 result[i] = (InterfaceDecl)supported_interfaces_.get(i); 610 } 611 return result; 612 } 613 614 617 public Initializer[] 618 getInitializers() 619 { 620 Initializer[] result = new Initializer[initializers_.size()]; 621 for (int i=0;i<result.length;i++) 622 { 623 result[i] = (Initializer)initializers_.get(i); 624 } 625 return result; 626 } 627 628 634 637 public void 638 destroy() 639 { 640 if (base_value_!=null) 641 base_value_.removeRef(); 642 643 for (int i=0;i<abstract_base_values_.size();i++) 644 { 645 ((ValueRef)abstract_base_values_.get(i)).removeRef(); 646 } 647 for (int i=0;i<supported_interfaces_.size();i++) 648 { 649 ((InterfaceRef)supported_interfaces_.get(i)).removeRef(); 650 } 651 for (int i=0;i<initializers_.size();i++) 652 { 653 ((InitializerImpl)initializers_.get(i)).destroy(); 654 } 655 super.destroy(); 656 } 657 658 663 protected org.omg.CORBA.Contained 664 getContained() 665 { 666 return ext_value_def_; 667 } 668 669 675 680 protected org.omg.CORBA.Container 681 getContainer() 682 { 683 return ext_value_def_; 684 } 685 686 699 protected org.omg.CORBA.ExtAttributeDef 700 createExtAttribute(AttributeDecl attribute, 701 org.omg.CORBA.IDLType type, 702 org.omg.CORBA.AttributeMode mode, 703 org.omg.CORBA.ExceptionDef [] get_exceptions, 704 org.omg.CORBA.ExceptionDef [] set_exceptions) 705 { 706 org.omg.CORBA.ExtAttributeDef ext_attribute_def = 708 getExtValueDef().create_ext_attribute(attribute.getId(), 709 attribute.getName(), 710 attribute.getVersion(), 711 type, mode, 712 get_exceptions, 713 set_exceptions); 714 return ext_attribute_def; 715 } 716 717 730 protected org.omg.CORBA.OperationDef 731 createOperation(OperationDecl operation, 732 org.omg.CORBA.IDLType type, 733 org.omg.CORBA.OperationMode mode, 734 org.omg.CORBA.ParameterDescription [] params, 735 org.omg.CORBA.ExceptionDef [] exceptions, 736 String [] contexts) 737 { 738 org.omg.CORBA.OperationDef operation_def = 740 getExtValueDef().create_operation(operation.getId(), 741 operation.getName(), 742 operation.getVersion(), 743 type, mode, 744 params, 745 exceptions, 746 contexts); 747 return operation_def; 748 } 749 750 758 public Declaration[] 759 getContents(boolean exclude_inherited, int limited_types) 760 { 761 if (exclude_inherited) 762 return super.getContents(exclude_inherited, limited_types); 763 764 Declaration[] res = super.getContents(exclude_inherited, limited_types); 765 InterfaceDecl[] itfs = getSupportedInterfaces(); 766 for (int i=0;i<itfs.length;i++) 767 { 768 Declaration[] tmp1 = itfs[i].getContents(exclude_inherited, limited_types); 769 Declaration[] tmp2 = res; 770 res = new Declaration[tmp1.length+tmp2.length]; 771 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 772 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 773 } 774 ValueDecl[] vals = getAbstractValues(); 775 for (int i=0;i<vals.length;i++) 776 { 777 Declaration[] tmp1 = vals[i].getContents(exclude_inherited, limited_types); 778 Declaration[] tmp2 = res; 779 res = new Declaration[tmp1.length+tmp2.length]; 780 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 781 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 782 } 783 if (base_value_==null) 784 return res; 785 786 Declaration[] tmp1 = base_value_.getContents(exclude_inherited, limited_types); 787 Declaration[] tmp2 = res; 788 res = new Declaration[tmp1.length+tmp2.length]; 789 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 790 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 791 return res; 792 } 793 794 800 803 protected void 804 createContainer() 805 { 806 org.omg.CORBA.ValueDef [] abstract_base_values = 807 new org.omg.CORBA.ValueDef [abstract_base_values_.size()]; 808 for(int i=0; i<abstract_base_values.length; i++) 809 { 810 abstract_base_values[i] = ((ValueDeclImpl)(abstract_base_values_.get(i))).getExtValueDef(); 811 } 812 813 org.omg.CORBA.InterfaceDef [] supported_interfaces = 814 new org.omg.CORBA.InterfaceDef [supported_interfaces_.size()]; 815 for(int i=0; i<supported_interfaces.length; i++) 816 { 817 supported_interfaces[i] = 818 ((InterfaceDeclImpl)(supported_interfaces_.get(i))).getExtInterfaceDef(); 819 } 820 821 ext_value_def_ = the_parent_.getContainer().create_ext_value(getId(), getName(), getVersion(), 823 is_custom_, is_abstract_, 824 getBaseValueDef(), 825 is_truncatable_, 826 abstract_base_values, 827 supported_interfaces, 828 new org.omg.CORBA.ExtInitializer[0]); 829 } 830 831 834 protected void 835 completeContainer() 836 { 837 org.omg.CORBA.ValueDef base_value = getBaseValueDef(); 838 if(base_value != null) 839 getExtValueDef().base_value(base_value); 840 841 org.omg.CORBA.ValueDef [] abstract_base_values = 842 new org.omg.CORBA.ValueDef [abstract_base_values_.size()]; 843 for(int i=0; i<abstract_base_values.length; i++) 844 { 845 abstract_base_values[i] = 846 ((ValueDeclImpl)(abstract_base_values_.get(i))).getExtValueDef(); 847 } 848 849 if(abstract_base_values.length != 0) 850 getExtValueDef().abstract_base_values(abstract_base_values); 851 852 org.omg.CORBA.InterfaceDef [] supported_interfaces = 853 new org.omg.CORBA.InterfaceDef [supported_interfaces_.size()]; 854 for(int i=0; i<supported_interfaces.length; i++) 855 { 856 supported_interfaces[i] = 857 ((InterfaceDeclImpl)(supported_interfaces_.get(i))).getExtInterfaceDef(); 858 } 859 860 if(supported_interfaces.length != 0) 861 getExtValueDef().supported_interfaces(supported_interfaces); 862 863 org.omg.CORBA.ExtInitializer[] initializers = 864 new org.omg.CORBA.ExtInitializer[initializers_.size()]; 865 for(int i=0; i<initializers.length; i++) 866 { 867 initializers[i] = 868 ((InitializerImpl)(initializers_.get(i))).getExtInitializer(); 869 } 870 871 if(initializers.length != 0) 872 getExtValueDef().ext_initializers(initializers); 873 } 874 } 875 | Popular Tags |