Return-Path: Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 63712 invoked by uid 500); 24 Aug 2003 02:30:16 -0000 Received: (qmail 63705 invoked from network); 24 Aug 2003 02:30:16 -0000 Received: from minotaur.apache.org (209.237.227.194) by daedalus.apache.org with SMTP; 24 Aug 2003 02:30:16 -0000 Received: (qmail 79934 invoked by uid 1328); 24 Aug 2003 02:30:10 -0000 Date: 24 Aug 2003 02:30:10 -0000 Message-ID: <20030824023010.79933.qmail@minotaur.apache.org> From: dmitri@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/jxpath/src/java/org/apache/commons/jxpath JXPathContextFactory.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N dmitri 2003/08/23 19:30:10 Modified: jxpath/src/java/org/apache/commons/jxpath JXPathContextFactory.java Log: Fixed Bug 22333: JXPathContextFactory doesn't cache most common result of search Revision Changes Path 1.6 +26 -48 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContextFactory.java Index: JXPathContextFactory.java =================================================================== RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContextFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JXPathContextFactory.java 11 Mar 2003 00:59:12 -0000 1.5 +++ JXPathContextFactory.java 24 Aug 2003 02:30:10 -0000 1.6 @@ -95,6 +95,12 @@ private static final String DEFAULT_FACTORY_CLASS = "org.apache.commons.jxpath.ri.JXPathContextFactoryReferenceImpl"; + /** Avoid reading all the files when the findFactory + method is called the second time ( cache the result of + finding the default impl ) + */ + private static String factoryImplName = null; + protected JXPathContextFactory () { } @@ -135,12 +141,9 @@ * available or cannot be instantiated. */ public static JXPathContextFactory newInstance() { - String factoryImplName = - findFactory(FACTORY_NAME_PROPERTY, DEFAULT_FACTORY_CLASS); - if (factoryImplName == null) { - throw new JXPathContextFactoryConfigurationError( - "No default implementation found"); + factoryImplName = + findFactory(FACTORY_NAME_PROPERTY, DEFAULT_FACTORY_CLASS); } JXPathContextFactory factoryImpl; @@ -177,11 +180,6 @@ // This code is duplicated in all factories. // Keep it in sync or move it to a common place // Because it's small probably it's easier to keep it here - /** Avoid reading all the files when the findFactory - method is called the second time ( cache the result of - finding the default impl ) - */ - private static String foundFactory = null; /** Temp debug code - this will be removed after we test everything */ @@ -203,26 +201,6 @@ @return class name of the JXPathContextFactory */ private static String findFactory(String property, String defaultFactory) { - // Use the system property first - try { - String systemProp = System.getProperty(property); - if (systemProp != null) { - if (debug) { - System.err.println( - "JXPath: found system property" + systemProp); - } - return systemProp; - } - - } - catch (SecurityException se) { - // Ignore - } - - if (foundFactory != null) { - return foundFactory; - } - // Use the factory ID system property first try { String systemProp = System.getProperty(property); @@ -252,13 +230,13 @@ if (f.exists()) { Properties props = new Properties(); props.load(new FileInputStream(f)); - foundFactory = props.getProperty(property); - if (debug) { - System.err.println( - "JXPath: found java.home property " + foundFactory); - } - if (foundFactory != null) { - return foundFactory; + String factory = props.getProperty(property); + if (factory != null) { + if (debug) { + System.err.println( + "JXPath: found java.home property " + factory); + } + return factory; } } } @@ -287,15 +265,15 @@ BufferedReader rd = new BufferedReader(new InputStreamReader(is)); - foundFactory = rd.readLine(); + String factory = rd.readLine(); rd.close(); - if (debug) { - System.err.println( - "JXPath: loaded from services: " + foundFactory); - } - if (foundFactory != null && !"".equals(foundFactory)) { - return foundFactory; + if (factory != null && !"".equals(factory)) { + if (debug) { + System.err.println( + "JXPath: loaded from services: " + factory); + } + return factory; } } }