|
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 * NCInterfaceType represents any non-special, non-conforming interface. |
|
42 * <p> |
|
43 * The static forNCInterface(...) method must be used to obtain an instance. |
|
44 * @author Bryan Atsatt |
|
45 */ |
|
46 public class NCInterfaceType extends InterfaceType { |
|
47 |
|
48 //_____________________________________________________________________ |
|
49 // Public Interfaces |
|
50 //_____________________________________________________________________ |
|
51 |
|
52 /** |
|
53 * Create an NCInterfaceType for the given class. |
|
54 * |
|
55 * If the class is not a properly formed or if some other error occurs, the |
|
56 * return value will be null, and errors will have been reported to the |
|
57 * supplied BatchEnvironment. |
|
58 */ |
|
59 public static NCInterfaceType forNCInterface( ClassDefinition classDef, |
|
60 ContextStack stack) { |
|
61 if (stack.anyErrors()) return null; |
|
62 |
|
63 boolean doPop = false; |
|
64 try { |
|
65 // Do we already have it? |
|
66 |
|
67 sun.tools.java.Type theType = classDef.getType(); |
|
68 Type existing = getType(theType,stack); |
|
69 |
|
70 if (existing != null) { |
|
71 |
|
72 if (!(existing instanceof NCInterfaceType)) return null; // False hit. |
|
73 |
|
74 // Yep, so return it... |
|
75 |
|
76 return (NCInterfaceType) existing; |
|
77 } |
|
78 |
|
79 NCInterfaceType it = new NCInterfaceType(stack, classDef); |
|
80 putType(theType,it,stack); |
|
81 stack.push(it); |
|
82 doPop = true; |
|
83 |
|
84 if (it.initialize(stack)) { |
|
85 stack.pop(true); |
|
86 return it; |
|
87 } else { |
|
88 removeType(theType,stack); |
|
89 stack.pop(false); |
|
90 return null; |
|
91 } |
|
92 } catch (CompilerError e) { |
|
93 if (doPop) stack.pop(false); |
|
94 return null; |
|
95 } |
|
96 } |
|
97 |
|
98 /** |
|
99 * Return a string describing this type. |
|
100 */ |
|
101 public String getTypeDescription () { |
|
102 return "Non-conforming interface"; |
|
103 } |
|
104 |
|
105 //_____________________________________________________________________ |
|
106 // Internal/Subclass Interfaces |
|
107 //_____________________________________________________________________ |
|
108 |
|
109 /** |
|
110 * Create a NCInterfaceType instance for the given class. The resulting |
|
111 * object is not yet completely initialized. |
|
112 */ |
|
113 private NCInterfaceType(ContextStack stack, ClassDefinition classDef) { |
|
114 super(stack,classDef,TYPE_NC_INTERFACE | TM_INTERFACE | TM_COMPOUND); |
|
115 } |
|
116 |
|
117 //_____________________________________________________________________ |
|
118 // Internal Interfaces |
|
119 //_____________________________________________________________________ |
|
120 |
|
121 /** |
|
122 * Initialize this instance. |
|
123 */ |
|
124 private boolean initialize (ContextStack stack) { |
|
125 |
|
126 if (stack.getEnv().getParseNonConforming()) { |
|
127 |
|
128 Vector directInterfaces = new Vector(); |
|
129 Vector directMethods = new Vector(); |
|
130 Vector directMembers = new Vector(); |
|
131 |
|
132 try { |
|
133 |
|
134 // need to include parent interfaces in IDL generation... |
|
135 addNonRemoteInterfaces( directInterfaces,stack ); |
|
136 |
|
137 // Get methods... |
|
138 |
|
139 if (addAllMethods(getClassDefinition(),directMethods,false,false,stack) != null) { |
|
140 |
|
141 // Get conforming constants... |
|
142 |
|
143 if (addConformingConstants(directMembers,false,stack)) { |
|
144 |
|
145 // We're ok, so pass 'em up... |
|
146 |
|
147 if (!initialize(directInterfaces,directMethods,directMembers,stack,false)) { |
|
148 return false; |
|
149 } |
|
150 } |
|
151 } |
|
152 return true; |
|
153 |
|
154 } catch (ClassNotFound e) { |
|
155 classNotFound(stack,e); |
|
156 } |
|
157 return false; |
|
158 } else { |
|
159 return initialize(null,null,null,stack,false); |
|
160 } |
|
161 } |
|
162 } |