|
1 /* |
|
2 * Copyright (c) 1997, 2012, 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.xml.internal.xsom; |
|
27 |
|
28 import com.sun.xml.internal.xsom.visitor.XSSimpleTypeFunction; |
|
29 import com.sun.xml.internal.xsom.visitor.XSSimpleTypeVisitor; |
|
30 |
|
31 import java.util.List; |
|
32 |
|
33 /** |
|
34 * Simple type. |
|
35 * |
|
36 * @author |
|
37 * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) |
|
38 */ |
|
39 public interface XSSimpleType extends XSType, XSContentType |
|
40 { |
|
41 /** |
|
42 * Gets the base type as XSSimpleType. |
|
43 * |
|
44 * Equivalent to |
|
45 * <code> |
|
46 * (XSSimpleType)getBaseType() |
|
47 * </code> |
|
48 * Since this is a simple type, we know that the base type |
|
49 * is also a simple type. |
|
50 * |
|
51 * The only exception is xs:anySimpleType, which has xs:anyType |
|
52 * as the base type. |
|
53 * |
|
54 * @return |
|
55 * null if this is xs:anySimpleType. Otherwise non-null. |
|
56 */ |
|
57 XSSimpleType getSimpleBaseType(); |
|
58 |
|
59 /** |
|
60 * Gets the variety of this simple type. |
|
61 */ |
|
62 XSVariety getVariety(); |
|
63 |
|
64 /** |
|
65 * Gets the ancestor primitive {@link XSSimpleType} if |
|
66 * this type is {@link XSVariety#ATOMIC atomic}. |
|
67 * |
|
68 * @return |
|
69 * null otherwise. |
|
70 */ |
|
71 XSSimpleType getPrimitiveType(); |
|
72 |
|
73 /** |
|
74 * Returns true if this is a primitive built-in simple type |
|
75 * (that directly derives from xs:anySimpleType, by definition.) |
|
76 */ |
|
77 boolean isPrimitive(); |
|
78 |
|
79 /** |
|
80 * Gets the nearest ancestor {@link XSListSimpleType} (including itself) |
|
81 * if the variety of this type is {@link XSVariety#LIST list}. |
|
82 * |
|
83 * @return otherwise return null |
|
84 */ |
|
85 XSListSimpleType getBaseListType(); |
|
86 |
|
87 /** |
|
88 * Gets the nearest ancestor {@link XSUnionSimpleType} (including itself) |
|
89 * if the variety of this type is {@link XSVariety#UNION union}. |
|
90 * |
|
91 * @return otherwise return null |
|
92 */ |
|
93 XSUnionSimpleType getBaseUnionType(); |
|
94 |
|
95 /** |
|
96 * Returns true if this type definition is marked as 'final' |
|
97 * with respect to the given {@link XSVariety}. |
|
98 * |
|
99 * @return |
|
100 * true if the type is marked final. |
|
101 */ |
|
102 boolean isFinal(XSVariety v); |
|
103 |
|
104 /** |
|
105 * If this {@link XSSimpleType} is redefined by another simple type, |
|
106 * return that component. |
|
107 * |
|
108 * @return null |
|
109 * if this component has not been redefined. |
|
110 */ |
|
111 public XSSimpleType getRedefinedBy(); |
|
112 |
|
113 /** |
|
114 * Gets the effective facet object of the given name. |
|
115 * |
|
116 * <p> |
|
117 * For example, if a simple type "foo" is derived from |
|
118 * xs:string by restriction with the "maxLength" facet and |
|
119 * another simple type "bar" is derived from "foo" by |
|
120 * restriction with another "maxLength" facet, this method |
|
121 * will return the latter one, because that is the most |
|
122 * restrictive, effective facet. |
|
123 * |
|
124 * <p> |
|
125 * For those facets that can have multiple values |
|
126 * (pattern facets and enumeration facets), this method |
|
127 * will return only the first one. |
|
128 * TODO: allow clients to access all of them by some means. |
|
129 * |
|
130 * @return |
|
131 * If this datatype has a facet of the given name, |
|
132 * return that object. If the facet is not specified |
|
133 * anywhere in its derivation chain, null will be returned. |
|
134 */ |
|
135 XSFacet getFacet( String name ); |
|
136 |
|
137 /** |
|
138 * For multi-valued facets (enumeration and pattern), obtain all values. |
|
139 * |
|
140 * @see #getFacet(String) |
|
141 * |
|
142 * @return |
|
143 * can be empty but never null. |
|
144 */ |
|
145 List<XSFacet> getFacets( String name ); |
|
146 |
|
147 |
|
148 |
|
149 void visit( XSSimpleTypeVisitor visitor ); |
|
150 <T> T apply( XSSimpleTypeFunction<T> function ); |
|
151 |
|
152 /** Returns true if <code>this instanceof XSRestrictionSimpleType</code>. */ |
|
153 boolean isRestriction(); |
|
154 /** Returns true if <code>this instanceof XSListSimpleType</code>. */ |
|
155 boolean isList(); |
|
156 /** Returns true if <code>this instanceof XSUnionSimpleType</code>. */ |
|
157 boolean isUnion(); |
|
158 |
|
159 XSRestrictionSimpleType asRestriction(); |
|
160 XSListSimpleType asList(); |
|
161 XSUnionSimpleType asUnion(); |
|
162 } |