/** * <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 <tt>schemaLanguage</tt> parameter is null. */ public SchemaFactory newFactory(String schemaLanguage) { if (schemaLanguage == null) { throw new NullPointerException("schemaLanguage == null"); } SchemaFactory f = _newFactory(schemaLanguage); if (debug) { if (f != null) { debugPrintln("factory '" + f.getClass().getName() + "' was found for " + schemaLanguage); } else { debugPrintln("unable to find a factory for " + schemaLanguage); } } return f; }
if (debug) debugPrintln("Looking up system property '"+propertyName+"'" ); String r = System.getProperty(propertyName); if (r != null && r.length() > 0) { if (debug) debugPrintln("The value is '"+r+"'"); sf = createInstance(r); if(sf!=null) return sf; debugPrintln("The property is undefined."); debugPrintln("failed to look up system property '"+propertyName+"'" ); t.printStackTrace(); firstTime = false; if(f.exists()){ if (debug) debugPrintln("Read properties file " + f); cacheProps.load(new FileInputStream(f)); if (debug) debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties"); sf = createInstance(factoryClassName); if(sf != null){ return sf; for (URL resource : createServiceFileIterator()) { if (debug) debugPrintln("looking into " + resource); try { sf = loadFromServicesFile(schemaLanguage,resource.toExternalForm(), resource.openStream()); if(sf!=null) return sf;
/** * <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 SchemaFactoryFinder(ClassLoader loader) { this.classLoader = loader; if( debug ) { debugDisplayClassLoader(); } }
if (debug) debugPrintln("instantiating "+className); Class clazz; if( classLoader!=null ) else clazz = Class.forName(className); if(debug) debugPrintln("loaded it from "+which(clazz)); Object o = clazz.newInstance(); return (SchemaFactory)o; if (debug) debugPrintln(className+" is not assignable to "+SERVICE_CLASS.getName()); debugPrintln("failed to instantiate "+className); if(debug) t.printStackTrace();
if (debug) debugPrintln("Reading "+resourceName ); SchemaFactory foundFactory = (SchemaFactory) createInstance(factoryClassName); if (foundFactory.isSchemaLanguageSupported(schemaLanguage)) { resultFactory = foundFactory;
SchemaFactory f = new SchemaFactoryFinder(cl).newFactory(schemaLanguage); if (f == null) { throw new IllegalArgumentException(schemaLanguage);
private void debugDisplayClassLoader() { if (classLoader == Thread.currentThread().getContextClassLoader()) { debugPrintln("using thread context class loader ("+classLoader+") for search"); return; } if (classLoader == ClassLoader.getSystemClassLoader()) { debugPrintln("using system class loader ("+classLoader+") for search"); return; } debugPrintln("using class loader (" + classLoader + ") for search"); }
debugPrintln("Looking up system property '"+propertyName+"'" ); String r = ss.getSystemProperty(propertyName); if(r!=null) { debugPrintln("The value is '"+r+"'"); sf = createInstance(r); 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(); firstTime = false; if(ss.doesFileExist(f)){ debugPrintln("Read properties file " + f); cacheProps.load(ss.getFileInputStream(f)); debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties"); sf = createInstance(factoryClassName); if(sf != null){ return sf; Iterator sitr = createServiceFileIterator(); while(sitr.hasNext()) { URL resource = (URL)sitr.next(); debugPrintln("looking into " + resource); try {
private static String which( Class clazz ) { return which( clazz.getName(), clazz.getClassLoader() ); }
SchemaFactory schemaFactory = null; debugPrintln("createInstance(" + className + ")"); Class clazz = createClass(className); if (clazz == null) { debugPrintln("failed to getClass(" + className + ")"); return null; debugPrintln("loaded " + className + " from " + which(clazz)); schemaFactory = (SchemaFactory) clazz.newInstance(); } catch (ClassCastException classCastException) { debugPrintln("could not instantiate " + clazz.getName()); if (debug) { classCastException.printStackTrace(); debugPrintln("could not instantiate " + clazz.getName()); if (debug) { illegalAccessException.printStackTrace(); debugPrintln("could not instantiate " + clazz.getName()); if (debug) { instantiationException.printStackTrace();
SchemaFactory f = new SchemaFactoryFinder(cl).createInstance(factoryClassName); if (f == null) { throw new IllegalArgumentException(
final String isSchemaLanguageSupportedMethod = "isSchemaLanguageSupported"; debugPrintln("Reading " + inputName); Class clazz = createClass(line); if (clazz == null) { continue;
/** * Looks up a value in a property file * while producing all sorts of debug messages. * * @return null * if there was an error. */ private SchemaFactory loadFromProperty( String keyName, String resourceName, InputStream in ) throws IOException { debugPrintln("Reading "+resourceName ); Properties props=new Properties(); props.load(in); in.close(); String factoryClassName = props.getProperty(keyName); if(factoryClassName != null){ debugPrintln("found "+keyName+" = " + factoryClassName); return createInstance(factoryClassName); } else { debugPrintln(keyName+" is not in the property file"); return null; } }
if (debug) debugPrintln("instanciating "+className); Class clazz; if( classLoader!=null ) else clazz = Class.forName(className); if(debug) debugPrintln("loaded it from "+which(clazz)); Object o = clazz.newInstance(); return (SchemaFactory)o; if (debug) debugPrintln(className+" is not assignable to "+SERVICE_CLASS.getName()); } catch( Throwable t ) { debugPrintln("failed to instanciate "+className); if(debug) t.printStackTrace();
SchemaFactory f = new SchemaFactoryFinder(cl).newFactory(schemaLanguage); if (f == null) { throw new IllegalArgumentException(schemaLanguage);
/** * Returns an {@link Iterator} that enumerates all * the META-INF/services files that we care. */ private Iterable<URL> createServiceFileIterator() { if (classLoader == null) { ClassLoader classLoader = SchemaFactoryFinder.class.getClassLoader(); return Collections.singleton(classLoader.getResource(SERVICE_ID)); } else { try { Enumeration<URL> e = classLoader.getResources(SERVICE_ID); if (debug && !e.hasMoreElements()) { debugPrintln("no "+SERVICE_ID+" file was found"); } // wrap it into an Iterator. return Collections.list(e); } catch (IOException e) { if (debug) { debugPrintln("failed to enumerate resources "+SERVICE_ID); e.printStackTrace(); } return Collections.emptySet(); } } }
private static String which( Class clazz ) { return which( clazz.getName(), clazz.getClassLoader() ); }
if (debug) debugPrintln("Looking up system property '"+propertyName+"'" ); String r = System.getProperty(propertyName); if (r != null && r.length() > 0) { if (debug) debugPrintln("The value is '"+r+"'"); sf = createInstance(r); if(sf!=null) return sf; debugPrintln("The property is undefined."); debugPrintln("failed to look up system property '"+propertyName+"'" ); t.printStackTrace(); firstTime = false; if(f.exists()){ if (debug) debugPrintln("Read properties file " + f); cacheProps.load(new FileInputStream(f)); if (debug) debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties"); sf = createInstance(factoryClassName); if(sf != null){ return sf; for (URL resource : createServiceFileIterator()) { if (debug) debugPrintln("looking into " + resource); try { sf = loadFromServicesFile(schemaLanguage,resource.toExternalForm(), resource.openStream()); if(sf!=null) return sf;
/** * <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. */ public SchemaFactory newFactory(String schemaLanguage) { 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; }
if (debug) debugPrintln("Reading "+resourceName ); SchemaFactory foundFactory = (SchemaFactory) createInstance(factoryClassName); if (foundFactory.isSchemaLanguageSupported(schemaLanguage)) { resultFactory = foundFactory;