View Javadoc
1   /*
2    * Copyright 2005 Werner Guttmann
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  package org.exolab.castor.xml.schema;
15  
16  import org.exolab.castor.xml.schema.facets.MaxExclusive;
17  import org.exolab.castor.xml.schema.facets.MaxInclusive;
18  import org.exolab.castor.xml.schema.facets.MinExclusive;
19  import org.exolab.castor.xml.schema.facets.MinInclusive;
20  
21  /**
22   * A factory to create instances of {@link Facet}s.
23   *
24   * @see Facet
25   * @author <a href="mailto:sergei.ivanov@mail.ru">Sergei Ivanov</a>
26   * @version $Revision: 6465 $ $Date: 2006-04-13 06:47:36 -0600 (Thu, 13 Apr 2006) $
27   */
28  public final class FacetFactory {
29  
30    /**
31     * A private constructor to disallow direct instantiation.
32     */
33    private FacetFactory() {}
34  
35    /**
36     * The singleton instance of the factory.
37     */
38    private static final FacetFactory INSTANCE = new FacetFactory();
39  
40    /**
41     * Returns the singleton instance of the facet factory.
42     * 
43     * @return factory instance
44     */
45    public static FacetFactory getInstance() {
46      return INSTANCE;
47    }
48  
49    /**
50     * Creates a new instance of a facet.
51     * 
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  }