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.InterfaceDecl; 43 44 45 import org.objectweb.openccm.ast.api.AttributeDecl; 46 47 48 import org.objectweb.openccm.ast.api.OperationDecl; 49 50 51 import org.objectweb.openccm.ast.api.ValueDecl; 52 53 54 import org.objectweb.openccm.ast.api.ValueList; 55 56 57 import org.objectweb.openccm.ast.api.InterfaceList; 58 59 60 import org.objectweb.openccm.ast.api.Initializer; 61 62 63 import org.objectweb.openccm.ast.api.InitializerList; 64 65 66 import org.objectweb.openccm.ast.api.Parameter; 67 68 69 import org.objectweb.openccm.ast.api.ExceptionDecl; 70 71 72 import org.omg.CORBA.ValueDef ; 73 74 75 import org.omg.CORBA.ExtValueDef; 76 import org.omg.CORBA.ExtValueDefHelper; 77 78 79 import org.omg.CORBA.InterfaceDef ; 80 81 126 127 public class ValueDeclImpl 128 extends ForwardScopeIDLImpl 129 implements ValueDecl, 130 IDLTypeWrapper 131 { 132 138 139 protected ExtValueDef ext_value_def_; 140 141 142 protected boolean is_custom_; 143 144 145 protected boolean is_abstract_; 146 147 148 protected boolean is_truncatable_; 149 150 151 protected ValueDeclImpl base_value_; 152 153 154 protected ValueListImpl abstract_base_values_; 155 156 157 protected InterfaceListImpl supported_interfaces_; 158 159 160 protected InitializerListImpl initializers_; 161 162 168 174 public 175 ValueDeclImpl(Repository rep, ScopeImpl parent) 176 { 177 super(rep, parent); 179 180 ext_value_def_ = null; 182 is_custom_ = false; 183 is_abstract_ = false; 184 is_truncatable_ = false; 185 base_value_ = null; 186 abstract_base_values_ = new ValueListImpl(); 187 supported_interfaces_ = new InterfaceListImpl(); 188 initializers_ = new InitializerListImpl(); 189 } 190 191 197 203 208 protected void 209 load(org.omg.CORBA.Contained contained) 210 { 211 ext_value_def_ = ExtValueDefHelper.narrow(contained); 212 is_custom_ = ext_value_def_.is_custom(); 213 is_abstract_ = ext_value_def_.is_abstract(); 214 is_truncatable_ = ext_value_def_.is_truncatable(); 215 216 ValueDef baseValue = ext_value_def_.base_value(); 217 if (baseValue!=null) 218 setBaseValue((ValueDecl)getRepository().lookupId(baseValue.id())); 219 220 super.load(contained); 223 224 ValueDef [] abstract_base_values = ext_value_def_.abstract_base_values(); 225 for (int i=0; i<abstract_base_values.length; i++) 226 abstract_base_values_.add( 227 (ValueDecl)getRepository(). 228 lookupId(abstract_base_values[i].id())); 229 230 InterfaceDef [] supported_interfaces = 231 ext_value_def_.supported_interfaces(); 232 for (int i=0; i<supported_interfaces.length; i++) 233 supported_interfaces_.add( 234 (InterfaceDecl)getRepository(). 235 lookupId(supported_interfaces[i].id())); 236 237 org.omg.CORBA.ExtInitializer[] initializers = 238 ext_value_def_.ext_initializers(); 239 for (int i=0; i<initializers.length; i++) 240 { 241 Initializer initializer = startInitializer(initializers[i].name); 242 initializers_.add(initializer); 243 org.omg.CORBA.StructMember [] params = initializers[i].members; 245 for (int j=0; j<params.length; j++) 246 { 247 initializer.getParameterList(). 248 addInParam(params[j].name, 249 getRepository(). 250 getAsTypeRef(params[j].type_def)); 251 } 252 org.omg.CORBA.ExceptionDef [] exc = initializers[i].exceptions_def; 254 for (int j=0; j<exc.length; j++) 255 { 256 initializer.getExceptionList().add( 257 (ExceptionDecl)getRepository().lookupId(exc[j].id()) ); 258 } 259 } 260 } 261 262 267 protected void 268 loadAsMapping(org.omg.CORBA.Contained contained) 269 { 270 ext_value_def_ = ExtValueDefHelper.narrow(contained); 271 is_custom_ = ext_value_def_.is_custom(); 272 is_abstract_ = ext_value_def_.is_abstract(); 273 is_truncatable_ = ext_value_def_.is_truncatable(); 274 275 ValueDef baseValue = ext_value_def_.base_value(); 276 if (baseValue!=null) 277 setBaseValue((ValueDecl)getRepository(). 278 lookupMappedId(baseValue.id())); 279 280 super.loadAsMapping(contained); 283 284 285 ValueDef [] abstract_base_values = 286 ext_value_def_.abstract_base_values(); 287 for (int i=0; i<abstract_base_values.length; i++) 288 abstract_base_values_.add( 289 (ValueDecl)getRepository(). 290 lookupMappedId(abstract_base_values[i].id())); 291 292 InterfaceDef [] supported_interfaces = 293 ext_value_def_.supported_interfaces(); 294 for (int i=0; i<supported_interfaces.length; i++) 295 supported_interfaces_.add( 296 (InterfaceDecl)getRepository(). 297 lookupMappedId(supported_interfaces[i].id())); 298 299 org.omg.CORBA.ExtInitializer[] initializers = 300 ext_value_def_.ext_initializers(); 301 for (int i=0; i<initializers.length; i++) 302 { 303 Initializer initializer = startInitializer(initializers[i].name); 304 initializers_.add(initializer); 305 org.omg.CORBA.StructMember [] params = initializers[i].members; 307 for (int j=0; j<params.length; j++) 308 { 309 initializer.getParameterList(). 310 addInParam(params[j].name, 311 getRepository(). 312 getAsMappedTypeRef(params[j].type_def)); 313 } 314 org.omg.CORBA.ExceptionDef [] exc = initializers[i].exceptions_def; 316 for (int j=0; j<exc.length; j++) 317 { 318 initializer.getExceptionList().add( 319 (ExceptionDecl)getRepository().lookupId(exc[j].id()) ); 320 } 321 } 322 } 323 324 329 protected org.omg.CORBA.Contained 330 getContained() 331 { 332 return ext_value_def_; 333 } 334 335 341 354 protected org.omg.CORBA.ExtAttributeDef 355 createExtAttribute(AttributeDecl attribute, 356 org.omg.CORBA.IDLType type, 357 org.omg.CORBA.AttributeMode mode, 358 org.omg.CORBA.ExceptionDef [] get_exceptions, 359 org.omg.CORBA.ExceptionDef [] set_exceptions) 360 { 361 org.omg.CORBA.ExtAttributeDef ext_attribute_def = 363 getExtValueDef().create_ext_attribute(attribute.getId(), 364 attribute.getName(), 365 attribute.getVersion(), 366 type, mode, 367 get_exceptions, 368 set_exceptions); 369 return ext_attribute_def; 370 } 371 372 385 protected org.omg.CORBA.OperationDef 386 createOperation(OperationDecl operation, 387 org.omg.CORBA.IDLType type, 388 org.omg.CORBA.OperationMode mode, 389 org.omg.CORBA.ParameterDescription [] params, 390 org.omg.CORBA.ExceptionDef [] exceptions, 391 String [] contexts) 392 { 393 org.omg.CORBA.OperationDef operation_def = 395 getExtValueDef().create_operation(operation.getId(), 396 operation.getName(), 397 operation.getVersion(), 398 type, mode, 399 params, 400 exceptions, 401 contexts); 402 return operation_def; 403 } 404 405 410 protected org.omg.CORBA.Container 411 getContainer() 412 { 413 return ext_value_def_; 414 } 415 416 422 428 431 protected void 432 createContainer() 433 { 434 ext_value_def_ = the_parent_.getContainer(). 436 create_ext_value(getId(), getName(), getVersion(), 437 is_custom_, is_abstract_, 438 getBaseValueDef(), 439 is_truncatable_, 440 abstract_base_values_.getValueDefSeq(), 441 supported_interfaces_.getInterfaceDefSeq(), 442 new org.omg.CORBA.ExtInitializer[0]); 443 } 444 445 448 protected void 449 completeContainer() 450 { 451 ValueDef base_value = getBaseValueDef(); 452 if(base_value != null) 453 getExtValueDef().base_value(base_value); 454 455 if(abstract_base_values_.getSize() != 0) 456 getExtValueDef().abstract_base_values(abstract_base_values_.getValueDefSeq()); 457 458 if(supported_interfaces_.getSize() != 0) 459 getExtValueDef().supported_interfaces(supported_interfaces_.getInterfaceDefSeq()); 460 461 if(initializers_.getSize() != 0) 462 getExtValueDef().ext_initializers(initializers_.getExtInitializerSeq()); 463 } 464 465 471 476 public ExtValueDef 477 getBaseValueDef() 478 { 479 return (base_value_ != null) 480 ? (base_value_.getExtValueDef()) : null; 481 } 482 483 488 public ExtValueDef 489 getExtValueDef() 490 { 491 return ext_value_def_; 492 } 493 494 499 public ValueDef 500 getValueDef() 501 { 502 return ext_value_def_; 503 } 504 505 511 519 public Declaration[] 520 getDependencies() 521 { 522 if (dependencies_!=null) 523 return dependencies_; 524 525 dependencies_ = new Declaration[0]; 526 java.util.List value_depend = new java.util.ArrayList (); 527 Declaration[] depend = null; 528 529 if (getBaseValue()!=null) 531 { 532 value_depend.add(getBaseValue()); 533 depend = getBaseValue().getDependencies(); 534 for (int j=0; j<depend.length; j++) 535 { 536 if (depend[j]!=this) 537 value_depend.add(depend[j]); 538 } 539 } 540 541 ValueDecl[] abs = abstract_base_values_.getValues(); 543 for (int i=0; i<abs.length; i++) 544 { 545 value_depend.add(abs[i]); 546 depend = abs[i].getDependencies(); 547 for (int j=0; j<depend.length; j++) 548 { 549 if ((depend[j]!=this) && 550 (value_depend.indexOf(depend[j])==-1)) 551 value_depend.add(depend[j]); 552 } 553 } 554 555 InterfaceDecl[] supp = supported_interfaces_.getInterfaces(); 557 for (int i=0; i<supp.length; i++) 558 { 559 value_depend.add(supp[i]); 560 depend = supp[i].getDependencies(); 561 for (int j=0; j<depend.length; j++) 562 { 563 if ((depend[j]!=this) && 564 (value_depend.indexOf(depend[j])==-1)) 565 value_depend.add(depend[j]); 566 } 567 } 568 569 Initializer[] inits = initializers_.getInitializers(); 571 for (int i=0; i<inits.length; i++) 572 { 573 Parameter[] parameters = inits[i].getParameterList(). 574 getParameters(); 575 for (int j=0; j<parameters.length; j++) 576 { 577 TypeRef param_type = parameters[j].getType(); 578 depend = param_type.getDependencies(); 579 for (int k=0; k<depend.length; k++) 580 { 581 if ((!containsDecl(depend[k])) && 582 (depend[k]!=this) && 583 (value_depend.indexOf(depend[k])==-1)) 584 value_depend.add(depend[k]); 585 } 586 } 587 } 588 589 Declaration[] decls = getContents(true, DeclarationKind.dk_all); 591 for (int i=0; i<decls.length; i++) 592 { 593 depend = decls[i].getDependencies(); 594 for (int j=0; j<depend.length; j++) 595 { 596 if ((!containsDecl(depend[j])) && 597 (depend[j]!=this) && 598 (value_depend.indexOf(depend[j])==-1)) 599 value_depend.add(depend[j]); 600 } 601 } 602 603 dependencies_ = (Declaration[])value_depend.toArray(new Declaration[0]); 604 return dependencies_; 605 } 606 607 613 618 public long 619 getDeclKind() 620 { 621 return DeclarationKind.dk_value; 622 } 623 624 630 641 public Declaration 642 find(String name) 643 { 644 Declaration decl = super.find(name); 646 647 if(decl != null) return decl; 649 650 if(base_value_ != null) 652 { 653 decl = base_value_.find(name); 654 655 if(decl != null) return decl; 657 } 658 659 decl = abstract_base_values_.find(name); 661 662 if(decl != null) return decl; 664 665 decl = supported_interfaces_.find(name); 667 668 return null; 670 } 671 672 680 public Declaration[] 681 getContents(boolean exclude_inherited, 682 long limited_types) 683 { 684 if (exclude_inherited) 685 return super.getContents(exclude_inherited, limited_types); 686 687 Declaration[] res = super.getContents(exclude_inherited, limited_types); 688 689 InterfaceDecl[] itfs = supported_interfaces_.getInterfaces(); 690 for (int i=0; i<itfs.length; i++) 691 { 692 Declaration[] tmp1 = itfs[i].getContents(exclude_inherited, limited_types); 693 Declaration[] tmp2 = res; 694 res = new Declaration[tmp1.length+tmp2.length]; 695 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 696 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 697 } 698 ValueDecl[] vals = abstract_base_values_.getValues(); 699 for (int i=0; i<vals.length; i++) 700 { 701 Declaration[] tmp1 = vals[i].getContents(exclude_inherited, limited_types); 702 Declaration[] tmp2 = res; 703 res = new Declaration[tmp1.length+tmp2.length]; 704 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 705 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 706 } 707 if (base_value_==null) 708 return res; 709 710 Declaration[] tmp1 = base_value_.getContents(exclude_inherited, limited_types); 711 Declaration[] tmp2 = res; 712 res = new Declaration[tmp1.length+tmp2.length]; 713 System.arraycopy(tmp2, 0, res, 0, tmp2.length); 714 System.arraycopy(tmp1, 0, res, tmp2.length, tmp1.length); 715 return res; 716 } 717 718 724 730 735 public TypeKind 736 getTypeKind() 737 { 738 return TypeKind.tk_value; 739 } 740 741 747 752 public void 753 setCustom(boolean b) 754 { 755 is_custom_ = b; 756 } 757 758 763 public boolean 764 isCustom() 765 { 766 return is_custom_; 767 } 768 769 774 public void 775 setAbstract(boolean b) 776 { 777 is_abstract_ = b; 778 } 779 780 785 public boolean 786 isAbstract() 787 { 788 return is_abstract_; 789 } 790 791 796 public void 797 setTruncatable(boolean b) 798 { 799 is_truncatable_ = b; 800 } 801 802 807 public boolean 808 isTruncatable() 809 { 810 return is_truncatable_; 811 } 812 813 818 public void 819 setBaseValue(ValueDecl value) 820 { 821 if(value != null) 822 { 823 base_value_ = (ValueDeclImpl)value; 824 } 825 } 826 827 832 public ValueDecl 833 getBaseValue() 834 { 835 return base_value_; 836 } 837 838 843 public boolean 844 isPrimaryKey() 845 { 846 boolean is_pk = false; 847 ValueDecl[] abs = abstract_base_values_.getValues(); 848 for (int i=0;i<abs.length;i++) 849 { 850 if (abs[i].getAbsoluteName().equals("::Components::PrimaryKeyBase")) 851 return true; 852 853 is_pk = abs[i].isPrimaryKey(); 854 if (is_pk) 855 return true; 856 } 857 858 if (getBaseValue()!=null) 859 is_pk = getBaseValue().isPrimaryKey(); 860 861 return is_pk; 862 } 863 864 869 public ValueList 870 getAbstractValueList() 871 { 872 return abstract_base_values_; 873 } 874 875 876 881 public InterfaceList 882 getSupportedInterfaceList() 883 { 884 return supported_interfaces_; 885 } 886 887 892 public InitializerList 893 getInitializerList() 894 { 895 return initializers_; 896 } 897 898 904 909 public org.omg.CORBA.IDLType 910 getIDLType() 911 { 912 return ext_value_def_; 913 } 914 } 915 | Popular Tags |