KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > rmi > iiop > compiler > Compiler


1 /*
2  * Copyright 2004 The Apache Software Foundation or its licensors, as
3  * applicable.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19 package gcc.rmi.iiop.compiler;
20
21 import gcc.generator.GenOptions;
22 import gcc.generator.JVariable;
23 import gcc.generator.JParameter;
24
25 import java.util.HashMap;
26 import java.lang.reflect.Method;
27
28 public class Compiler
29 {
30     protected Class _riClass;
31     protected GenOptions _genOptions;
32     protected ClassLoader _cl;
33     protected boolean _simpleIDL = false;
34
35     protected static HashMap _readMethods;
36     protected static HashMap _writeMethods;
37     protected static HashMap _overloadTypes;
38
39     static
40     {
41         _readMethods = new HashMap();
42         _readMethods.put("boolean", "readBoolean");
43         _readMethods.put("char", "readChar");
44         _readMethods.put("byte", "readByte");
45         _readMethods.put("short", "readShort");
46         _readMethods.put("int", "readInt");
47         _readMethods.put("long", "readLong");
48         _readMethods.put("float", "readFloat");
49         _readMethods.put("double", "readDouble");
50
51         _writeMethods = new HashMap();
52         _writeMethods.put("boolean", "writeBoolean");
53         _writeMethods.put("char", "writeChar");
54         _writeMethods.put("byte", "writeByte");
55         _writeMethods.put("short", "writeShort");
56         _writeMethods.put("int", "writeInt");
57         _writeMethods.put("long", "writeLong");
58         _writeMethods.put("float", "writeFloat");
59         _writeMethods.put("double", "writeDouble");
60
61         _overloadTypes = new HashMap();
62         _overloadTypes.put("boolean", "boolean");
63         _overloadTypes.put("byte", "octet");
64         _overloadTypes.put("char", "wchar");
65         _overloadTypes.put("double", "double");
66         _overloadTypes.put("float", "float");
67         _overloadTypes.put("int", "long");
68         _overloadTypes.put("long", "long_long");
69         _overloadTypes.put("short", "short");
70         _overloadTypes.put("java.lang.Class", "javax_rmi_CORBA.ClassDesc");
71         _overloadTypes.put("java.lang.String", "CORBA.WStringValue");
72         _overloadTypes.put("org.omg.CORBA.Object", "Object");
73         _overloadTypes.put("org.omg.CORBA.Any", "org_omg_boxedIDL_CORBA.Any");
74         _overloadTypes.put("org.omg.CORBA.TypeCode", "org_omg_boxedIDL_CORBA.TypeCode");
75     }
76
77     public Compiler(Class remoteInterface)
78     {
79         this( remoteInterface, null );
80     }
81
82     public Compiler( Class riClass, GenOptions go )
83     {
84         _riClass = riClass;
85
86         _cl = _riClass.getClassLoader();
87         if (_cl == null)
88         {
89             _cl = ClassLoader.getSystemClassLoader();
90         }
91         
92         if (go == null)
93         {
94             go = new GenOptions();
95         }
96
97         _genOptions = go;
98     }
99
100     //
101
// Properties
102
//
103

104     public boolean isSimpleIDL()
105     {
106         return _simpleIDL;
107     }
108
109     public void setSimpleIDL(boolean simpleIDL)
110     {
111         _simpleIDL = simpleIDL;
112     }
113
114     public GenOptions getGenOptions()
115     {
116         return _genOptions;
117     }
118
119     public void setGenOptions(GenOptions genOptions)
120     {
121         _genOptions = genOptions;
122     }
123
124     public JParameter[] getMethodParms( Method m )
125     {
126         Class p[] = m.getParameterTypes();
127         JParameter parms[] = null;
128
129         if (p != null)
130         {
131             parms = new JParameter[p.length];
132
133             int i;
134             for( i=0; i<p.length; i++ )
135             {
136                 parms[i] = new JParameter( p[i], "p"+i );
137             }
138         }
139
140         return parms;
141     }
142     
143     protected String getReadMethod( JVariable v )
144     {
145         String rc = null;
146
147         if (v != null)
148         {
149             rc = (String)_readMethods.get(v.getTypeDecl());
150         }
151
152         return rc;
153     }
154
155     protected String getWriteMethod( JVariable v )
156     {
157         String rc = null;
158
159         if (v != null)
160         {
161             rc = (String)_writeMethods.get(v.getTypeDecl());
162         }
163
164         return rc;
165     }
166
167
168 }
169
Popular Tags