You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by cu...@apache.org on 2011/11/05 18:17:33 UTC
svn commit: r1197994 [6/10] - in /openjpa/trunk:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/
openjpa-jdbc/src/main/java/org/...
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Id.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Id.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Id.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Id.java Sat Nov 5 17:17:26 2011
@@ -67,7 +67,8 @@ public final class Id
* instance.
*/
public Id(String str, OpenJPAConfiguration conf, ClassLoader brokerLoader) {
- this(str, (conf == null) ? brokerLoader : conf.getClassLoader());
+ this(str, (conf == null) ? brokerLoader : conf.
+ getClassResolverInstance().getClassLoader(Id.class, brokerLoader));
}
/**
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java Sat Nov 5 17:17:26 2011
@@ -146,7 +146,7 @@ public class ImplHelper {
}
/**
- * Generate a value for the given metadata.
+ * Generate a value for the given metadaa.
*/
private static Object generateValue(StoreContext ctx,
ClassMetaData meta, FieldMetaData fmd, int typeCode) {
@@ -157,7 +157,8 @@ public class ImplHelper {
SequenceMetaData smd = (fmd == null)
? meta.getIdentitySequenceMetaData()
: fmd.getValueSequenceMetaData();
- return JavaTypes.convert(smd.getInstance().next(ctx, meta), typeCode);
+ return JavaTypes.convert(smd.getInstance(ctx.getClassLoader()).
+ next(ctx, meta), typeCode);
case ValueStrategies.UUID_STRING:
return UUIDGenerator.nextString(UUIDGenerator.TYPE1);
case ValueStrategies.UUID_HEX:
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Serialization.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Serialization.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Serialization.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Serialization.java Sat Nov 5 17:17:26 2011
@@ -48,7 +48,8 @@ import org.apache.openjpa.lib.util.Multi
*/
public class Serialization {
- private static final Localizer _loc = Localizer.forPackage(Serialization.class);
+ private static final Localizer _loc = Localizer.forPackage
+ (Serialization.class);
/**
* Serialize a value that might contain persistent objects. Replaces
@@ -57,7 +58,8 @@ public class Serialization {
public static byte[] serialize(Object val, StoreContext ctx) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try {
- ObjectOutputStream objs = new PersistentObjectOutputStream(bytes, ctx);
+ ObjectOutputStream objs = new PersistentObjectOutputStream(bytes,
+ ctx);
objs.writeObject(val);
objs.flush();
return bytes.toByteArray();
@@ -98,7 +100,8 @@ public class Serialization {
/**
* Constructor; supply underlying stream.
*/
- public PersistentObjectOutputStream(OutputStream delegate, StoreContext ctx)
+ public PersistentObjectOutputStream(OutputStream delegate,
+ StoreContext ctx)
throws IOException {
super(delegate);
_ctx = ctx;
@@ -152,7 +155,8 @@ public class Serialization {
* Constructor; supply source stream and broker to
* use for persistent object lookups.
*/
- public PersistentObjectInputStream(InputStream delegate, StoreContext ctx)
+ public PersistentObjectInputStream(InputStream delegate,
+ StoreContext ctx)
throws IOException {
super(delegate);
_ctx = ctx;
@@ -166,7 +170,7 @@ public class Serialization {
protected void addContextClassLoaders(MultiClassLoader loader) {
super.addContextClassLoaders(loader);
- loader.addClassLoader(_ctx.getConfiguration().getClassLoader());
+ loader.addClassLoader(_ctx.getClassLoader());
}
protected Object resolveObject(Object obj) {
Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties (original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties Sat Nov 5 17:17:26 2011
@@ -206,8 +206,7 @@ bad-brokerfactory: Could not invoke the
named factory class "{0}".
bad-new-brokerfactory: Could not invoke the static newInstance method on the \
named factory class "{0}".
-bad-brokerfactory-class: The named BrokerFactory "{0}" can not be loaded by \
- classloader "{1}".
+bad-brokerfactory-class: The named BrokerFactory "{0}" is not valid.
instantiate-abstract: Cannot instantiate abstract class of type "{0}" with \
object id "{1}"; this may indicate that the inheritance discriminator \
for the class is not configured correctly.
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java Sat Nov 5 17:17:26 2011
@@ -53,7 +53,8 @@ import org.apache.tools.ant.types.Path;
*/
public abstract class AbstractTask extends MatchingTask {
- private static final Localizer _loc = Localizer.forPackage(AbstractTask.class);
+ private static final Localizer _loc = Localizer.forPackage
+ (AbstractTask.class);
protected final List<FileSet> fileSets = new ArrayList<FileSet>();
protected boolean haltOnError = true;
@@ -81,7 +82,7 @@ public abstract class AbstractTask exten
/**
* Whether we want to delegate to the parent ClassLoader
- * for resolving classes. This may "taint" classes.
+ * for resolveing classes. This may "taint" classes.
*/
public void setUseParentClassloader(boolean useParent) {
this.useParent = useParent;
@@ -114,12 +115,11 @@ public abstract class AbstractTask exten
if (_cl != null)
return _cl;
- if (classpath != null) {
+ if (classpath != null)
_cl = new AntClassLoader(getProject(), classpath, useParent);
- } else {
+ else
_cl = new AntClassLoader(getProject().getCoreLoader(), getProject(),
new Path(getProject()), useParent);
- }
_cl.setIsolated(isolate);
return _cl;
@@ -159,7 +159,9 @@ public abstract class AbstractTask exten
if (_conf == null)
_conf = newConfiguration();
if (_conf.getPropertiesResource() == null) {
- ConfigurationProvider cp = ProductDerivations.loadDefaults();
+ ConfigurationProvider cp = ProductDerivations.loadDefaults
+ (AccessController.doPrivileged(
+ J2DoPrivHelper.getClassLoaderAction(_conf.getClass())));
if (cp != null)
cp.setInto(_conf);
}
@@ -185,10 +187,11 @@ public abstract class AbstractTask exten
String[] dsFiles = ds.getIncludedFiles();
for (int j = 0; j < dsFiles.length; j++) {
File f = new File(dsFiles[j]);
- if (!( AccessController.doPrivileged(J2DoPrivHelper.isFileAction(f))).booleanValue()) {
+ if (!( AccessController.doPrivileged(J2DoPrivHelper
+ .isFileAction(f))).booleanValue())
f = new File(ds.getBasedir(), dsFiles[j]);
- }
- files.add(AccessController.doPrivileged(J2DoPrivHelper.getAbsolutePathAction(f)));
+ files.add(AccessController.doPrivileged(
+ J2DoPrivHelper.getAbsolutePathAction(f)));
}
}
return (String[]) files.toArray(new String[files.size()]);
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java Sat Nov 5 17:17:26 2011
@@ -40,17 +40,18 @@ public abstract class AbstractProductDer
throws Exception {
}
- public ConfigurationProvider loadGlobals()
+ public ConfigurationProvider loadGlobals(ClassLoader loader)
throws Exception {
return null;
}
- public ConfigurationProvider loadDefaults()
+ public ConfigurationProvider loadDefaults(ClassLoader loader)
throws Exception {
return null;
}
- public ConfigurationProvider load(String resource, String anchor)
+ public ConfigurationProvider load(String resource, String anchor,
+ ClassLoader loader)
throws Exception {
return null;
}
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/BooleanValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/BooleanValue.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/BooleanValue.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/BooleanValue.java Sat Nov 5 17:17:26 2011
@@ -23,15 +23,19 @@ package org.apache.openjpa.lib.conf;
*
* @author Marc Prud'hommeaux
*/
-public class BooleanValue extends Value<Boolean> {
+public class BooleanValue extends Value {
private boolean value;
public BooleanValue(String prop) {
- super(Boolean.class, prop);
+ super(prop);
setAliasListComprehensive(true);
}
+ public Class<Boolean> getValueType() {
+ return boolean.class;
+ }
+
/**
* The internal value.
*/
@@ -55,10 +59,13 @@ public class BooleanValue extends Value<
}
protected void setInternalString(String val) {
- set(Boolean.valueOf(val));
+ set(Boolean.valueOf(val).booleanValue());
}
protected void setInternalObject(Object obj) {
- set(obj == null ? false : (Boolean)obj);
+ if (obj == null)
+ set(false);
+ else
+ set(((Boolean) obj).booleanValue());
}
}
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/BootstrapException.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/BootstrapException.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/BootstrapException.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/BootstrapException.java Sat Nov 5 17:17:26 2011
@@ -24,7 +24,6 @@ package org.apache.openjpa.lib.conf;
* @since 0.4.1.4
*
*/
-@SuppressWarnings("serial")
public class BootstrapException extends RuntimeException {
private boolean _fatal = false;
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java Sat Nov 5 17:17:26 2011
@@ -33,14 +33,10 @@ import org.apache.openjpa.lib.util.Close
/**
* Interface for generic configuration objects. Includes the ability
* to write configuration to and from {@link Properties} instances. Instances
- * are thread-safe for reads, but not for writes.
- * <br>
- * A configuration comprises of {@link Value values}. The configuration is
- * responsible for loading the values.
+ * are threadsafe for reads, but not for writes.
*
* @author Marc Prud'hommeaux
* @author Abe White
- * @author Pinaki Poddar
*/
public interface Configuration
extends BeanInfo, Serializable, Closeable, Cloneable {
@@ -151,23 +147,24 @@ public interface Configuration
/**
* Return the {@link Value} for the given property, or null if none.
*/
- public Value<?> getValue(String property);
+ public Value getValue(String property);
/**
* Return the set of all {@link Value}s.
*/
- public Value<?>[] getValues();
+ public Value[] getValues();
/**
* Add the given value to the set of configuration properties. This
* method replaces any existing value under the same property.
*/
- public <T> Value<T> addValue(Value<T> val);
+ public <T extends Value> T addValue(T val);
+ //public Value addValue(Value val);
/**
* Remove the given value from the set of configuration properties.
*/
- public boolean removeValue(Value<?> val);
+ public boolean removeValue(Value val);
/**
* A properties representation of this Configuration.
@@ -248,23 +245,33 @@ public interface Configuration
* Free the resources used by this object.
*/
public void close();
-
- /**
- * Adds a class loader for loading plug-ins by class name.
- *
- * @param loader
- */
- public ClassLoader addClassLoader(ClassLoader loader);
-
- /**
- * Gets the class loader for loading plug-ins by class name.
- *
- */
- public ClassLoader getClassLoader();
/**
* Return a copy of this configuration.
*/
public Object clone();
+ /**
+ * Modifies a <em>dynamic</em> property of this receiver even when
+ * {@link #setReadOnly(boolean) frozen}.
+ *
+ * @since 1.0.0
+ */
+// public void modifyDynamic(String property, Object newValue);
+//
+// /**
+// * Affirms if the given property can be modified <em>dynamically</em> i.e.
+// * even after the receiver is {@link #setReadOnly(boolean) frozen}.
+// *
+// * @since 1.0.0
+// */
+// public boolean isDynamic(String property);
+//
+// /**
+// * Gets the values that can be modified <em>dynamically</em> i.e.
+// * even after the receiver is {@link #setReadOnly(boolean) frozen}.
+// *
+// * @since 1.0.0
+// */
+// public Value[] getDynamicValues();
}
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java Sat Nov 5 17:17:26 2011
@@ -76,7 +76,6 @@ import serp.util.Strings;
* provides base configuration functionality, including serialization,
* the <code>equals</code> and <code>hashCode</code> contracts, and default
* property loading.
- * <br>
* Property descriptors for {@link Value} instances are constructed from
* the {@link Localizer} for the package of the configuration class. The
* following localized strings will be used for describing a value, where
@@ -99,8 +98,6 @@ import serp.util.Strings;
* <li><em>name</em>-displayorder: The order in which the property should
* be displayer.</li>
* </ul>
- * <p>
- *
*
* @author Abe White
*/
@@ -109,10 +106,10 @@ public class ConfigurationImpl
private static final String SEP = J2DoPrivHelper.getLineSeparator();
- private static final Localizer _loc = Localizer.forPackage(ConfigurationImpl.class);
+ private static final Localizer _loc = Localizer.forPackage
+ (ConfigurationImpl.class);
- public ObjectValue<LogFactory> logFactoryPlugin;
- private final MultiClassLoader _pluginLoader;
+ public ObjectValue logFactoryPlugin;
public StringValue id;
private String _product = null;
@@ -120,7 +117,7 @@ public class ConfigurationImpl
private Map _props = null;
private boolean _globals = false;
private String _auto = null;
- private final List<Value<?>> _vals = new ArrayList<Value<?>>();
+ private final List<Value> _vals = new ArrayList<Value>();
private Set<String> _supportedKeys;
// property listener helper
@@ -144,14 +141,9 @@ public class ConfigurationImpl
* @param loadGlobals whether to attempt to load the global properties
*/
public ConfigurationImpl(boolean loadGlobals) {
- _pluginLoader = AccessController.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
- _pluginLoader.addClassLoader(MultiClassLoader.THREAD_LOADER);
- _pluginLoader.addClassLoader(getClass().getClassLoader());
- _pluginLoader.addClassLoader(MultiClassLoader.SYSTEM_LOADER);
-
setProductName("openjpa");
- logFactoryPlugin = addPlugin(LogFactory.class, "Log", true);
+ logFactoryPlugin = addPlugin("Log", true);
String[] aliases = new String[]{
"true", LogFactoryImpl.class.getName(),
"openjpa", LogFactoryImpl.class.getName(),
@@ -177,13 +169,20 @@ public class ConfigurationImpl
* {@link ProductDerivation}s, and from System properties.
*/
public boolean loadGlobals() {
- ConfigurationProvider provider = ProductDerivations.loadGlobals();
- if (provider != null) {
+ MultiClassLoader loader = AccessController
+ .doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
+ loader.addClassLoader(AccessController.doPrivileged(
+ J2DoPrivHelper.getContextClassLoaderAction()));
+ loader.addClassLoader(getClass().getClassLoader());
+ ConfigurationProvider provider = ProductDerivations.loadGlobals(loader);
+ if (provider != null)
provider.setInto(this);
- }
+
// let system properties override other globals
try {
- fromProperties(new HashMap(AccessController.doPrivileged(J2DoPrivHelper.getPropertiesAction())));
+ fromProperties(new HashMap(
+ AccessController.doPrivileged(
+ J2DoPrivHelper.getPropertiesAction())));
} catch (SecurityException se) {
// security manager might disallow
}
@@ -208,8 +207,8 @@ public class ConfigurationImpl
public LogFactory getLogFactory() {
if (logFactoryPlugin.get() == null)
- logFactoryPlugin.instantiate(this);
- return logFactoryPlugin.get();
+ logFactoryPlugin.instantiate(LogFactory.class, this);
+ return (LogFactory) logFactoryPlugin.get();
}
public void setLogFactory(LogFactory logFactory) {
@@ -243,8 +242,8 @@ public class ConfigurationImpl
return getLog("openjpa.Runtime");
}
- public Value<?>[] getValues() {
- return _vals.toArray(new Value[_vals.size()]);
+ public Value[] getValues() {
+ return (Value[]) _vals.toArray(new Value[_vals.size()]);
}
/**
@@ -254,12 +253,12 @@ public class ConfigurationImpl
* with which the value has been registered. A value may have multiple
* equivalent names and this method searches with all equivalent names.
*/
- public Value<?> getValue(String property) {
+ public Value getValue(String property) {
if (property == null)
return null;
// search backwards so that custom values added after construction
- // are found quickly, since this will be the standard way of accessing them
+ // are found quickly, since this will be the std way of accessing them
for (int i = _vals.size()-1; i >= 0; i--) {
if (_vals.get(i).matches(property))
return _vals.get(i);
@@ -279,7 +278,7 @@ public class ConfigurationImpl
String getterName;
Method getter;
Object getterTarget;
- for (Value<?> val : _vals) {
+ for(Value val : _vals) {
getterName = val.getInstantiatingGetter();
if (getterName == null)
continue;
@@ -307,7 +306,8 @@ public class ConfigurationImpl
}
}
if (errs != null)
- throw new RuntimeException(_loc.get("get-prop-errs", errs.toString()).getMessage());
+ throw new RuntimeException(_loc.get("get-prop-errs",
+ errs.toString()).getMessage());
}
public boolean isReadOnly() {
@@ -325,7 +325,7 @@ public class ConfigurationImpl
_changeSupport.removePropertyChangeListener(listener);
}
- public void valueChanged(Value<?> val) {
+ public void valueChanged(Value val) {
if (_changeSupport == null && _props == null)
return;
@@ -352,8 +352,8 @@ public class ConfigurationImpl
preClose();
- ObjectValue<?> val;
- for (Value<?> v : _vals) {
+ ObjectValue val;
+ for(Value v : _vals) {
if (v instanceof Closeable) {
try { ((Closeable)v).close(); }
catch (Exception e) {}
@@ -363,7 +363,7 @@ public class ConfigurationImpl
if (!(v instanceof ObjectValue))
continue;
- val = (ObjectValue<?>) v;
+ val = (ObjectValue) v;
if (val.get() instanceof Closeable) {
try {
((Closeable) val.get()).close();
@@ -437,9 +437,9 @@ public class ConfigurationImpl
_pds = new PropertyDescriptor[_vals.size()];
List<String> failures = null;
- Value<?> val;
+ Value val;
for (int i = 0; i < _vals.size(); i++) {
- val = (Value<?>) _vals.get(i);
+ val = (Value) _vals.get(i);
try {
_pds[i] = getPropertyDescriptor(val);
} catch (MissingResourceException mre) {
@@ -462,7 +462,7 @@ public class ConfigurationImpl
/**
* Create a property descriptor for the given value.
*/
- private PropertyDescriptor getPropertyDescriptor(Value<?> val)
+ private PropertyDescriptor getPropertyDescriptor(Value val)
throws IntrospectionException {
String prop = val.getProperty();
prop = prop.substring(prop.lastIndexOf('.') + 1);
@@ -546,6 +546,7 @@ public class ConfigurationImpl
/**
* Find the given localized string, or return null if not found.
*/
+ @SuppressWarnings("unchecked")
private String findLocalized(String key, boolean fatal, Class<?> scope) {
// find the localizer package that contains this key
Localizer loc = null;
@@ -560,7 +561,8 @@ public class ConfigurationImpl
}
}
- for (Class<?> cls = getClass(); cls != Object.class; cls = cls.getSuperclass()) {
+ for (Class cls = getClass(); cls != Object.class;
+ cls = cls.getSuperclass()) {
loc = Localizer.forPackage(cls);
try {
return loc.getFatal(key).getMessage();
@@ -589,7 +591,7 @@ public class ConfigurationImpl
public Map toProperties(boolean storeDefaults) {
// clone properties before making any modifications; we need to keep
// the internal properties instance consistent to maintain equals and
- // hash code contracts
+ // hashcode contracts
Map<String, String> clone;
if (_props == null)
clone = new TreeMap<String, String>();
@@ -602,7 +604,7 @@ public class ConfigurationImpl
// with default values, add values to properties
if (_props == null || storeDefaults) {
String str;
- for (Value<?> val : _vals) {
+ for (Value val : _vals) {
// NOTE: Following was removed to hide Value.INVISIBLE properties, like connectionPassword
// if key in existing properties, we already know value is up to date
//if (_props != null && Configurations.containsProperty(val, _props) && val.isVisible())
@@ -633,13 +635,13 @@ public class ConfigurationImpl
}
// copy the input to avoid mutation issues
- if (map instanceof HashMap) {
+ if (map instanceof HashMap)
map = (Map) ((HashMap) map).clone();
- } else if (map instanceof Properties) {
+ else if (map instanceof Properties)
map = (Map) ((Properties) map).clone();
- } else {
+ else
map = new LinkedHashMap(map);
- }
+
Map remaining = new HashMap(map);
boolean ser = true;
Object o;
@@ -666,9 +668,9 @@ public class ConfigurationImpl
// now warn if there are any remaining properties that there
// is an unhandled prop, and remove the unknown properties
- Map.Entry<?,?> entry;
- for (Iterator<?> itr = remaining.entrySet().iterator(); itr.hasNext();) {
- entry = (Map.Entry<?,?>) itr.next();
+ Map.Entry entry;
+ for (Iterator itr = remaining.entrySet().iterator(); itr.hasNext();) {
+ entry = (Map.Entry) itr.next();
Object key = entry.getKey();
if (key != null) {
warnInvalidProperty((String) key);
@@ -682,7 +684,7 @@ public class ConfigurationImpl
}
public List<String> getPropertyKeys(String propertyName) {
- Value<?> value = getValue(propertyName);
+ Value value = getValue(propertyName);
return value == null ? Collections.EMPTY_LIST : value.getPropertyKeys();
}
@@ -698,7 +700,7 @@ public class ConfigurationImpl
return _supportedKeys;
_supportedKeys = new TreeSet<String>();
- for (Value<?> val : _vals) {
+ for (Value val : _vals) {
if (val.isPrivate())
continue;
List<String> keys = val.getPropertyKeys();
@@ -732,7 +734,7 @@ public class ConfigurationImpl
* Use this method instead of attempting to add the value directly because
* this will account for the property prefix.
*/
- private void setValue(Map map, Value<?> val) {
+ private void setValue(Map map, Value val) {
Object key = val.getLoadKey();
if (key == null) {
List<String> keys = val.getPropertyKeys();
@@ -746,7 +748,9 @@ public class ConfigurationImpl
key = "openjpa." + val.getProperty();
}
}
- map.put(key, val.getExternal());
+ Object external = val.isHidden() ? Value.INVISIBLE :
+ val instanceof ObjectValue ? val.getString() : val.get();
+ map.put(key, external);
}
/**
@@ -754,11 +758,12 @@ public class ConfigurationImpl
* property names. Detects if the given map contains multiple keys that
* are equivalent names for the given value.
*/
- private Object findValue(Map map, Value<?> val) {
+ private Object findValue(Map map, Value val) {
Object result = null;
List<String> partialKeys = val.getPropertyKeys();
for (String partialKey : partialKeys) {
- String key = ProductDerivations.getConfigurationKey(partialKey, map);
+ String key = ProductDerivations.getConfigurationKey(
+ partialKey, map);
if (map.containsKey(key)) {
// do not return immediately. Looping through all equivalent
// property names will detect if the Map contains multiple keys
@@ -775,9 +780,7 @@ public class ConfigurationImpl
*/
private void warnInvalidProperty(String propName) {
if (propName != null &&
- (propName.startsWith("java.") ||
- propName.startsWith("javax.persistence") ||
- propName.startsWith("sun.")))
+ (propName.startsWith("java.") || propName.startsWith("javax.persistence")|| propName.startsWith("sun.")))
return;
if (!isInvalidProperty(propName))
return;
@@ -802,7 +805,7 @@ public class ConfigurationImpl
private Collection<String> newPropertyList() {
String[] prefixes = ProductDerivations.getConfigurationPrefixes();
List<String> l = new ArrayList<String>(_vals.size() * prefixes.length);
- for(Value<?> v : _vals) {
+ for(Value v : _vals) {
for (int j = 0; j < prefixes.length; j++)
l.add(prefixes[j] + "." + v.getProperty());
}
@@ -840,12 +843,14 @@ public class ConfigurationImpl
*/
public void setProperties(String resourceName) throws IOException {
String anchor = null;
- if (resourceName.indexOf("#") != -1) {
+ if (resourceName.indexOf("#") != -1)
+ {
anchor = resourceName.substring(resourceName.lastIndexOf("#") + 1);
resourceName = resourceName.substring(0,
resourceName.length() - anchor.length() - 1);
}
- ProductDerivations.load(resourceName, anchor).setInto(this);
+ ProductDerivations.load(resourceName, anchor,
+ getClass().getClassLoader()).setInto(this);
_auto = resourceName;
}
@@ -855,7 +860,8 @@ public class ConfigurationImpl
* <code>propertiesFile</code> value with the name of a file.
*/
public void setPropertiesFile(File file) throws IOException {
- ProductDerivations.load(file, null).setInto(this);
+ ProductDerivations.load(file, null, getClass().getClassLoader()).
+ setInto(this);
_auto = file.toString();
}
@@ -888,10 +894,10 @@ public class ConfigurationImpl
ConfigurationImpl conf = (ConfigurationImpl) other;
if (_vals.size() != conf.getValues().length)
return false;
- for(Value<?> v : _vals) {
+ for(Value v : _vals) {
String propName = v.getProperty();
- Value<?> thisV = this.getValue(propName);
- Value<?> thatV = conf.getValue(propName);
+ Value thisV = this.getValue(propName);
+ Value thatV = conf.getValue(propName);
if (!thisV.equals(thatV)) {
return false;
}
@@ -906,7 +912,7 @@ public class ConfigurationImpl
*/
public int hashCode() {
int hash = 0;
- for(Value<?> v : _vals) {
+ for(Value v : _vals) {
hash += v.hashCode();
}
return hash;
@@ -938,8 +944,10 @@ public class ConfigurationImpl
// surround sequences of digits with dashes.
if (i != 0
- && ((!Character.isLetter(c) && Character.isLetter(propName.charAt(i - 1)))
- || (Character.isLetter(c) && !Character.isLetter(propName.charAt(i - 1)))))
+ && ((!Character.isLetter(c) && Character.isLetter(propName
+ .charAt(i - 1)))
+ || (Character.isLetter(c) && !Character.isLetter(propName
+ .charAt(i - 1)))))
buf.append('-');
buf.append(Character.toLowerCase(c));
@@ -951,6 +959,7 @@ public class ConfigurationImpl
* Implementation of the {@link Externalizable} interface to read from
* the properties written by {@link #writeExternal}.
*/
+ @SuppressWarnings("unchecked")
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException {
fromProperties((Map) in.readObject());
@@ -974,8 +983,10 @@ public class ConfigurationImpl
*/
public Object clone() {
try {
- Constructor<? extends Configuration> cons = getClass().getConstructor(new Class[]{ boolean.class });
- ConfigurationImpl clone = (ConfigurationImpl)cons.newInstance(new Object[]{ Boolean.FALSE });
+ Constructor cons = getClass().getConstructor
+ (new Class[]{ boolean.class });
+ ConfigurationImpl clone = (ConfigurationImpl) cons.newInstance
+ (new Object[]{ Boolean.FALSE });
clone.fromProperties(toProperties(true));
clone._props = (_props == null) ? null : new HashMap(_props);
clone._globals = _globals;
@@ -987,14 +998,14 @@ public class ConfigurationImpl
}
}
- public boolean removeValue(Value<?> val) {
+ public boolean removeValue(Value val) {
if (!_vals.remove(val))
return false;
val.removeListener(this);
return true;
}
- public <T> Value<T> addValue(Value<T> val) {
+ public <T extends Value> T addValue(T val) {
_vals.add(val);
val.addListener(this);
return val;
@@ -1058,93 +1069,27 @@ public class ConfigurationImpl
/**
* Add the given value to the set of configuration properties.
*/
- public <T> ObjectValue<T> addObject(Class<T> type, String property) {
- ObjectValue<T> val = new ObjectValue<T>(type, property);
- addValue(val);
- return val;
- }
-
- /**
- * Creates and adds a non-singleton {@link PluginValue plug-in value} of the given type.
- * Property name of the plug-in is the simple name of the given type.
- *
- * @param <T> type of the plug-in
- * @param type class of the plug-in, often an interface
- * @return the plug-in created
- */
- public <T> PluginValue<T> addPlugin(Class<T> type) {
- return addPlugin(type, false);
- }
-
- /**
- * Creates and adds a {@link PluginValue plug-in value} of the given type.
- * Property name of the plug-in is the simple name of the given type.
- *
- * @param <T> type of the plug-in
- * @param type class of the plug-in, often an interface
- * @param singleton whether this plug-in is a singleton for this configuration
- * @return the plug-in created
- */
- public <T> PluginValue<T> addPlugin(Class<T> type, boolean singleton) {
- return addPlugin(type, type.getSimpleName(), singleton);
- }
-
- /**
- * Creates and adds a {@link PluginValue plug-in value} of the given type of the given property name.
- * If the plug-in is a singleton set the instantiating getter method as <tt>get<property>Instance</tt>.
- *
- * @param <T> type of the plug-in
- * @param type class of the plug-in, often an interface
- * @param property name of the plug-in
- * @param singleton whether this plug-in is a singleton for this configuration
- * @return the plug-in created
- */
- public <T> PluginValue<T> addPlugin(Class<T> type, String property, boolean singleton) {
- PluginValue<T> val = new PluginValue<T>(type, property, singleton);
+ public ObjectValue addObject(String property) {
+ ObjectValue val = new ObjectValue(property);
addValue(val);
- if (singleton) {
- val.setInstantiatingGetter("get" + removePrefix(property) + "Instance");
- }
return val;
}
/**
* Add the given value to the set of configuration properties.
*/
- public <T> PluginListValue<T> addPluginList(Class<T[]> type, String property) {
- PluginListValue<T> val = new PluginListValue<T>(type, property);
+ public PluginValue addPlugin(String property, boolean singleton) {
+ PluginValue val = new PluginValue(property, singleton);
addValue(val);
return val;
}
-
+
/**
* Add the given value to the set of configuration properties.
*/
- public <T extends Enum<T>> EnumValue<T> addEnum(Class<T> type, String property) {
- EnumValue<T> val = new EnumValue<T>(type, property);
+ public PluginListValue addPluginList(String property) {
+ PluginListValue val = new PluginListValue(property);
addValue(val);
return val;
}
-
- /**
- * Adds an additional class loader to load the plug-in values.
- */
- @Override
- public MultiClassLoader addClassLoader(ClassLoader loader) {
- _pluginLoader.addClassLoader(loader);
- return _pluginLoader;
- }
-
- /**
- * Gets the {@link MultiClassLoader special class loader} to load plug-in values.
- */
- @Override
- public MultiClassLoader getClassLoader() {
- return _pluginLoader;
- }
-
- private String removePrefix(String s) {
- int index = s.lastIndexOf('.');
- return index == -1 ? s : s.substring(index+1);
- }
}
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java Sat Nov 5 17:17:26 2011
@@ -20,21 +20,12 @@ package org.apache.openjpa.lib.conf;
import java.util.Map;
-import org.apache.openjpa.lib.util.MultiClassLoader;
-
/**
- * Implementations of this interface populates {@link Configuration}s in
- * some {@link ProductDerivation environment-specific} way. Implementations must implement the
+ * Implementations of this interface can populate {@link Configuration}s in
+ * some environment-specific way. Implementations must implement the
* <code>equals</code> and <code>hashCode</code> methods so that equivalent
* configurations compare equal.
- * <br>
- * A provider looks up resources and resolves classes by their names <em>before</em>
- * runtime is initialized. The class loader used by a provider eventually is
- * {@link #setInto(Configuration) set} in the {@link Configuration configuration} for runtime.
- *
*
- * @author Abe White
- * @author Pinaki Poddar
* @nojavadoc
* @since 0.4.0.0
*/
@@ -61,12 +52,4 @@ public interface ConfigurationProvider {
* Set loaded information into the given configuration.
*/
public void setInto(Configuration conf);
-
-
- /**
- * Gets the loader to load plug-in and resources by class name.
- *
- * @since 2.2.0
- */
- public MultiClassLoader getClassLoader();
}
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java Sat Nov 5 17:17:26 2011
@@ -28,6 +28,8 @@ import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Properties;
+import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -38,9 +40,11 @@ import org.apache.commons.lang.exception
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.lib.util.MultiClassLoader;
import org.apache.openjpa.lib.util.Options;
import org.apache.openjpa.lib.util.ParseException;
import org.apache.openjpa.lib.util.StringDistance;
+import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
import serp.util.Strings;
@@ -52,8 +56,15 @@ import serp.util.Strings;
*/
public class Configurations {
- private static final Localizer _loc = Localizer.forPackage(Configurations.class);
+ private static final Localizer _loc = Localizer.forPackage
+ (Configurations.class);
+ private static final 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.
*/
@@ -90,7 +101,8 @@ public class Configurations {
// clsName(props) form
if (clsName)
return plugin.substring(0, openParen).trim();
- String prop = plugin.substring(openParen + 1, plugin.length() - 1).trim();
+ String prop = plugin.substring(openParen + 1,
+ plugin.length() - 1).trim();
return (prop.length() == 0) ? null : prop;
}
@@ -140,17 +152,33 @@ public class Configurations {
return getPlugin(cls, serializeProperties(props));
}
+ /**
+ * Create the instance with the given class name, using the given
+ * class loader. No configuration of the instance is performed by
+ * this method.
+ */
+ public static Object newInstance(String clsName, ClassLoader loader) {
+ return newInstance(clsName, null, null, loader, true);
+ }
- public static Object newInstance(String clsName, Configuration conf, String props) {
- return newInstance(clsName, conf, parseProperties(props));
+ /**
+ * Create and configure an instance with the given class name and
+ * properties as a String.
+ */
+ public static Object newInstance(String clsName, Configuration conf,
+ String props, ClassLoader loader) {
+ Object obj = newInstance(clsName, null, conf, loader, true);
+ configureInstance(obj, conf, props);
+ return obj;
}
+
/**
- * Create and configure an instance with the given class name and properties.
- * The class name is loaded using the {@link Configuration#getClassLoader() class loader} of
- * the given configuration.
+ * Create and configure an instance with the given class name and
+ * properties.
*/
- public static Object newInstance(String clsName, Configuration conf, Properties props) {
- Object obj = newInstance(clsName, null, conf, conf.getClassLoader(), true);
+ public static Object newInstance(String clsName, Configuration conf,
+ Properties props, ClassLoader loader) {
+ Object obj = newInstance(clsName, null, conf, loader, true);
configureInstance(obj, conf, props);
return obj;
}
@@ -159,30 +187,52 @@ public class Configurations {
* Helper method used by members of this package to instantiate plugin
* values.
*/
- static <T> T newInstance(String clsName, Value<T> val, Configuration conf, ClassLoader loader, boolean fatal) {
+ static Object newInstance(String clsName, Value val, Configuration conf,
+ ClassLoader loader, boolean fatal) {
if (StringUtils.isEmpty(clsName))
return null;
- Class<T> cls = null;
+
+ Class cls = null;
+
while (cls == null) {
- try {
- cls = (Class<T>)Class.forName(clsName, true, loader);
- } catch (Exception e) {
- if (loader != null) { // Try one more time with loader=null
- loader = null;
- } else {
- RuntimeException re = getCreateException(clsName, val, loader, e);
- if (fatal)
- throw re;
- Log log = (conf == null) ? null : conf.getConfigurationLog();
- if (log != null && log.isErrorEnabled())
- log.error(_loc.get("plugin-creation-exception", val), e);
- return null;
+ // can't have a null reference in the map, so use symbolic
+ // constant as key
+ Object key = loader == null ? NULL_LOADER : loader;
+ Map loaderCache = (Map) _loaders.get(key);
+ if (loaderCache == null) { // We don't have a cache for this loader.
+ loaderCache = new ConcurrentHashMap();
+ _loaders.put(key, loaderCache);
+ } else { // We have a cache for this loader.
+ cls = (Class) loaderCache.get(clsName);
+ }
+
+ if (cls == null) {
+ try {
+ cls = Strings.toClass(clsName, findDerivedLoader(conf,
+ loader));
+ loaderCache.put(clsName, cls);
+ } catch (RuntimeException re) {
+ if (loader != null) // Try one more time with loader=null
+ loader = null;
+ else {
+ 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 {
- return (T) AccessController.doPrivileged(J2DoPrivHelper.newInstanceAction(cls));
+ return AccessController.doPrivileged(
+ J2DoPrivHelper.newInstanceAction(cls));
} catch (Exception e) {
if (e instanceof PrivilegedActionException) {
e = ((PrivilegedActionException) e).getException();
@@ -198,7 +248,48 @@ public class Configurations {
}
}
-
+ /**
+ * Attempt to find a derived loader that delegates to our target loader.
+ * This allows application loaders that delegate appropriately for known
+ * classes first crack at class names.
+ */
+ private static ClassLoader findDerivedLoader(Configuration conf,
+ ClassLoader loader) {
+ // we always prefer the thread loader, because it's the only thing we
+ // can access that isn't bound to the OpenJPA classloader, unless
+ // the conf object is of a custom class
+ ClassLoader ctxLoader = AccessController.doPrivileged(
+ J2DoPrivHelper.getContextClassLoaderAction());
+ if (loader == null) {
+ if (ctxLoader != null)
+ return ctxLoader;
+ if (conf != null)
+ return AccessController.doPrivileged(
+ J2DoPrivHelper.getClassLoaderAction(conf.getClass()));
+ return Configurations.class.getClassLoader();
+ }
+
+ for (ClassLoader parent = ctxLoader; parent != null;
+ parent = AccessController.doPrivileged(
+ J2DoPrivHelper.getParentAction(parent))) {
+ if (parent == loader)
+ return ctxLoader;
+ }
+ if (conf != null) {
+ for (ClassLoader parent = (ClassLoader)
+ AccessController.doPrivileged(
+ J2DoPrivHelper.getClassLoaderAction(conf.getClass()));
+ parent != null;
+ parent = AccessController.doPrivileged(
+ J2DoPrivHelper.getParentAction(parent))) {
+ if (parent == loader)
+ return AccessController.doPrivileged(
+ J2DoPrivHelper.getClassLoaderAction(conf.getClass()));
+ }
+ }
+ return loader;
+ }
+
/**
* Return a List<String> of all the fully-qualified anchors specified in the
* properties location listed in <code>opts</code>. If no properties
@@ -224,7 +315,8 @@ public class Configurations {
return Arrays.asList(new String[] { props });
}
- return ProductDerivations.getFullyQualifiedAnchorsInPropertiesLocation(props);
+ return ProductDerivations.getFullyQualifiedAnchorsInPropertiesLocation(
+ props);
}
/**
@@ -255,14 +347,14 @@ public class Configurations {
File file = new File(path);
if ((AccessController.doPrivileged(J2DoPrivHelper
.isFileAction(file))).booleanValue())
- provider = ProductDerivations.load(file, anchor);
+ provider = ProductDerivations.load(file, anchor, null);
else {
file = new File("META-INF" + File.separatorChar + path);
if ((AccessController.doPrivileged(J2DoPrivHelper
.isFileAction(file))).booleanValue())
- provider = ProductDerivations.load(file, anchor);
+ provider = ProductDerivations.load(file, anchor, null);
else
- provider = ProductDerivations.load(path, anchor);
+ provider = ProductDerivations.load(path, anchor, null);
}
if (provider != null)
provider.setInto(conf);
@@ -271,7 +363,7 @@ public class Configurations {
props).getMessage(), Configurations.class.getName(),
props);
} else {
- provider = ProductDerivations.loadDefaults();
+ provider = ProductDerivations.loadDefaults(null);
if (provider != null)
provider.setInto(conf);
}
@@ -281,7 +373,8 @@ public class Configurations {
/**
* Helper method to throw an informative description on instantiation error.
*/
- private static RuntimeException getCreateException(String clsName, Value val, ClassLoader loader, Exception e) {
+ private static RuntimeException getCreateException(String clsName,
+ Value val, Exception e) {
// re-throw the exception with some better information
final String msg;
final Object[] params;
@@ -289,27 +382,30 @@ public class Configurations {
String alias = val.alias(clsName);
String[] aliases = val.getAliases();
String[] keys;
- if (aliases.length == 0) {
+ if (aliases.length == 0)
keys = aliases;
- } else {
+ else {
keys = new String[aliases.length / 2];
- for (int i = 0; i < aliases.length; i += 2) {
+ for (int i = 0; i < aliases.length; i += 2)
keys[i / 2] = aliases[i];
- }
- Arrays.sort(keys);
}
+
String closest;
if (keys.length == 0) {
msg = "invalid-plugin";
- params = new Object[]{val.getProperty(), alias, e.toString(), loader};
- } else if ((closest = StringDistance.getClosestLevenshteinDistance(alias, keys, 0.5f)) == null) {
+ params = new Object[]{ val.getProperty(), alias, e.toString(), };
+ } else if ((closest = StringDistance.getClosestLevenshteinDistance
+ (alias, keys, 0.5f)) == null) {
msg = "invalid-plugin-aliases";
- params = new Object[]{val.getProperty(), alias, e.toString(), keys, loader};
+ params = new Object[]{
+ val.getProperty(), alias, e.toString(),
+ new TreeSet<String>(Arrays.asList(keys)), };
} else {
msg = "invalid-plugin-aliases-hint";
- params = new Object[]{val.getProperty(), alias, e.toString(), keys, closest, loader};
+ params = new Object[]{
+ val.getProperty(), alias, e.toString(),
+ new TreeSet<String>(Arrays.asList(keys)), closest, };
}
- e.printStackTrace();
return new ParseException(_loc.get(msg, params), e);
}
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/DoubleValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/DoubleValue.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/DoubleValue.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/DoubleValue.java Sat Nov 5 17:17:26 2011
@@ -25,14 +25,17 @@ import org.apache.commons.lang.StringUti
*
* @author Marc Prud'hommeaux
*/
-public class DoubleValue extends Value<Double> {
+public class DoubleValue extends Value {
private double value;
public DoubleValue(String prop) {
- super(Double.class, prop);
+ super(prop);
}
+ public Class<Double> getValueType() {
+ return double.class;
+ }
/**
* The internal value.
@@ -57,10 +60,16 @@ public class DoubleValue extends Value<D
}
protected void setInternalString(String val) {
- set (StringUtils.isEmpty(val) ? 0D : Double.parseDouble(val));
+ if (StringUtils.isEmpty(val))
+ set(0D);
+ else
+ set(Double.parseDouble(val));
}
protected void setInternalObject(Object obj) {
- set (obj == null ? 0D : ((Number)obj).doubleValue());
+ if (obj == null)
+ set(0D);
+ else
+ set(((Number) obj).doubleValue());
}
}
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/FileValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/FileValue.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/FileValue.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/FileValue.java Sat Nov 5 17:17:26 2011
@@ -29,12 +29,16 @@ import org.apache.openjpa.lib.util.J2DoP
*
* @author Marc Prud'hommeaux
*/
-public class FileValue extends Value<File> {
+public class FileValue extends Value {
private File value;
public FileValue(String prop) {
- super(File.class, prop);
+ super(prop);
+ }
+
+ public Class<File> getValueType() {
+ return File.class;
}
/**
@@ -65,7 +69,7 @@ public class FileValue extends Value<Fil
}
protected void setInternalObject(Object obj) {
- set((File)obj);
+ set((File) obj);
}
}
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/IntValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/IntValue.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/IntValue.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/IntValue.java Sat Nov 5 17:17:26 2011
@@ -25,12 +25,16 @@ import org.apache.commons.lang.StringUti
*
* @author Marc Prud'hommeaux
*/
-public class IntValue extends Value<Number> {
+public class IntValue extends Value {
private int value;
public IntValue(String prop) {
- super(Number.class, prop);
+ super(prop);
+ }
+
+ public Class<Integer> getValueType() {
+ return int.class;
}
/**
@@ -56,10 +60,16 @@ public class IntValue extends Value<Numb
}
protected void setInternalString(String val) {
- set (StringUtils.isEmpty(val) ? 0 : Integer.parseInt(val));
+ if (StringUtils.isEmpty(val))
+ set(0);
+ else
+ set(Integer.parseInt(val));
}
- protected void setInternalObject(Object num) {
- set (num == null ? 0 : ((Number)num).intValue());
+ protected void setInternalObject(Object obj) {
+ if (obj == null)
+ set(0);
+ else
+ set(((Number) obj).intValue());
}
}
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java Sat Nov 5 17:17:26 2011
@@ -18,51 +18,37 @@
*/
package org.apache.openjpa.lib.conf;
-import java.security.AccessController;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.openjpa.lib.log.Log;
-import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer;
-import org.apache.openjpa.lib.util.MultiClassLoader;
/**
* Simple configuration provider that sets configuration based on a
* provided map.
- * <br>
- * This provider uses a {@link MultiClassLoader flat class loader} comprised
- * of system class loader, context class loader and the loader that loaded
- * this class itself.
*
* @author Abe White
- * @author Pinaki Poddar
* @nojavadoc
*/
public class MapConfigurationProvider implements ConfigurationProvider {
- private Map _props;
- private final MultiClassLoader _loader;
- private static final Localizer _loc = Localizer.forPackage(MapConfigurationProvider.class);
+
+ private static final Localizer _loc = Localizer.forPackage
+ (MapConfigurationProvider.class);
+
+ private Map _props = null;
/**
- * Constructs a provider with default class loading scheme that employs
- * system class loader, current thread context class loader and the
- * class loader that loaded this class itself.
+ * Construct with null properties.
*/
public MapConfigurationProvider() {
- _loader = AccessController.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
- _loader.addClassLoader(MultiClassLoader.SYSTEM_LOADER);
- _loader.addClassLoader(MultiClassLoader.THREAD_LOADER);
- _loader.addClassLoader(this.getClass().getClassLoader());
}
-
/**
* Constructor; supply properties map.
*/
public MapConfigurationProvider(Map props) {
- this();
addProperties(props);
}
@@ -89,18 +75,13 @@ public class MapConfigurationProvider im
}
/**
- * Set properties and class loader into configuration.
+ * Set properties into configuration. If the log is non-null, will log
+ * a TRACE message about the set.
*/
protected void setInto(Configuration conf, Log log) {
- conf.addClassLoader(getClassLoader());
if (log != null && log.isTraceEnabled())
log.trace(_loc.get("conf-load", getProperties()));
if (_props != null)
conf.fromProperties(_props);
}
-
- @Override
- public MultiClassLoader getClassLoader() {
- return _loader;
- }
}
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ObjectValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ObjectValue.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ObjectValue.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ObjectValue.java Sat Nov 5 17:17:26 2011
@@ -18,72 +18,45 @@
*/
package org.apache.openjpa.lib.conf;
+import java.security.AccessController;
+
import org.apache.commons.lang.ObjectUtils;
+import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.lib.util.ReferenceMap;
+import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
/**
* An object {@link Value}.
*
* @author Abe White
- * @author Pinaki Poddar
*/
-public class ObjectValue<T> extends Value<T> {
+public class ObjectValue extends Value {
- private static final Localizer _loc = Localizer.forPackage(ObjectValue.class);
+ private static final Localizer _loc = Localizer.forPackage
+ (ObjectValue.class);
// cache the types' classloader
-// private static ConcurrentReferenceHashMap _classloaderCache =
-// new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.WEAK);
+ private static ConcurrentReferenceHashMap _classloaderCache =
+ new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.WEAK);
- private T _value = null;
+ private Object _value = null;
- public ObjectValue(Class<T> type, String prop) {
- super(type, prop);
- }
-
- public void setAlias(String key, Class<? extends T> value) {
- setAlias(key, value.getName());
- }
-
- /**
- * Sets the fully-qualified name of the given class as the value for an alias with fixed
- * name <tt>"default"</tt>.
- * Also set the string value to the key i.e. value of this plug-in is set to its
- * default value.
- *
- * @param value value for the alias. also the value set to this plug-in.
- *
- * @see #setDefaultAlias(String, Class)
- */
- public void setDefaultAlias(Class<? extends T> value) {
- setDefaultAlias("default", value);
- }
-
- /**
- * Sets the given key as the default alias for the fully-qualified name of the given class.
- * Also set the string value to the key i.e. value of this plug-in is set to its
- * default value.
- *
- * @param key alias which is also the default
- * @param value value for the alias. also the value set to this plug-in.
- */
- public void setDefaultAlias(String key, Class<? extends T> value) {
- setAlias(key, value == null ? null : value.getName());
- setDefault(key);
- setString(key);
+ public ObjectValue(String prop) {
+ super(prop);
}
/**
* The internal value.
*/
- public T get() {
+ public Object get() {
return _value;
}
/**
* The internal value.
*/
- public void set(T obj) {
+ public void set(Object obj) {
set(obj, false);
}
@@ -92,7 +65,7 @@ public class ObjectValue<T> extends Valu
*
* @param derived if true, this value was derived from other properties
*/
- public void set(T obj, boolean derived) {
+ public void set(Object obj, boolean derived) {
if (!derived) assertChangeable();
Object oldValue = _value;
_value = obj;
@@ -106,28 +79,29 @@ public class ObjectValue<T> extends Valu
* Instantiate the object as an instance of the given class. Equivalent
* to <code>instantiate(type, conf, true)</code>.
*/
- public T instantiate(Configuration conf) {
- return instantiate(conf, true);
+ public Object instantiate(Class<?> type, Configuration conf) {
+ return instantiate(type, conf, true);
}
/**
* Instantiate the object as an instance of the given class.
*/
- public T instantiate(Configuration conf, boolean fatal) {
+ public Object instantiate(Class<?> type, Configuration conf, boolean fatal)
+ {
throw new UnsupportedOperationException();
}
/**
* Configure the given object.
*/
- public Object configure(T obj, Configuration conf) {
+ public Object configure(Object obj, Configuration conf) {
return configure(obj, conf, true);
}
/**
* Configure the given object.
*/
- public Object configure(T obj, Configuration conf, boolean fatal) {
+ public Object configure(Object obj, Configuration conf, boolean fatal) {
throw new UnsupportedOperationException();
}
@@ -135,10 +109,25 @@ public class ObjectValue<T> extends Valu
* Allow subclasses to instantiate additional plugins. This method does
* not perform configuration.
*/
- public T newInstance(String clsName, Configuration conf, boolean fatal) {
- return Configurations.newInstance(clsName, this, conf, conf.getClassLoader(), fatal);
+ public Object newInstance(String clsName, Class<?> type, Configuration conf,
+ boolean fatal) {
+ ClassLoader cl = (ClassLoader) _classloaderCache.get(type);
+ if (cl == null) {
+ cl = AccessController.doPrivileged(
+ J2DoPrivHelper.getClassLoaderAction(type));
+ if (cl == null) { // System classloader is returned as null
+ cl = AccessController.doPrivileged(
+ J2DoPrivHelper.getSystemClassLoaderAction());
+ }
+ _classloaderCache.put(type, cl);
+ }
+ return Configurations.newInstance(clsName, this, conf, cl, fatal);
+ }
+
+ public Class<?> getValueType() {
+ return Object.class;
}
-
+
/**
* Implement this method to synchronize internal data with the new
* object value.
@@ -154,15 +143,11 @@ public class ObjectValue<T> extends Valu
if (str == null)
set(null);
else
- throw new IllegalArgumentException(_loc.get("cant-set-string", getProperty()).getMessage());
+ throw new IllegalArgumentException(_loc.get("cant-set-string",
+ getProperty()).getMessage());
}
protected void setInternalObject(Object obj) {
- set((T)obj);
+ set(obj);
}
-
- public Object getExternal() {
- return isHidden() ? Value.INVISIBLE : getString();
- }
-
}
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginListValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginListValue.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginListValue.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginListValue.java Sat Nov 5 17:17:26 2011
@@ -31,18 +31,15 @@ import org.apache.commons.lang.StringUti
* @author Abe White
* @see PluginValue
*/
-public class PluginListValue<T> extends ObjectValue<T[]> {
+public class PluginListValue extends ObjectValue {
private static final String[] EMPTY = new String[0];
private String[] _names = EMPTY;
private String[] _props = EMPTY;
-
- private final Class<T> elemType;
- public PluginListValue(Class<T[]> cls, String prop) {
- super(cls, prop);
- elemType = (Class<T>)cls.getComponentType();
+ public PluginListValue(String prop) {
+ super(prop);
}
/**
@@ -84,16 +81,17 @@ public class PluginListValue<T> extends
/**
* Instantiate the plugins as instances of the given class.
*/
- public T[] instantiate(Configuration conf, boolean fatal) {
- T[] ret;
- if (_names.length == 0) {
- ret = (T[])Array.newInstance(elemType, 0);
- } else {
- ret = (T[]) Array.newInstance(elemType, _names.length);
+ public Object instantiate(Class<?> elemType, Configuration conf,
+ boolean fatal) {
+ Object[] ret;
+ if (_names.length == 0)
+ ret = (Object[]) Array.newInstance(elemType, 0);
+ else {
+ ret = (Object[]) Array.newInstance(elemType, _names.length);
for (int i = 0; i < ret.length; i++) {
- PluginValue<T> elem = new PluginValue<T>(elemType, "element", false);
- ret[i] = elem.newInstance(_names[i], conf, fatal);
- Configurations.configureInstance(ret[i], conf, _props[i], getProperty());
+ ret[i] = newInstance(_names[i], elemType, conf, fatal);
+ Configurations.configureInstance(ret[i], conf, _props[i],
+ getProperty());
}
}
set(ret, true);
@@ -184,6 +182,10 @@ public class PluginListValue<T> extends
valueChanged();
}
+ public Class<Object []> getValueType() {
+ return Object[].class;
+ }
+
protected void objectChanged() {
Object[] vals = (Object[]) get();
if (vals == null || vals.length == 0)
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java Sat Nov 5 17:17:26 2011
@@ -33,16 +33,17 @@ import org.apache.openjpa.lib.util.Local
*
* @author Abe White
*/
-public class PluginValue<T> extends ObjectValue<T> {
+public class PluginValue extends ObjectValue {
- private static final Localizer _loc = Localizer.forPackage(PluginValue.class);
+ private static final Localizer _loc = Localizer.forPackage
+ (PluginValue.class);
private final boolean _singleton;
private String _name = null;
private String _props = null;
- public PluginValue(Class<T> type, String prop, boolean singleton) {
- super(type, prop);
+ public PluginValue(String prop, boolean singleton) {
+ super(prop);
_singleton = singleton;
}
@@ -97,25 +98,32 @@ public class PluginValue<T> extends Obje
/**
* Instantiate the plugin as an instance of the given class.
*/
- public T instantiate(Configuration conf, boolean fatal) {
- T obj = newInstance(_name, conf, fatal);
- return configure(obj, conf, fatal);
+ public Object instantiate(Class<?> type, Configuration conf, boolean fatal)
+ {
+ Object obj = newInstance(_name, type, conf, fatal);
+ Configurations.configureInstance(obj, conf, _props,
+ (fatal) ? getProperty() : null);
+ if (_singleton)
+ set(obj, true);
+ return obj;
}
/**
* Configure the given object.
*/
- public T configure(T obj, Configuration conf, boolean fatal) {
- Configurations.configureInstance(obj, conf, _props, fatal ? getProperty() : null);
+ public Object configure(Object obj, Configuration conf, boolean fatal) {
+ Configurations.configureInstance(obj, conf, _props,
+ (fatal) ? getProperty() : null);
if (_singleton)
set(obj, true);
return obj;
}
- public void set(T obj, boolean derived) {
+ public void set(Object obj, boolean derived) {
if (!_singleton)
- throw new IllegalStateException(_loc.get("not-singleton", getProperty()).getMessage());
+ throw new IllegalStateException(_loc.get("not-singleton",
+ getProperty()).getMessage());
super.set(obj, derived);
}
@@ -133,6 +141,10 @@ public class PluginValue<T> extends Obje
valueChanged();
}
+ public Class<Object> getValueType() {
+ return Object.class;
+ }
+
protected void objectChanged() {
Object obj = get();
_name = (obj == null) ? unalias(null) : obj.getClass().getName();
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java Sat Nov 5 17:17:26 2011
@@ -25,12 +25,10 @@ import java.util.Set;
/**
* Hooks for deriving products with additional functionality.
- * Parses configuration information from global, default or explicitly-specified
+ * Parses configuration information from global, default or explictly-specified
* resources. All implementations of this interface will have a chance to mutate
* a {@link Configuration} both before and after the user-specified
- * configuration data is loaded.
- * <br>
- * The order in which the product derivations are
+ * configuration data is loaded. The order in which the product derivations are
* evaluated is determined by the specificity of the derivation type.
*
* @author Abe White
@@ -57,21 +55,23 @@ public interface ProductDerivation {
* loading classes for the product this derivation represents to be sure
* they exist. Throw any throwable to indicate an invalid derivation.
* Invalid derivations will not be used.
- * Throw non-fatal {@link BootstrapException} to supress error reporting.
*/
- public void validate() throws Exception;
+ public void validate()
+ throws Exception;
/**
* Load globals into the returned ConfigurationProvider, or return null if
* no globals are found.
*/
- public ConfigurationProvider loadGlobals() throws Exception;
+ public ConfigurationProvider loadGlobals(ClassLoader loader)
+ throws Exception;
/**
* Load defaults into the returned ConfigurationProvider, or return null if
* no defaults are found.
*/
- public ConfigurationProvider loadDefaults() throws Exception;
+ public ConfigurationProvider loadDefaults(ClassLoader loader)
+ throws Exception;
/**
* Load the given given resource into the returned ConfigurationProvider,
@@ -81,7 +81,9 @@ public interface ProductDerivation {
* @param anchor optional named anchor within a multiple-configuration
* resource
*/
- public ConfigurationProvider load(String resource, String anchor) throws Exception;
+ public ConfigurationProvider load(String resource, String anchor,
+ ClassLoader loader)
+ throws Exception;
/**
* Load given file, or return null if it is not a file this receiver
@@ -89,7 +91,8 @@ public interface ProductDerivation {
*
* @param anchor optional named anchor within a multiple-configuration file
*/
- public ConfigurationProvider load(File file, String anchor) throws Exception;
+ public ConfigurationProvider load(File file, String anchor)
+ throws Exception;
/**
* Return a string identifying the default resource location for this
@@ -110,7 +113,8 @@ public interface ProductDerivation {
*
* @since 1.1.0
*/
- public List<String> getAnchorsInFile(File file) throws IOException, Exception;
+ public List<String> getAnchorsInFile(File file) throws IOException,
+ Exception;
/**
* Return a List<String> of all the anchors defined in
Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java Sat Nov 5 17:17:26 2011
@@ -34,6 +34,7 @@ import java.util.TreeSet;
import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
+import org.apache.openjpa.lib.util.JavaVersions;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.MultiClassLoader;
import org.apache.openjpa.lib.util.Services;
@@ -47,7 +48,8 @@ import org.apache.openjpa.lib.util.Servi
*/
public class ProductDerivations {
- private static final Localizer _loc = Localizer.forPackage(ProductDerivations.class);
+ private static final Localizer _loc = Localizer.forPackage
+ (ProductDerivations.class);
private static final ProductDerivation[] _derivations;
private static final String[] _derivationNames;
@@ -60,25 +62,22 @@ public class ProductDerivations {
l.addClassLoader(1, AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()));
_derivationNames = Services.getImplementors(ProductDerivation.class, l);
_derivationErrors = new Throwable[_derivationNames.length];
- List<ProductDerivation> derivations = new ArrayList<ProductDerivation>(_derivationNames.length);
+ List<ProductDerivation> derivations =
+ new ArrayList<ProductDerivation>(_derivationNames.length);
boolean errors = false;
for (int i = 0; i < _derivationNames.length; i++) {
try {
ProductDerivation d = (ProductDerivation)
- AccessController.doPrivileged(J2DoPrivHelper.newInstanceAction(
+ AccessController.doPrivileged(
+ J2DoPrivHelper.newInstanceAction(
Class.forName(_derivationNames[i], true, l)));
d.validate();
derivations.add(d);
} catch (Throwable t) {
- if (t instanceof BootstrapException && !((BootstrapException)t).isFatal()) {
- // do nothing
- } else {
- if (t instanceof PrivilegedActionException) {
- t = ((PrivilegedActionException) t).getException();
- }
- _derivationErrors[i] = t;
- errors = true;
- }
+ if (t instanceof PrivilegedActionException)
+ t = ((PrivilegedActionException) t).getException();
+ _derivationErrors[i] = t;
+ errors = true;
}
}
@@ -93,11 +92,14 @@ public class ProductDerivations {
// if some derivations weren't instantiable, warn
if (errors)
- System.err.println(_loc.get("bad-product-derivations", ProductDerivations.class.getName()));
+ System.err.println(_loc.get("bad-product-derivations",
+ ProductDerivations.class.getName()));
for (int i = 0; i < _derivationErrors.length; i++) {
- if (_derivationErrors[i] != null) {
- System.err.println(_derivationNames[i] + ":" + _derivationErrors[i]);
- }
+ if (_derivationErrors[i] == null)
+ continue;
+ System.err.println(_derivationNames[i] + ":" +
+ _derivationErrors[i]);
+ break;
}
Collections.sort(derivations, new ProductDerivationComparator());
@@ -158,18 +160,22 @@ public class ProductDerivations {
for (int i = 0; map != null && i < _prefixes.length; i++) {
String fullKey = _prefixes[i] + "." + partialKey;
if (map.containsKey(fullKey)) {
- if (firstKey == null) {
+ if (firstKey == null)
firstKey = fullKey;
- } else {
+ else {
// if we've already found a property with a previous
// prefix, then this is a collision.
- throw new IllegalStateException(_loc.get("dup-with-different-prefixes", firstKey, fullKey)
+ throw new IllegalStateException(_loc.get(
+ "dup-with-different-prefixes", firstKey, fullKey)
.getMessage());
}
}
}
- return (firstKey == null) ? _prefixes[0] + "." + partialKey : firstKey;
+ if (firstKey == null)
+ return _prefixes[0] + "." + partialKey;
+ else
+ return firstKey;
}
/**
@@ -252,16 +258,20 @@ public class ProductDerivations {
* @param anchor optional named anchor within a multiple-configuration
* resource
*/
- public static ConfigurationProvider load(String resource, String anchor) {
+ public static ConfigurationProvider load(String resource, String anchor,
+ ClassLoader loader) {
if (StringUtils.isEmpty(resource))
return null;
+ if (loader == null)
+ loader = AccessController.doPrivileged(
+ J2DoPrivHelper.getContextClassLoaderAction());
ConfigurationProvider provider = null;
StringBuilder errs = null;
// most specific to least
Throwable err = null;
for (int i = _derivations.length - 1; i >= 0; i--) {
try {
- provider = _derivations[i].load(resource, anchor);
+ provider = _derivations[i].load(resource, anchor, loader);
if (provider != null)
return provider;
} catch (Throwable t) {
@@ -284,9 +294,13 @@ public class ProductDerivations {
*
* @param anchor optional named anchor within a multiple-configuration file
*/
- public static ConfigurationProvider load(File file, String anchor) {
+ public static ConfigurationProvider load(File file, String anchor,
+ ClassLoader loader) {
if (file == null)
return null;
+ if (loader == null)
+ loader = AccessController.doPrivileged(
+ J2DoPrivHelper.getContextClassLoaderAction());
ConfigurationProvider provider = null;
StringBuilder errs = null;
Throwable err = null;
@@ -315,21 +329,26 @@ public class ProductDerivations {
/**
* Return a {@link ConfigurationProvider} that has parsed system defaults.
*/
- public static ConfigurationProvider loadDefaults() {
- return load(false);
+ public static ConfigurationProvider loadDefaults(ClassLoader loader) {
+ return load(loader, false);
}
/**
* Return a {@link ConfigurationProvider} that has parsed system globals.
*/
- public static ConfigurationProvider loadGlobals() {
- return load(true);
+ public static ConfigurationProvider loadGlobals(ClassLoader loader) {
+ return load(loader, true);
}
/**
* Load a built-in resource location.
*/
- private static ConfigurationProvider load(boolean globals) {
+ private static ConfigurationProvider load(ClassLoader loader,
+ boolean globals) {
+ if (loader == null)
+ loader = AccessController.doPrivileged(
+ J2DoPrivHelper.getContextClassLoaderAction());
+
ConfigurationProvider provider = null;
StringBuilder errs = null;
String type = (globals) ? "globals" : "defaults";
@@ -337,8 +356,8 @@ public class ProductDerivations {
// most specific to least
for (int i = _derivations.length - 1; i >= 0; i--) {
try {
- provider = (globals) ? _derivations[i].loadGlobals()
- : _derivations[i].loadDefaults();
+ provider = (globals) ? _derivations[i].loadGlobals(loader)
+ : _derivations[i].loadDefaults(loader);
if (provider != null)
return provider;
} catch (Throwable t) {
@@ -379,39 +398,47 @@ public class ProductDerivations {
StringBuilder errs = null;
Throwable err = null;
for (int i = _derivations.length - 1; i >= 0; i--) {
- ProductDerivation d = _derivations[i];
try {
if (propertiesLocation == null) {
- String loc = d.getDefaultResourceLocation();
- addAll(fqAnchors, loc, d.getAnchorsInResource(loc));
+ String loc = _derivations[i].getDefaultResourceLocation();
+ addAll(fqAnchors, loc,
+ _derivations[i].getAnchorsInResource(loc));
continue;
}
File f = new File(propertiesLocation);
- if (J2DoPrivHelper.isFileAction(f).run().booleanValue()) {
- addAll(fqAnchors, propertiesLocation, d.getAnchorsInFile(f));
+ if (((Boolean) J2DoPrivHelper.isFileAction(f).run())
+ .booleanValue()) {
+ addAll(fqAnchors, propertiesLocation,
+ _derivations[i].getAnchorsInFile(f));
} else {
- f = new File("META-INF" + File.separatorChar + propertiesLocation);
- if (J2DoPrivHelper.isFileAction(f).run().booleanValue()) {
- addAll(fqAnchors, propertiesLocation, d.getAnchorsInFile(f));
+ f = new File("META-INF" + File.separatorChar
+ + propertiesLocation);
+ if (((Boolean) J2DoPrivHelper.isFileAction(f).run())
+ .booleanValue()) {
+ addAll(fqAnchors, propertiesLocation,
+ _derivations[i].getAnchorsInFile(f));
} else {
- addAll(fqAnchors, propertiesLocation, d.getAnchorsInResource(propertiesLocation));
+ addAll(fqAnchors, propertiesLocation,
+ _derivations[i].getAnchorsInResource(
+ propertiesLocation));
}
}
} catch (Throwable t) {
err = t;
errs = (errs == null) ? new StringBuilder() : errs.append("\n");
- errs.append(d.getClass().getName() + ":" + t);
+ errs.append(_derivations[i].getClass().getName() + ":" + t);
}
}
reportErrors(errs, propertiesLocation, err);
return fqAnchors;
}
- private static void addAll(Collection<String> collection, String base, Collection<String> newMembers) {
+ private static void addAll(Collection collection, String base,
+ Collection newMembers) {
if (newMembers == null || collection == null)
return;
- for (Iterator<String> iter = newMembers.iterator(); iter.hasNext(); ) {
+ for (Iterator iter = newMembers.iterator(); iter.hasNext(); ) {
String fqLoc = base + "#" + iter.next();
if (!collection.contains(fqLoc))
collection.add(fqLoc);