< prev index next >
src/java.xml/share/classes/javax/xml/validation/SchemaFactoryFinder.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 32,41 ****
--- 32,42 ----
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Properties;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
+ import java.util.function.Supplier;
/**
* Implementation of {@link SchemaFactory#newInstance(String)}.
*
* @author <a href="Kohsuke.Kawaguchi@Sun.com">Kohsuke Kawaguchi</a>
*** 70,84 ****
}
/**
* <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>
--- 71,85 ----
}
/**
* <p>Conditional debug printing.</p>
*
! * @param msgGen Supplier function that returns debug message
*/
! private static void debugPrintln(Supplier<String> msgGen) {
if (debug) {
! System.err.println("JAXP: " + msgGen.get());
}
}
/**
* <p><code>ClassLoader</code> to use to find <code>SchemaFactory</code>.</p>
*** 104,126 ****
}
private void debugDisplayClassLoader() {
try {
if( classLoader == ss.getContextClassLoader() ) {
! debugPrintln("using thread context class loader ("+classLoader+") for search");
return;
}
} catch( Throwable unused ) {
// 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 SchemaFactory} object for the specified
* schema language.</p>
--- 105,127 ----
}
private void debugDisplayClassLoader() {
try {
if( classLoader == ss.getContextClassLoader() ) {
! debugPrintln(()->"using thread context class loader ("+classLoader+") for search");
return;
}
} catch( Throwable unused ) {
// 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 SchemaFactory} object for the specified
* schema language.</p>
*** 140,152 ****
if(schemaLanguage==null) {
throw new NullPointerException();
}
SchemaFactory f = _newFactory(schemaLanguage);
if (f != null) {
! debugPrintln("factory '" + f.getClass().getName() + "' was found for " + schemaLanguage);
} else {
! debugPrintln("unable to find a factory for " + schemaLanguage);
}
return f;
}
/**
--- 141,153 ----
if(schemaLanguage==null) {
throw new NullPointerException();
}
SchemaFactory f = _newFactory(schemaLanguage);
if (f != null) {
! debugPrintln(()->"factory '" + f.getClass().getName() + "' was found for " + schemaLanguage);
} else {
! debugPrintln(()->"unable to find a factory for " + schemaLanguage);
}
return f;
}
/**
*** 161,181 ****
String propertyName = SERVICE_CLASS.getName() + ":" + schemaLanguage;
// system property look up
try {
! debugPrintln("Looking up system property '"+propertyName+"'" );
String r = ss.getSystemProperty(propertyName);
if(r!=null) {
! debugPrintln("The value is '"+r+"'");
sf = createInstance(r, true);
if(sf!=null) return sf;
} else
! debugPrintln("The property is undefined.");
} catch( Throwable t ) {
if( debug ) {
! debugPrintln("failed to look up system property '"+propertyName+"'" );
t.printStackTrace();
}
}
String javah = ss.getSystemProperty( "java.home" );
--- 162,182 ----
String propertyName = SERVICE_CLASS.getName() + ":" + schemaLanguage;
// system property look up
try {
! debugPrintln(()->"Looking up system property '"+propertyName+"'" );
String r = ss.getSystemProperty(propertyName);
if(r!=null) {
! debugPrintln(()->"The value is '"+r+"'");
sf = createInstance(r, true);
if(sf!=null) return sf;
} else
! debugPrintln(()->"The property is undefined.");
} catch( Throwable t ) {
if( debug ) {
! debugPrintln(()->"failed to look up system property '"+propertyName+"'" );
t.printStackTrace();
}
}
String javah = ss.getSystemProperty( "java.home" );
*** 189,206 ****
synchronized(cacheProps){
if(firstTime){
File f=new File( configFile );
firstTime = false;
if(ss.doesFileExist(f)){
! debugPrintln("Read properties file " + f);
cacheProps.load(ss.getFileInputStream(f));
}
}
}
}
final String factoryClassName = cacheProps.getProperty(propertyName);
! debugPrintln("found " + factoryClassName + " in $java.home/conf/jaxp.properties");
if (factoryClassName != null) {
sf = createInstance(factoryClassName, true);
if(sf != null){
return sf;
--- 190,207 ----
synchronized(cacheProps){
if(firstTime){
File f=new File( configFile );
firstTime = false;
if(ss.doesFileExist(f)){
! debugPrintln(()->"Read properties file " + f);
cacheProps.load(ss.getFileInputStream(f));
}
}
}
}
final String factoryClassName = cacheProps.getProperty(propertyName);
! debugPrintln(()->"found " + factoryClassName + " in $java.home/conf/jaxp.properties");
if (factoryClassName != null) {
sf = createInstance(factoryClassName, true);
if(sf != null){
return sf;
*** 223,237 ****
return factoryImpl;
}
// platform default
if(schemaLanguage.equals("http://www.w3.org/2001/XMLSchema")) {
! debugPrintln("attempting to use the platform default XML Schema validator");
return createInstance("com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory", true);
}
! debugPrintln("all things were tried, but none was found. bailing out.");
return null;
}
/** <p>Create class using appropriate ClassLoader.</p>
*
--- 224,238 ----
return factoryImpl;
}
// platform default
if(schemaLanguage.equals("http://www.w3.org/2001/XMLSchema")) {
! debugPrintln(()->"attempting to use the platform default XML Schema validator");
return createInstance("com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory", true);
}
! debugPrintln(()->"all things were tried, but none was found. bailing out.");
return null;
}
/** <p>Create class using appropriate ClassLoader.</p>
*
*** 278,296 ****
}
SchemaFactory createInstance( String className, boolean useServicesMechanism ) {
SchemaFactory schemaFactory = null;
! debugPrintln("createInstance(" + className + ")");
// get Class from className
Class<?> clazz = createClass(className);
if (clazz == null) {
! debugPrintln("failed to getClass(" + className + ")");
return null;
}
! debugPrintln("loaded " + className + " from " + which(clazz));
// instantiate Class as a SchemaFactory
try {
if (!SchemaFactory.class.isAssignableFrom(clazz)) {
throw new ClassCastException(clazz.getName()
--- 279,297 ----
}
SchemaFactory createInstance( String className, boolean useServicesMechanism ) {
SchemaFactory schemaFactory = null;
! debugPrintln(()->"createInstance(" + className + ")");
// get Class from className
Class<?> clazz = createClass(className);
if (clazz == null) {
! debugPrintln(()->"failed to getClass(" + className + ")");
return null;
}
! debugPrintln(()->"loaded " + className + " from " + which(clazz));
// instantiate Class as a SchemaFactory
try {
if (!SchemaFactory.class.isAssignableFrom(clazz)) {
throw new ClassCastException(clazz.getName()
*** 301,323 ****
}
if (schemaFactory == null) {
schemaFactory = (SchemaFactory) clazz.newInstance();
}
} catch (ClassCastException classCastException) {
! debugPrintln("could not instantiate " + clazz.getName());
if (debug) {
classCastException.printStackTrace();
}
return null;
} catch (IllegalAccessException illegalAccessException) {
! debugPrintln("could not instantiate " + clazz.getName());
if (debug) {
illegalAccessException.printStackTrace();
}
return null;
} catch (InstantiationException instantiationException) {
! debugPrintln("could not instantiate " + clazz.getName());
if (debug) {
instantiationException.printStackTrace();
}
return null;
}
--- 302,324 ----
}
if (schemaFactory == null) {
schemaFactory = (SchemaFactory) clazz.newInstance();
}
} catch (ClassCastException classCastException) {
! debugPrintln(()->"could not instantiate " + clazz.getName());
if (debug) {
classCastException.printStackTrace();
}
return null;
} catch (IllegalAccessException illegalAccessException) {
! debugPrintln(()->"could not instantiate " + clazz.getName());
if (debug) {
illegalAccessException.printStackTrace();
}
return null;
} catch (InstantiationException instantiationException) {
! debugPrintln(()->"could not instantiate " + clazz.getName());
if (debug) {
instantiationException.printStackTrace();
}
return null;
}
< prev index next >