You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geronimo.apache.org by Jason Dillon <ja...@planet57.com> on 2007/03/09 06:22:42 UTC
Re: 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
Why are all of these new bits adorned this odd header with ** stuff?
I thought this was the std header to be used:
<snip>
/**
* 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.
*/
</snip>
--jason
On Mar 8, 2007, at 9:13 PM, hogstrom@apache.org wrote:
> 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);
> }
>
>