src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/dv/DTDDVFactory.java

Print this page


   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  */
  36 public abstract class DTDDVFactory {
  37 
  38     private static final String DEFAULT_FACTORY_CLASS = "com.sun.org.apache.xerces.internal.impl.dv.dtd.DTDDVFactoryImpl";




  39 
  40     /**
  41      * Get an instance of the default DTDDVFactory implementation.
  42      *
  43      * @return  an instance of DTDDVFactory implementation
  44      * @exception DVFactoryException  cannot create an instance of the specified
  45      *                                class name or the default class name
  46      */
  47     public static final DTDDVFactory getInstance() throws DVFactoryException {
  48         return getInstance(DEFAULT_FACTORY_CLASS);
  49     }
  50 
  51     /**
  52      * Get an instance of DTDDVFactory implementation.
  53      *
  54      * @param factoryClass  name of the implementation to load.
  55      * @return  an instance of DTDDVFactory implementation
  56      * @exception DVFactoryException  cannot create an instance of the specified
  57      *                                class name or the default class name
  58      */
  59     public static final DTDDVFactory getInstance(String factoryClass) throws DVFactoryException {
  60         try {
  61             // if the class name is not specified, use the default one





  62             return (DTDDVFactory)
  63                 (ObjectFactory.newInstance(factoryClass, true));

  64         }
  65         catch (ClassCastException e) {
  66             throw new DVFactoryException("DTD factory class " + factoryClass + " does not extend from DTDDVFactory.");
  67         }
  68     }
  69 
  70     // can't create a new object of this class
  71     protected DTDDVFactory() {}
  72 
  73     /**
  74      * return a dtd type of the given name
  75      *
  76      * @param name  the name of the datatype
  77      * @return      the datatype validator of the given name
  78      */
  79     public abstract DatatypeValidator getBuiltInDV(String name);
  80 
  81     /**
  82      * get all built-in DVs, which are stored in a hashtable keyed by the name
  83      *
   1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.

   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  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 com.sun.org.apache.xerces.internal.impl.dv.dtd.DTDDVFactoryImpl;
  24 import com.sun.org.apache.xerces.internal.impl.dv.dtd.XML11DTDDVFactoryImpl;
  25 import com.sun.org.apache.xerces.internal.utils.ObjectFactory;
  26 import java.util.Hashtable;
  27 
  28 /**
  29  * The factory to create and return DTD types. The implementation should
  30  * store the created datatypes in static data, so that they can be shared by
  31  * multiple parser instance, and multiple threads.
  32  *
  33  * @xerces.internal
  34  *
  35  * @author Sandy Gao, IBM
  36  *
  37  */
  38 public abstract class DTDDVFactory {
  39 
  40     private static final String DEFAULT_FACTORY_CLASS =
  41             "com.sun.org.apache.xerces.internal.impl.dv.dtd.DTDDVFactoryImpl";
  42 
  43     private static final String XML11_DATATYPE_VALIDATOR_FACTORY =
  44         "com.sun.org.apache.xerces.internal.impl.dv.dtd.XML11DTDDVFactoryImpl";
  45 
  46     /**
  47      * Get an instance of the default DTDDVFactory implementation.
  48      *
  49      * @return  an instance of DTDDVFactory implementation
  50      * @exception DVFactoryException  cannot create an instance of the specified
  51      *                                class name or the default class name
  52      */
  53     public static final DTDDVFactory getInstance() throws DVFactoryException {
  54         return getInstance(DEFAULT_FACTORY_CLASS);
  55     }
  56 
  57     /**
  58      * Get an instance of DTDDVFactory implementation.
  59      *
  60      * @param factoryClass  name of the implementation to load.
  61      * @return  an instance of DTDDVFactory implementation
  62      * @exception DVFactoryException  cannot create an instance of the specified
  63      *                                class name or the default class name
  64      */
  65     public static final DTDDVFactory getInstance(String factoryClass) throws DVFactoryException {
  66         try {
  67             if (DEFAULT_FACTORY_CLASS.equals(factoryClass)) {
  68                 return new DTDDVFactoryImpl();
  69             } else if (XML11_DATATYPE_VALIDATOR_FACTORY.equals(factoryClass)) {
  70                 return new XML11DTDDVFactoryImpl();
  71             } else {
  72                 //fall back for compatibility
  73                 return (DTDDVFactory)
  74                     (ObjectFactory.newInstance(factoryClass, true));
  75             }
  76         }
  77         catch (ClassCastException e) {
  78             throw new DVFactoryException("DTD factory class " + factoryClass + " does not extend from DTDDVFactory.");
  79         }
  80     }
  81 
  82     // can't create a new object of this class
  83     protected DTDDVFactory() {}
  84 
  85     /**
  86      * return a dtd type of the given name
  87      *
  88      * @param name  the name of the datatype
  89      * @return      the datatype validator of the given name
  90      */
  91     public abstract DatatypeValidator getBuiltInDV(String name);
  92 
  93     /**
  94      * get all built-in DVs, which are stored in a hashtable keyed by the name
  95      *