001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.tools.xjc.model.nav;
038:
039: import java.lang.reflect.Type;
040: import java.util.Collection;
041:
042: import com.sun.codemodel.JClass;
043: import com.sun.xml.bind.v2.model.nav.Navigator;
044: import com.sun.xml.bind.v2.runtime.Location;
045:
046: /**
047: * {@link Navigator} implementation for XJC.
048: *
049: * Most of the Navigator methods are used for parsing the model, which doesn't happen
050: * in XJC. So Most of the methods aren't really implemented. Implementations should
051: * be filled in as needed.
052: *
053: * @author Kohsuke Kawaguchi
054: */
055: public final class NavigatorImpl implements
056: Navigator<NType, NClass, Void, Void> {
057: public static final NavigatorImpl theInstance = new NavigatorImpl();
058:
059: private NavigatorImpl() {
060: }
061:
062: public NClass getSuperClass(NClass nClass) {
063: throw new UnsupportedOperationException();
064: }
065:
066: public NType getBaseClass(NType nt, NClass base) {
067: if (nt instanceof EagerNType) {
068: EagerNType ent = (EagerNType) nt;
069: if (base instanceof EagerNClass) {
070: EagerNClass enc = (EagerNClass) base;
071: return create(REFLECTION.getBaseClass(ent.t, enc.c));
072: }
073: // lazy class can never be a base type of an eager type
074: return null;
075: }
076: if (nt instanceof NClassByJClass) {
077: NClassByJClass nnt = (NClassByJClass) nt;
078: if (base instanceof EagerNClass) {
079: EagerNClass enc = (EagerNClass) base;
080: return ref(nnt.clazz.getBaseClass(enc.c));
081: }
082: }
083:
084: throw new UnsupportedOperationException();
085: }
086:
087: public String getClassName(NClass nClass) {
088: throw new UnsupportedOperationException();
089: }
090:
091: public String getTypeName(NType type) {
092: return type.fullName();
093: }
094:
095: public String getClassShortName(NClass nClass) {
096: throw new UnsupportedOperationException();
097: }
098:
099: public Collection<? extends Void> getDeclaredFields(NClass nClass) {
100: throw new UnsupportedOperationException();
101: }
102:
103: public Void getDeclaredField(NClass clazz, String fieldName) {
104: throw new UnsupportedOperationException();
105: }
106:
107: public Collection<? extends Void> getDeclaredMethods(NClass nClass) {
108: throw new UnsupportedOperationException();
109: }
110:
111: public NClass getDeclaringClassForField(Void aVoid) {
112: throw new UnsupportedOperationException();
113: }
114:
115: public NClass getDeclaringClassForMethod(Void aVoid) {
116: throw new UnsupportedOperationException();
117: }
118:
119: public NType getFieldType(Void aVoid) {
120: throw new UnsupportedOperationException();
121: }
122:
123: public String getFieldName(Void aVoid) {
124: throw new UnsupportedOperationException();
125: }
126:
127: public String getMethodName(Void aVoid) {
128: throw new UnsupportedOperationException();
129: }
130:
131: public NType getReturnType(Void aVoid) {
132: throw new UnsupportedOperationException();
133: }
134:
135: public NType[] getMethodParameters(Void aVoid) {
136: throw new UnsupportedOperationException();
137: }
138:
139: public boolean isStaticMethod(Void aVoid) {
140: throw new UnsupportedOperationException();
141: }
142:
143: public boolean isSubClassOf(NType sub, NType sup) {
144: throw new UnsupportedOperationException();
145: }
146:
147: public NClass ref(Class c) {
148: return create(c);
149: }
150:
151: public NClass ref(JClass c) {
152: if (c == null)
153: return null;
154: return new NClassByJClass(c);
155: }
156:
157: public NType use(NClass nc) {
158: return nc;
159: }
160:
161: public NClass asDecl(NType nt) {
162: if (nt instanceof NClass)
163: return (NClass) nt;
164: else
165: return null;
166: }
167:
168: public NClass asDecl(Class c) {
169: return ref(c);
170: }
171:
172: public boolean isArray(NType nType) {
173: throw new UnsupportedOperationException();
174: }
175:
176: public boolean isArrayButNotByteArray(NType t) {
177: throw new UnsupportedOperationException();
178: }
179:
180: public NType getComponentType(NType nType) {
181: throw new UnsupportedOperationException();
182: }
183:
184: public NType getTypeArgument(NType nt, int i) {
185: if (nt instanceof EagerNType) {
186: EagerNType ent = (EagerNType) nt;
187: return create(REFLECTION.getTypeArgument(ent.t, i));
188: }
189: if (nt instanceof NClassByJClass) {
190: NClassByJClass nnt = (NClassByJClass) nt;
191: return ref(nnt.clazz.getTypeParameters().get(i));
192: }
193:
194: throw new UnsupportedOperationException();
195: }
196:
197: public boolean isParameterizedType(NType nt) {
198: if (nt instanceof EagerNType) {
199: EagerNType ent = (EagerNType) nt;
200: return REFLECTION.isParameterizedType(ent.t);
201: }
202: if (nt instanceof NClassByJClass) {
203: NClassByJClass nnt = (NClassByJClass) nt;
204: return nnt.clazz.isParameterized();
205: }
206:
207: throw new UnsupportedOperationException();
208: }
209:
210: public boolean isPrimitive(NType type) {
211: throw new UnsupportedOperationException();
212: }
213:
214: public NType getPrimitive(Class primitiveType) {
215: return create(primitiveType);
216: }
217:
218: public static final NType create(Type t) {
219: if (t == null)
220: return null;
221: if (t instanceof Class)
222: return create((Class) t);
223:
224: return new EagerNType(t);
225: }
226:
227: public static NClass create(Class c) {
228: if (c == null)
229: return null;
230: return new EagerNClass(c);
231: }
232:
233: /**
234: * Creates a {@link NType} representation for a parameterized type
235: * {@code RawType<ParamType1,ParamType2,...> }.
236: */
237: public static NType createParameterizedType(NClass rawType,
238: NType... args) {
239: return new NParameterizedType(rawType, args);
240: }
241:
242: public static NType createParameterizedType(Class rawType,
243: NType... args) {
244: return new NParameterizedType(create(rawType), args);
245: }
246:
247: public Location getClassLocation(final NClass c) {
248: // not really needed for XJC but doesn't hurt to have one
249: return new Location() {
250: public String toString() {
251: return c.fullName();
252: }
253: };
254: }
255:
256: public Location getFieldLocation(Void _) {
257: throw new IllegalStateException();
258: }
259:
260: public Location getMethodLocation(Void _) {
261: throw new IllegalStateException();
262: }
263:
264: public boolean hasDefaultConstructor(NClass nClass) {
265: throw new UnsupportedOperationException();
266: }
267:
268: public boolean isStaticField(Void aVoid) {
269: throw new IllegalStateException();
270: }
271:
272: public boolean isPublicMethod(Void aVoid) {
273: throw new IllegalStateException();
274: }
275:
276: public boolean isPublicField(Void aVoid) {
277: throw new IllegalStateException();
278: }
279:
280: public boolean isEnum(NClass c) {
281: return isSubClassOf(c, create(Enum.class));
282: }
283:
284: public <T> NType erasure(NType type) {
285: if (type instanceof NParameterizedType) {
286: NParameterizedType pt = (NParameterizedType) type;
287: return pt.rawType;
288: }
289: return type;
290: }
291:
292: public boolean isAbstract(NClass clazz) {
293: return clazz.isAbstract();
294: }
295:
296: /**
297: * @deprecated
298: * no class generated by XJC is final.
299: */
300: public boolean isFinal(NClass clazz) {
301: return false;
302: }
303:
304: public Void[] getEnumConstants(NClass clazz) {
305: throw new UnsupportedOperationException();
306: }
307:
308: public NType getVoidType() {
309: return ref(void.class);
310: }
311:
312: public String getPackageName(NClass clazz) {
313: // TODO: implement this method later
314: throw new UnsupportedOperationException();
315: }
316:
317: public NClass findClass(String className, NClass referencePoint) {
318: // TODO: implement this method later
319: throw new UnsupportedOperationException();
320: }
321:
322: public boolean isBridgeMethod(Void method) {
323: throw new UnsupportedOperationException();
324: }
325:
326: public boolean isOverriding(Void method, NClass clazz) {
327: throw new UnsupportedOperationException();
328: }
329:
330: public boolean isInterface(NClass clazz) {
331: throw new UnsupportedOperationException();
332: }
333:
334: public boolean isTransient(Void f) {
335: throw new UnsupportedOperationException();
336: }
337:
338: public boolean isInnerClass(NClass clazz) {
339: throw new UnsupportedOperationException();
340: }
341: }
|