View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 2001, 2002,2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *      http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package com.sun.org.apache.xerces.internal.impl.dv;
22  
23  import java.util.Hashtable;
24  import com.sun.org.apache.xerces.internal.utils.ObjectFactory;
25  
26  /**
27   * The factory to create and return DTD types. The implementation should
28   * store the created datatypes in static data, so that they can be shared by
29   * multiple parser instance, and multiple threads.
30   *
31   * @xerces.internal
32   *
33   * @author Sandy Gao, IBM
34   *
35   * @version $Id: DTDDVFactory.java,v 1.6 2010-11-01 04:39:43 joehw Exp $
36   */
37  public abstract class DTDDVFactory {
38  
39      private static final String DEFAULT_FACTORY_CLASS = "com.sun.org.apache.xerces.internal.impl.dv.dtd.DTDDVFactoryImpl";
40  
41      /**
42       * Get an instance of the default DTDDVFactory implementation.
43       *
44       * @return  an instance of DTDDVFactory implementation
45       * @exception DVFactoryException  cannot create an instance of the specified
46       *                                class name or the default class name
47       */
48      public static final DTDDVFactory getInstance() throws DVFactoryException {
49          return getInstance(DEFAULT_FACTORY_CLASS);
50      }
51  
52      /**
53       * Get an instance of DTDDVFactory implementation.
54       *
55       * @param factoryClass  name of the implementation to load.
56       * @return  an instance of DTDDVFactory implementation
57       * @exception DVFactoryException  cannot create an instance of the specified
58       *                                class name or the default class name
59       */
60      public static final DTDDVFactory getInstance(String factoryClass) throws DVFactoryException {
61          try {
62              // if the class name is not specified, use the default one
63              return (DTDDVFactory)
64                  (ObjectFactory.newInstance(factoryClass, true));
65          }
66          catch (ClassCastException e) {
67              throw new DVFactoryException("DTD factory class " + factoryClass + " does not extend from DTDDVFactory.");
68          }
69      }
70  
71      // can't create a new object of this class
72      protected DTDDVFactory() {}
73  
74      /**
75       * return a dtd type of the given name
76       *
77       * @param name  the name of the datatype
78       * @return      the datatype validator of the given name
79       */
80      public abstract DatatypeValidator getBuiltInDV(String name);
81  
82      /**
83       * get all built-in DVs, which are stored in a hashtable keyed by the name
84       *
85       * @return      a hashtable which contains all datatypes
86       */
87      public abstract Hashtable getBuiltInTypes();
88  
89  }