You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-cvs@xml.apache.org by mr...@apache.org on 2006/04/07 23:56:26 UTC
svn commit: r392432 - in /xml/commons/trunk/java/external/src/javax/xml:
datatype/FactoryFinder.java parsers/FactoryFinder.java
transform/FactoryFinder.java validation/SchemaFactoryFinder.java
xpath/XPathFactoryFinder.java
Author: mrglavas
Date: Fri Apr 7 14:56:25 2006
New Revision: 392432
URL: http://svn.apache.org/viewcvs?rev=392432&view=rev
Log:
Reducing creation of short lived objects. The debug print method
calls were creating instances of StringBuffer and String which
are never read.
Modified:
xml/commons/trunk/java/external/src/javax/xml/datatype/FactoryFinder.java
xml/commons/trunk/java/external/src/javax/xml/parsers/FactoryFinder.java
xml/commons/trunk/java/external/src/javax/xml/transform/FactoryFinder.java
xml/commons/trunk/java/external/src/javax/xml/validation/SchemaFactoryFinder.java
xml/commons/trunk/java/external/src/javax/xml/xpath/XPathFactoryFinder.java
Modified: xml/commons/trunk/java/external/src/javax/xml/datatype/FactoryFinder.java
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/external/src/javax/xml/datatype/FactoryFinder.java?rev=392432&r1=392431&r2=392432&view=diff
==============================================================================
--- xml/commons/trunk/java/external/src/javax/xml/datatype/FactoryFinder.java (original)
+++ xml/commons/trunk/java/external/src/javax/xml/datatype/FactoryFinder.java Fri Apr 7 14:56:25 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2005 The Apache Software Foundation.
+ * Copyright 2003-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -115,7 +115,7 @@
classLoader = ss.getContextClassLoader();
- debugPrintln(
+ if (debug) debugPrintln(
"Using context class loader: "
+ classLoader);
@@ -123,7 +123,7 @@
// if we have no Context ClassLoader
// so use the current ClassLoader
classLoader = FactoryFinder.class.getClassLoader();
- debugPrintln(
+ if (debug) debugPrintln(
"Using the class loader of FactoryFinder: "
+ classLoader);
}
@@ -190,7 +190,7 @@
try {
String systemProp = ss.getSystemProperty(factoryId);
if (systemProp != null) {
- debugPrintln("found " + systemProp + " in the system property " + factoryId);
+ if (debug) debugPrintln("found " + systemProp + " in the system property " + factoryId);
return newInstance(systemProp, classLoader);
}
} catch (SecurityException se) {
@@ -208,14 +208,14 @@
File f = new File(configFile);
firstTime = false;
if (ss.doesFileExist(f)) {
- debugPrintln("Read properties file " + f);
+ if (debug) debugPrintln("Read properties file " + f);
cacheProps.load(ss.getFileInputStream(f));
}
}
}
}
factoryClassName = cacheProps.getProperty(factoryId);
- debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");
+ if (debug) debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");
if (factoryClassName != null) {
return newInstance(factoryClassName, classLoader);
@@ -237,7 +237,7 @@
"Provider for " + factoryId + " cannot be found", null);
}
- debugPrintln("loaded from fallback value: " + fallbackClassName);
+ if (debug) debugPrintln("loaded from fallback value: " + fallbackClassName);
return newInstance(fallbackClassName, classLoader);
}
@@ -275,7 +275,7 @@
return null;
}
- debugPrintln("found jar resource=" + serviceId +
+ if (debug) debugPrintln("found jar resource=" + serviceId +
" using ClassLoader: " + cl);
BufferedReader rd;
@@ -306,7 +306,7 @@
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
- debugPrintln("found in resource, value="
+ if (debug) debugPrintln("found in resource, value="
+ factoryClassName);
return newInstance(factoryClassName, cl);
Modified: xml/commons/trunk/java/external/src/javax/xml/parsers/FactoryFinder.java
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/external/src/javax/xml/parsers/FactoryFinder.java?rev=392432&r1=392431&r2=392432&view=diff
==============================================================================
--- xml/commons/trunk/java/external/src/javax/xml/parsers/FactoryFinder.java (original)
+++ xml/commons/trunk/java/external/src/javax/xml/parsers/FactoryFinder.java Fri Apr 7 14:56:25 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2005 The Apache Software Foundation.
+ * Copyright 2003-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,15 +18,12 @@
package javax.xml.parsers;
-import java.io.File;
-import java.io.FileInputStream;
-
-import java.util.Properties;
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.Properties;
/**
* This class is duplicated for each JAXP subpackage so keep it in
@@ -118,7 +115,7 @@
}
Object instance = providerClass.newInstance();
- dPrint("created new instance of " + providerClass +
+ if (debug) dPrint("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return instance;
} catch (ClassNotFoundException x) {
@@ -158,13 +155,13 @@
classLoader = FactoryFinder.class.getClassLoader();
}
- dPrint("find factoryId =" + factoryId);
+ if (debug) dPrint("find factoryId =" + factoryId);
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
if( systemProp!=null) {
- dPrint("found system property, value=" + systemProp);
+ if (debug) dPrint("found system property, value=" + systemProp);
return newInstance(systemProp, classLoader, true );
}
} catch (SecurityException se) {
@@ -184,7 +181,7 @@
File f=new File( configFile );
firstTime = false;
if(ss.doesFileExist(f)){
- dPrint("Read properties file "+f);
+ if (debug) dPrint("Read properties file "+f);
//cacheProps.load( new FileInputStream(f));
cacheProps.load(ss.getFileInputStream(f));
}
@@ -194,7 +191,7 @@
factoryClassName = cacheProps.getProperty(factoryId);
if(factoryClassName != null){
- dPrint("found in $java.home/jaxp.properties, value=" + factoryClassName);
+ if (debug) dPrint("found in $java.home/jaxp.properties, value=" + factoryClassName);
return newInstance(factoryClassName, classLoader, true);
}
} catch(Exception ex ) {
@@ -211,7 +208,7 @@
"Provider for " + factoryId + " cannot be found", null);
}
- dPrint("loaded from fallback value: " + fallbackClassName);
+ if (debug) dPrint("loaded from fallback value: " + fallbackClassName);
return newInstance(fallbackClassName, classLoader, true);
}
@@ -249,7 +246,7 @@
return null;
}
- dPrint("found jar resource=" + serviceId +
+ if (debug) dPrint("found jar resource=" + serviceId +
" using ClassLoader: " + cl);
// Read the service provider name in UTF-8 as specified in
@@ -296,7 +293,7 @@
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
- dPrint("found in resource, value="
+ if (debug) dPrint("found in resource, value="
+ factoryClassName);
// Note: here we do not want to fall back to the current
Modified: xml/commons/trunk/java/external/src/javax/xml/transform/FactoryFinder.java
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/external/src/javax/xml/transform/FactoryFinder.java?rev=392432&r1=392431&r2=392432&view=diff
==============================================================================
--- xml/commons/trunk/java/external/src/javax/xml/transform/FactoryFinder.java (original)
+++ xml/commons/trunk/java/external/src/javax/xml/transform/FactoryFinder.java Fri Apr 7 14:56:25 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2005 The Apache Software Foundation.
+ * Copyright 2003-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,15 +18,12 @@
package javax.xml.transform;
-import java.io.File;
-import java.io.FileInputStream;
-
-import java.util.Properties;
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.Properties;
/**
* This class is duplicated for each JAXP subpackage so keep it in
@@ -118,7 +115,7 @@
}
Object instance = providerClass.newInstance();
- dPrint("created new instance of " + providerClass +
+ if (debug) dPrint("created new instance of " + providerClass +
" using ClassLoader: " + cl);
return instance;
} catch (ClassNotFoundException x) {
@@ -158,13 +155,13 @@
classLoader = FactoryFinder.class.getClassLoader();
}
- dPrint("find factoryId =" + factoryId);
+ if (debug) dPrint("find factoryId =" + factoryId);
// Use the system property first
try {
String systemProp = ss.getSystemProperty(factoryId);
if( systemProp!=null) {
- dPrint("found system property, value=" + systemProp);
+ if (debug) dPrint("found system property, value=" + systemProp);
return newInstance(systemProp, classLoader, true );
}
} catch (SecurityException se) {
@@ -184,7 +181,7 @@
File f=new File( configFile );
firstTime = false;
if(ss.doesFileExist(f)){
- dPrint("Read properties file "+f);
+ if (debug) dPrint("Read properties file "+f);
//cacheProps.load( new FileInputStream(f));
cacheProps.load(ss.getFileInputStream(f));
}
@@ -194,7 +191,7 @@
factoryClassName = cacheProps.getProperty(factoryId);
if(factoryClassName != null){
- dPrint("found in $java.home/jaxp.properties, value=" + factoryClassName);
+ if (debug) dPrint("found in $java.home/jaxp.properties, value=" + factoryClassName);
return newInstance(factoryClassName, classLoader, true);
}
} catch(Exception ex ) {
@@ -211,7 +208,7 @@
"Provider for " + factoryId + " cannot be found", null);
}
- dPrint("loaded from fallback value: " + fallbackClassName);
+ if (debug) dPrint("loaded from fallback value: " + fallbackClassName);
return newInstance(fallbackClassName, classLoader, true);
}
@@ -249,7 +246,7 @@
return null;
}
- dPrint("found jar resource=" + serviceId +
+ if (debug) dPrint("found jar resource=" + serviceId +
" using ClassLoader: " + cl);
// Read the service provider name in UTF-8 as specified in
@@ -296,7 +293,7 @@
if (factoryClassName != null &&
! "".equals(factoryClassName)) {
- dPrint("found in resource, value="
+ if (debug) dPrint("found in resource, value="
+ factoryClassName);
// Note: here we do not want to fall back to the current
Modified: xml/commons/trunk/java/external/src/javax/xml/validation/SchemaFactoryFinder.java
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/external/src/javax/xml/validation/SchemaFactoryFinder.java?rev=392432&r1=392431&r2=392432&view=diff
==============================================================================
--- xml/commons/trunk/java/external/src/javax/xml/validation/SchemaFactoryFinder.java (original)
+++ xml/commons/trunk/java/external/src/javax/xml/validation/SchemaFactoryFinder.java Fri Apr 7 14:56:25 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation.
+ * Copyright 2003-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -136,10 +136,12 @@
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);
+ 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;
}
@@ -157,14 +159,16 @@
// system property look up
try {
- debugPrintln("Looking up system property '"+propertyName+"'" );
+ if (debug) debugPrintln("Looking up system property '"+propertyName+"'" );
String r = ss.getSystemProperty(propertyName);
- if(r!=null) {
- debugPrintln("The value is '"+r+"'");
+ if (r != null) {
+ if (debug) debugPrintln("The value is '"+r+"'");
sf = createInstance(r);
if(sf!=null) return sf;
- } else
+ }
+ else if (debug) {
debugPrintln("The property is undefined.");
+ }
} catch( Throwable t ) {
if( debug ) {
debugPrintln("failed to look up system property '"+propertyName+"'" );
@@ -186,14 +190,14 @@
File f=new File( configFile );
firstTime = false;
if(ss.doesFileExist(f)){
- debugPrintln("Read properties file " + f);
+ if (debug) debugPrintln("Read properties file " + f);
cacheProps.load(ss.getFileInputStream(f));
}
}
}
}
factoryClassName = cacheProps.getProperty(propertyName);
- debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");
+ if (debug) debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");
if (factoryClassName != null) {
sf = createInstance(factoryClassName);
@@ -233,7 +237,7 @@
Iterator sitr = createServiceFileIterator();
while(sitr.hasNext()) {
URL resource = (URL)sitr.next();
- debugPrintln("looking into " + resource);
+ if (debug) debugPrintln("looking into " + resource);
try {
sf = loadFromServicesFile(schemaLanguage,resource.toExternalForm(),ss.getURLInputStream(resource));
if(sf!=null) return sf;
@@ -247,11 +251,11 @@
// platform default
if (schemaLanguage.equals("http://www.w3.org/2001/XMLSchema")) {
- debugPrintln("attempting to use the platform default XML Schema validator");
+ if (debug) debugPrintln("attempting to use the platform default XML Schema validator");
return createInstance("org.apache.xerces.jaxp.validation.XMLSchemaFactory");
}
- debugPrintln("all things were tried, but none was found. bailing out.");
+ if (debug) debugPrintln("all things were tried, but none was found. bailing out.");
return null;
}
@@ -266,7 +270,7 @@
*/
private SchemaFactory createInstance( String className ) {
try {
- debugPrintln("instanciating "+className);
+ if (debug) debugPrintln("instanciating "+className);
Class clazz;
if( classLoader!=null )
clazz = classLoader.loadClass(className);
@@ -278,7 +282,7 @@
if( o instanceof SchemaFactory )
return (SchemaFactory)o;
- debugPrintln(className+" is not assignable to "+SERVICE_CLASS.getName());
+ if (debug) debugPrintln(className+" is not assignable to "+SERVICE_CLASS.getName());
} catch( Throwable t ) {
debugPrintln("failed to instanciate "+className);
if(debug) t.printStackTrace();
@@ -302,30 +306,6 @@
}
/**
- * 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;
- }
- }
-
- /**
* Returns an {@link Iterator} that enumerates all
* the META-INF/services files that we care.
*/
@@ -342,7 +322,7 @@
try {
//final Enumeration e = classLoader.getResources(SERVICE_ID);
final Enumeration e = ss.getResources(classLoader, SERVICE_ID);
- if(!e.hasMoreElements()) {
+ if(debug && !e.hasMoreElements()) {
debugPrintln("no "+SERVICE_ID+" file was found");
}
@@ -361,8 +341,10 @@
}
};
} catch (IOException e) {
- debugPrintln("failed to enumerate resources "+SERVICE_ID);
- if(debug) e.printStackTrace();
+ if (debug) {
+ debugPrintln("failed to enumerate resources "+SERVICE_ID);
+ e.printStackTrace();
+ }
return new ArrayList().iterator(); // empty iterator
}
}
@@ -371,7 +353,7 @@
/** Searches for a SchemaFactory for a given schema language in a META-INF/services file. */
private SchemaFactory loadFromServicesFile(String schemaLanguage, String resourceName, InputStream in) {
- debugPrintln("Reading "+resourceName );
+ if (debug) debugPrintln("Reading "+resourceName );
// Read the service provider name in UTF-8 as specified in
// the jar spec. Unfortunately this fails in Microsoft
Modified: xml/commons/trunk/java/external/src/javax/xml/xpath/XPathFactoryFinder.java
URL: http://svn.apache.org/viewcvs/xml/commons/trunk/java/external/src/javax/xml/xpath/XPathFactoryFinder.java?rev=392432&r1=392431&r2=392432&view=diff
==============================================================================
--- xml/commons/trunk/java/external/src/javax/xml/xpath/XPathFactoryFinder.java (original)
+++ xml/commons/trunk/java/external/src/javax/xml/xpath/XPathFactoryFinder.java Fri Apr 7 14:56:25 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation.
+ * Copyright 2003-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -30,6 +29,8 @@
import java.util.NoSuchElementException;
import java.util.Properties;
+import javax.xml.validation.SchemaFactory;
+
/**
* Implementation of {@link XPathFactory#newInstance(String)}.
*
@@ -135,10 +136,12 @@
public XPathFactory newFactory(String uri) {
if(uri==null) throw new NullPointerException();
XPathFactory f = _newFactory(uri);
- if (f != null) {
- debugPrintln("factory '" + f.getClass().getName() + "' was found for " + uri);
- } else {
- debugPrintln("unable to find a factory for " + 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;
}
@@ -157,14 +160,16 @@
// system property look up
try {
- debugPrintln("Looking up system property '"+propertyName+"'" );
+ if (debug) debugPrintln("Looking up system property '"+propertyName+"'" );
String r = ss.getSystemProperty(propertyName);
if(r!=null) {
- debugPrintln("The value is '"+r+"'");
+ if (debug) debugPrintln("The value is '"+r+"'");
sf = createInstance(r);
if(sf!=null) return sf;
- } else
+ }
+ else if (debug) {
debugPrintln("The property is undefined.");
+ }
} catch( Throwable t ) {
if( debug ) {
debugPrintln("failed to look up system property '"+propertyName+"'" );
@@ -186,14 +191,14 @@
File f=new File( configFile );
firstTime = false;
if(ss.doesFileExist(f)){
- debugPrintln("Read properties file " + f);
+ if (debug) debugPrintln("Read properties file " + f);
cacheProps.load(ss.getFileInputStream(f));
}
}
}
}
factoryClassName = cacheProps.getProperty(propertyName);
- debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");
+ if (debug) debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");
if (factoryClassName != null) {
sf = createInstance(factoryClassName);
@@ -211,7 +216,7 @@
Iterator sitr = createServiceFileIterator();
while(sitr.hasNext()) {
URL resource = (URL)sitr.next();
- debugPrintln("looking into " + resource);
+ if (debug) debugPrintln("looking into " + resource);
try {
sf = loadFromServicesFile(uri, resource.toExternalForm(), ss.getURLInputStream(resource));
if(sf!=null) return sf;
@@ -225,11 +230,11 @@
// platform default
if(uri.equals(XPathFactory.DEFAULT_OBJECT_MODEL_URI)) {
- debugPrintln("attempting to use the platform default W3C DOM XPath lib");
+ if (debug) debugPrintln("attempting to use the platform default W3C DOM XPath lib");
return createInstance("org.apache.xpath.jaxp.XPathFactoryImpl");
}
- debugPrintln("all things were tried, but none was found. bailing out.");
+ if (debug) debugPrintln("all things were tried, but none was found. bailing out.");
return null;
}
@@ -244,7 +249,7 @@
*/
private XPathFactory createInstance( String className ) {
try {
- debugPrintln("instanciating "+className);
+ if (debug) debugPrintln("instanciating "+className);
Class clazz;
if( classLoader!=null )
clazz = classLoader.loadClass(className);
@@ -256,10 +261,12 @@
if( o instanceof XPathFactory )
return (XPathFactory)o;
- debugPrintln(className+" is not assignable to "+SERVICE_CLASS.getName());
+ if (debug) debugPrintln(className+" is not assignable to "+SERVICE_CLASS.getName());
} catch( Throwable t ) {
- debugPrintln("failed to instanciate "+className);
- if(debug) t.printStackTrace();
+ if (debug) {
+ debugPrintln("failed to instanciate "+className);
+ t.printStackTrace();
+ }
}
return null;
}
@@ -282,7 +289,7 @@
/** Searches for a XPathFactory for a given uri in a META-INF/services file. */
private XPathFactory loadFromServicesFile(String uri, String resourceName, InputStream in) {
- debugPrintln("Reading " + resourceName );
+ if (debug) debugPrintln("Reading " + resourceName );
BufferedReader rd;
try {
@@ -358,7 +365,7 @@
try {
//final Enumeration e = classLoader.getResources(SERVICE_ID);
final Enumeration e = ss.getResources(classLoader, SERVICE_ID);
- if(!e.hasMoreElements()) {
+ if (debug && !e.hasMoreElements()) {
debugPrintln("no "+SERVICE_ID+" file was found");
}
@@ -377,8 +384,10 @@
}
};
} catch (IOException e) {
- debugPrintln("failed to enumerate resources "+SERVICE_ID);
- if(debug) e.printStackTrace();
+ if (debug) {
+ debugPrintln("failed to enumerate resources "+SERVICE_ID);
+ e.printStackTrace();
+ }
return new ArrayList().iterator(); // empty iterator
}
}