001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.internal.xjc.model.nav;
027:
028: import java.lang.reflect.Type;
029: import java.util.Collection;
030:
031: import com.sun.codemodel.internal.JClass;
032: import com.sun.xml.internal.bind.v2.model.nav.Navigator;
033: import com.sun.xml.internal.bind.v2.runtime.Location;
034:
035: /**
036: * {@link Navigator} implementation for XJC.
037: *
038: * Most of the Navigator methods are used for parsing the model, which doesn't happen
039: * in XJC. So Most of the methods aren't really implemented. Implementations should
040: * be filled in as needed.
041: *
042: * @author Kohsuke Kawaguchi
043: */
044: public final class NavigatorImpl implements
045: Navigator<NType, NClass, Void, Void> {
046: public static final NavigatorImpl theInstance = new NavigatorImpl();
047:
048: private NavigatorImpl() {
049: }
050:
051: public NClass getSuperClass(NClass nClass) {
052: throw new UnsupportedOperationException();
053: }
054:
055: public NType getBaseClass(NType nt, NClass base) {
056: if (nt instanceof EagerNType) {
057: EagerNType ent = (EagerNType) nt;
058: if (base instanceof EagerNClass) {
059: EagerNClass enc = (EagerNClass) base;
060: return create(REFLECTION.getBaseClass(ent.t, enc.c));
061: }
062: // lazy class can never be a base type of an eager type
063: return null;
064: }
065: if (nt instanceof NClassByJClass) {
066: NClassByJClass nnt = (NClassByJClass) nt;
067: if (base instanceof EagerNClass) {
068: EagerNClass enc = (EagerNClass) base;
069: return ref(nnt.clazz.getBaseClass(enc.c));
070: }
071: }
072:
073: throw new UnsupportedOperationException();
074: }
075:
076: public String getClassName(NClass nClass) {
077: throw new UnsupportedOperationException();
078: }
079:
080: public String getTypeName(NType type) {
081: return type.fullName();
082: }
083:
084: public String getClassShortName(NClass nClass) {
085: throw new UnsupportedOperationException();
086: }
087:
088: public Collection<? extends Void> getDeclaredFields(NClass nClass) {
089: throw new UnsupportedOperationException();
090: }
091:
092: public Void getDeclaredField(NClass clazz, String fieldName) {
093: throw new UnsupportedOperationException();
094: }
095:
096: public Collection<? extends Void> getDeclaredMethods(NClass nClass) {
097: throw new UnsupportedOperationException();
098: }
099:
100: public NClass getDeclaringClassForField(Void aVoid) {
101: throw new UnsupportedOperationException();
102: }
103:
104: public NClass getDeclaringClassForMethod(Void aVoid) {
105: throw new UnsupportedOperationException();
106: }
107:
108: public NType getFieldType(Void aVoid) {
109: throw new UnsupportedOperationException();
110: }
111:
112: public String getFieldName(Void aVoid) {
113: throw new UnsupportedOperationException();
114: }
115:
116: public String getMethodName(Void aVoid) {
117: throw new UnsupportedOperationException();
118: }
119:
120: public NType getReturnType(Void aVoid) {
121: throw new UnsupportedOperationException();
122: }
123:
124: public NType[] getMethodParameters(Void aVoid) {
125: throw new UnsupportedOperationException();
126: }
127:
128: public boolean isStaticMethod(Void aVoid) {
129: throw new UnsupportedOperationException();
130: }
131:
132: public boolean isSubClassOf(NType sub, NType sup) {
133: throw new UnsupportedOperationException();
134: }
135:
136: public NClass ref(Class c) {
137: return create(c);
138: }
139:
140: public NClass ref(JClass c) {
141: if (c == null)
142: return null;
143: return new NClassByJClass(c);
144: }
145:
146: public NType use(NClass nc) {
147: return nc;
148: }
149:
150: public NClass asDecl(NType nt) {
151: if (nt instanceof NClass)
152: return (NClass) nt;
153: else
154: return null;
155: }
156:
157: public NClass asDecl(Class c) {
158: return ref(c);
159: }
160:
161: public boolean isArray(NType nType) {
162: throw new UnsupportedOperationException();
163: }
164:
165: public boolean isArrayButNotByteArray(NType t) {
166: throw new UnsupportedOperationException();
167: }
168:
169: public NType getComponentType(NType nType) {
170: throw new UnsupportedOperationException();
171: }
172:
173: public NType getTypeArgument(NType nt, int i) {
174: if (nt instanceof EagerNType) {
175: EagerNType ent = (EagerNType) nt;
176: return create(REFLECTION.getTypeArgument(ent.t, i));
177: }
178: if (nt instanceof NClassByJClass) {
179: NClassByJClass nnt = (NClassByJClass) nt;
180: return ref(nnt.clazz.getTypeParameters().get(i));
181: }
182:
183: throw new UnsupportedOperationException();
184: }
185:
186: public boolean isParameterizedType(NType nt) {
187: if (nt instanceof EagerNType) {
188: EagerNType ent = (EagerNType) nt;
189: return REFLECTION.isParameterizedType(ent.t);
190: }
191: if (nt instanceof NClassByJClass) {
192: NClassByJClass nnt = (NClassByJClass) nt;
193: return nnt.clazz.isParameterized();
194: }
195:
196: throw new UnsupportedOperationException();
197: }
198:
199: public boolean isPrimitive(NType type) {
200: throw new UnsupportedOperationException();
201: }
202:
203: public NType getPrimitive(Class primitiveType) {
204: return create(primitiveType);
205: }
206:
207: public static final NType create(Type t) {
208: if (t == null)
209: return null;
210: if (t instanceof Class)
211: return create((Class) t);
212:
213: return new EagerNType(t);
214: }
215:
216: public static NClass create(Class c) {
217: if (c == null)
218: return null;
219: return new EagerNClass(c);
220: }
221:
222: /**
223: * Creates a {@link NType} representation for a parameterized type
224: * {@code RawType<ParamType1,ParamType2,...> }.
225: */
226: public static NType createParameterizedType(NClass rawType,
227: NType... args) {
228: return new NParameterizedType(rawType, args);
229: }
230:
231: public static NType createParameterizedType(Class rawType,
232: 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) {
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: }
|