src/share/jaxws_classes/com/sun/tools/internal/xjc/model/nav/NavigatorImpl.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
equal deleted inserted replaced
284:88b85470e72c 286:f50545b5e2f1
1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.internal.xjc.model.nav;
27
28 import java.lang.reflect.Type;
29 import java.util.Collection;
30
31 import com.sun.codemodel.internal.JClass;
32 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
33 import com.sun.xml.internal.bind.v2.runtime.Location;
34
35 /**
36 * {@link Navigator} implementation for XJC.
37 *
38 * Most of the Navigator methods are used for parsing the model, which doesn't happen
39 * in XJC. So Most of the methods aren't really implemented. Implementations should
40 * be filled in as needed.
41 *
42 * @author Kohsuke Kawaguchi
43 */
44 public final class NavigatorImpl implements Navigator<NType,NClass,Void,Void> {
45 public static final NavigatorImpl theInstance = new NavigatorImpl();
46
47 private NavigatorImpl() {
48 }
49
50 public NClass getSuperClass(NClass nClass) {
51 throw new UnsupportedOperationException();
52 }
53
54 public NType getBaseClass(NType nt, NClass base) {
55 if(nt instanceof EagerNType) {
56 EagerNType ent = (EagerNType) nt;
57 if (base instanceof EagerNClass) {
58 EagerNClass enc = (EagerNClass) base;
59 return create(REFLECTION.getBaseClass(ent.t, enc.c));
60 }
61 // lazy class can never be a base type of an eager type
62 return null;
63 }
64 if (nt instanceof NClassByJClass) {
65 NClassByJClass nnt = (NClassByJClass) nt;
66 if (base instanceof EagerNClass) {
67 EagerNClass enc = (EagerNClass) base;
68 return ref(nnt.clazz.getBaseClass(enc.c));
69 }
70 }
71
72 throw new UnsupportedOperationException();
73 }
74
75 public String getClassName(NClass nClass) {
76 throw new UnsupportedOperationException();
77 }
78
79 public String getTypeName(NType type) {
80 return type.fullName();
81 }
82
83 public String getClassShortName(NClass nClass) {
84 throw new UnsupportedOperationException();
85 }
86
87 public Collection<? extends Void> getDeclaredFields(NClass nClass) {
88 throw new UnsupportedOperationException();
89 }
90
91 public Void getDeclaredField(NClass clazz, String fieldName) {
92 throw new UnsupportedOperationException();
93 }
94
95 public Collection<? extends Void> getDeclaredMethods(NClass nClass) {
96 throw new UnsupportedOperationException();
97 }
98
99 public NClass getDeclaringClassForField(Void aVoid) {
100 throw new UnsupportedOperationException();
101 }
102
103 public NClass getDeclaringClassForMethod(Void aVoid) {
104 throw new UnsupportedOperationException();
105 }
106
107 public NType getFieldType(Void aVoid) {
108 throw new UnsupportedOperationException();
109 }
110
111 public String getFieldName(Void aVoid) {
112 throw new UnsupportedOperationException();
113 }
114
115 public String getMethodName(Void aVoid) {
116 throw new UnsupportedOperationException();
117 }
118
119 public NType getReturnType(Void aVoid) {
120 throw new UnsupportedOperationException();
121 }
122
123 public NType[] getMethodParameters(Void aVoid) {
124 throw new UnsupportedOperationException();
125 }
126
127 public boolean isStaticMethod(Void aVoid) {
128 throw new UnsupportedOperationException();
129 }
130
131 public boolean isFinalMethod(Void aVoid) {
132 throw new UnsupportedOperationException();
133 }
134
135 public boolean isSubClassOf(NType sub, NType sup) {
136 throw new UnsupportedOperationException();
137 }
138
139 public NClass ref(Class c) {
140 return create(c);
141 }
142
143 public NClass ref(JClass c) {
144 if(c==null) return null;
145 return new NClassByJClass(c);
146 }
147
148 public NType use(NClass nc) {
149 return nc;
150 }
151
152 public NClass asDecl(NType nt) {
153 if(nt instanceof NClass)
154 return (NClass)nt;
155 else
156 return null;
157 }
158
159 public NClass asDecl(Class c) {
160 return ref(c);
161 }
162
163 public boolean isArray(NType nType) {
164 throw new UnsupportedOperationException();
165 }
166
167 public boolean isArrayButNotByteArray(NType t) {
168 throw new UnsupportedOperationException();
169 }
170
171
172 public NType getComponentType(NType nType) {
173 throw new UnsupportedOperationException();
174 }
175
176 public NType getTypeArgument(NType nt, int i) {
177 if (nt instanceof EagerNType) {
178 EagerNType ent = (EagerNType) nt;
179 return create(REFLECTION.getTypeArgument(ent.t,i));
180 }
181 if (nt instanceof NClassByJClass) {
182 NClassByJClass nnt = (NClassByJClass) nt;
183 return ref(nnt.clazz.getTypeParameters().get(i));
184 }
185
186 throw new UnsupportedOperationException();
187 }
188
189 public boolean isParameterizedType(NType nt) {
190 if (nt instanceof EagerNType) {
191 EagerNType ent = (EagerNType) nt;
192 return REFLECTION.isParameterizedType(ent.t);
193 }
194 if (nt instanceof NClassByJClass) {
195 NClassByJClass nnt = (NClassByJClass) nt;
196 return nnt.clazz.isParameterized();
197 }
198
199 throw new UnsupportedOperationException();
200 }
201
202 public boolean isPrimitive(NType type) {
203 throw new UnsupportedOperationException();
204 }
205
206 public NType getPrimitive(Class primitiveType) {
207 return create(primitiveType);
208 }
209
210
211 public static final NType create(Type t) {
212 if(t==null) return null;
213 if(t instanceof Class)
214 return create((Class)t);
215
216 return new EagerNType(t);
217 }
218
219 public static NClass create( Class c ) {
220 if(c==null) return null;
221 return new EagerNClass(c);
222 }
223
224 /**
225 * Creates a {@link NType} representation for a parameterized type
226 * {@code RawType&lt;ParamType1,ParamType2,...> }.
227 */
228 public static NType createParameterizedType( NClass rawType, NType... args ) {
229 return new NParameterizedType(rawType,args);
230 }
231
232 public static NType createParameterizedType( Class rawType, NType... args ) {
233 return new NParameterizedType(create(rawType),args);
234 }
235
236 public Location getClassLocation(final NClass c) {
237 // not really needed for XJC but doesn't hurt to have one
238 return new Location() {
239 public String toString() {
240 return c.fullName();
241 }
242 };
243 }
244
245 public Location getFieldLocation(Void _) {
246 throw new IllegalStateException();
247 }
248
249 public Location getMethodLocation(Void _) {
250 throw new IllegalStateException();
251 }
252
253 public boolean hasDefaultConstructor(NClass nClass) {
254 throw new UnsupportedOperationException();
255 }
256
257 public boolean isStaticField(Void aVoid) {
258 throw new IllegalStateException();
259 }
260
261 public boolean isPublicMethod(Void aVoid) {
262 throw new IllegalStateException();
263 }
264
265 public boolean isPublicField(Void aVoid) {
266 throw new IllegalStateException();
267 }
268
269 public boolean isEnum(NClass c) {
270 return isSubClassOf(c,create(Enum.class));
271 }
272
273 public <T> NType erasure(NType type) {
274 if(type instanceof NParameterizedType) {
275 NParameterizedType pt = (NParameterizedType) type;
276 return pt.rawType;
277 }
278 return type;
279 }
280
281 public boolean isAbstract(NClass clazz) {
282 return clazz.isAbstract();
283 }
284
285 /**
286 * @deprecated
287 * no class generated by XJC is final.
288 */
289 public boolean isFinal(NClass clazz) {
290 return false;
291 }
292
293 public Void[] getEnumConstants(NClass clazz) {
294 throw new UnsupportedOperationException();
295 }
296
297 public NType getVoidType() {
298 return ref(void.class);
299 }
300
301 public String getPackageName(NClass clazz) {
302 // TODO: implement this method later
303 throw new UnsupportedOperationException();
304 }
305
306 public NClass findClass(String className, NClass referencePoint) {
307 // TODO: implement this method later
308 throw new UnsupportedOperationException();
309 }
310
311 public boolean isBridgeMethod(Void method) {
312 throw new UnsupportedOperationException();
313 }
314
315 public boolean isOverriding(Void method,NClass clazz) {
316 throw new UnsupportedOperationException();
317 }
318
319 public boolean isInterface(NClass clazz) {
320 throw new UnsupportedOperationException();
321 }
322
323 public boolean isTransient(Void f) {
324 throw new UnsupportedOperationException();
325 }
326
327 public boolean isInnerClass(NClass clazz) {
328 throw new UnsupportedOperationException();
329 }
330
331 @Override
332 public boolean isSameType(NType t1, NType t2) {
333 throw new UnsupportedOperationException();
334 }
335 }

mercurial