View Javadoc

1   /*
2    * Copyright 2004,2007 The Apache Software Foundation.
3    * Portions Copyright 2006 International Business Machines Corp.
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.ws.commons.schema;
19  
20  import org.w3c.dom.Element;
21  
22  /**
23   * Abstract class for all facets that are used when simple types are
24   * derived by restriction.
25   */
26  
27  public abstract class XmlSchemaFacet extends XmlSchemaAnnotated {
28  
29      /**
30       * Creates new XmlSchemaFacet
31       */
32  
33  
34      protected XmlSchemaFacet() {
35      }
36  
37      protected XmlSchemaFacet(Object value, boolean fixed) {
38          this.value = value;
39          this.fixed = fixed;
40      }
41  
42      boolean fixed;
43  
44      Object value;
45  
46      public boolean isFixed() {
47          return fixed;
48      }
49  
50      public void setFixed(boolean fixed) {
51          this.fixed = fixed;
52      }
53  
54      public Object getValue() {
55          return value;
56      }
57  
58      public void setValue(Object value) {
59          this.value = value;
60      }
61  
62      public static XmlSchemaFacet construct(Element el) {
63          String name = el.getLocalName();
64          boolean fixed = false;
65          if (el.getAttribute("fixed").equals("true")) {
66              fixed = true;
67          }
68          XmlSchemaFacet facet;
69          if (name.equals("enumeration")) {
70              facet = new XmlSchemaEnumerationFacet();
71          } else if (name.equals("fractionDigits")) {
72              facet = new XmlSchemaFractionDigitsFacet();
73          } else if (name.equals("length")) {
74              facet = new XmlSchemaLengthFacet();
75          } else if (name.equals("maxExclusive")) {
76              facet = new XmlSchemaMaxExclusiveFacet();
77          } else if (name.equals("maxInclusive")) {
78              facet = new XmlSchemaMaxInclusiveFacet();
79          } else if (name.equals("maxLength")) {
80              facet = new XmlSchemaMaxLengthFacet();
81          } else if (name.equals("minLength")) {
82              facet = new XmlSchemaMinLengthFacet();
83          } else if (name.equals("minExclusive")) {
84              facet = new XmlSchemaMinExclusiveFacet();
85          } else if (name.equals("minInclusive")) {
86              facet = new XmlSchemaMinInclusiveFacet();
87          } else if (name.equals("pattern")) {
88              facet = new XmlSchemaPatternFacet();
89          } else if (name.equals("totalDigits")) {
90              facet = new XmlSchemaTotalDigitsFacet();
91          } else if (name.equals("whiteSpace")) {
92              facet = new XmlSchemaWhiteSpaceFacet();
93          } else {
94              throw new XmlSchemaException("Incorrect facet with name \""
95                                           + name + "\" found.");
96          }
97          if (el.hasAttribute("id"))facet.setId(el.getAttribute("id"));
98          facet.setFixed(fixed);
99          facet.setValue(el.getAttribute("value"));
100         return facet;
101     }
102 }