Author: veithen Date: Mon Dec 15 16:27:35 2008 New Revision: 726892 URL: http://svn.apache.org/viewvc?rev=726892&view=rev Log: Refactored some duplicate code into a new method.
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=726892&r1=726891&r2=726892&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 Dec 15 16:27:35 2008 @@ -286,6 +286,16 @@ public static void reset() { } + // This has package access since it is used from within anonymous inner classes + static XMLInputFactory newXMLInputFactory(boolean isNetworkDetached) { + XMLInputFactory factory = XMLInputFactory.newInstance(); + if (isNetworkDetached) { + factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, + Boolean.FALSE); + } + return factory; + } + /** * @return XMLInputFactory for the current classloader */ @@ -318,12 +328,7 @@ AccessController.doPrivileged( new PrivilegedAction() { public Object run() { - XMLInputFactory f = XMLInputFactory.newInstance(); - if (isNetworkDetached) { - f.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, - Boolean.FALSE); - } - return f; + return newXMLInputFactory(isNetworkDetached); } }); } catch (ClassCastException cce) { @@ -338,22 +343,16 @@ AccessController.doPrivileged( new PrivilegedAction() { public Object run() { - XMLInputFactory f = null; ClassLoader saveCL = getContextClassLoader(); try { Thread.currentThread(). setContextClassLoader( XMLInputFactory.class.getClassLoader()); - f =XMLInputFactory.newInstance(); - if (isNetworkDetached) { - f.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, - Boolean.FALSE); - } + return newXMLInputFactory(isNetworkDetached); } finally { Thread.currentThread(). setContextClassLoader(saveCL); } - return f; } }); } @@ -392,19 +391,13 @@ public Object run() { Thread currentThread = Thread.currentThread(); ClassLoader savedClassLoader = currentThread.getContextClassLoader(); - XMLInputFactory factory = null; try { currentThread.setContextClassLoader(StAXUtils.class.getClassLoader()); - factory = XMLInputFactory.newInstance(); - if (isNetworkDetached) { - factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, - Boolean.FALSE); - } + return newXMLInputFactory(isNetworkDetached); } finally { currentThread.setContextClassLoader(savedClassLoader); } - return factory; } }); if (isNetworkDetached) {