View Javadoc
1   /*
2    * Copyright 2005 Werner Guttmann
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  package org.exolab.castor.xml.schema;
17  
18  import org.exolab.castor.xml.schema.facets.MaxExclusive;
19  import org.exolab.castor.xml.schema.facets.MaxInclusive;
20  import org.exolab.castor.xml.schema.facets.MinExclusive;
21  import org.exolab.castor.xml.schema.facets.MinInclusive;
22  
23  /**
24   * A factory to create instances of {@link Facet}s.
25   *
26   * @see Facet
27   * @author <a href="mailto:sergei.ivanov@mail.ru">Sergei Ivanov</a>
28   * @version $Revision: 6465 $ $Date: 2006-04-13 06:47:36 -0600 (Thu, 13 Apr 2006) $
29   */
30  public final class FacetFactory {
31  
32      /**
33       * A private constructor to disallow direct instantiation.
34       */
35      private FacetFactory() { }
36  
37      /**
38       * The singleton instance of the factory.
39       */
40      private static final FacetFactory INSTANCE = new FacetFactory();
41  
42      /**
43       * Returns the singleton instance of the facet factory.
44       * @return factory instance
45       */
46      public static FacetFactory getInstance() {
47          return INSTANCE;
48      }
49  
50      /**
51       * Creates a new instance of a facet.
52       * @param name facet name (implies facet type)
53       * @param value value of the facet
54       * @return a new facet instance
55       */
56      public Facet createFacet(final String name, final String value) {
57          Facet facet = null;
58          if (Facet.MIN_EXCLUSIVE.equals(name)) {
59              facet = new MinExclusive(value);
60          } else if (Facet.MIN_INCLUSIVE.equals(name)) {
61              facet = new MinInclusive(value);
62          } else if (Facet.MAX_INCLUSIVE.equals(name)) {
63              facet = new MaxInclusive(value);
64          } else if (Facet.MAX_EXCLUSIVE.equals(name)) {
65              facet = new MaxExclusive(value);
66          } else {
67              facet = new Facet(name, value);
68          }
69  //        facet.setOwningType(parent);
70          return facet;
71      }
72  }