1 22 package org.jboss.iiop.rmi.ir; 23 24 import org.omg.CORBA.ORB ; 25 import org.omg.CORBA.Any ; 26 import org.omg.CORBA.TypeCode ; 27 import org.omg.CORBA.TCKind ; 28 import org.omg.CORBA.DefinitionKind ; 29 import org.omg.CORBA.Repository ; 30 import org.omg.CORBA.RepositoryHelper; 31 import org.omg.CORBA.ParameterDescription ; 32 import org.omg.CORBA.ParameterMode ; 33 import org.omg.CORBA.StructMember ; 34 import org.omg.CORBA.ExceptionDef ; 35 import org.omg.CORBA.ExceptionDefHelper; 36 import org.omg.PortableServer.POA ; 37 38 import org.jboss.iiop.rmi.Util; 39 import org.jboss.iiop.rmi.ContainerAnalysis; 40 import org.jboss.iiop.rmi.InterfaceAnalysis; 41 import org.jboss.iiop.rmi.ExceptionAnalysis; 42 import org.jboss.iiop.rmi.ValueAnalysis; 43 import org.jboss.iiop.rmi.ValueMemberAnalysis; 44 import org.jboss.iiop.rmi.ConstantAnalysis; 45 import org.jboss.iiop.rmi.AttributeAnalysis; 46 import org.jboss.iiop.rmi.OperationAnalysis; 47 import org.jboss.iiop.rmi.ParameterAnalysis; 48 import org.jboss.iiop.rmi.RMIIIOPViolationException; 49 import org.jboss.iiop.rmi.RmiIdlUtil; 50 51 import java.util.ArrayList ; 52 import java.util.HashMap ; 53 import java.util.List ; 54 import java.util.Map ; 55 56 import javax.naming.InitialContext ; 57 import javax.naming.NamingException ; 58 59 65 public class InterfaceRepository 66 { 67 69 71 73 76 private static Map primitiveTypeCodeMap; 77 78 81 private static Map constantTypeCodeMap; 82 83 static { 84 ORB orb; 86 try { 87 orb = (ORB )new InitialContext ().lookup("java:/JBossCorbaORB"); 88 } catch (NamingException ex) { 89 throw new RuntimeException ("Cannot lookup java:/JBossCorbaORB: "+ex); 90 } 91 92 primitiveTypeCodeMap = new HashMap (); 94 primitiveTypeCodeMap.put(Void.TYPE, 95 orb.get_primitive_tc(TCKind.tk_void)); 96 primitiveTypeCodeMap.put(Boolean.TYPE, 97 orb.get_primitive_tc(TCKind.tk_boolean)); 98 primitiveTypeCodeMap.put(Character.TYPE, 99 orb.get_primitive_tc(TCKind.tk_wchar)); 100 primitiveTypeCodeMap.put(Byte.TYPE, 101 orb.get_primitive_tc(TCKind.tk_octet)); 102 primitiveTypeCodeMap.put(Short.TYPE, 103 orb.get_primitive_tc(TCKind.tk_short)); 104 primitiveTypeCodeMap.put(Integer.TYPE, 105 orb.get_primitive_tc(TCKind.tk_long)); 106 primitiveTypeCodeMap.put(Long.TYPE, 107 orb.get_primitive_tc(TCKind.tk_longlong)); 108 primitiveTypeCodeMap.put(Float.TYPE, 109 orb.get_primitive_tc(TCKind.tk_float)); 110 primitiveTypeCodeMap.put(Double.TYPE, 111 orb.get_primitive_tc(TCKind.tk_double)); 112 113 constantTypeCodeMap = new HashMap (primitiveTypeCodeMap); 115 constantTypeCodeMap.put(String .class, orb.create_wstring_tc(0)); 116 } 117 118 121 private static final org.jboss.logging.Logger logger = 122 org.jboss.logging.Logger.getLogger(InterfaceRepository.class); 123 124 126 public InterfaceRepository(ORB orb, POA poa, String name) 127 { 128 this.orb = orb; 129 this.poa = poa; 130 impl = new RepositoryImpl(orb, poa, name); 131 } 132 133 135 138 public void mapClass(Class cls) 139 throws RMIIIOPViolationException, IRConstructionException 140 { 141 getTypeCode(cls); 144 } 145 146 147 150 public void finishBuild() 151 throws IRConstructionException 152 { 153 impl.allDone(); 154 } 155 156 159 public Repository getReference() 160 { 161 return RepositoryHelper.narrow(impl.getReference()); 162 } 163 164 167 public void shutdown() 168 { 169 impl.shutdown(); 170 } 171 172 174 176 178 180 182 185 RepositoryImpl impl; 186 187 190 private ORB orb = null; 191 192 195 private POA poa = null; 196 197 201 private Map typeCodeMap = new HashMap (primitiveTypeCodeMap); 202 203 206 private Map interfaceMap = new HashMap (); 207 208 211 private Map valueMap = new HashMap (); 212 213 216 private Map exceptionMap = new HashMap (); 217 218 221 private Map arrayMap = new HashMap (); 222 223 224 230 private AliasDefImpl javaIoSerializable = null; 231 232 238 private AliasDefImpl javaIoExternalizable = null; 239 240 246 private AliasDefImpl javaLang_Object = null; 247 248 254 private ValueDefImpl javaLangString = null; 255 256 262 private ValueDefImpl javaxRmiCORBAClassDesc = null; 263 264 265 269 private TypeCode getConstantTypeCode(Class cls) 270 throws IRConstructionException 271 { 272 if (cls == null) 273 throw new IllegalArgumentException ("Null class"); 274 275 TypeCode ret = (TypeCode )constantTypeCodeMap.get(cls); 276 277 if (ret == null) 278 throw new IRConstructionException("Bad class \"" + cls.getName() + 279 "\" for a constant."); 280 281 return ret; 282 } 283 284 296 private TypeCode getTypeCode(Class cls) 297 throws IRConstructionException, RMIIIOPViolationException 298 { 299 if (cls == null) 300 throw new IllegalArgumentException ("Null class"); 301 302 TypeCode ret = (TypeCode )typeCodeMap.get(cls); 303 304 if (ret == null) { 305 if (cls == java.lang.String .class) 306 ret = getJavaLangString().type(); 307 else if (cls == java.lang.Object .class) 308 ret = getJavaLang_Object().type(); 309 else if (cls == java.lang.Class .class) 310 ret = getJavaxRmiCORBAClassDesc().type(); 311 else if (cls == java.io.Serializable .class) 312 ret = getJavaIoSerializable().type(); 313 else if (cls == java.io.Externalizable .class) 314 ret = getJavaIoExternalizable().type(); 315 else { 316 addClass(cls); 318 319 ret = (TypeCode )typeCodeMap.get(cls); 321 322 if (ret == null) 323 throw new IRConstructionException("TypeCode for class " + 324 cls.getName() + " unknown."); 325 else 326 return ret; 327 } 328 329 typeCodeMap.put(cls, ret); 330 } 331 332 return ret; 333 } 334 335 341 private void addTypeCode(Class cls, TypeCode typeCode) 342 throws IRConstructionException 343 { 344 if (cls == null) 345 throw new IllegalArgumentException ("Null class"); 346 347 TypeCode tc = (TypeCode )typeCodeMap.get(cls); 348 349 if (tc != null) 350 throw new IllegalArgumentException ("Class " + cls.getName() + 351 " already has TypeCode."); 352 353 logger.trace("InterfaceRepository: added typecode for " + cls.getName()); 354 typeCodeMap.put(cls, typeCode); 355 } 356 357 362 private AliasDefImpl getJavaIoSerializable() 363 throws IRConstructionException 364 { 365 if (javaIoSerializable == null) { 366 final String id = "IDL:java/io/Serializable:1.0"; 367 final String name = "Serializable"; 368 final String version = "1.0"; 369 370 ModuleDefImpl m = ensurePackageExists("java.io"); 372 373 TypeCode typeCode = orb.create_alias_tc(id, name, 374 orb.get_primitive_tc(TCKind.tk_any)); 375 378 javaIoSerializable = new AliasDefImpl(id, name, version, m, 379 typeCode, impl); 380 m.add(name, javaIoSerializable); 381 } 382 383 return javaIoSerializable; 384 } 385 386 391 private AliasDefImpl getJavaIoExternalizable() 392 throws IRConstructionException 393 { 394 if (javaIoExternalizable == null) { 395 final String id = "IDL:java/io/Externalizable:1.0"; 396 final String name = "Externalizable"; 397 final String version = "1.0"; 398 399 ModuleDefImpl m = ensurePackageExists("java.io"); 401 402 TypeCode typeCode = orb.create_alias_tc(id, name, 403 orb.get_primitive_tc(TCKind.tk_any)); 404 407 javaIoExternalizable = new AliasDefImpl(id, name, version, m, 408 typeCode, impl); 409 m.add(name, javaIoExternalizable); 410 } 411 412 return javaIoExternalizable; 413 } 414 415 420 private AliasDefImpl getJavaLang_Object() 421 throws IRConstructionException 422 { 423 if (javaLang_Object == null) { 424 final String id = "IDL:java/lang/_Object:1.0"; 425 final String name = "_Object"; 426 final String version = "1.0"; 427 428 ModuleDefImpl m = ensurePackageExists("java.lang"); 430 431 TypeCode typeCode = orb.create_alias_tc(id, name, 432 orb.get_primitive_tc(TCKind.tk_any)); 433 436 javaLang_Object = new AliasDefImpl(id, name, version, m, 437 typeCode, impl); 438 m.add(name, javaLang_Object); 439 } 440 441 return javaLang_Object; 442 } 443 444 449 private ValueDefImpl getJavaLangString() 450 throws IRConstructionException 451 { 452 if (javaLangString == null) { 453 ModuleDefImpl m = ensurePackageExists("org.omg.CORBA"); 454 ValueDefImpl val = 455 new ValueDefImpl("IDL:omg.org/CORBA/WStringValue:1.0", 456 "WStringValue", "1.0", 457 m, false, false, 458 new String [0], new String [0], 459 orb.get_primitive_tc(TCKind.tk_null), 460 impl); 461 ValueMemberDefImpl vmdi = 462 new ValueMemberDefImpl("IDL:omg.org/CORBA/WStringValue.data:1.0", 463 "data", "1.0", orb.create_wstring_tc(0), 464 true, val, impl); 465 val.add("data", vmdi); 466 m.add("WStringValue", val); 467 468 javaLangString = val; 469 } 470 471 return javaLangString; 472 } 473 474 479 private ValueDefImpl getJavaxRmiCORBAClassDesc() 480 throws IRConstructionException, RMIIIOPViolationException 481 { 482 if (javaxRmiCORBAClassDesc == null) { 483 ValueAnalysis va = ValueAnalysis.getValueAnalysis(javax.rmi.CORBA.ClassDesc .class); 485 ValueDefImpl val = addValue(va); 486 487 if (!"RMI:javax.rmi.CORBA.ClassDesc:B7C4E3FC9EBDC311:CFBF02CF5294176B".equals(val.id()) ) 489 logger.debug("Compatibility problem: Class " + 490 "javax.rmi.CORBA.ClassDesc does not conform " + 491 "to the Java(TM) Language to IDL Mapping "+ 492 "Specification (01-06-07), section 1.3.5.11."); 493 494 javaxRmiCORBAClassDesc = val; 495 } 496 497 return javaxRmiCORBAClassDesc; 498 } 499 500 501 510 private ModuleDefImpl ensurePackageExists(String pkgName) 511 throws IRConstructionException 512 { 513 return ensurePackageExists(impl, "", pkgName); 514 } 515 516 529 private ModuleDefImpl ensurePackageExists(LocalContainer c, 530 String previous, 531 String remainder) 532 throws IRConstructionException 533 { 534 if ("".equals(remainder)) 535 return (ModuleDefImpl)c; 537 int idx = remainder.indexOf('.'); 538 String base; 539 540 if (idx == -1) 541 base = remainder; 542 else 543 base = remainder.substring(0, idx); 544 base = Util.javaToIDLName(base); 545 546 if (previous.equals("")) 547 previous = base; 548 else 549 previous = previous + "/" + base; 550 if (idx == -1) 551 remainder = ""; 552 else 553 remainder = remainder.substring(idx + 1); 554 555 LocalContainer next = null; 556 LocalContained contained = (LocalContained)c._lookup(base); 557 558 if (contained instanceof LocalContainer) 559 next = (LocalContainer)contained; 560 else if (contained != null) 561 throw new IRConstructionException("Name collision while creating package."); 562 563 if (next == null) { 564 String id = "IDL:" + previous + ":1.0"; 565 566 ModuleDefImpl m = new ModuleDefImpl(id, base, "1.0", c, impl); 568 logger.trace("Created module \"" + id + "\"."); 569 570 c.add(base, m); 571 572 if (idx == -1) 573 return m; 575 next = (LocalContainer)c._lookup(base); } else if (next.def_kind() != DefinitionKind.dk_Module) 578 throw new IRConstructionException("Name collision while creating package."); 579 580 return ensurePackageExists(next, previous, remainder); 581 } 582 583 586 private void addConstants(LocalContainer container, 587 ContainerAnalysis ca) 588 throws RMIIIOPViolationException, IRConstructionException 589 { 590 ConstantAnalysis[] consts = ca.getConstants(); 591 for (int i = 0; i < consts.length; ++i) { 592 ConstantDefImpl cDef; 593 String cid = ca.getMemberRepositoryId(consts[i].getJavaName()); 594 String cName = consts[i].getIDLName(); 595 596 Class cls = consts[i].getType(); 597 logger.trace("Constant["+i+"] class: " + cls.getName()); 598 TypeCode typeCode = getConstantTypeCode(cls); 599 600 Any value = orb.create_any(); 601 consts[i].insertValue(value); 602 603 logger.trace("Adding constant: " + cid); 604 cDef = new ConstantDefImpl(cid, cName, "1.0", 605 typeCode, value, container, impl); 606 container.add(cName, cDef); 607 } 608 } 609 610 613 private void addAttributes(LocalContainer container, 614 ContainerAnalysis ca) 615 throws RMIIIOPViolationException, IRConstructionException 616 { 617 AttributeAnalysis[] attrs = ca.getAttributes(); 618 logger.trace("Attribute count: " + attrs.length); 619 for (int i = 0; i < attrs.length; ++i) { 620 AttributeDefImpl aDef; 621 String aid = ca.getMemberRepositoryId(attrs[i].getJavaName()); 622 String aName = attrs[i].getIDLName(); 623 624 Class cls = attrs[i].getCls(); 625 logger.trace("Attribute["+i+"] class: " + cls.getName()); 626 627 TypeCode typeCode = getTypeCode(cls); 628 629 logger.trace("Adding: " + aid); 630 aDef = new AttributeDefImpl(aid, aName, "1.0", attrs[i].getMode(), 631 typeCode, container, impl); 632 container.add(aName, aDef); 633 } 634 } 635 636 639 private void addOperations(LocalContainer container, 640 ContainerAnalysis ca) 641 throws RMIIIOPViolationException, IRConstructionException 642 { 643 OperationAnalysis[] ops = ca.getOperations(); 644 logger.debug("Operation count: " + ops.length); 645 for (int i = 0; i < ops.length; ++i) { 646 OperationDefImpl oDef; 647 String oName = ops[i].getIDLName(); 648 String oid = ca.getMemberRepositoryId(oName); 649 650 Class cls = ops[i].getReturnType(); 651 logger.debug("Operation["+i+"] return type class: " + cls.getName()); 652 TypeCode typeCode = getTypeCode(cls); 653 654 ParameterAnalysis[] ps = ops[i].getParameters(); 655 ParameterDescription [] params = new ParameterDescription [ps.length]; 656 for (int j = 0; j < ps.length; ++j) { 657 params[j] = new ParameterDescription (ps[j].getIDLName(), 658 getTypeCode(ps[j].getCls()), 659 null, ParameterMode.PARAM_IN); 661 } 662 663 ExceptionAnalysis[] exc = ops[i].getMappedExceptions(); 664 ExceptionDef [] exceptions = new ExceptionDef [exc.length]; 665 for (int j = 0; j < exc.length; ++j) { 666 ExceptionDefImpl e = addException(exc[j]); 667 exceptions[j] = ExceptionDefHelper.narrow(e.getReference()); 668 } 669 670 logger.debug("Adding: " + oid); 671 oDef = new OperationDefImpl(oid, oName, "1.0", container, 672 typeCode, params, exceptions, impl); 673 container.add(oName, oDef); 674 } 675 } 676 677 682 private String [] addInterfaces(ContainerAnalysis ca) 683 throws RMIIIOPViolationException, IRConstructionException 684 { 685 logger.trace("Adding interfaces: "); 686 InterfaceAnalysis[] interfaces = ca.getInterfaces(); 687 List base_interfaces = new ArrayList (); 688 for (int i = 0; i < interfaces.length; ++i) { 689 InterfaceDefImpl idi = addInterface(interfaces[i]); 690 base_interfaces.add(idi.id()); 691 logger.trace(" " + idi.id()); 692 } 693 String [] strArr = new String [base_interfaces.size()]; 694 return (String [])base_interfaces.toArray(strArr); 695 } 696 697 702 private String [] addAbstractBaseValuetypes(ContainerAnalysis ca) 703 throws RMIIIOPViolationException, IRConstructionException 704 { 705 logger.trace("Adding abstract valuetypes: "); 706 ValueAnalysis[] abstractValuetypes = ca.getAbstractBaseValuetypes(); 707 List abstract_base_valuetypes = new ArrayList (); 708 for (int i = 0; i < abstractValuetypes.length; ++i) { 709 ValueDefImpl vdi = addValue(abstractValuetypes[i]); 710 abstract_base_valuetypes.add(vdi.id()); 711 logger.trace(" " + vdi.id()); 712 } 713 String [] strArr = new String [abstract_base_valuetypes.size()]; 714 return (String [])abstract_base_valuetypes.toArray(strArr); 715 } 716 717 720 private void addClass(Class cls) 721 throws RMIIIOPViolationException, IRConstructionException 722 { 723 if (cls.isPrimitive()) 724 return; 726 if (cls.isArray()) { 727 addArray(cls); 729 } else if (cls.isInterface()) { 730 if (!RmiIdlUtil.isAbstractValueType(cls)) { 731 InterfaceAnalysis ia = InterfaceAnalysis.getInterfaceAnalysis(cls); 733 734 addInterface(ia); 736 } 737 else { 738 ValueAnalysis va = ValueAnalysis.getValueAnalysis(cls); 740 741 addValue(va); 743 } 744 } else if (Exception .class.isAssignableFrom(cls)) { ExceptionAnalysis ea = ExceptionAnalysis.getExceptionAnalysis(cls); 747 748 addException(ea); 750 } else { ValueAnalysis va = ValueAnalysis.getValueAnalysis(cls); 753 754 addValue(va); 756 } 757 } 758 759 762 private ValueBoxDefImpl addArray(Class cls) 763 throws RMIIIOPViolationException, IRConstructionException 764 { 765 if (!cls.isArray()) 766 throw new IllegalArgumentException ("Not an array class."); 767 768 ValueBoxDefImpl vbDef; 769 770 vbDef = (ValueBoxDefImpl)arrayMap.get(cls); 772 if (vbDef != null) 773 return vbDef; 775 int dimensions = 0; 776 Class compType = cls; 777 778 do { 779 compType = compType.getComponentType(); 780 ++dimensions; 781 } while (compType.isArray()); 782 783 String typeName; 784 String moduleName; 785 TypeCode typeCode; 786 787 if (compType.isPrimitive()) { 788 if (compType == Boolean.TYPE) { 789 typeName = "boolean"; 790 typeCode = orb.get_primitive_tc(TCKind.tk_boolean); 791 } else if (compType == Character.TYPE) { 792 typeName = "wchar"; 793 typeCode = orb.get_primitive_tc(TCKind.tk_wchar); 794 } else if (compType == Byte.TYPE) { 795 typeName = "octet"; 796 typeCode = orb.get_primitive_tc(TCKind.tk_octet); 797 } else if (compType == Short.TYPE) { 798 typeName = "short"; 799 typeCode = orb.get_primitive_tc(TCKind.tk_short); 800 } else if (compType == Integer.TYPE) { 801 typeName = "long"; 802 typeCode = orb.get_primitive_tc(TCKind.tk_long); 803 } else if (compType == Long.TYPE) { 804 typeName = "long_long"; 805 typeCode = orb.get_primitive_tc(TCKind.tk_longlong); 806 } else if (compType == Float.TYPE) { 807 typeName = "float"; 808 typeCode = orb.get_primitive_tc(TCKind.tk_float); 809 } else if (compType == Double.TYPE) { 810 typeName = "double"; 811 typeCode = orb.get_primitive_tc(TCKind.tk_double); 812 } else { 813 throw new IRConstructionException("Unknown primitive type for " + 814 "array type: " + cls.getName()); 815 } 816 817 moduleName = "org.omg.boxedRMI"; 818 } else { 819 typeCode = getTypeCode(compType); 821 if (compType == java.lang.String .class) 822 typeName = getJavaLangString().name(); 823 else if (compType == java.lang.Object .class) 824 typeName = getJavaLang_Object().name(); 825 else if (compType == java.lang.Class .class) 826 typeName = getJavaxRmiCORBAClassDesc().name(); 827 else if (compType == java.io.Serializable .class) 828 typeName = getJavaIoSerializable().name(); 829 else if (compType == java.io.Externalizable .class) 830 typeName = getJavaIoExternalizable().name(); 831 else if (compType.isInterface() && 832 !RmiIdlUtil.isAbstractValueType(compType)) 833 typeName = ((InterfaceDefImpl)interfaceMap.get(compType)).name(); 834 else if (Exception .class.isAssignableFrom(compType)) typeName = ((ExceptionDefImpl)exceptionMap.get(compType)).name(); 836 else typeName = ((ValueDefImpl)valueMap.get(compType)).name(); 838 839 moduleName = "org.omg.boxedRMI." + compType.getPackage().getName(); 840 } 841 842 ModuleDefImpl m = ensurePackageExists(moduleName); 844 845 Class [] types = new Class [dimensions]; 847 types[dimensions-1] = cls; 848 for (int i = dimensions - 2; i >= 0; --i) 849 types[i] = types[i+1].getComponentType(); 850 851 for (int i = 0; i < dimensions; ++i) { 853 Class type = types[i]; 854 855 typeCode = orb.create_sequence_tc(0, typeCode); 856 vbDef = (ValueBoxDefImpl)arrayMap.get(type); 857 if (vbDef == null) { 858 String id = Util.getIRIdentifierOfClass(type); 859 860 SequenceDefImpl sdi = new SequenceDefImpl(typeCode, impl); 861 862 String name = "seq" + (i+1) + "_" + typeName; 863 TypeCode boxTypeCode = orb.create_value_box_tc(id, name, typeCode); 866 vbDef = new ValueBoxDefImpl(id, name, "1.0", m, boxTypeCode, impl); 867 868 addTypeCode(type, vbDef.type()); 869 m.add(name, vbDef); 870 impl.putSequenceImpl(id, typeCode, sdi, vbDef); 871 872 arrayMap.put(type, vbDef); 874 typeCode = boxTypeCode; 875 } else 876 typeCode = vbDef.type(); 877 } 878 879 return vbDef; 881 } 882 883 886 private InterfaceDefImpl addInterface(InterfaceAnalysis ia) 887 throws RMIIIOPViolationException, IRConstructionException 888 { 889 InterfaceDefImpl iDef; 890 Class cls = ia.getCls(); 891 892 iDef = (InterfaceDefImpl)interfaceMap.get(cls); 894 if (iDef != null) 895 return iDef; 897 if (ia.isAbstractInterface()) 898 logger.trace("Adding abstract interface: " + ia.getRepositoryId()); 899 900 ModuleDefImpl m = ensurePackageExists(cls.getPackage().getName()); 902 903 String [] base_interfaces = addInterfaces(ia); 905 906 String base = cls.getName(); 908 base = base.substring(base.lastIndexOf('.')+1); 909 base = Util.javaToIDLName(base); 910 911 iDef = new InterfaceDefImpl(ia.getRepositoryId(), 912 base, "1.0", m, 913 base_interfaces, impl); 914 addTypeCode(cls, iDef.type()); 915 m.add(base, iDef); 916 interfaceMap.put(cls, iDef); 918 addConstants(iDef, ia); 920 921 addAttributes(iDef, ia); 923 924 addOperations(iDef, ia); 926 927 logger.trace("Added interface: " + ia.getRepositoryId()); 928 return iDef; 929 } 930 931 934 private ValueDefImpl addValue(ValueAnalysis va) 935 throws RMIIIOPViolationException, IRConstructionException 936 { 937 ValueDefImpl vDef; 938 Class cls = va.getCls(); 939 940 vDef = (ValueDefImpl)valueMap.get(cls); 942 if (vDef != null) 943 return vDef; 945 ModuleDefImpl m = ensurePackageExists(cls.getPackage().getName()); 947 948 String [] supported_interfaces = addInterfaces(va); 950 951 String [] abstract_base_valuetypes = addAbstractBaseValuetypes(va); 953 954 ValueDefImpl superValue = null; 956 ValueAnalysis superAnalysis = va.getSuperAnalysis(); 957 if (superAnalysis != null) 958 superValue = addValue(superAnalysis); 959 960 String base = cls.getName(); 962 base = base.substring(base.lastIndexOf('.')+1); 963 base = Util.javaToIDLName(base); 964 965 TypeCode baseTypeCode; 966 if (superValue == null) 967 baseTypeCode = orb.get_primitive_tc(TCKind.tk_null); 968 else 969 baseTypeCode = superValue.type(); 970 971 vDef = new ValueDefImpl(va.getRepositoryId(), base, "1.0", 972 m, 973 va.isAbstractValue(), 974 va.isCustom(), 975 supported_interfaces, 976 abstract_base_valuetypes, 977 baseTypeCode, 978 impl); 979 addTypeCode(cls, vDef.type()); 980 logger.debug("Value: base=" + base); 981 m.add(base, vDef); 982 valueMap.put(cls, vDef); 984 addConstants(vDef, va); 986 987 ValueMemberAnalysis[] vmas = va.getMembers(); 989 logger.debug("Value member count: " + vmas.length); 990 for (int i = 0; i < vmas.length; ++i) { 991 ValueMemberDefImpl vmDef; 992 String vmid = va.getMemberRepositoryId(vmas[i].getJavaName()); 993 String vmName = vmas[i].getIDLName(); 994 995 Class vmCls = vmas[i].getCls(); 996 logger.debug("ValueMembers["+i+"] class: " + vmCls.getName()); 997 TypeCode typeCode = getTypeCode(vmCls); 998 999 boolean vmPublic = vmas[i].isPublic(); 1000 1001 logger.debug("Adding value member: " + vmid); 1002 vmDef = new ValueMemberDefImpl(vmid, vmName, "1.0", 1003 typeCode, vmPublic, vDef, impl); 1004 vDef.add(vmName, vmDef); 1005 } 1006 1007 addAttributes(vDef, va); 1009 1010 1012 return vDef; 1013 } 1014 1015 1018 private ExceptionDefImpl addException(ExceptionAnalysis ea) 1019 throws RMIIIOPViolationException, IRConstructionException 1020 { 1021 ExceptionDefImpl eDef; 1022 Class cls = ea.getCls(); 1023 1024 eDef = (ExceptionDefImpl)exceptionMap.get(cls); 1026 if (eDef != null) 1027 return eDef; 1029 ValueDefImpl vDef = addValue(ea); 1031 1032 ModuleDefImpl m = ensurePackageExists(cls.getPackage().getName()); 1034 String base = cls.getName(); 1035 base = base.substring(base.lastIndexOf('.')+1); 1036 if (base.endsWith("Exception")) 1037 base = base.substring(0, base.length()-9); 1038 base = Util.javaToIDLName(base + "Ex"); 1039 1040 StructMember [] members = new StructMember [1]; 1041 members[0] = new StructMember ("value", vDef.type(), null); 1042 TypeCode typeCode 1043 = orb.create_exception_tc(ea.getExceptionRepositoryId(), 1044 base, members); 1045 1046 eDef = new ExceptionDefImpl(ea.getExceptionRepositoryId(), base, "1.0", 1047 typeCode, vDef, m, impl); 1048 logger.debug("Exception: base=" + base); 1049 m.add(base, eDef); 1050 exceptionMap.put(cls, eDef); 1052 return eDef; 1053 } 1054 1055 1056 } 1058 | Popular Tags |