You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by di...@apache.org on 2008/02/25 18:10:18 UTC
svn commit: r630938 -
/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java
Author: dims
Date: Mon Feb 25 09:10:16 2008
New Revision: 630938
URL: http://svn.apache.org/viewvc?rev=630938&view=rev
Log:
sorry, we should avoid calls to newInstance() as well
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java?rev=630938&r1=630937&r2=630938&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java Mon Feb 25 09:10:16 2008
@@ -43,6 +43,8 @@
public class StAXUtils {
private static Log log = LogFactory.getLog(StAXUtils.class);
private static boolean isDebugEnabled = log.isDebugEnabled();
+ private static XMLInputFactory inputFactory = null;
+ private static XMLOutputFactory outputFactory = null;
/**
* Gets an XMLInputFactory instance from pool.
@@ -50,22 +52,25 @@
* @return an XMLInputFactory instance.
*/
public static XMLInputFactory getXMLInputFactory() {
- return (XMLInputFactory) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- Thread currentThread = Thread.currentThread();
- ClassLoader savedClassLoader = currentThread.getContextClassLoader();
- XMLInputFactory factory = null;
- try {
- currentThread.setContextClassLoader(StAXUtils.class.getClassLoader());
- factory = XMLInputFactory.newInstance();
+ if (inputFactory == null) {
+ inputFactory = (XMLInputFactory) AccessController.doPrivileged(
+ new PrivilegedAction() {
+ public Object run() {
+ Thread currentThread = Thread.currentThread();
+ ClassLoader savedClassLoader = currentThread.getContextClassLoader();
+ XMLInputFactory factory = null;
+ try {
+ currentThread.setContextClassLoader(StAXUtils.class.getClassLoader());
+ factory = XMLInputFactory.newInstance();
+ }
+ finally {
+ currentThread.setContextClassLoader(savedClassLoader);
+ }
+ return factory;
}
- finally {
- currentThread.setContextClassLoader(savedClassLoader);
- }
- return factory;
- }
- });
+ });
+ }
+ return inputFactory;
}
/**
@@ -153,24 +158,27 @@
* @return an XMLOutputFactory instance.
*/
public static XMLOutputFactory getXMLOutputFactory() {
- return (XMLOutputFactory) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
-
- Thread currentThread = Thread.currentThread();
- ClassLoader savedClassLoader = currentThread.getContextClassLoader();
- XMLOutputFactory factory = null;
- try {
- currentThread.setContextClassLoader(StAXUtils.class.getClassLoader());
- factory = XMLOutputFactory.newInstance();
- factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.FALSE);
+ if (outputFactory == null) {
+ outputFactory = (XMLOutputFactory) AccessController.doPrivileged(
+ new PrivilegedAction() {
+ public Object run() {
+
+ Thread currentThread = Thread.currentThread();
+ ClassLoader savedClassLoader = currentThread.getContextClassLoader();
+ XMLOutputFactory factory = null;
+ try {
+ currentThread.setContextClassLoader(StAXUtils.class.getClassLoader());
+ factory = XMLOutputFactory.newInstance();
+ factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.FALSE);
+ }
+ finally {
+ currentThread.setContextClassLoader(savedClassLoader);
+ }
+ return factory;
}
- finally {
- currentThread.setContextClassLoader(savedClassLoader);
- }
- return factory;
- }
- });
+ });
+ }
+ return outputFactory;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org