/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Implementation of {@link SchemaFactory#newInstance(String)}.
*
* @author <a href="Kohsuke.Kawaguchi@Sun.com">Kohsuke Kawaguchi</a>
* @version $Revision: 1.8 $, $Date: 2010-11-01 04:36:13 $
* @since 1.5
*/
class SchemaFactoryFinder {
/** debug support code. */
private static boolean debug = false;
/**
*<p> Take care of restrictions imposed by java security model </p>
*/
/**
* <p>Cache properties for performance.</p>
*/
/**
* <p>First time requires initialization overhead.</p>
*/
private static volatile boolean firstTime = true;
static {
try {
} catch (Exception _) {
debug = false;
}
}
/**
* <p>Conditional debug printing.</p>
*
* @param msg to print
*/
if (debug) {
}
}
/**
* <p><code>ClassLoader</code> to use to find <code>SchemaFactory</code>.</p>
*/
/**
* <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.
*/
this.classLoader = loader;
if( debug ) {
}
}
private void debugDisplayClassLoader() {
try {
return;
}
} catch( Throwable _ ) {
; // getContextClassLoader() undefined in JDK1.1
}
return;
}
}
/**
* <p>Creates a new {@link SchemaFactory} object for the specified
* schema language.</p>
*
* @param schemaLanguage
* See {@link SchemaFactory Schema Language} table in <code>SchemaFactory</code>
* for the list of available schema languages.
*
* @return <code>null</code> if the callee fails to create one.
*
* @throws NullPointerException
* If the <code>schemaLanguage</code> parameter is null.
*/
if (f != null) {
} else {
}
return f;
}
/**
* <p>Lookup a <code>SchemaFactory</code> for the given <code>schemaLanguage</code>.</p>
*
* @param schemaLanguage Schema language to lookup <code>SchemaFactory</code> for.
*
* @return <code>SchemaFactory</code> for the given <code>schemaLanguage</code>.
*/
// system property look up
try {
if(r!=null) {
sf = createInstance(r, true);
} else
debugPrintln("The property is undefined.");
} catch( Throwable t ) {
if( debug ) {
t.printStackTrace();
}
}
// try to read from $java.home/lib/jaxp.properties
try {
if(firstTime){
synchronized(cacheProps){
if(firstTime){
firstTime = false;
if(ss.doesFileExist(f)){
debugPrintln("Read properties file " + f);
}
}
}
}
if (factoryClassName != null) {
return sf;
}
}
if (debug) {
}
}
try {
} catch(IOException e) {
if( debug ) {
e.printStackTrace();
}
}
}
// platform default
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>
*
* @param className Name of class to create.
* @return Created class or <code>null</code>.
*/
// make sure we have access to restricted packages
boolean internal = false;
internal = true;
}
}
try {
} else {
}
} catch (Throwable t) {
if(debug) t.printStackTrace();
return null;
}
return clazz;
}
/**
* <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.
*/
return createInstance( className, false );
}
// get Class from className
return null;
}
// instantiate Class as a SchemaFactory
try {
if (!useServicesMechanism) {
}
if (schemaFactory == null) {
}
} catch (ClassCastException classCastException) {
if (debug) {
}
return null;
} catch (IllegalAccessException illegalAccessException) {
if (debug) {
}
return null;
} catch (InstantiationException instantiationException) {
if (debug) {
}
return null;
}
return schemaFactory;
}
/**
* Try to construct using newTransformerFactoryNoServiceLoader
* method if available.
*/
) {
// Retain maximum compatibility if no security manager.
return null;
}
try {
"newXMLSchemaFactoryNoServiceLoader"
);
} catch (NoSuchMethodException exc) {
return null;
return null;
}
}
/** Iterator that lazily computes one value and returns it. */
private boolean seen = false;
if(seen) throw new NoSuchElementException();
seen = true;
return value();
}
}
/**
* Looks up a value in a property file
* while producing all sorts of debug messages.
*
* @return null
* if there was an error.
*/
throws IOException {
if(factoryClassName != null){
return createInstance(factoryClassName);
} else {
return null;
}
}
/**
* <p>Look up a value in a property file.</p>
*
* <p>Set <code>debug</code> to <code>true</code> to trace property evaluation.</p>
*
* @param schemaLanguage Schema Language to support.
* @param inputName Name of <code>InputStream</code>.
* @param in <code>InputStream</code> of properties.
*
* @return <code>SchemaFactory</code> as determined by <code>keyName</code> value or <code>null</code> if there was an error.
*
* @throws IOException If IO error reading from <code>in</code>.
*/
throws IOException {
// read from InputStream until a match is found
// '#' is comment char
switch (comment) {
case -1: break; // no comment
}
// trim whitespace
// any content left on line?
continue;
}
// line content is now the name of the class
continue;
}
// create an instance of the Class
try {
} catch (ClassCastException classCastExcpetion) {
continue;
} catch (InstantiationException instantiationException) {
continue;
} catch (IllegalAccessException illegalAccessException) {
continue;
}
// does this Class support desired Schema?
try {
Method isSchemaLanguageSupported = clazz.getMethod(isSchemaLanguageSupportedMethod, stringClassArray);
Boolean supported = (Boolean) isSchemaLanguageSupported.invoke(schemaFactory, schemaLanguageObjectArray);
if (supported.booleanValue()) {
break;
}
} catch (NoSuchMethodException noSuchMethodException) {
} catch (IllegalAccessException illegalAccessException) {
} catch (InvocationTargetException invocationTargetException) {
}
}
// clean up
configFile.close();
// return new instance of SchemaFactory or null
return schemaFactory;
}
/**
* Returns an {@link Iterator} that enumerates all
*/
if (classLoader == null) {
return new SingleIterator() {
//return (ClassLoader.getSystemResource( SERVICE_ID ));
}
};
} else {
try {
//final Enumeration e = classLoader.getResources(SERVICE_ID);
if(!e.hasMoreElements()) {
}
// wrap it into an Iterator.
return new Iterator() {
public void remove() {
throw new UnsupportedOperationException();
}
public boolean hasNext() {
return e.hasMoreElements();
}
return e.nextElement();
}
};
} catch (IOException e) {
if(debug) e.printStackTrace();
}
}
}
}
/**
* <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
*/
//URL it = loader.getResource(classnameAsResource);
} else {
return null;
}
}
}