Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 51836 invoked from network); 9 Mar 2007 05:13:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Mar 2007 05:13:51 -0000 Received: (qmail 54275 invoked by uid 500); 9 Mar 2007 05:13:59 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 54233 invoked by uid 500); 9 Mar 2007 05:13:59 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 54222 invoked by uid 99); 9 Mar 2007 05:13:59 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Mar 2007 21:13:59 -0800 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Mar 2007 21:13:50 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id E94651A9838; Thu, 8 Mar 2007 21:13:29 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r516305 - in /geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream: FactoryLocator.java XMLInputFactory.java XMLOutputFactory.java Date: Fri, 09 Mar 2007 05:13:29 -0000 To: scm@geronimo.apache.org From: hogstrom@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070309051329.E94651A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: hogstrom Date: Thu Mar 8 21:13:28 2007 New Revision: 516305 URL: http://svn.apache.org/viewvc?view=rev&rev=516305 Log: Did some additional work on XMLInput/Output Factories Added: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java (with props) Modified: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/XMLInputFactory.java geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/XMLOutputFactory.java Added: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java?view=auto&rev=516305 ============================================================================== --- geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java (added) +++ geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java Thu Mar 8 21:13:28 2007 @@ -0,0 +1,131 @@ +/* + ** + ** Licensed to the Apache Software Foundation (ASF) under one + ** or more contributor license agreements. See the NOTICE file + ** distributed with this work for additional information + ** regarding copyright ownership. The ASF licenses this file + ** to you under the Apache License, Version 2.0 (the + ** "License"); you may not use this file except in compliance + ** with the License. You may obtain a copy of the License at + ** + ** http://www.apache.org/licenses/LICENSE-2.0 + ** + ** Unless required by applicable law or agreed to in writing, + ** software distributed under the License is distributed on an + ** "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ** KIND, either express or implied. See the License for the + ** specific language governing permissions and limitations + ** under the License. + */ +package javax.xml.stream; + +import java.io.InputStream; +import java.io.File; +import java.io.FileInputStream; + +import java.util.Properties; +import java.io.BufferedReader; +import java.io.InputStreamReader; + +/* + * Alrighty...here is the beef on the newInstance methods: + * + * 1. Use the javax.xml.stream.XMLInputFactory system property. 2. Use the + * properties file "lib/stax.properties" in the JRE directory. This + * configuration file is in standard java.util.Properties format and contains + * the fully qualified name of the implementation class with the key being the + * system property defined above. 3. Use the Services API (as detailed in the + * JAR specification), if available, to determine the classname. The Services + * API will look for a classname in the file + * META-INF/services/javax.xml.stream.XMLInputFactory in jars available to the + * runtime. Platform default XMLInputFactory instance. + * + * Once an application has obtained a reference to a XMLInputFactory it can use + * the factory to configure and obtain stream instances. + */ + +class FactoryLocator { + static Object locate(String factoryId) throws FactoryConfigurationError { + return locate(factoryId, null); + } + + static Object locate(String factoryId, String fallbackClassName) + throws FactoryConfigurationError { + return locate(factoryId, fallbackClassName, null); + } + + static Object locate(String factoryId, + String fallbackClassName, + ClassLoader classLoader) throws FactoryConfigurationError { + try { + String prop = System.getProperty(factoryId); + if (prop != null) { + return newInstance(prop, classLoader); + } + } catch (Exception e) { + } + + try { + String configFile = System.getProperty("java.home") + + File.separator + "lib" + File.separator + + "jaxp.properties"; + File f = new File(configFile); + if (f.exists()) { + Properties props = new Properties(); + props.load(new FileInputStream(f)); + String factoryClassName = props.getProperty(factoryId); + return newInstance(factoryClassName, classLoader); + } + } catch (Exception e) { + } + + String serviceId = "META-INF/services/" + factoryId; + try { + InputStream is = null; + + if (classLoader == null) { + is = ClassLoader.getSystemResourceAsStream(serviceId); + } else { + is = classLoader.getResourceAsStream(serviceId); + } + + if (is != null) { + BufferedReader br = new BufferedReader(new InputStreamReader( + is, "UTF-8")); + String factoryClassName = br.readLine(); + br.close(); + + if (factoryClassName != null && !"".equals(factoryClassName)) { + return newInstance(factoryClassName, classLoader); + } + } + } catch (Exception ex) { + } + + if (fallbackClassName == null) { + throw new FactoryConfigurationError("Unable to locate factory for " + + factoryId + ".", null); + } + return newInstance(fallbackClassName, classLoader); + } + + private static Object newInstance(String className, ClassLoader classLoader) + throws FactoryConfigurationError { + try { + Class spiClass; + if (classLoader == null) { + spiClass = Class.forName(className); + } else { + spiClass = classLoader.loadClass(className); + } + return spiClass.newInstance(); + } catch (ClassNotFoundException x) { + throw new FactoryConfigurationError("Requested factory " + + className + " cannot be located.", x); + } catch (Exception x) { + throw new FactoryConfigurationError("Requested factory " + + className + " could not be instantiated: " + x, x); + } + } + +} \ No newline at end of file Propchange: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/FactoryLocator.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/XMLInputFactory.java URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/XMLInputFactory.java?view=diff&rev=516305&r1=516304&r2=516305 ============================================================================== --- geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/XMLInputFactory.java (original) +++ geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/XMLInputFactory.java Thu Mar 8 21:13:28 2007 @@ -23,21 +23,13 @@ public abstract class XMLInputFactory { public static final java.lang.String ALLOCATOR = "javax.xml.stream.allocator"; - public static final java.lang.String IS_COALESCING = "javax.xml.stream.isCoalescing"; - public static final java.lang.String IS_NAMESPACE_AWARE = "javax.xml.stream.isNamespaceAware"; - public static final java.lang.String IS_REPLACING_ENTITY_REFERENCES = "javax.xml.stream.isReplacingEntityReferences"; - public static final java.lang.String IS_SUPPORTING_EXTERNAL_ENTITIES = "javax.xml.stream.isSupportingExternalEntities"; - public static final java.lang.String IS_VALIDATING = "javax.xml.stream.isValidating"; - public static final java.lang.String REPORTER = "javax.xml.stream.reporter"; - public static final java.lang.String RESOLVER = "javax.xml.stream.resolver"; - public static final java.lang.String SUPPORT_DTD = "javax.xml.stream.supportDTD"; protected XMLInputFactory() { @@ -45,14 +37,14 @@ public static XMLInputFactory newInstance() throws FactoryConfigurationError { - // TODO - Implement Factory Finder methods - return null; + // We'll assume the XMLInputFactory from the RI as a backup. + return (XMLInputFactory)FactoryLocator.locate("javax.xml.stream.XMLInputFactory", "com.bea.xml.stream.MXParserFactory"); } public static XMLInputFactory newInstance(java.lang.String factoryId, java.lang.ClassLoader classLoader) throws FactoryConfigurationError { - // TODO - Implement Factory Finder methods - return null; + // We'll assume the XMLInputFactory from the RI as a backup. + return (XMLInputFactory)FactoryLocator.locate(factoryId, "com.bea.xml.stream.MXParserFactory", classLoader); } public abstract XMLStreamReader createXMLStreamReader(java.io.Reader reader) Modified: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/XMLOutputFactory.java URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/XMLOutputFactory.java?view=diff&rev=516305&r1=516304&r2=516305 ============================================================================== --- geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/XMLOutputFactory.java (original) +++ geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/stream/XMLOutputFactory.java Thu Mar 8 21:13:28 2007 @@ -1,5 +1,52 @@ package javax.xml.stream; public abstract class XMLOutputFactory { + public static final String IS_REPAIRING_NAMESPACES = "javax.xml.stream.isRepairingNamespaces"; + public static XMLOutputFactory newInstance() + throws FactoryConfigurationError { + return (XMLOutputFactory) FactoryLocator.locate( + "javax.xml.stream.XMLOutputFactory", + "com.bea.xml.stream.MXParserFactory"); + } + + public static XMLOutputFactory newInstance(String factoryId, + java.lang.ClassLoader classLoader) throws FactoryConfigurationError { + return (XMLOutputFactory) FactoryLocator.locate(factoryId, + "com.bea.xml.stream.MXParserFactory", classLoader); + } + + public abstract XMLStreamWriter createXMLStreamWriter(java.io.Writer stream) + throws XMLStreamException; + + public abstract XMLStreamWriter createXMLStreamWriter( + java.io.OutputStream stream) throws XMLStreamException; + + public abstract XMLStreamWriter createXMLStreamWriter( + java.io.OutputStream stream, String encoding) + throws XMLStreamException; + + public abstract XMLStreamWriter createXMLStreamWriter( + javax.xml.transform.Result result) throws XMLStreamException; + + public abstract XMLEventWriter createXMLEventWriter( + javax.xml.transform.Result result) throws XMLStreamException; + + public abstract XMLEventWriter createXMLEventWriter( + java.io.OutputStream stream) throws XMLStreamException; + + public abstract XMLEventWriter createXMLEventWriter( + java.io.OutputStream stream, String encoding) + throws XMLStreamException; + + public abstract XMLEventWriter createXMLEventWriter(java.io.Writer stream) + throws XMLStreamException; + + public abstract void setProperty(String name, Object value) + throws IllegalArgumentException; + + public abstract Object getProperty(String name) + throws IllegalArgumentException; + + public abstract boolean isPropertySupported(String name); }