neilg 2002/07/24 08:02:59 Modified: java/src/org/apache/xerces/impl/dv SchemaDVFactory.java DTDDVFactory.java Log: changing behaviour of datatype factories so that they may be used to create multiple instance of the datatypes. This means that our default implementation must be used for instance document validation, but the factories can still serve a useful role as gateways to standalone datatype libraries. Revision Changes Path 1.8 +15 -35 xml-xerces/java/src/org/apache/xerces/impl/dv/SchemaDVFactory.java Index: SchemaDVFactory.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/SchemaDVFactory.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SchemaDVFactory.java 16 May 2002 18:25:53 -0000 1.7 +++ SchemaDVFactory.java 24 Jul 2002 15:02:58 -0000 1.8 @@ -79,61 +79,41 @@ private static final String DEFAULT_FACTORY_CLASS = "org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl"; - private static String fFactoryClass = null; - private static SchemaDVFactory fFactoryInstance = null; - /** - * Set the class name of the schema dv factory implementation. This method - * can only be called before the first time the method <code>getInstance</code> - * successfully returns, otherwise a DVFactoryException will be thrown. + * Get a default instance of SchemaDVFactory implementation. * - * @param className the class name of the SchemaDVFactory implementation - * @exception DVFactoryException the method cannot be called at this time + * @return an instance of SchemaDVFactory implementation + * @exception DVFactoryException cannot create an instance of the specified + * class name or the default class name */ - public static synchronized final void setFactoryClass(String factoryClass) throws DVFactoryException { - // if the factory instance has been created, it's an error. - if (fFactoryInstance != null) - throw new DVFactoryException("Cannot set the class name now. The class name '"+fFactoryClass+"' is already used."); + public static synchronized final SchemaDVFactory getInstance() throws DVFactoryException { + return getInstance(DEFAULT_FACTORY_CLASS); + } //getInstance(): SchemaDVFactory - fFactoryClass = factoryClass; - } /** * Get an instance of SchemaDVFactory implementation. * - * If <code>setFactoryClass</code> is called before this method, - * the passed-in class name will be used to create the factory instance. - * Otherwise, a default implementation is used. - * - * After the first time this method successfully returns, any subsequent - * invocation to this method returns the same instance. - * + * @param factoryClass name of the schema factory implementation to instantiate. * @return an instance of SchemaDVFactory implementation * @exception DVFactoryException cannot create an instance of the specified * class name or the default class name */ - public static synchronized final SchemaDVFactory getInstance() throws DVFactoryException { - // if the factory instance has been created, just return it. - if (fFactoryInstance != null) - return fFactoryInstance; + public static synchronized final SchemaDVFactory getInstance(String factoryClass) throws DVFactoryException { try { // if the class name is not specified, use the default one - if (fFactoryClass == null) - fFactoryClass = DEFAULT_FACTORY_CLASS; - fFactoryInstance = (SchemaDVFactory)(Class.forName(fFactoryClass).newInstance()); + return (SchemaDVFactory)(Class.forName( factoryClass).newInstance()); } catch (ClassNotFoundException e1) { - throw new DVFactoryException("Schema factory class " + fFactoryClass + " not found."); + throw new DVFactoryException("Schema factory class " + factoryClass + " not found."); } catch (IllegalAccessException e2) { - throw new DVFactoryException("Schema factory class " + fFactoryClass + " found but cannot be loaded."); + throw new DVFactoryException("Schema factory class " + factoryClass + " found but cannot be loaded."); } catch (InstantiationException e3) { - throw new DVFactoryException("Schema factory class " + fFactoryClass + " loaded but cannot be instantiated (no empty public constructor?)."); + throw new DVFactoryException("Schema factory class " + factoryClass + " loaded but cannot be instantiated (no empty public constructor?)."); } catch (ClassCastException e4) { - throw new DVFactoryException("Schema factory class " + fFactoryClass + " does not extend from SchemaDVFactory."); + throw new DVFactoryException("Schema factory class " + factoryClass + " does not extend from SchemaDVFactory."); } - // return the newly created dv factory instance - return fFactoryInstance; } // can't create a new object of this class 1.5 +14 -36 xml-xerces/java/src/org/apache/xerces/impl/dv/DTDDVFactory.java Index: DTDDVFactory.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/DTDDVFactory.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DTDDVFactory.java 19 Mar 2002 15:49:11 -0000 1.4 +++ DTDDVFactory.java 24 Jul 2002 15:02:58 -0000 1.5 @@ -72,61 +72,39 @@ private static final String DEFAULT_FACTORY_CLASS = "org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl"; - private static String fFactoryClass = null; - private static DTDDVFactory fFactoryInstance = null; - /** - * Set the class name of the dtd factory implementation. This method - * can only be called before the first time the method <code>getInstance</code> - * successfully returns, otherwise a DVFactoryException will be thrown. + * Get an instance of the default DTDDVFactory implementation. * - * @param className the class name of the DTDDVFactory implementation - * @exception DVFactoryException the method cannot be called at this time + * @return an instance of DTDDVFactory implementation + * @exception DVFactoryException cannot create an instance of the specified + * class name or the default class name */ - public static synchronized final void setFactoryClass(String factoryClass) throws DVFactoryException { - // if the factory instance has been created, it's an error. - if (fFactoryInstance != null) - throw new DVFactoryException("Cannot set the class name now. The class name '"+fFactoryClass+"' is already used."); - - fFactoryClass = factoryClass; + public static synchronized final DTDDVFactory getInstance() throws DVFactoryException { + return getInstance(DEFAULT_FACTORY_CLASS); } /** * Get an instance of DTDDVFactory implementation. * - * If <code>setFactoryClass</code> is called before this method, - * the passed-in class name will be used to create the factory instance. - * Otherwise, a default implementation is used. - * - * After the first time this method successfully returns, any subsequent - * invocation to this method returns the same instance. - * + * @param factoryClass name of the implementation to load. * @return an instance of DTDDVFactory implementation * @exception DVFactoryException cannot create an instance of the specified * class name or the default class name */ - public static synchronized final DTDDVFactory getInstance() throws DVFactoryException { - // if the factory instance has been created, just return it. - if (fFactoryInstance != null) - return fFactoryInstance; + public static synchronized final DTDDVFactory getInstance(String factoryClass) throws DVFactoryException { try { // if the class name is not specified, use the default one - if (fFactoryClass == null) - fFactoryClass = DEFAULT_FACTORY_CLASS; - fFactoryInstance = (DTDDVFactory)(Class.forName(fFactoryClass).newInstance()); + return (DTDDVFactory)(Class.forName(factoryClass).newInstance()); } catch (ClassNotFoundException e1) { - throw new DVFactoryException("DTD factory class " + fFactoryClass + " not found."); + throw new DVFactoryException("DTD factory class " + factoryClass + " not found."); } catch (IllegalAccessException e2) { - throw new DVFactoryException("DTD factory class " + fFactoryClass + " found but cannot be loaded."); + throw new DVFactoryException("DTD factory class " + factoryClass + " found but cannot be loaded."); } catch (InstantiationException e3) { - throw new DVFactoryException("DTD factory class " + fFactoryClass + " loaded but cannot be instantiated (no empty public constructor?)."); + throw new DVFactoryException("DTD factory class " + factoryClass + " loaded but cannot be instantiated (no empty public constructor?)."); } catch (ClassCastException e4) { - throw new DVFactoryException("DTD factory class " + fFactoryClass + " does not extend from DTDDVFactory."); + throw new DVFactoryException("DTD factory class " + factoryClass + " does not extend from DTDDVFactory."); } - - // return the newly created dv factory instance - return fFactoryInstance; } // can't create a new object of this class
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]