diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
commit | 97b8365cafc3a344a22d3980b8ed885f5c6d8357 (patch) | |
tree | 996a5f57d4a68c53473382e45cb22f574cb3e4db /libjava/classpath/javax/xml | |
parent | c648dedbde727ca3f883bb5fd773aa4af70d3369 (diff) | |
download | gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.zip gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.gz gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.bz2 |
Merged gcj-eclipse branch to trunk.
From-SVN: r120621
Diffstat (limited to 'libjava/classpath/javax/xml')
-rw-r--r-- | libjava/classpath/javax/xml/parsers/DocumentBuilderFactory.java | 2 | ||||
-rw-r--r-- | libjava/classpath/javax/xml/validation/SchemaFactory.java | 101 |
2 files changed, 102 insertions, 1 deletions
diff --git a/libjava/classpath/javax/xml/parsers/DocumentBuilderFactory.java b/libjava/classpath/javax/xml/parsers/DocumentBuilderFactory.java index 0dc574e..9312e65 100644 --- a/libjava/classpath/javax/xml/parsers/DocumentBuilderFactory.java +++ b/libjava/classpath/javax/xml/parsers/DocumentBuilderFactory.java @@ -50,7 +50,7 @@ import javax.xml.validation.Schema; * Factory for obtaining document builders. * Instances of this class are <em>not</em> guaranteed to be thread safe. * - * @author (a href='mailto:dog@gnu.org'>Chris Burdess</a) + * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> */ public abstract class DocumentBuilderFactory { diff --git a/libjava/classpath/javax/xml/validation/SchemaFactory.java b/libjava/classpath/javax/xml/validation/SchemaFactory.java index 0042ea3..0c24104 100644 --- a/libjava/classpath/javax/xml/validation/SchemaFactory.java +++ b/libjava/classpath/javax/xml/validation/SchemaFactory.java @@ -37,8 +37,14 @@ exception statement from your version. */ package javax.xml.validation; +import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; import java.net.URL; +import java.util.Properties; import javax.xml.XMLConstants; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; @@ -68,6 +74,71 @@ public abstract class SchemaFactory */ public static final SchemaFactory newInstance(String schemaLanguage) { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (loader == null) + { + loader = SchemaFactory.class.getClassLoader(); + } + final String factoryClassName = "javax.xml.validation.SchemaFactory"; + String className = null; + int count = 0; + do + { + className = getFactoryClassName(loader, schemaLanguage, count++); + if (className != null) + { + try + { + Class t = (loader != null) ? loader.loadClass(className) : + Class.forName(className); + return (SchemaFactory) t.newInstance(); + } + catch (Exception e) + { + // Ignore any errors and continue algorithm. + // This method doesn't have a means of propagating + // class instantiation errors. + className = null; + } + } + } + while (className == null && count < 2); + try + { + String serviceKey = "/META-INF/services/" + factoryClassName; + InputStream in = (loader != null) ? + loader.getResourceAsStream(serviceKey) : + SchemaFactory.class.getResourceAsStream(serviceKey); + if (in != null) + { + BufferedReader r = + new BufferedReader(new InputStreamReader(in)); + try + { + for (String line = r.readLine(); line != null; + line = r.readLine()) + { + Class t = (loader != null) ? loader.loadClass(className) : + Class.forName(className); + SchemaFactory ret = (SchemaFactory) t.newInstance(); + if (ret.isSchemaLanguageSupported(schemaLanguage)) + return ret; + } + } + catch (Exception e) + { + // Fall through. See above. + } + finally + { + r.close(); + } + } + } + catch (IOException e) + { + } + // Default schema factories for Classpath if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schemaLanguage)) return new gnu.xml.validation.xmlschema.XMLSchemaSchemaFactory(); if (XMLConstants.RELAXNG_NS_URI.equals(schemaLanguage)) @@ -75,6 +146,36 @@ public abstract class SchemaFactory throw new IllegalArgumentException(schemaLanguage); } + private static String getFactoryClassName(ClassLoader loader, + String schemaLanguage, int attempt) + { + final String factoryClassName = "javax.xml.validation.SchemaFactory"; + final String propertyName = factoryClassName + ":" + schemaLanguage; + switch (attempt) + { + case 0: + return System.getProperty(propertyName); + case 1: + try + { + File file = new File(System.getProperty("java.home")); + file = new File(file, "lib"); + file = new File(file, "jaxp.properties"); + InputStream in = new FileInputStream(file); + Properties props = new Properties(); + props.load(in); + in.close(); + return props.getProperty(propertyName); + } + catch (IOException e) + { + return null; + } + default: + return null; + } + } + /** * Indicates whether the specified schema language is supported. * @param schemaLanguage the URI of a schema language (see |