KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > idl > BaseType


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-2004 Gerald Brose.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20
21 package org.jacorb.idl;
22
23 /**
24  * Represents IDL base types
25  *
26  * @author Gerald Brose
27  * @version $Id: BaseType.java,v 1.19 2004/05/06 12:39:58 nicolas Exp $
28  */

29
30
31 import java.io.PrintWriter JavaDoc;
32
33 class BaseType
34     extends SimpleTypeSpec
35 {
36     public BaseType( int num )
37     {
38         super( num );
39     }
40
41     /**
42      * ignore, these types don't need to know their package
43      */

44
45     public void setPackage( String JavaDoc s )
46     {
47         s = parser.pack_replace( s );
48     }
49
50     public TypeSpec typeSpec()
51     {
52         return type_spec.typeSpec();
53     }
54
55     public boolean basic()
56     {
57         return type_spec.basic();
58     }
59
60     public boolean isSwitchType()
61     {
62         return (
63                 type_spec instanceof SwitchTypeSpec &&
64                 ( (SwitchTypeSpec)type_spec ).isSwitchable()
65                 );
66     }
67
68     /**
69      * does nothing, will be overwritten in subclasses
70      */

71
72     public void parse()
73     {
74     }
75
76     public static boolean isBasicName( String JavaDoc typeName )
77     {
78         // The type may be an array type e.g. float[][] so chop off any array
79
// designators for the comparison.
80
int index = typeName.indexOf ('[');
81         String JavaDoc toMatch = typeName.substring (0, (index == -1 ? typeName.length () : index));
82
83         return
84         (
85             toMatch.equals ("long") ||
86             toMatch.equals ("int") ||
87             toMatch.equals ("short") ||
88             toMatch.equals ("float") ||
89             toMatch.equals ("double") ||
90             toMatch.equals ("byte") ||
91             toMatch.equals ("boolean") ||
92             toMatch.equals ("char") ||
93             toMatch.equals ("java.lang.String")
94         );
95     }
96
97     public void setEnclosingSymbol( IdlSymbol s )
98     {
99         if( enclosing_symbol != null && enclosing_symbol != s )
100             throw new RuntimeException JavaDoc( "Compiler Error: trying to reassign container for " + name );
101         enclosing_symbol = s;
102     }
103
104     /** the "kind of TypeCode" for this type */
105
106     public int getTCKind()
107     {
108         return ( (BaseType)type_spec ).getTCKind();
109     }
110
111     protected String JavaDoc typeCodeExpressionSkeleton( int kind )
112     {
113         return "org.omg.CORBA.ORB.init().get_primitive_tc("
114                 + "org.omg.CORBA.TCKind.from_int(" + kind + "))";
115     }
116
117     public String JavaDoc getTypeCodeExpression()
118     {
119         return typeCodeExpressionSkeleton( getTCKind() );
120     }
121
122     public String JavaDoc toString()
123     {
124         if( type_spec != null )
125             return type_spec.toString();
126         else
127             return "BaseType";
128     }
129
130     public String JavaDoc typeName()
131     {
132         return type_spec.typeName();
133     }
134
135
136
137     public String JavaDoc id()
138     {
139         return "IDL:*primitive*:1.0";
140     }
141
142     /**
143      * does nothing, will be overwritten in subclasses
144      */

145
146     public void print( PrintWriter JavaDoc ps )
147     {
148     }
149
150
151 }
152
153
Popular Tags