1 26 27 package org.objectweb.corba.generator.dependencies.lib; 28 29 import org.objectweb.openccm.ast.api.TypeKind; 31 import org.objectweb.openccm.ast.api.DeclarationKind; 32 import org.objectweb.openccm.ast.api.ConstantDecl; 33 import org.objectweb.openccm.ast.api.EnumDecl; 34 import org.objectweb.openccm.ast.api.StructDecl; 35 import org.objectweb.openccm.ast.api.UnionDecl; 36 import org.objectweb.openccm.ast.api.AbstractInterfaceDecl; 37 import org.objectweb.openccm.ast.api.LocalInterfaceDecl; 38 import org.objectweb.openccm.ast.api.InterfaceDecl; 39 import org.objectweb.openccm.ast.api.ValueDecl; 40 import org.objectweb.openccm.ast.api.ValueBoxDecl; 41 import org.objectweb.openccm.ast.api.ValueMemberDecl; 42 import org.objectweb.openccm.ast.api.ExceptionDecl; 43 import org.objectweb.openccm.ast.api.AliasDecl; 44 import org.objectweb.openccm.ast.api.AnyValue; 45 import org.objectweb.openccm.ast.api.AttributeDecl; 46 import org.objectweb.openccm.ast.api.TypeRef; 47 import org.objectweb.openccm.ast.api.UnionMember; 48 import org.objectweb.openccm.ast.api.Parameter; 49 import org.objectweb.openccm.ast.api.OperationDecl; 50 import org.objectweb.openccm.ast.api.Scope; 51 import org.objectweb.openccm.ast.api.Declaration; 52 import org.objectweb.openccm.ast.api.Initializer; 53 import org.objectweb.openccm.ast.api.StructMember; 54 import java.util.Set ; 55 56 63 64 public class IDL2DeclarationDependencies 65 implements org.objectweb.corba.generator.dependencies.api.IDL2DeclarationDependencies 66 { 67 73 74 org.objectweb.openccm.generator.translator.idl2java.api.CommonTranslator _translator; 75 76 82 85 public 86 IDL2DeclarationDependencies() 87 { 88 _translator = new org.objectweb.openccm.generator.translator.idl2java.lib.CommonTranslator(); 90 } 91 92 98 105 protected void 106 addObjectClass(Set files, String name) 107 { 108 files.add( new String (name + ".class") ); 109 } 110 111 118 protected void 119 addHelperClass(Set files, String name) 120 { 121 files.add( new String (name + "Helper.class") ); 122 } 123 124 131 protected void 132 addHolderClass(Set files, String name) 133 { 134 files.add( new String (name + "Holder.class") ); 135 } 136 137 146 protected void 147 addStantardIdlFiles(Set files, String name) 148 { 149 addObjectClass(files, name); 150 addHelperClass(files, name); 151 addHolderClass(files, name); 152 } 153 154 161 protected void 162 addOperationsClass(Set files, String name) 163 { 164 files.add( new String (name + "Operations.class") ); 165 } 166 167 175 protected void 176 addPoaIdlFiles(Set files, String name) 177 { 178 files.add( new String (name + "POA*.class") ); 179 files.add( new String (name + "POATie.class") ); 180 } 181 182 191 protected void 192 addStubClass(Set files, String name) 193 { 194 int index = name.lastIndexOf("/"); 195 196 if (index == -1) 198 { 199 files.add( new String ("_" + name + "Stub.class") ); 200 } 201 else 202 { 203 files.add( new String ( name.substring(0, index+1) + "_" + 204 name.substring(index+1) + "Stub.class") ); 205 } 206 } 207 208 214 222 public Set 223 getConstantDependencies(ConstantDecl aconst, 224 Set visited) 225 { 226 Set files = new java.util.HashSet (); 227 228 if ( visited.contains(aconst) ) 230 { 231 return files; 232 } 233 else 234 { 235 visited.add(aconst); 237 } 238 239 if ( (aconst.getParent().getDeclKind() == DeclarationKind.dk_interface) 240 || (aconst.getParent().getDeclKind() == DeclarationKind.dk_abstract_interface) 241 || (aconst.getParent().getDeclKind() == DeclarationKind.dk_local_interface) ) 242 { 243 String path = null; 244 245 path = _translator.getAsDirectory(aconst); 246 addObjectClass( files, path + aconst.getName() ); 248 } 249 250 files.addAll( getTypeRefDependencies(aconst.getType(), visited) ); 252 253 visited.add(aconst); 255 256 return files; 257 } 258 259 267 public Set 268 getEnumDependencies(EnumDecl enumDecl, 269 Set visited) 270 { 271 String path = null; 272 Set files = new java.util.HashSet (); 273 274 if ( visited.contains(enumDecl) ) 276 { 277 return files; 278 } 279 else 280 { 281 visited.add(enumDecl); 283 } 284 285 path = _translator.getAsDirectory(enumDecl); 286 addStantardIdlFiles( files, path + enumDecl.getName() ); 287 288 return files; 289 } 290 291 299 public Set 300 getStructDependencies(StructDecl struct, 301 Set visited) 302 { 303 String path = null; 304 StructMember[] members = null; 305 Set files = new java.util.HashSet (); 306 307 if ( visited.contains(struct) ) 309 { 310 return files; 311 } 312 else 313 { 314 visited.add(struct); 316 } 317 318 path = _translator.getAsDirectory(struct); 319 addStantardIdlFiles( files, path + struct.getName() ); 320 321 members = struct.getMemberList().getStructMembers(); 323 for (int i=0; i<members.length; i++) 324 { 325 files.addAll( getTypeRefDependencies(members[i].getType(), visited) ); 326 } 327 328 return files; 329 } 330 331 339 public Set 340 getUnionDependencies(UnionDecl union, 341 Set visited) 342 { 343 String path = null; 344 UnionMember[] members = null; 345 Set files = new java.util.HashSet (); 346 347 if ( visited.contains(union) ) 349 { 350 return files; 351 } 352 else 353 { 354 visited.add(union); 356 } 357 358 path = _translator.getAsDirectory(union); 359 addStantardIdlFiles( files, path + union.getName() ); 360 361 files.addAll( getTypeRefDependencies(union.getDiscriminator(), visited) ); 363 364 members = union.getMemberList().getUnionMembers(); 366 for (int i=0; i<members.length; i++) 367 { 368 files.addAll( getTypeRefDependencies(members[i].getType(), visited) ); 369 } 370 371 return files; 372 } 373 374 382 public Set 383 getAbstractInterfaceDependencies(AbstractInterfaceDecl itf, 384 Set visited) 385 { 386 String path = null; 387 InterfaceDecl[] bases = null; 388 Set files = new java.util.HashSet (); 389 390 if ( visited.contains(itf) ) 392 { 393 return files; 394 } 395 else 396 { 397 visited.add(itf); 399 } 400 401 path = _translator.getAsDirectory(itf); 402 addStantardIdlFiles( files, path + itf.getName() ); 404 addStubClass( files, path + itf.getName() ); 405 406 bases = itf.getInheritedInterfaceList().getInterfaces(); 408 for (int i=0; i<bases.length; i++) 409 { 410 files.addAll( getAbstractInterfaceDependencies((AbstractInterfaceDecl) bases[i], visited) ); 411 } 412 413 files.addAll( getContentsDependencies(itf, visited) ); 415 416 return files; 417 } 418 419 427 public Set 428 getLocalInterfaceDependencies(LocalInterfaceDecl itf, 429 Set visited) 430 { 431 String path = null; 432 InterfaceDecl[] bases = null; 433 Set files = new java.util.HashSet (); 434 435 if ( visited.contains(itf) ) 437 { 438 return files; 439 } 440 else 441 { 442 visited.add(itf); 444 } 445 446 path = _translator.getAsDirectory(itf); 447 addStantardIdlFiles( files, path + itf.getName() ); 449 addOperationsClass( files, path + itf.getName() ); 450 451 bases = itf.getInheritedInterfaceList().getInterfaces(); 453 for (int i=0; i<bases.length; i++) 454 { 455 files.addAll( getLocalInterfaceDependencies((LocalInterfaceDecl) bases[i], visited) ); 456 } 457 458 files.addAll( getContentsDependencies(itf, visited) ); 460 461 return files; 462 } 463 464 473 public Set 474 getInterfaceDependencies(InterfaceDecl itf, 475 boolean server, 476 Set visited) 477 { 478 String path = null; 479 InterfaceDecl[] bases = null; 480 Set files = new java.util.HashSet (); 481 482 if ( visited.contains(itf) ) 484 { 485 return files; 486 } 487 else 488 { 489 visited.add(itf); 491 } 492 493 path = _translator.getAsDirectory(itf); 494 addStantardIdlFiles( files, path + itf.getName() ); 496 addStubClass( files, path + itf.getName() ); 497 addOperationsClass( files, path + itf.getName() ); 498 if (server) 499 { 500 addPoaIdlFiles( files, path + itf.getName() ); 501 } 502 503 bases = itf.getInheritedInterfaceList().getInterfaces(); 505 for (int i=0; i<bases.length; i++) 506 { 507 files.addAll( getInterfaceDependencies(bases[i], server, visited) ); 508 } 509 510 files.addAll( getContentsDependencies(itf, visited) ); 512 513 return files; 514 } 515 516 524 public Set 525 getValueTypeDependencies(ValueDecl value, 526 Set visited) 527 { 528 String path = null; 529 Set files = new java.util.HashSet (); 530 531 if ( visited.contains(value) ) 533 { 534 return files; 535 } 536 else 537 { 538 visited.add(value); 540 } 541 542 path = _translator.getAsDirectory(value); 543 addStantardIdlFiles( files, path + value.getName() ); 545 547 if (value.getBaseValue() != null) 549 { 550 files.addAll( getValueTypeDependencies(value.getBaseValue(), visited) ); 551 } 552 553 ValueDecl[] abs = value.getAbstractValueList().getValues(); 555 for (int i=0; i<abs.length; i++) 556 { 557 files.addAll( getValueTypeDependencies(abs[i], visited) ); 558 } 559 560 InterfaceDecl[] supp = value.getSupportedInterfaceList().getInterfaces(); 562 for (int i=0; i<supp.length; i++) 563 { 564 if (supp[i].getDeclKind() == DeclarationKind.dk_abstract_interface) 565 { 566 files.addAll( getAbstractInterfaceDependencies((AbstractInterfaceDecl) supp[i], visited) ); 567 } 568 else if (supp[i].getDeclKind() == DeclarationKind.dk_local_interface) 569 { 570 files.addAll( getLocalInterfaceDependencies((LocalInterfaceDecl) supp[i], visited) ); 571 } 572 } 574 575 Initializer[] inits = value.getInitializerList().getInitializers(); 577 for (int i=0; i<inits.length; i++) 578 { 579 Parameter[] parameters = inits[i].getParameterList(). 580 getParameters(); 581 for (int j=0; j<parameters.length; j++) 582 { 583 files.addAll( getTypeRefDependencies(parameters[j].getType(), visited) ); 584 } 585 } 586 587 files.addAll( getContentsDependencies(value, visited) ); 589 590 return files; 591 } 592 593 601 public Set 602 getValueBoxDependencies(ValueBoxDecl box, 603 Set visited) 604 { 605 String path = null; 606 Set files = new java.util.HashSet (); 607 608 if ( visited.contains(box) ) 610 { 611 return files; 612 } 613 else 614 { 615 visited.add(box); 617 } 618 619 path = _translator.getAsDirectory(box); 620 addStantardIdlFiles( files, path + box.getName() ); 624 625 files.addAll( getTypeRefDependencies(box.getType(), visited) ); 627 628 return files; 629 } 630 631 639 public Set 640 getExceptionDependencies(ExceptionDecl ex, 641 Set visited) 642 { 643 String path = null; 644 StructMember[] members = null; 645 Set files = new java.util.HashSet (); 646 647 if ( visited.contains(ex) ) 649 { 650 return files; 651 } 652 else 653 { 654 visited.add(ex); 656 } 657 658 path = _translator.getAsDirectory(ex); 659 addStantardIdlFiles( files, path + ex.getName() ); 660 661 members = ex.getMemberList().getStructMembers(); 663 for (int i=0; i<members.length; i++) 664 { 665 files.addAll( getTypeRefDependencies(members[i].getType(), visited) ); 666 } 667 668 return files; 669 } 670 671 679 public Set 680 getAnyValueDependencies(AnyValue any, 681 Set visited) 682 { 683 return new java.util.HashSet (); 685 } 686 687 695 public Set 696 getAliasDependencies(AliasDecl alias, 697 Set visited) 698 { 699 String path = null; 700 Set files = new java.util.HashSet (); 701 TypeKind tk = null; 702 703 if ( visited.contains(alias) ) 705 { 706 return files; 707 } 708 else 709 { 710 visited.add(alias); 712 } 713 714 path = _translator.getAsDirectory(alias); 715 addHelperClass( files, path + alias.getName() ); 716 717 files.addAll( getTypeRefDependencies(alias.getType(), visited) ); 719 720 tk = alias.getType().getTypeKind(); 722 if ( ( tk == TypeKind.tk_sequence) 723 || ( tk == TypeKind.tk_array) ) 724 { 725 addHolderClass( files, path + alias.getName() ); 726 } 727 728 return files; 729 } 730 731 739 public Set 740 getAttributeDependencies(AttributeDecl att, 741 Set visited) 742 { 743 Set files = new java.util.HashSet (); 744 745 if ( visited.contains(att) ) 747 { 748 return files; 749 } 750 else 751 { 752 visited.add(att); 754 } 755 756 files.addAll( getTypeRefDependencies(att.getType(), visited) ); 758 759 ExceptionDecl[] excs = null; 761 762 if ( att.isReadonly() ) 763 { 764 excs = att.getExceptions(); 765 for (int i=0; i<excs.length; i++) 766 files.addAll( getExceptionDependencies(excs[i], visited) ); 767 } 768 else 769 { 770 excs = att.getGetExceptions(); 771 for (int i=0; i<excs.length; i++) 772 files.addAll( getExceptionDependencies(excs[i], visited) ); 773 774 excs = att.getSetExceptions(); 775 for (int i=0; i<excs.length; i++) 776 files.addAll( getExceptionDependencies(excs[i], visited) ); 777 } 778 779 return files; 780 } 781 782 790 public Set 791 getOperationDependencies(OperationDecl op, 792 Set visited) 793 { 794 Set files = new java.util.HashSet (); 795 796 if ( visited.contains(op) ) 798 { 799 return files; 800 } 801 else 802 { 803 visited.add(op); 805 } 806 807 files.addAll( getTypeRefDependencies(op.getType(), visited) ); 809 810 ExceptionDecl[] excs = op.getExceptionList().getExceptions(); 812 for (int i=0; i<excs.length; i++) 813 { 814 files.addAll( getExceptionDependencies(excs[i], visited) ); 815 } 816 817 Parameter[] parameters = op.getParameterList().getParameters(); 819 for (int i=0;i<parameters.length;i++) 820 { 821 files.addAll( getTypeRefDependencies(parameters[i].getType(), visited) ); 822 } 823 824 return files; 825 } 826 827 835 public Set 836 getContentsDependencies(Scope scope, 837 Set visited) 838 { 839 Set files = null; 840 Declaration[] decls = null; 841 842 files = new java.util.HashSet (); 843 decls = scope.getContents(true, DeclarationKind.dk_all); 844 845 for (int i=0; i<decls.length; i++) 846 { 847 files.addAll( getDeclarationDependencies(decls[i], visited) ); 848 } 849 850 return files; 851 } 852 853 861 public Set 862 getDeclarationDependencies(Declaration decl, 863 Set visited) 864 { 865 Set files = null; 866 867 files = new java.util.HashSet (); 868 869 if ( visited.contains(decl) ) 871 { 872 return files; 873 } 874 875 if (decl.getDeclKind() == DeclarationKind.dk_module) 876 { 877 files.addAll( getContentsDependencies((Scope) decl, visited) ); 878 } 879 else if (decl.getDeclKind() == DeclarationKind.dk_abstract_interface) 880 { 881 files.addAll( getAbstractInterfaceDependencies((AbstractInterfaceDecl) decl, visited) ); 882 } 883 else if (decl.getDeclKind() == DeclarationKind.dk_local_interface) 884 { 885 files.addAll( getLocalInterfaceDependencies((LocalInterfaceDecl) decl, visited) ); 886 } 887 else if (decl.getDeclKind() == DeclarationKind.dk_interface) 888 { 889 files.addAll( getInterfaceDependencies((InterfaceDecl) decl, false, visited) ); 891 } 892 else if (decl.getDeclKind() == DeclarationKind.dk_attribute) 893 { 894 files.addAll( getAttributeDependencies((AttributeDecl) decl, visited) ); 895 } 896 else if (decl.getDeclKind() == DeclarationKind.dk_alias) 897 { 898 files.addAll( getAliasDependencies((AliasDecl) decl, visited) ); 899 } 900 else if (decl.getDeclKind() == DeclarationKind.dk_constant) 901 { 902 files.addAll( getConstantDependencies((ConstantDecl) decl, visited) ); 903 } 904 else if (decl.getDeclKind() == DeclarationKind.dk_enum) 905 { 906 files.addAll( getEnumDependencies((EnumDecl) decl, visited) ); 907 } 908 else if (decl.getDeclKind() == DeclarationKind.dk_exception) 909 { 910 files.addAll( getExceptionDependencies((ExceptionDecl) decl, visited) ); 911 } 912 else if (decl.getDeclKind() == DeclarationKind.dk_operation) 913 { 914 files.addAll( getOperationDependencies((OperationDecl) decl, visited) ); 915 } 916 else if (decl.getDeclKind() == DeclarationKind.dk_struct) 917 { 918 files.addAll( getStructDependencies((StructDecl) decl, visited) ); 919 } 920 else if (decl.getDeclKind() == DeclarationKind.dk_union) 921 { 922 files.addAll( getUnionDependencies((UnionDecl) decl, visited) ); 923 } 924 else if (decl.getDeclKind() == DeclarationKind.dk_value_box) 925 { 926 files.addAll( getValueBoxDependencies((ValueBoxDecl) decl, visited) ); 927 } 928 else if (decl.getDeclKind() == DeclarationKind.dk_value) 929 { 930 files.addAll( getValueTypeDependencies((ValueDecl) decl, visited) ); 931 } 932 else if (decl.getDeclKind() == DeclarationKind.dk_value_member) 933 { 934 ValueMemberDecl member = null; 935 936 visited.add(member); 938 939 member = (ValueMemberDecl) decl; 940 files.addAll( getTypeRefDependencies(member.getType(), visited) ); 941 } 942 else 943 { 944 } 947 948 return files; 949 } 950 951 959 public Set 960 getTypeRefDependencies(TypeRef type, 961 Set visited) 962 { 963 TypeKind tk = null; 964 Set files = new java.util.HashSet (); 965 966 tk = type.getTypeKind(); 967 968 if (type.isDeclaration()) 970 { 971 Declaration decl = (Declaration) type; 972 973 if (tk == TypeKind.tk_struct) 974 { 975 files.addAll( getStructDependencies((StructDecl) decl, visited) ); 976 } 977 else if (tk == TypeKind.tk_union) 978 { 979 files.addAll( getUnionDependencies((UnionDecl) decl, visited) ); 980 } 981 else if (tk == TypeKind.tk_enum) 982 { 983 files.addAll( getEnumDependencies((EnumDecl) decl, visited) ); 984 } 985 else if (tk == TypeKind.tk_exception) 986 { 987 files.addAll( getExceptionDependencies((ExceptionDecl) decl, visited) ); 988 } 989 else if (tk == TypeKind.tk_value_box) 990 { 991 files.addAll( getValueBoxDependencies((ValueBoxDecl) decl, visited) ); 992 } 993 else if (tk == TypeKind.tk_value) 994 { 995 files.addAll( getValueTypeDependencies((ValueDecl) decl, visited) ); 996 } 997 else if (tk == TypeKind.tk_abstract_interface) 998 { 999 files.addAll( getAbstractInterfaceDependencies((AbstractInterfaceDecl) decl, visited) ); 1000 } 1001 else if (tk == TypeKind.tk_local_interface) 1002 { 1003 files.addAll( getLocalInterfaceDependencies((LocalInterfaceDecl) decl, visited) ); 1004 } 1005 else if (tk == TypeKind.tk_interface) 1006 { 1007 files.addAll( getInterfaceDependencies((InterfaceDecl) decl, false, visited) ); 1008 } 1009 else if (tk == TypeKind.tk_alias) 1010 { 1011 files.addAll( getAliasDependencies((AliasDecl) decl, visited) ); 1012 } 1013 } 1014 1015 return files; 1016 } 1017 1018 1024} 1025 | Popular Tags |