KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > xml > XsDerivationSet


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.xs.xml;
18
19 import java.util.StringTokenizer JavaDoc;
20
21 /** <p>Implementation of <code>xs:derivationset</code>.
22  * Follows this specification:
23  * <pre>
24  * &lt;xs:simpleType name="derivationSet"&gt;
25  * &lt;xs:annotation&gt;
26  * &lt;xs:documentation&gt;
27  * A utility type, not for public use
28  * &lt;/xs:documentation&gt;
29  * &lt;xs:documentation&gt;
30  * #all or (possibly empty) subset of {extension, restriction}
31  * &lt;/xs:documentation&gt;
32  * &lt;/xs:annotation&gt;
33  * &lt;xs:union&gt;
34  * &lt;xs:simpleType&gt;
35  * &lt;xs:restriction base="xs:token"&gt;
36  * &lt;xs:enumeration value="#all"/&gt;
37  * &lt;/xs:restriction&gt;
38  * &lt;/xs:simpleType&gt;
39  * &lt;xs:simpleType&gt;
40  * &lt;xs:list itemType="xs:reducedDerivationControl"/&gt;
41  * &lt;/xs:simpleType&gt;
42  * &lt;/xs:union&gt;
43  * &lt;/xs:simpleType&gt;
44  * </pre>
45  * </p>
46  *
47  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
48  */

49 public class XsDerivationSet {
50   boolean extensionAllowed, restrictionAllowed;
51
52   /** <p>Returns whether extension is allowed.</p>
53    */

54   public boolean isExtensionAllowed() {
55     return extensionAllowed;
56   }
57
58   /** <p>Sets whether extension is allowed.</p>
59    */

60   public void setExtensionAllowed(boolean pExtensionAllowed) {
61     extensionAllowed = pExtensionAllowed;
62   }
63
64   /** <p>Returns whether restriction is allowed.</p>
65    */

66   public boolean isRestrictionAllowed() {
67     return restrictionAllowed;
68   }
69
70   /** <p>Sets whether restriction is allowed.</p>
71    */

72   public void setRestrictionAllowed(boolean pRestrictionAllowed) {
73     restrictionAllowed = pRestrictionAllowed;
74   }
75
76   /** <p>Returns a <code>DerivationSet</code> matching the given
77    * value.</p>
78    */

79   public static XsDerivationSet valueOf(String JavaDoc pValue) {
80     return new XsDerivationSet(pValue);
81   }
82
83   /** <p>Creates a new DerivationSet with the given value.</p>
84    */

85   public XsDerivationSet(String JavaDoc pValue) {
86     if ("#all".equals(pValue)) {
87       setExtensionAllowed(true);
88       setRestrictionAllowed(true);
89     } else {
90       for (StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(pValue, " "); st.hasMoreTokens(); ) {
91         String JavaDoc s = st.nextToken();
92         if ("extension".equals(s)) {
93           setExtensionAllowed(true);
94         } else if ("restriction".equals(s)) {
95           setRestrictionAllowed(true);
96         } else {
97           throw new IllegalArgumentException JavaDoc("Invalid derivation set value: " + pValue + "; the token " + s + " did not resolve to either of 'extension' or 'restriction'");
98         }
99       }
100     }
101   }
102
103   public String JavaDoc toString() {
104     if (isExtensionAllowed()) {
105       if (isRestrictionAllowed()) {
106         return "extension restriction";
107       } else {
108         return "extension";
109       }
110     } else {
111       if (isRestrictionAllowed()) {
112         return "restriction";
113       } else {
114         return "";
115       }
116     }
117   }
118
119   public boolean equals(Object JavaDoc o) {
120     if (o == null || !(XsDerivationSet.class.equals(o.getClass()))) {
121       return false;
122     }
123     XsDerivationSet ds = (XsDerivationSet) o;
124     return ds.extensionAllowed == extensionAllowed &&
125             ds.restrictionAllowed == restrictionAllowed;
126   }
127
128   public int hashCode() {
129     int result = 0;
130     if (extensionAllowed) { result += 1; }
131     if (restrictionAllowed) { result += 2; }
132     return result;
133   }
134 }
135
Popular Tags