|
1 /* |
|
2 * Portions Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 /* |
|
27 * Licensed Materials - Property of IBM |
|
28 * RMI-IIOP v1.0 |
|
29 * Copyright IBM Corp. 1998 1999 All Rights Reserved |
|
30 * |
|
31 */ |
|
32 |
|
33 package sun.rmi.rmic.iiop; |
|
34 |
|
35 import java.util.Vector; |
|
36 import sun.tools.java.CompilerError; |
|
37 import sun.tools.java.ClassNotFound; |
|
38 import sun.tools.java.ClassDefinition; |
|
39 |
|
40 /** |
|
41 * NCClassType represents any non-special class which does not |
|
42 * extends one or more interfaces which inherit from java.rmi.Remote. |
|
43 * <p> |
|
44 * The static forImplementation(...) method must be used to obtain an instance, |
|
45 * and will return null if the ClassDefinition is non-conforming. |
|
46 * |
|
47 * @author Bryan Atsatt |
|
48 */ |
|
49 public class NCClassType extends ClassType { |
|
50 |
|
51 //_____________________________________________________________________ |
|
52 // Public Interfaces |
|
53 //_____________________________________________________________________ |
|
54 |
|
55 /** |
|
56 * Create an NCClassType for the given class. |
|
57 * |
|
58 * If the class is not a properly formed or if some other error occurs, the |
|
59 * return value will be null, and errors will have been reported to the |
|
60 * supplied BatchEnvironment. |
|
61 */ |
|
62 public static NCClassType forNCClass(ClassDefinition classDef, |
|
63 ContextStack stack) { |
|
64 |
|
65 if (stack.anyErrors()) return null; |
|
66 |
|
67 boolean doPop = false; |
|
68 try { |
|
69 // Do we already have it? |
|
70 |
|
71 sun.tools.java.Type theType = classDef.getType(); |
|
72 Type existing = getType(theType,stack); |
|
73 |
|
74 if (existing != null) { |
|
75 |
|
76 if (!(existing instanceof NCClassType)) return null; // False hit. |
|
77 |
|
78 // Yep, so return it... |
|
79 |
|
80 return (NCClassType) existing; |
|
81 |
|
82 } |
|
83 |
|
84 NCClassType it = new NCClassType(stack, classDef); |
|
85 putType(theType,it,stack); |
|
86 stack.push(it); |
|
87 doPop = true; |
|
88 |
|
89 if (it.initialize(stack)) { |
|
90 stack.pop(true); |
|
91 return it; |
|
92 } else { |
|
93 removeType(theType,stack); |
|
94 stack.pop(false); |
|
95 return null; |
|
96 } |
|
97 } catch (CompilerError e) { |
|
98 if (doPop) stack.pop(false); |
|
99 return null; |
|
100 } |
|
101 } |
|
102 |
|
103 /** |
|
104 * Return a string describing this type. |
|
105 */ |
|
106 public String getTypeDescription () { |
|
107 return addExceptionDescription("Non-conforming class"); |
|
108 } |
|
109 |
|
110 //_____________________________________________________________________ |
|
111 // Internal/Subclass Interfaces |
|
112 //_____________________________________________________________________ |
|
113 |
|
114 /** |
|
115 * Create a NCClassType instance for the given class. The resulting |
|
116 * object is not yet completely initialized. |
|
117 */ |
|
118 private NCClassType(ContextStack stack, ClassDefinition classDef) { |
|
119 super(stack,classDef,TYPE_NC_CLASS | TM_CLASS | TM_COMPOUND); |
|
120 } |
|
121 |
|
122 //_____________________________________________________________________ |
|
123 // Internal Interfaces |
|
124 //_____________________________________________________________________ |
|
125 |
|
126 /** |
|
127 * Initialize this instance. |
|
128 */ |
|
129 private boolean initialize (ContextStack stack) { |
|
130 if (!initParents(stack)) { |
|
131 return false; |
|
132 } |
|
133 |
|
134 if (stack.getEnv().getParseNonConforming()) { |
|
135 |
|
136 Vector directInterfaces = new Vector(); |
|
137 Vector directMethods = new Vector(); |
|
138 Vector directMembers = new Vector(); |
|
139 |
|
140 try { |
|
141 |
|
142 // Get methods... |
|
143 |
|
144 if (addAllMethods(getClassDefinition(),directMethods,false,false,stack) != null) { |
|
145 |
|
146 // Update parent class methods... |
|
147 |
|
148 if (updateParentClassMethods(getClassDefinition(),directMethods,false,stack) != null) { |
|
149 |
|
150 // Get conforming constants... |
|
151 |
|
152 if (addConformingConstants(directMembers,false,stack)) { |
|
153 |
|
154 // We're ok, so pass 'em up... |
|
155 |
|
156 if (!initialize(directInterfaces,directMethods,directMembers,stack,false)) { |
|
157 return false; |
|
158 } |
|
159 } |
|
160 } |
|
161 } |
|
162 return true; |
|
163 |
|
164 } catch (ClassNotFound e) { |
|
165 classNotFound(stack,e); |
|
166 } |
|
167 return false; |
|
168 } else { |
|
169 return initialize(null,null,null,stack,false); |
|
170 } |
|
171 } |
|
172 } |