You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/10/23 13:47:20 UTC

svn commit: r707355 [2/2] - in /servicemix/smx4/specs/trunk: ./ jaxp-api-1.3/ jaxp-api-1.3/src/ jaxp-api-1.3/src/main/ jaxp-api-1.3/src/main/java/ jaxp-api-1.3/src/main/java/javax/ jaxp-api-1.3/src/main/java/javax/xml/ jaxp-api-1.3/src/main/java/javax/...

Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/xpath/SecuritySupport.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/xpath/SecuritySupport.java?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/xpath/SecuritySupport.java (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/xpath/SecuritySupport.java Thu Oct 23 04:47:18 2008
@@ -0,0 +1,160 @@
+/*
+ * 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.
+ */
+// $Id: SecuritySupport.java 446598 2006-09-15 12:55:40Z jeremias $
+
+package javax.xml.xpath;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Enumeration;
+
+/**
+ * This class is duplicated for each JAXP subpackage so keep it in sync.
+ * It is package private and therefore is not exposed as part of the JAXP
+ * API.
+ *
+ * Security related methods that only work on J2SE 1.2 and newer.
+ */
+final class SecuritySupport  {
+    
+    private SecuritySupport() {}
+    
+    static ClassLoader getContextClassLoader() {
+	return (ClassLoader)
+		AccessController.doPrivileged(new PrivilegedAction() {
+	    public Object run() {
+		ClassLoader cl = null;
+		try {
+		    cl = Thread.currentThread().getContextClassLoader();
+		} catch (SecurityException ex) { }
+		return cl;
+	    }
+	});
+    }
+
+    static String getSystemProperty(final String propName) {
+	return (String)
+            AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    return System.getProperty(propName);
+                }
+            });
+    }
+
+    static FileInputStream getFileInputStream(final File file)
+        throws FileNotFoundException
+    {
+	try {
+            return (FileInputStream)
+                AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                    public Object run() throws FileNotFoundException {
+                        return new FileInputStream(file);
+                    }
+                });
+	} catch (PrivilegedActionException e) {
+	    throw (FileNotFoundException)e.getException();
+	}
+    }
+
+    static InputStream getURLInputStream(final URL url)
+        throws IOException
+    {
+	try {
+            return (InputStream)
+                AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                    public Object run() throws IOException {
+                        return url.openStream();
+                    }
+                });
+	} catch (PrivilegedActionException e) {
+	    throw (IOException)e.getException();
+	}
+    }
+
+    static URL getResourceAsURL(final ClassLoader cl,
+                                final String name)
+    {
+        return (URL)
+            AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    URL url;
+                    if (cl == null) {
+                        url = ClassLoader.getSystemResource(name);
+                    } else {
+                        url = cl.getSystemResource(name);
+                    }
+                    return url;
+                }
+            });
+    }
+
+    static Enumeration getResources(final ClassLoader cl,
+                                    final String name) throws IOException
+    {
+        try{
+        return (Enumeration)
+            AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                public Object run() throws IOException{
+                    Enumeration enumeration;
+                    if (cl == null) {
+                        enumeration = ClassLoader.getSystemResources(name);
+                    } else {
+                        enumeration = cl.getSystemResources(name);
+                    }
+                    return enumeration;
+                }
+            });
+        }catch(PrivilegedActionException e){
+            throw (IOException)e.getException();
+        }
+    }
+    
+    static InputStream getResourceAsStream(final ClassLoader cl,
+                                           final String name)
+    {
+        return (InputStream)
+            AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    InputStream ris;
+                    if (cl == null) {
+                        ris = ClassLoader.getSystemResourceAsStream(name);
+                    } else {
+                        ris = cl.getResourceAsStream(name);
+                    }
+                    return ris;
+                }
+            });
+    }
+
+    static boolean doesFileExist(final File f) {
+    return ((Boolean)
+            AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    return f.exists() ? Boolean.TRUE : Boolean.FALSE;
+                }
+            })).booleanValue();
+    }
+
+}

Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/xpath/XPathFactoryFinder.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/xpath/XPathFactoryFinder.java?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/xpath/XPathFactoryFinder.java (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/javax/xml/xpath/XPathFactoryFinder.java Thu Oct 23 04:47:18 2008
@@ -0,0 +1,437 @@
+/*
+ * 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.
+ */
+// $Id: XPathFactoryFinder.java 446598 2006-09-15 12:55:40Z jeremias $
+
+package javax.xml.xpath;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.Properties;
+
+import javax.xml.validation.SchemaFactory;
+
+/**
+ * Implementation of {@link XPathFactory#newInstance(String)}.
+ * 
+ * @author <a href="Kohsuke.Kawaguchi@Sun.com">Kohsuke Kawaguchi</a>
+ * @version $Revision: 446598 $, $Date: 2006-09-15 08:55:40 -0400 (Fri, 15 Sep 2006) $
+ * @since 1.5
+ */
+final class XPathFactoryFinder {
+    
+    /** debug support code. */
+    private static boolean debug = false;
+    
+    /**
+     * Default columns per line.
+     */
+    private static final int DEFAULT_LINE_LENGTH = 80;
+    
+    static {
+        // Use try/catch block to support applets
+        try {
+            String val = SecuritySupport.getSystemProperty("jaxp.debug");
+            // Allow simply setting the prop to turn on debug
+            debug = val != null && (! "false".equals(val));
+        } catch (Exception _) {
+            debug = false;
+        }
+    }
+
+    /**
+     * <p>Cache properties for performance.</p>
+     */
+	private static Properties cacheProps = new Properties();
+    
+	/**
+	 * <p>First time requires initialization overhead.</p>
+	 */
+	private static boolean firstTime = true;
+    
+    /**
+     * <p>Conditional debug printing.</p>
+     * 
+     * @param msg to print
+     */
+    private static void debugPrintln(String msg) {
+        if (debug) {
+            System.err.println("JAXP: " + msg);
+        }
+    }
+    
+    /**
+     * <p><code>ClassLoader</code> to use to find <code>SchemaFactory</code>.</p>
+     */
+    private final ClassLoader classLoader;
+    
+    /**
+     * <p>Constructor that specifies <code>ClassLoader</code> to use
+     * to find <code>SchemaFactory</code>.</p>
+     * 
+     * @param loader
+     *      to be used to load resource, {@link SchemaFactory}, and
+     *      {@link SchemaFactoryLoader} implementations during
+     *      the resolution process.
+     *      If this parameter is null, the default system class loader
+     *      will be used.
+     */
+    public XPathFactoryFinder(ClassLoader loader) {
+        this.classLoader = loader;
+        if( debug ) {
+            debugDisplayClassLoader();
+        }
+    }
+    
+    private void debugDisplayClassLoader() {
+        try {
+            if( classLoader == SecuritySupport.getContextClassLoader() ) {
+                debugPrintln("using thread context class loader ("+classLoader+") for search");
+                return;
+            }
+        } catch( Throwable _ ) {
+            ; // getContextClassLoader() undefined in JDK1.1 
+        }
+        
+        if( classLoader==ClassLoader.getSystemClassLoader() ) {
+            debugPrintln("using system class loader ("+classLoader+") for search");
+            return;
+        }
+
+        debugPrintln("using class loader ("+classLoader+") for search");
+    }
+    
+    /**
+     * <p>Creates a new {@link XPathFactory} object for the specified
+     * schema language.</p>
+     * 
+     * @param uri
+     *       Identifies the underlying object model.
+     * 
+     * @return <code>null</code> if the callee fails to create one.
+     * 
+     * @throws NullPointerException
+     *      If the parameter is null.
+     */
+    public XPathFactory newFactory(String uri) {
+        if(uri==null)        throw new NullPointerException();
+        XPathFactory f = _newFactory(uri);
+        if (debug) {
+            if (f != null) {
+                debugPrintln("factory '" + f.getClass().getName() + "' was found for " + uri);
+            } else {
+                debugPrintln("unable to find a factory for " + uri);
+            }
+        }
+        return f;
+    }
+    
+    /**
+     * <p>Lookup a {@link XPathFactory} for the given object model.</p>
+     * 
+     * @param uri identifies the object model.
+     *  
+     * @return {@link XPathFactory} for the given object model.
+     */
+    private XPathFactory _newFactory(String uri) {
+        XPathFactory sf;
+        
+        String propertyName = SERVICE_CLASS.getName() + ":" + uri;
+        
+        try {
+            // If we are deployed into an OSGi environment, leverage it
+            Class spiClass = org.apache.servicemix.specs.locator.OsgiLocator.locate(propertyName);
+            if (spiClass != null) {
+                return (XPathFactory) spiClass.newInstance();
+            }
+        } catch (Throwable e) {
+        }
+
+        // system property look up
+        try {
+            if (debug) debugPrintln("Looking up system property '"+propertyName+"'" );
+            String r = SecuritySupport.getSystemProperty(propertyName);
+            if(r!=null) {
+                if (debug) debugPrintln("The value is '"+r+"'");
+                sf = createInstance(r);
+                if(sf!=null)    return sf;
+            } 
+            else if (debug) {
+                debugPrintln("The property is undefined.");
+            }
+        } catch( Throwable t ) {
+            if( debug ) {
+                debugPrintln("failed to look up system property '"+propertyName+"'" );
+                t.printStackTrace();
+            }
+        }
+        
+        String javah = SecuritySupport.getSystemProperty( "java.home" );
+        String configFile = javah + File.separator +
+        "lib" + File.separator + "jaxp.properties";
+
+        String factoryClassName = null ;
+
+        // try to read from $java.home/lib/jaxp.properties
+        try {
+            if(firstTime){
+                synchronized(cacheProps){
+                    if(firstTime){
+                        File f=new File( configFile );
+                        firstTime = false;
+                        if(SecuritySupport.doesFileExist(f)){
+                            if (debug) debugPrintln("Read properties file " + f);                                
+                            cacheProps.load(SecuritySupport.getFileInputStream(f));
+                        }
+                    }
+                }
+            }
+            factoryClassName = cacheProps.getProperty(propertyName);            
+            if (debug) debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties"); 
+
+            if (factoryClassName != null) {
+                sf = createInstance(factoryClassName);
+                if(sf != null){
+                    return sf;
+                }
+            }
+        } catch (Exception ex) {
+            if (debug) {
+                ex.printStackTrace();
+            } 
+        }
+                    
+        // try META-INF/services files
+        Iterator sitr = createServiceFileIterator();
+        while(sitr.hasNext()) {
+            URL resource = (URL)sitr.next();
+            if (debug) debugPrintln("looking into " + resource);
+            try {
+                sf = loadFromServicesFile(uri, resource.toExternalForm(), SecuritySupport.getURLInputStream(resource));
+                if(sf!=null)    return sf;
+            } catch(IOException e) {
+                if( debug ) {
+                    debugPrintln("failed to read "+resource);
+                    e.printStackTrace();
+                }
+            }
+        }
+        
+        // platform default
+        if(uri.equals(XPathFactory.DEFAULT_OBJECT_MODEL_URI)) {
+            if (debug) debugPrintln("attempting to use the platform default W3C DOM XPath lib");
+            return createInstance("org.apache.xpath.jaxp.XPathFactoryImpl");
+        }
+        
+        if (debug) debugPrintln("all things were tried, but none was found. bailing out.");
+        return null;
+    }
+    
+    /**
+     * <p>Creates an instance of the specified and returns it.</p>
+     * 
+     * @param className
+     *      fully qualified class name to be instanciated.
+     * 
+     * @return null
+     *      if it fails. Error messages will be printed by this method. 
+     */
+    private XPathFactory createInstance( String className ) {
+        try {
+            if (debug) debugPrintln("instanciating "+className);
+            Class clazz;
+            if( classLoader!=null )
+                clazz = classLoader.loadClass(className);
+            else
+                clazz = Class.forName(className);
+            if(debug)       debugPrintln("loaded it from "+which(clazz));
+            Object o = clazz.newInstance();
+            
+            if( o instanceof XPathFactory )
+                return (XPathFactory)o;
+            
+            if (debug) debugPrintln(className+" is not assignable to "+SERVICE_CLASS.getName());
+        } catch( Throwable t ) {
+            if (debug) {
+                debugPrintln("failed to instanciate "+className);
+                t.printStackTrace();
+            }
+        }
+        return null;
+    }
+    
+    /** Iterator that lazily computes one value and returns it. */
+    private static abstract class SingleIterator implements Iterator {
+        private boolean seen = false;
+        
+        public final void remove() { throw new UnsupportedOperationException(); }
+        public final boolean hasNext() { return !seen; }
+        public final Object next() {
+            if(seen)    throw new NoSuchElementException();
+            seen = true;
+            return value();
+        }
+        
+        protected abstract Object value();
+    }
+    
+    /** Searches for a XPathFactory for a given uri in a META-INF/services file. */
+    private XPathFactory loadFromServicesFile(String uri, String resourceName, InputStream in) {
+
+        if (debug) debugPrintln("Reading " + resourceName );
+        
+        BufferedReader rd;
+        try {
+            rd = new BufferedReader(new InputStreamReader(in, "UTF-8"), DEFAULT_LINE_LENGTH);
+        } catch (java.io.UnsupportedEncodingException e) {
+            rd = new BufferedReader(new InputStreamReader(in), DEFAULT_LINE_LENGTH);
+        }
+        
+        String factoryClassName = null;
+        XPathFactory resultFactory = null;
+        // See spec for provider-configuration files: http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Provider%20Configuration%20File
+        while (true) {
+            try {
+                factoryClassName = rd.readLine();   
+            } catch (IOException x) {
+                // No provider found
+                break;
+            }
+            if (factoryClassName != null) {
+                // Ignore comments in the provider-configuration file
+                int hashIndex = factoryClassName.indexOf('#');
+                if (hashIndex != -1) {
+                    factoryClassName = factoryClassName.substring(0, hashIndex);
+                }
+                
+                // Ignore leading and trailing whitespace
+                factoryClassName = factoryClassName.trim();
+                
+                // If there's no text left or if this was a blank line, go to the next one.
+                if (factoryClassName.length() == 0) {
+                    continue;
+                }
+                
+                try {
+                    // Found the right XPathFactory if its isObjectModelSupported(String uri) method returns true.
+                    XPathFactory foundFactory = (XPathFactory) createInstance(factoryClassName);
+                    if (foundFactory.isObjectModelSupported(uri)) {
+                        resultFactory = foundFactory;
+                        break;
+                    }
+                }
+                catch (Exception e) {}
+            }
+            else {
+                break;
+            }
+        }
+        
+        try {
+            // try to close the reader.
+            rd.close();
+        }
+        // Ignore the exception.
+        catch (IOException exc) {}
+        
+        return resultFactory;
+    }
+        
+    /**
+     * Returns an {@link Iterator} that enumerates all 
+     * the META-INF/services files that we care.
+     */
+    private Iterator createServiceFileIterator() {
+        if (classLoader == null) {
+            return new SingleIterator() {
+                protected Object value() {
+                    ClassLoader classLoader = XPathFactoryFinder.class.getClassLoader();
+                    return SecuritySupport.getResourceAsURL(classLoader, SERVICE_ID);
+                    //return (ClassLoader.getSystemResource( SERVICE_ID ));
+                }
+            };
+        } else {
+            try {
+                //final Enumeration e = classLoader.getResources(SERVICE_ID);
+                final Enumeration e = SecuritySupport.getResources(classLoader, SERVICE_ID);
+                if (debug && !e.hasMoreElements()) {
+                    debugPrintln("no "+SERVICE_ID+" file was found");
+                }
+                
+                // wrap it into an Iterator.
+                return new Iterator() {
+                    public void remove() {
+                        throw new UnsupportedOperationException();
+                    }
+
+                    public boolean hasNext() {
+                        return e.hasMoreElements();
+                    }
+
+                    public Object next() {
+                        return e.nextElement();
+                    }
+                };
+            } catch (IOException e) {
+                if (debug) {
+                    debugPrintln("failed to enumerate resources "+SERVICE_ID);
+                    e.printStackTrace();
+                }
+                return new ArrayList().iterator();  // empty iterator
+            }
+        }
+    }
+    
+    private static final Class SERVICE_CLASS = XPathFactory.class;
+    private static final String SERVICE_ID = "META-INF/services/" + SERVICE_CLASS.getName();
+    
+    
+    
+    private static String which( Class clazz ) {
+        return which( clazz.getName(), clazz.getClassLoader() );
+    }
+
+    /**
+     * <p>Search the specified classloader for the given classname.</p>
+     *
+     * @param classname the fully qualified name of the class to search for
+     * @param loader the classloader to search
+     * 
+     * @return the source location of the resource, or null if it wasn't found
+     */
+    private static String which(String classname, ClassLoader loader) {
+
+        String classnameAsResource = classname.replace('.', '/') + ".class";
+        
+        if( loader==null )  loader = ClassLoader.getSystemClassLoader();
+        
+        //URL it = loader.getResource(classnameAsResource);
+        URL it = SecuritySupport.getResourceAsURL(loader, classnameAsResource);
+        if (it != null) {
+            return it.toString();
+        } else {
+            return null;
+        }
+    }
+}

Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/w3c/dom/html/HTMLDOMImplementation.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/w3c/dom/html/HTMLDOMImplementation.java?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/w3c/dom/html/HTMLDOMImplementation.java (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/w3c/dom/html/HTMLDOMImplementation.java Thu Oct 23 04:47:18 2008
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2000 World Wide Web Consortium,
+ * (Massachusetts Institute of Technology, Institut National de
+ * Recherche en Informatique et en Automatique, Keio University). All
+ * Rights Reserved. This program is distributed under the W3C's Software
+ * Intellectual Property License. This program is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See W3C License http://www.w3.org/Consortium/Legal/ for more
+ * details.
+ */
+
+package org.w3c.dom.html;
+
+import org.w3c.dom.DOMImplementation;
+
+/**
+ *  The <code>HTMLDOMImplementation</code> interface extends the 
+ * <code>DOMImplementation</code> interface with a method for creating an 
+ * HTML document instance.
+ * <p>See also the <a href='http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510'>Document Object Model (DOM) Level 2 Specification</a>.
+ * @since DOM Level 2
+ */
+public interface HTMLDOMImplementation extends DOMImplementation {
+    /**
+     *  Creates an <code>HTMLDocument</code> object with the minimal tree made 
+     * of the following elements: <code>HTML</code> , <code>HEAD</code> , 
+     * <code>TITLE</code> , and <code>BODY</code> .
+     * @param title  The title of the document to be set as the content of the 
+     *   <code>TITLE</code> element, through a child <code>Text</code> node.
+     * @return  A new <code>HTMLDocument</code> object.
+     */
+    public HTMLDocument createHTMLDocument(String title);
+
+}
+

Added: servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/xml/sax/helpers/XMLReaderFactory.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/xml/sax/helpers/XMLReaderFactory.java?rev=707355&view=auto
==============================================================================
--- servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/xml/sax/helpers/XMLReaderFactory.java (added)
+++ servicemix/smx4/specs/trunk/jaxp-api-1.3/src/main/java/org/xml/sax/helpers/XMLReaderFactory.java Thu Oct 23 04:47:18 2008
@@ -0,0 +1,255 @@
+// XMLReaderFactory.java - factory for creating a new reader.
+// http://www.saxproject.org
+// Written by David Megginson
+// and by David Brownell
+// NO WARRANTY!  This class is in the Public Domain.
+// $Id: XMLReaderFactory.java 226251 2005-06-21 19:19:22Z mrglavas $
+
+package org.xml.sax.helpers;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import org.xml.sax.XMLReader;
+import org.xml.sax.SAXException;
+
+
+/**
+ * Factory for creating an XML reader.
+ *
+ * <blockquote>
+ * <em>This module, both source code and documentation, is in the
+ * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
+ * See <a href='http://www.saxproject.org'>http://www.saxproject.org</a>
+ * for further information.
+ * </blockquote>
+ *
+ * <p>This class contains static methods for creating an XML reader
+ * from an explicit class name, or based on runtime defaults:</p>
+ *
+ * <pre>
+ * try {
+ *   XMLReader myReader = XMLReaderFactory.createXMLReader();
+ * } catch (SAXException e) {
+ *   System.err.println(e.getMessage());
+ * }
+ * </pre>
+ *
+ * <p><strong>Note to Distributions bundled with parsers:</strong>
+ * You should modify the implementation of the no-arguments
+ * <em>createXMLReader</em> to handle cases where the external
+ * configuration mechanisms aren't set up.  That method should do its
+ * best to return a parser when one is in the class path, even when
+ * nothing bound its class name to <code>org.xml.sax.driver</code> so
+ * those configuration mechanisms would see it.</p>
+ *
+ * @since SAX 2.0
+ * @author David Megginson, David Brownell
+ * @version 2.0.1 (sax2r2)
+ */
+final public class XMLReaderFactory
+{
+    /**
+     * Private constructor.
+     *
+     * <p>This constructor prevents the class from being instantiated.</p>
+     */
+    private XMLReaderFactory ()
+    {
+    }
+    
+    private static final String property = "org.xml.sax.driver";
+    
+    /**
+     * Default columns per line.
+     */
+    private static final int DEFAULT_LINE_LENGTH = 80;
+    
+    /**
+     * Attempt to create an XMLReader from system defaults.
+     * In environments which can support it, the name of the XMLReader
+     * class is determined by trying each these options in order, and
+     * using the first one which succeeds:</p> <ul>
+     *
+     * <li>If the system property <code>org.xml.sax.driver</code>
+     * has a value, that is used as an XMLReader class name. </li>
+     *
+     * <li>The JAR "Services API" is used to look for a class name
+     * in the <em>META-INF/services/org.xml.sax.driver</em> file in
+     * jarfiles available to the runtime.</li>
+     *
+     * <li> SAX parser distributions are strongly encouraged to provide
+     * a default XMLReader class name that will take effect only when
+     * previous options (on this list) are not successful.</li>
+     *
+     * <li>Finally, if {@link ParserFactory#makeParser()} can
+     * return a system default SAX1 parser, that parser is wrapped in
+     * a {@link ParserAdapter}.  (This is a migration aid for SAX1
+     * environments, where the <code>org.xml.sax.parser</code> system
+     * property will often be usable.) </li>
+     *
+     * </ul>
+     *
+     * <p> In environments such as small embedded systems, which can not
+     * support that flexibility, other mechanisms to determine the default
+     * may be used. </p>
+     *
+     * <p>Note that many Java environments allow system properties to be
+     * initialized on a command line.  This means that <em>in most cases</em>
+     * setting a good value for that property ensures that calls to this
+     * method will succeed, except when security policies intervene.
+     * This will also maximize application portability to older SAX
+     * environments, with less robust implementations of this method.
+     * </p>
+     *
+     * @return A new XMLReader.
+     * @exception org.xml.sax.SAXException If no default XMLReader class
+     *            can be identified and instantiated.
+     * @see #createXMLReader(java.lang.String)
+     */
+    public static XMLReader createXMLReader ()
+    throws SAXException
+    {
+        String		className = null;
+        SecuritySupport ss = SecuritySupport.getInstance();
+        ClassLoader	loader = NewInstance.getClassLoader ();
+        
+        // 1. try the JVM-instance-wide system property
+        try { className = ss.getSystemProperty (property); }
+        catch (Exception e) { /* normally fails for applets */ }
+        
+        // 2. if that fails, try META-INF/services/
+        if (className == null) {
+            String      service = "META-INF/services/" + property;
+            
+            InputStream is = null;
+            
+            // First try the Context ClassLoader
+            ClassLoader cl = ss.getContextClassLoader();
+            if (cl != null) {
+                is = ss.getResourceAsStream(cl, service);
+                
+                // If no provider found then try the current ClassLoader
+                if (is == null) {
+                    cl = XMLReaderFactory.class.getClassLoader();
+                    is = ss.getResourceAsStream(cl, service);
+                }
+            } else {
+                // No Context ClassLoader or JDK 1.1 so try the current
+                // ClassLoader
+                cl = XMLReaderFactory.class.getClassLoader();
+                is = ss.getResourceAsStream(cl, service);
+            }
+            
+            if (is != null) {
+                
+                // Read the service provider name in UTF-8 as specified in
+                // the jar spec.  Unfortunately this fails in Microsoft
+                // VJ++, which does not implement the UTF-8
+                // encoding. Theoretically, we should simply let it fail in
+                // that case, since the JVM is obviously broken if it
+                // doesn't support such a basic standard.  But since there
+                // are still some users attempting to use VJ++ for
+                // development, we have dropped in a fallback which makes a
+                // second attempt using the platform's default encoding. In
+                // VJ++ this is apparently ASCII, which is a subset of
+                // UTF-8... and since the strings we'll be reading here are
+                // also primarily limited to the 7-bit ASCII range (at
+                // least, in English versions), this should work well
+                // enough to keep us on the air until we're ready to
+                // officially decommit from VJ++. [Edited comment from
+                // jkesselm]
+                BufferedReader rd;
+                try {
+                    rd = new BufferedReader(new InputStreamReader(is, "UTF-8"), DEFAULT_LINE_LENGTH);
+                } catch (java.io.UnsupportedEncodingException e) {
+                    rd = new BufferedReader(new InputStreamReader(is), DEFAULT_LINE_LENGTH);
+                }
+                
+                try {
+                    // XXX Does not handle all possible input as specified by the
+                    // Jar Service Provider specification
+                    className = rd.readLine();
+                } 
+                catch (Exception x) {
+                    // No provider found
+                } 
+                finally {
+                    try { 
+                        // try to close the reader. 
+                        rd.close(); 
+                    } 
+                    // Ignore the exception. 
+                    catch (IOException exc) {}
+                }
+            }
+        }
+        
+        // 3. Distro-specific fallback
+        if (className == null) {
+            // BEGIN DISTRIBUTION-SPECIFIC
+            
+            // EXAMPLE:
+            // className = "com.example.sax.XmlReader";
+            // or a $JAVA_HOME/jre/lib/*properties setting...
+            className = "org.apache.xerces.parsers.SAXParser";
+            
+            // END DISTRIBUTION-SPECIFIC
+        }
+        
+        // do we know the XMLReader implementation class yet?
+        if (className != null)
+            return loadClass (loader, className);
+        
+        // 4. panic -- adapt any SAX1 parser
+        try {
+            return new ParserAdapter (ParserFactory.makeParser ());
+        } catch (Exception e) {
+            throw new SAXException ("Can't create default XMLReader; "
+                    + "is system property org.xml.sax.driver set?");
+        }
+    }
+    
+    
+    /**
+     * Attempt to create an XML reader from a class name.
+     *
+     * <p>Given a class name, this method attempts to load
+     * and instantiate the class as an XML reader.</p>
+     *
+     * <p>Note that this method will not be usable in environments where
+     * the caller (perhaps an applet) is not permitted to load classes
+     * dynamically.</p>
+     *
+     * @return A new XML reader.
+     * @exception org.xml.sax.SAXException If the class cannot be
+     *            loaded, instantiated, and cast to XMLReader.
+     * @see #createXMLReader()
+     */
+    public static XMLReader createXMLReader (String className)
+    throws SAXException
+    {
+        return loadClass (NewInstance.getClassLoader (), className);
+    }
+    
+    private static XMLReader loadClass (ClassLoader loader, String className)
+    throws SAXException
+    {
+        try {
+            return (XMLReader) NewInstance.newInstance (loader, className);
+        } catch (ClassNotFoundException e1) {
+            throw new SAXException("SAX2 driver class " + className +
+                    " not found", e1);
+        } catch (IllegalAccessException e2) {
+            throw new SAXException("SAX2 driver class " + className +
+                    " found but cannot be loaded", e2);
+        } catch (InstantiationException e3) {
+            throw new SAXException("SAX2 driver class " + className +
+                    " loaded but cannot be instantiated (no empty public constructor?)",
+                    e3);
+        } catch (ClassCastException e4) {
+            throw new SAXException("SAX2 driver class " + className +
+                    " does not implement XMLReader", e4);
+        }
+    }
+}

Modified: servicemix/smx4/specs/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/pom.xml?rev=707355&r1=707354&r2=707355&view=diff
==============================================================================
--- servicemix/smx4/specs/trunk/pom.xml (original)
+++ servicemix/smx4/specs/trunk/pom.xml Thu Oct 23 04:47:18 2008
@@ -40,6 +40,7 @@
         <module>stax-api-1.0</module>
         <module>jaxb-api-2.0</module>
         <module>jaxb-api-2.1</module>
+        <module>jaxp-api-1.3</module>
         <module>jaxws-api-2.0</module>
         <module>jaxws-api-2.1</module>
         <module>jbi-api-1.0</module>