23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.internal.xjc.model; |
26 package com.sun.tools.internal.xjc.model; |
27 |
27 |
|
28 import javax.xml.XMLConstants; |
28 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
29 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
29 import javax.xml.namespace.QName; |
30 import javax.xml.namespace.QName; |
30 |
31 |
31 import com.sun.tools.internal.xjc.model.nav.NClass; |
32 import com.sun.tools.internal.xjc.model.nav.NClass; |
32 import com.sun.tools.internal.xjc.model.nav.NType; |
33 import com.sun.tools.internal.xjc.model.nav.NType; |
33 import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder; |
34 import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder; |
34 import com.sun.xml.internal.bind.v2.model.core.PropertyInfo; |
35 import com.sun.xml.internal.bind.v2.model.core.PropertyInfo; |
35 import com.sun.xml.internal.bind.v2.model.core.TypeRef; |
36 import com.sun.xml.internal.bind.v2.model.core.TypeRef; |
36 import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil; |
37 import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil; |
|
38 import com.sun.xml.internal.xsom.XSType; |
37 import com.sun.xml.internal.xsom.XmlString; |
39 import com.sun.xml.internal.xsom.XmlString; |
38 import com.sun.xml.internal.xsom.XSElementDecl; |
40 import com.sun.xml.internal.xsom.XSElementDecl; |
39 import com.sun.istack.internal.Nullable; |
41 import com.sun.istack.internal.Nullable; |
40 |
42 |
41 /** |
43 /** |
72 public QName getTypeName() { |
74 public QName getTypeName() { |
73 return typeName; |
75 return typeName; |
74 } |
76 } |
75 |
77 |
76 public static QName getSimpleTypeName(XSElementDecl decl) { |
78 public static QName getSimpleTypeName(XSElementDecl decl) { |
77 if(decl==null) return null; |
79 if(decl==null || !decl.getType().isSimpleType()) |
78 QName typeName = null; |
80 return null; // null if not simple type |
79 if(decl.getType().isSimpleType()) |
81 return resolveSimpleTypeName(decl.getType()); |
80 typeName = BGMBuilder.getName(decl.getType()); |
82 } |
81 return typeName; |
83 |
|
84 /** |
|
85 * Recursively search for type name. |
|
86 * |
|
87 * This is needed to find correct type for refs like: |
|
88 * |
|
89 *<xs:simpleType name="parent"> |
|
90 * <xs:restriction base="xs:date"/> |
|
91 *</xs:simpleType> |
|
92 *<xs:simpleType name="child"> |
|
93 * <xs:restriction base="parent"/> |
|
94 *</xs:simpleType> |
|
95 * |
|
96 *<xs:element name="testField" type="child"/> |
|
97 * |
|
98 * @param declType given type |
|
99 * @return simpleTypeName or null |
|
100 */ |
|
101 private static QName resolveSimpleTypeName(XSType declType) { |
|
102 QName name = BGMBuilder.getName(declType); |
|
103 if (name != null && !XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(name.getNamespaceURI())) |
|
104 return resolveSimpleTypeName(declType.getBaseType()); |
|
105 else |
|
106 return name; |
82 } |
107 } |
83 |
108 |
84 public CTypeRef(CNonElement type, QName elementName, QName typeName, boolean nillable, XmlString defaultValue) { |
109 public CTypeRef(CNonElement type, QName elementName, QName typeName, boolean nillable, XmlString defaultValue) { |
85 assert type!=null; |
110 assert type!=null; |
86 assert elementName!=null; |
111 assert elementName!=null; |