47 |
47 |
48 import com.sun.codemodel.internal.JExpr; |
48 import com.sun.codemodel.internal.JExpr; |
49 import com.sun.codemodel.internal.JExpression; |
49 import com.sun.codemodel.internal.JExpression; |
50 import com.sun.codemodel.internal.JType; |
50 import com.sun.codemodel.internal.JType; |
51 import com.sun.tools.internal.xjc.model.nav.NClass; |
51 import com.sun.tools.internal.xjc.model.nav.NClass; |
|
52 import com.sun.xml.internal.bind.v2.model.annotation.Locatable; |
|
53 import com.sun.xml.internal.bind.v2.model.core.BuiltinLeafInfo; |
|
54 import com.sun.xml.internal.bind.v2.model.core.Element; |
|
55 import com.sun.xml.internal.bind.v2.model.core.LeafInfo; |
|
56 import com.sun.xml.internal.bind.v2.runtime.Location; |
52 import com.sun.tools.internal.xjc.model.nav.NType; |
57 import com.sun.tools.internal.xjc.model.nav.NType; |
53 import com.sun.tools.internal.xjc.model.nav.NavigatorImpl; |
58 import com.sun.tools.internal.xjc.model.nav.NavigatorImpl; |
54 import com.sun.tools.internal.xjc.outline.Aspect; |
59 import com.sun.tools.internal.xjc.outline.Aspect; |
55 import com.sun.tools.internal.xjc.outline.Outline; |
60 import com.sun.tools.internal.xjc.outline.Outline; |
56 import com.sun.tools.internal.xjc.runtime.ZeroOneBooleanAdapter; |
61 import com.sun.tools.internal.xjc.runtime.ZeroOneBooleanAdapter; |
57 import com.sun.tools.internal.xjc.util.NamespaceContextAdapter; |
62 import com.sun.tools.internal.xjc.util.NamespaceContextAdapter; |
58 import com.sun.xml.internal.bind.DatatypeConverterImpl; |
|
59 import com.sun.xml.internal.bind.v2.WellKnownNamespace; |
63 import com.sun.xml.internal.bind.v2.WellKnownNamespace; |
60 import com.sun.xml.internal.bind.v2.model.core.ID; |
64 import com.sun.xml.internal.bind.v2.model.core.ID; |
61 import com.sun.xml.internal.bind.v2.model.impl.BuiltinLeafInfoImpl; |
|
62 import com.sun.xml.internal.xsom.XSComponent; |
65 import com.sun.xml.internal.xsom.XSComponent; |
63 import com.sun.xml.internal.xsom.XmlString; |
66 import com.sun.xml.internal.xsom.XmlString; |
64 |
67 |
65 import org.xml.sax.Locator; |
68 import org.xml.sax.Locator; |
66 |
69 |
90 * a general {@link TypeUse} objects. |
93 * a general {@link TypeUse} objects. |
91 * |
94 * |
92 * |
95 * |
93 * @author Kohsuke Kawaguchi |
96 * @author Kohsuke Kawaguchi |
94 */ |
97 */ |
95 public abstract class CBuiltinLeafInfo extends BuiltinLeafInfoImpl<NType,NClass> implements CNonElement { |
98 public abstract class CBuiltinLeafInfo implements CNonElement, BuiltinLeafInfo<NType,NClass>, LeafInfo<NType,NClass>, Location { |
|
99 |
|
100 private final NType type; |
|
101 /** |
|
102 * Can be null for anonymous types. |
|
103 */ |
|
104 private final QName typeName; |
|
105 |
|
106 private final QName[] typeNames; |
96 |
107 |
97 private final ID id; |
108 private final ID id; |
98 |
109 |
99 // no derived class other than the spec-defined ones. definitely not for enum. |
110 // no derived class other than the spec-defined ones. definitely not for enum. |
100 private CBuiltinLeafInfo(NType typeToken, QName typeName, ID id) { |
111 private CBuiltinLeafInfo(NType typeToken, ID id, QName... typeNames) { |
101 super(typeToken,typeName); |
112 this.type = typeToken; |
|
113 this.typeName = typeNames.length>0?typeNames[0]:null; |
|
114 this.typeNames = typeNames; |
102 this.id = id; |
115 this.id = id; |
103 } |
116 } |
104 |
117 |
105 /** |
118 /** |
106 * Gets the code model representation of this type. |
119 * Gets the code model representation of this type. |
170 public final TypeUse makeMimeTyped( MimeType mt ) { |
183 public final TypeUse makeMimeTyped( MimeType mt ) { |
171 return TypeUseFactory.makeMimeTyped(this,mt); |
184 return TypeUseFactory.makeMimeTyped(this,mt); |
172 } |
185 } |
173 |
186 |
174 /** |
187 /** |
|
188 * @deprecated always return false at this level. |
|
189 */ |
|
190 public final boolean isElement() { |
|
191 return false; |
|
192 } |
|
193 |
|
194 /** |
|
195 * @deprecated always return null at this level. |
|
196 */ |
|
197 public final QName getElementName() { |
|
198 return null; |
|
199 } |
|
200 |
|
201 /** |
|
202 * @deprecated always return null at this level. |
|
203 */ |
|
204 public final Element<NType,NClass> asElement() { |
|
205 return null; |
|
206 } |
|
207 |
|
208 /** |
|
209 * A reference to the representation of the type. |
|
210 */ |
|
211 public NType getType() { |
|
212 return type; |
|
213 } |
|
214 |
|
215 /** |
|
216 * Returns all the type names recognized by this bean info. |
|
217 * |
|
218 * @return |
|
219 * do not modify the returned array. |
|
220 */ |
|
221 public final QName[] getTypeNames() { |
|
222 return typeNames; |
|
223 } |
|
224 |
|
225 /** |
|
226 * Leaf-type cannot be referenced from IDREF. |
|
227 * |
|
228 * @deprecated |
|
229 * why are you calling a method whose return value is always known? |
|
230 */ |
|
231 public final boolean canBeReferencedByIDREF() { |
|
232 return false; |
|
233 } |
|
234 |
|
235 public QName getTypeName() { |
|
236 return typeName; |
|
237 } |
|
238 |
|
239 public Locatable getUpstream() { |
|
240 return null; |
|
241 } |
|
242 |
|
243 public Location getLocation() { |
|
244 // this isn't very accurate, but it's not too bad |
|
245 // doing it correctly need leaves to hold navigator. |
|
246 // otherwise revisit the design so that we take navigator as a parameter |
|
247 return this; |
|
248 } |
|
249 |
|
250 public boolean isSimpleType() { |
|
251 return true; |
|
252 } |
|
253 |
|
254 /** |
175 * {@link CBuiltinLeafInfo} for Java classes that have |
255 * {@link CBuiltinLeafInfo} for Java classes that have |
176 * the spec defined built-in binding semantics. |
256 * the spec defined built-in binding semantics. |
177 */ |
257 */ |
178 private static abstract class Builtin extends CBuiltinLeafInfo { |
258 private static abstract class Builtin extends CBuiltinLeafInfo { |
179 protected Builtin(Class c, String typeName) { |
259 protected Builtin(Class c, String typeName) { |
180 this(c,typeName,com.sun.xml.internal.bind.v2.model.core.ID.NONE); |
260 this(c,typeName,com.sun.xml.internal.bind.v2.model.core.ID.NONE); |
181 } |
261 } |
182 protected Builtin(Class c, String typeName, ID id) { |
262 protected Builtin(Class c, String typeName, ID id) { |
183 super(NavigatorImpl.theInstance.ref(c), new QName(WellKnownNamespace.XML_SCHEMA,typeName),id); |
263 super(NavigatorImpl.theInstance.ref(c), id, new QName(WellKnownNamespace.XML_SCHEMA,typeName)); |
184 LEAVES.put(getType(),this); |
264 LEAVES.put(getType(),this); |
185 } |
265 } |
186 |
266 |
187 /** |
267 /** |
188 * No vendor customization in the built-in classes. |
268 * No vendor customization in the built-in classes. |
213 return JExpr.lit(lexical.value); |
293 return JExpr.lit(lexical.value); |
214 } |
294 } |
215 }; |
295 }; |
216 public static final CBuiltinLeafInfo BOOLEAN = new Builtin(Boolean.class,"boolean") { |
296 public static final CBuiltinLeafInfo BOOLEAN = new Builtin(Boolean.class,"boolean") { |
217 public JExpression createConstant(Outline outline, XmlString lexical) { |
297 public JExpression createConstant(Outline outline, XmlString lexical) { |
218 return JExpr.lit(DatatypeConverterImpl._parseBoolean(lexical.value)); |
298 return JExpr.lit(DatatypeConverter.parseBoolean(lexical.value)); |
219 } |
299 } |
220 }; |
300 }; |
221 public static final CBuiltinLeafInfo INT = new Builtin(Integer.class,"int") { |
301 public static final CBuiltinLeafInfo INT = new Builtin(Integer.class,"int") { |
222 public JExpression createConstant(Outline outline, XmlString lexical) { |
302 public JExpression createConstant(Outline outline, XmlString lexical) { |
223 return JExpr.lit(DatatypeConverterImpl._parseInt(lexical.value)); |
303 return JExpr.lit(DatatypeConverter.parseInt(lexical.value)); |
224 } |
304 } |
225 }; |
305 }; |
226 public static final CBuiltinLeafInfo LONG = new Builtin(Long.class,"long") { |
306 public static final CBuiltinLeafInfo LONG = new Builtin(Long.class,"long") { |
227 public JExpression createConstant(Outline outline, XmlString lexical) { |
307 public JExpression createConstant(Outline outline, XmlString lexical) { |
228 return JExpr.lit(DatatypeConverterImpl._parseLong(lexical.value)); |
308 return JExpr.lit(DatatypeConverter.parseLong(lexical.value)); |
229 } |
309 } |
230 }; |
310 }; |
231 public static final CBuiltinLeafInfo BYTE = new Builtin(Byte.class,"byte") { |
311 public static final CBuiltinLeafInfo BYTE = new Builtin(Byte.class,"byte") { |
232 public JExpression createConstant(Outline outline, XmlString lexical) { |
312 public JExpression createConstant(Outline outline, XmlString lexical) { |
233 return JExpr.cast( |
313 return JExpr.cast( |
234 outline.getCodeModel().BYTE, |
314 outline.getCodeModel().BYTE, |
235 JExpr.lit(DatatypeConverterImpl._parseByte(lexical.value))); |
315 JExpr.lit(DatatypeConverter.parseByte(lexical.value))); |
236 } |
316 } |
237 }; |
317 }; |
238 public static final CBuiltinLeafInfo SHORT = new Builtin(Short.class,"short") { |
318 public static final CBuiltinLeafInfo SHORT = new Builtin(Short.class,"short") { |
239 public JExpression createConstant(Outline outline, XmlString lexical) { |
319 public JExpression createConstant(Outline outline, XmlString lexical) { |
240 return JExpr.cast( |
320 return JExpr.cast( |
241 outline.getCodeModel().SHORT, |
321 outline.getCodeModel().SHORT, |
242 JExpr.lit(DatatypeConverterImpl._parseShort(lexical.value))); |
322 JExpr.lit(DatatypeConverter.parseShort(lexical.value))); |
243 } |
323 } |
244 }; |
324 }; |
245 public static final CBuiltinLeafInfo FLOAT = new Builtin(Float.class,"float") { |
325 public static final CBuiltinLeafInfo FLOAT = new Builtin(Float.class,"float") { |
246 public JExpression createConstant(Outline outline, XmlString lexical) { |
326 public JExpression createConstant(Outline outline, XmlString lexical) { |
247 return JExpr.lit(DatatypeConverterImpl._parseFloat(lexical.value)); |
327 return JExpr.lit(DatatypeConverter.parseFloat(lexical.value)); |
248 } |
328 } |
249 }; |
329 }; |
250 public static final CBuiltinLeafInfo DOUBLE = new Builtin(Double.class,"double") { |
330 public static final CBuiltinLeafInfo DOUBLE = new Builtin(Double.class,"double") { |
251 public JExpression createConstant(Outline outline, XmlString lexical) { |
331 public JExpression createConstant(Outline outline, XmlString lexical) { |
252 return JExpr.lit(DatatypeConverterImpl._parseDouble(lexical.value)); |
332 return JExpr.lit(DatatypeConverter.parseDouble(lexical.value)); |
253 } |
333 } |
254 }; |
334 }; |
255 public static final CBuiltinLeafInfo QNAME = new Builtin(QName.class,"QName") { |
335 public static final CBuiltinLeafInfo QNAME = new Builtin(QName.class,"QName") { |
256 public JExpression createConstant(Outline outline, XmlString lexical) { |
336 public JExpression createConstant(Outline outline, XmlString lexical) { |
257 QName qn = DatatypeConverterImpl._parseQName(lexical.value,new NamespaceContextAdapter(lexical)); |
337 QName qn = DatatypeConverter.parseQName(lexical.value,new NamespaceContextAdapter(lexical)); |
258 return JExpr._new(outline.getCodeModel().ref(QName.class)) |
338 return JExpr._new(outline.getCodeModel().ref(QName.class)) |
259 .arg(qn.getNamespaceURI()) |
339 .arg(qn.getNamespaceURI()) |
260 .arg(qn.getLocalPart()) |
340 .arg(qn.getLocalPart()) |
261 .arg(qn.getPrefix()); |
341 .arg(qn.getPrefix()); |
262 } |
342 } |