View Javadoc

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