KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > presentation > rmi > IDLType


1 /*
2  * @(#)IDLType.java 1.6 04/06/21
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.presentation.rmi ;
9
10 /**
11  * Holds information about the OMG IDL mapping of a Java type.
12  */

13 public class IDLType {
14
15     private Class JavaDoc cl_;
16
17     // terminology for OMG IDL type package name
18
private String JavaDoc[] modules_;
19
20     // name of element within module
21
private String JavaDoc memberName_;
22
23
24     public IDLType(Class JavaDoc cl, String JavaDoc[] modules, String JavaDoc memberName) {
25         cl_ = cl;
26         modules_ = modules;
27         memberName_ = memberName;
28     }
29
30     public IDLType(Class JavaDoc cl, String JavaDoc memberName) {
31     this( cl, new String JavaDoc[0], memberName ) ;
32     }
33
34     public Class JavaDoc getJavaClass() {
35         return cl_;
36     }
37
38     public String JavaDoc[] getModules()
39     {
40     return modules_ ;
41     }
42     
43     public String JavaDoc makeConcatenatedName( char separator, boolean fixIDLKeywords ) {
44     StringBuffer JavaDoc sbuff = new StringBuffer JavaDoc() ;
45     for (int ctr=0; ctr<modules_.length; ctr++) {
46         String JavaDoc mod = modules_[ctr] ;
47         if (ctr>0)
48         sbuff.append( separator ) ;
49         
50         if (fixIDLKeywords && IDLNameTranslatorImpl.isIDLKeyword(mod))
51         mod = IDLNameTranslatorImpl.mangleIDLKeywordClash( mod ) ;
52
53         sbuff.append( mod ) ;
54     }
55
56         return sbuff.toString() ;
57     }
58    
59     public String JavaDoc getModuleName() {
60     // Note that this should probably be makeConcatenatedName( '/', true )
61
// for spec compliance,
62
// but rmic does it this way, so we'll leave this.
63
// The effect is that an overloaded method like
64
// void foo( bar.typedef.Baz )
65
// will get an IDL name of foo__bar_typedef_Baz instead of
66
// foo__bar__typedef_Baz (note the extra _ before typedef).
67
return makeConcatenatedName( '_', false ) ;
68     }
69
70     public String JavaDoc getExceptionName() {
71     // Here we will check for IDL keyword collisions (see bug 5010332).
72
// This means that the repository ID for
73
// foo.exception.SomeException is
74
// "IDL:foo/_exception/SomeEx:1.0" (note the underscore in front
75
// of the exception module name).
76
String JavaDoc modName = makeConcatenatedName( '/', true ) ;
77
78     String JavaDoc suffix = "Exception" ;
79     String JavaDoc excName = memberName_ ;
80     if (excName.endsWith( suffix )) {
81         int last = excName.length() - suffix.length() ;
82         excName = excName.substring( 0, last ) ;
83     }
84    
85     // See bug 4989312: we must always add the Ex.
86
excName += "Ex" ;
87
88     if (modName.length() == 0)
89         return "IDL:" + excName + ":1.0" ;
90     else
91         return "IDL:" + modName + '/' + excName + ":1.0" ;
92     }
93
94     public String JavaDoc getMemberName() {
95         return memberName_;
96     }
97     
98     /**
99      * True if this type doesn't have a containing module. This
100      * would be true of a java type defined in the default package
101      * or a primitive.
102      */

103     public boolean hasModule() {
104         return (modules_.length > 0) ;
105     }
106 }
107
Popular Tags