OPENJPA-156. Applied Michael Dick's patch (thanks). Updated symbolic constant to use OpenJPA norms, changed references to external symbolic constants to use constants from the map impl being used, and reduced if-else statements for readability.

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@509793 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Linskey 2007-02-20 22:51:50 +00:00
parent 018cf3278a
commit 0b8bf2818c

View File

@ -23,6 +23,7 @@ import java.util.Map;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.Properties; import java.util.Properties;
import java.util.TreeSet; import java.util.TreeSet;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.NamingException; import javax.naming.NamingException;
@ -34,6 +35,9 @@ import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Options; import org.apache.openjpa.lib.util.Options;
import org.apache.openjpa.lib.util.ParseException; import org.apache.openjpa.lib.util.ParseException;
import org.apache.openjpa.lib.util.StringDistance; import org.apache.openjpa.lib.util.StringDistance;
import org.apache.openjpa.lib.util.concurrent.ConcurrentHashMap;
import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
import serp.util.Strings; import serp.util.Strings;
/** /**
@ -46,6 +50,12 @@ public class Configurations {
private static final Localizer _loc = Localizer.forPackage private static final Localizer _loc = Localizer.forPackage
(Configurations.class); (Configurations.class);
private static ConcurrentReferenceHashMap _loaders = new
ConcurrentReferenceHashMap(ConcurrentReferenceHashMap.WEAK,
ConcurrentReferenceHashMap.HARD);
private static final Object NULL_LOADER = "null-loader";
/** /**
* Return the class name from the given plugin string, or null if none. * Return the class name from the given plugin string, or null if none.
@ -163,18 +173,33 @@ public class Configurations {
if (StringUtils.isEmpty(clsName)) if (StringUtils.isEmpty(clsName))
return null; return null;
Class cls = null; Class cls = null;
try {
cls = Strings.toClass(clsName, findDerivedLoader(conf, loader)); // can't have a null reference in the map, so use symbolic
} catch (RuntimeException re) { // constant as key
if (val != null) Object key = loader == null ? NULL_LOADER : loader;
re = getCreateException(clsName, val, re); Map loaderCache = (Map) _loaders.get(key);
if (fatal) if (loaderCache == null) { // We don't have a cache for this loader.
throw re; loaderCache = new ConcurrentHashMap();
Log log = (conf == null) ? null : conf.getConfigurationLog(); _loaders.put(key, loaderCache);
if (log != null && log.isErrorEnabled()) } else { // We have a cache for this loader.
log.error(_loc.get("plugin-creation-exception", val), re); cls = (Class) loaderCache.get(clsName);
return null; }
if (cls == null) { // we haven't cached this.
try {
cls = Strings.toClass(clsName, findDerivedLoader(conf, loader));
loaderCache.put(clsName, cls);
} catch (RuntimeException re) {
if (val != null)
re = getCreateException(clsName, val, re);
if (fatal)
throw re;
Log log = (conf == null) ? null : conf.getConfigurationLog();
if (log != null && log.isErrorEnabled())
log.error(_loc.get("plugin-creation-exception", val), re);
return null;
}
} }
try { try {