IDLType.java revision 608:7e06bf1dcb09
1156952Sume/*
2156952Sume * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
3156952Sume * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4156952Sume *
5156952Sume * This code is free software; you can redistribute it and/or modify it
6156952Sume * under the terms of the GNU General Public License version 2 only, as
7156952Sume * published by the Free Software Foundation.  Oracle designates this
8156952Sume * particular file as subject to the "Classpath" exception as provided
9156952Sume * by Oracle in the LICENSE file that accompanied this code.
10156952Sume *
11156952Sume * This code is distributed in the hope that it will be useful, but WITHOUT
12156952Sume * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13156952Sume * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14156952Sume * version 2 for more details (a copy is included in the LICENSE file that
15156952Sume * accompanied this code).
16156952Sume *
17156952Sume * You should have received a copy of the GNU General Public License version
18156952Sume * 2 along with this work; if not, write to the Free Software Foundation,
19156952Sume * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20156952Sume *
21156952Sume * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22156952Sume * or visit www.oracle.com if you need additional information or have any
23156952Sume * questions.
24156952Sume */
25156952Sume
26156952Sumepackage com.sun.corba.se.impl.presentation.rmi ;
27156952Sume
28156952Sume/**
29156952Sume * Holds information about the OMG IDL mapping of a Java type.
30156952Sume */
31156952Sumepublic class IDLType {
32156952Sume
33156952Sume    private Class cl_;
34156952Sume
35156952Sume    // terminology for OMG IDL type package name
36156952Sume    private String[] modules_;
37156952Sume
38156952Sume    // name of element within module
39156952Sume    private String memberName_;
40156952Sume
41156952Sume
42156952Sume    public IDLType(Class cl, String[] modules, String memberName) {
43156952Sume        cl_ = cl;
44156952Sume        modules_ = modules;
45156952Sume        memberName_ = memberName;
46156952Sume    }
47156952Sume
48156952Sume    public IDLType(Class cl, String memberName) {
49156952Sume        this( cl, new String[0], memberName ) ;
50156952Sume    }
51156952Sume
52156952Sume    public Class getJavaClass() {
53156952Sume        return cl_;
54156952Sume    }
55156952Sume
56156952Sume    public String[] getModules()
57156952Sume    {
58156952Sume        return modules_ ;
59156952Sume    }
60156952Sume
61156952Sume    public String makeConcatenatedName( char separator, boolean fixIDLKeywords ) {
62156952Sume        StringBuffer sbuff = new StringBuffer() ;
63156952Sume        for (int ctr=0; ctr<modules_.length; ctr++) {
64156952Sume            String mod = modules_[ctr] ;
65156952Sume            if (ctr>0)
66156952Sume                sbuff.append( separator ) ;
67156952Sume
68156952Sume            if (fixIDLKeywords && IDLNameTranslatorImpl.isIDLKeyword(mod))
69270838Sume                mod = IDLNameTranslatorImpl.mangleIDLKeywordClash( mod ) ;
70156952Sume
71156956Sume            sbuff.append( mod ) ;
72156956Sume        }
73156952Sume
74156952Sume        return sbuff.toString() ;
75156952Sume    }
76156952Sume
77156952Sume    public String getModuleName() {
78156952Sume        // Note that this should probably be makeConcatenatedName( '/', true )
79156952Sume        // for spec compliance,
80156952Sume        // but rmic does it this way, so we'll leave this.
81156952Sume        // The effect is that an overloaded method like
82156952Sume        // void foo( bar.typedef.Baz )
83156952Sume        // will get an IDL name of foo__bar_typedef_Baz instead of
84156952Sume        // foo__bar__typedef_Baz (note the extra _ before typedef).
85156952Sume        return makeConcatenatedName( '_', false ) ;
86170244Sume    }
87156952Sume
88156952Sume    public String getExceptionName() {
89156952Sume        // Here we will check for IDL keyword collisions (see bug 5010332).
90156956Sume        // This means that the repository ID for
91156952Sume        // foo.exception.SomeException is
92156952Sume        // "IDL:foo/_exception/SomeEx:1.0" (note the underscore in front
93156952Sume        // of the exception module name).
94156952Sume        String modName = makeConcatenatedName( '/', true ) ;
95156952Sume
96156952Sume        String suffix = "Exception" ;
97156952Sume        String excName = memberName_ ;
98156952Sume        if (excName.endsWith( suffix )) {
99170244Sume            int last = excName.length() - suffix.length() ;
100156952Sume            excName = excName.substring( 0, last ) ;
101156952Sume        }
102156952Sume
103156952Sume        // See bug 4989312: we must always add the Ex.
104156952Sume        excName += "Ex" ;
105156952Sume
106156952Sume        if (modName.length() == 0)
107156952Sume            return "IDL:" + excName + ":1.0" ;
108156952Sume        else
109156952Sume            return "IDL:" + modName + '/' + excName + ":1.0" ;
110156952Sume    }
111156952Sume
112156952Sume    public String getMemberName() {
113156952Sume        return memberName_;
114156952Sume    }
115156952Sume
116156952Sume    /**
117156952Sume     * True if this type doesn't have a containing module.  This
118156952Sume     * would be true of a java type defined in the default package
119156952Sume     * or a primitive.
120156952Sume     */
121156952Sume    public boolean hasModule() {
122156952Sume        return (modules_.length > 0) ;
123156952Sume    }
124156952Sume}
125156952Sume