Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java Sat Oct 29 00:44:11 2011
@@ -28,13 +28,23 @@ import org.apache.openjpa.audit.Auditor;
import org.apache.openjpa.datacache.CacheDistributionPolicy;
import org.apache.openjpa.datacache.ConcurrentDataCache;
import org.apache.openjpa.datacache.ConcurrentQueryCache;
+import org.apache.openjpa.datacache.DataCache;
import org.apache.openjpa.datacache.DataCacheManager;
import org.apache.openjpa.datacache.DataCacheManagerImpl;
+import org.apache.openjpa.datacache.DefaultCacheDistributionPolicy;
import org.apache.openjpa.datacache.PartitionedDataCache;
+import org.apache.openjpa.datacache.QueryCache;
+import org.apache.openjpa.datacache.TypeBasedCacheDistributionPolicy;
+import org.apache.openjpa.ee.AutomaticManagedRuntime;
+import org.apache.openjpa.ee.InvocationManagedRuntime;
+import org.apache.openjpa.ee.JNDIManagedRuntime;
import org.apache.openjpa.ee.ManagedRuntime;
import org.apache.openjpa.enhance.RuntimeUnenhancedClassesModes;
import org.apache.openjpa.event.BrokerFactoryEventManager;
+import org.apache.openjpa.event.ExceptionOrphanedKeyAction;
import org.apache.openjpa.event.LifecycleEventManager;
+import org.apache.openjpa.event.LogOrphanedKeyAction;
+import org.apache.openjpa.event.NoneOrphanedKeyAction;
import org.apache.openjpa.event.OrphanedKeyAction;
import org.apache.openjpa.event.RemoteCommitEventManager;
import org.apache.openjpa.event.RemoteCommitProvider;
@@ -43,20 +53,25 @@ import org.apache.openjpa.instrumentatio
import org.apache.openjpa.kernel.AutoClear;
import org.apache.openjpa.kernel.BrokerImpl;
import org.apache.openjpa.kernel.ConnectionRetainModes;
+import org.apache.openjpa.kernel.DetachState;
import org.apache.openjpa.kernel.FinderCache;
+import org.apache.openjpa.kernel.InMemorySavepointManager;
import org.apache.openjpa.kernel.InverseManager;
import org.apache.openjpa.kernel.LockLevels;
import org.apache.openjpa.kernel.LockManager;
+import org.apache.openjpa.kernel.NoneLockManager;
import org.apache.openjpa.kernel.PreparedQueryCache;
import org.apache.openjpa.kernel.QueryFlushModes;
import org.apache.openjpa.kernel.RestoreState;
import org.apache.openjpa.kernel.SavepointManager;
import org.apache.openjpa.kernel.Seq;
+import org.apache.openjpa.kernel.VersionLockManager;
import org.apache.openjpa.kernel.exps.AggregateListener;
import org.apache.openjpa.kernel.exps.FilterListener;
import org.apache.openjpa.lib.conf.BooleanValue;
import org.apache.openjpa.lib.conf.ConfigurationImpl;
import org.apache.openjpa.lib.conf.Configurations;
+import org.apache.openjpa.lib.conf.EnumValue;
import org.apache.openjpa.lib.conf.IntValue;
import org.apache.openjpa.lib.conf.ObjectValue;
import org.apache.openjpa.lib.conf.PluginListValue;
@@ -72,10 +87,13 @@ import org.apache.openjpa.lib.util.Local
import org.apache.openjpa.meta.MetaDataFactory;
import org.apache.openjpa.meta.MetaDataRepository;
import org.apache.openjpa.util.ClassResolver;
+import org.apache.openjpa.util.ClassResolverImpl;
import org.apache.openjpa.util.ImplHelper;
import org.apache.openjpa.util.ProxyManager;
+import org.apache.openjpa.util.ProxyManagerImpl;
import org.apache.openjpa.util.StoreFacadeTypeRegistry;
import org.apache.openjpa.validation.ValidatingLifecycleEventManager;
+import org.apache.openjpa.validation.Validator;
/**
* Implementation of the {@link OpenJPAConfiguration} interface.
@@ -96,16 +114,16 @@ public class OpenJPAConfigurationImpl
protected RemoteCommitEventManager remoteEventManager = null;
// openjpa properties
- public ObjectValue classResolverPlugin;
+ public ObjectValue<ClassResolver> classResolverPlugin;
public BrokerValue brokerPlugin;
- public ObjectValue dataCachePlugin;
- public ObjectValue dataCacheManagerPlugin;
- public ObjectValue auditorPlugin;
- public ObjectValue cacheDistributionPolicyPlugin;
+ public ObjectValue<DataCache> dataCachePlugin;
+ public ObjectValue<DataCacheManager> dataCacheManagerPlugin;
+ public ObjectValue<Auditor> auditorPlugin;
+ public ObjectValue<CacheDistributionPolicy> cacheDistributionPolicyPlugin;
public IntValue dataCacheTimeout;
- public ObjectValue queryCachePlugin;
+ public ObjectValue<QueryCache> queryCachePlugin;
public BooleanValue dynamicDataStructs;
- public ObjectValue managedRuntimePlugin;
+ public ObjectValue<ManagedRuntime> managedRuntimePlugin;
public BooleanValue transactionMode;
public IntValue connectionRetainMode;
public IntValue fetchBatchSize;
@@ -116,17 +134,17 @@ public class OpenJPAConfigurationImpl
public IntValue queryTimeout;
public IntValue readLockLevel;
public IntValue writeLockLevel;
- public ObjectValue seqPlugin;
- public PluginListValue filterListenerPlugins;
- public PluginListValue aggregateListenerPlugins;
+ public ObjectValue<Seq> seqPlugin;
+ public PluginListValue<FilterListener> filterListenerPlugins;
+ public PluginListValue<AggregateListener> aggregateListenerPlugins;
public BooleanValue retryClassRegistration;
- public ObjectValue proxyManagerPlugin;
+ public ObjectValue<ProxyManager> proxyManagerPlugin;
public StringValue connectionUserName;
public StringValue connectionPassword;
- public PluginValue encryptionProvider;
+ public PluginValue<EncryptionProvider> encryptionProvider;
public StringValue connectionURL;
public StringValue connectionDriverName;
- public ObjectValue connectionFactory;
+ public ObjectValue<Object> connectionFactory;
public StringValue connectionFactoryName;
public StringValue connectionProperties;
public StringValue connectionFactoryProperties;
@@ -136,46 +154,46 @@ public class OpenJPAConfigurationImpl
public StringValue connection2URL;
public StringValue connection2DriverName;
public StringValue connection2Properties;
- public ObjectValue connectionFactory2;
+ public ObjectValue<Object> connectionFactory2;
public StringValue connectionFactory2Name;
public StringValue connectionFactory2Properties;
public BooleanValue optimistic;
public IntValue autoClear;
public BooleanValue retainState;
public IntValue restoreState;
- public ObjectValue detachStatePlugin;
+ public ObjectValue<DetachOptions> detachStatePlugin;
public BooleanValue ignoreChanges;
public BooleanValue nontransactionalRead;
public BooleanValue nontransactionalWrite;
public BooleanValue refreshFromDataCache;
public BooleanValue multithreaded;
public StringValue mapping;
- public PluginValue metaFactoryPlugin;
+ public PluginValue<MetaDataFactory> metaFactoryPlugin;
public MetaDataRepositoryValue metaRepositoryPlugin;
- public ObjectValue lockManagerPlugin;
- public ObjectValue inverseManagerPlugin;
- public ObjectValue savepointManagerPlugin;
- public ObjectValue orphanedKeyPlugin;
- public ObjectValue compatibilityPlugin;
- public ObjectValue callbackPlugin;
+ public ObjectValue<LockManager> lockManagerPlugin;
+ public ObjectValue<InverseManager> inverseManagerPlugin;
+ public ObjectValue<SavepointManager> savepointManagerPlugin;
+ public ObjectValue<OrphanedKeyAction> orphanedKeyPlugin;
+ public ObjectValue<Compatibility> compatibilityPlugin;
+ public ObjectValue<CallbackOptions> callbackPlugin;
public QueryCompilationCacheValue queryCompilationCachePlugin;
public IntValue runtimeUnenhancedClasses;
public CacheMarshallersValue cacheMarshallerPlugins;
public BooleanValue eagerInitialization;
- public PluginValue preparedQueryCachePlugin;
- public PluginValue finderCachePlugin;
- public ObjectValue specification;
+ public PluginValue<PreparedQueryCache> preparedQueryCachePlugin;
+ public PluginValue<FinderCache> finderCachePlugin;
+ public ObjectValue<Specification> specification;
public StringValue validationMode;
- public ObjectValue validationFactory;
- public ObjectValue validator;
- public ObjectValue lifecycleEventManager;
+ public ObjectValue<Object> validationFactory;
+ public ObjectValue<Validator> validator;
+ public ObjectValue<LifecycleEventManager> lifecycleEventManager;
public StringValue validationGroupPrePersist;
public StringValue validationGroupPreUpdate;
public StringValue validationGroupPreRemove;
public StringValue dataCacheMode;
public BooleanValue dynamicEnhancementAgent;
- public ObjectValue instrumentationManager;
- public PluginListValue instrumentationProviders;
+ public ObjectValue<InstrumentationManager> instrumentationManager;
+ public PluginListValue<InstrumentationProvider> instrumentationProviders;
// custom values
public BrokerFactoryValue brokerFactoryPlugin;
@@ -213,145 +231,87 @@ public class OpenJPAConfigurationImpl
super(false);
String[] aliases;
- classResolverPlugin = addPlugin("ClassResolver", true);
- aliases = new String[] {
- "default", "org.apache.openjpa.util.ClassResolverImpl",
- // deprecated alias
- "spec", "org.apache.openjpa.util.ClassResolverImpl", };
- classResolverPlugin.setAliases(aliases);
- classResolverPlugin.setDefault(aliases[0]);
- classResolverPlugin.setString(aliases[0]);
- classResolverPlugin.setInstantiatingGetter("getClassResolverInstance");
+ classResolverPlugin = addPlugin(ClassResolver.class, true);
+ classResolverPlugin.setDefaultAlias(ClassResolverImpl.class);
+ // deprecated alias
+ classResolverPlugin.setAlias("spec", ClassResolverImpl.class);
- brokerFactoryPlugin = new BrokerFactoryValue();
- addValue(brokerFactoryPlugin);
+ addValue(brokerFactoryPlugin = new BrokerFactoryValue());
- brokerPlugin = new BrokerValue();
- addValue(brokerPlugin);
+ addValue(brokerPlugin = new BrokerValue());
- dataCacheManagerPlugin = addPlugin("DataCacheManager", true);
- aliases =
- new String[] { "default", DataCacheManagerImpl.class.getName(), };
- dataCacheManagerPlugin.setAliases(aliases);
- dataCacheManagerPlugin.setDefault(aliases[0]);
- dataCacheManagerPlugin.setString(aliases[0]);
- dataCacheManagerPlugin.setInstantiatingGetter("getDataCacheManager");
+ dataCacheManagerPlugin = addPlugin(DataCacheManager.class, true);
+ dataCacheManagerPlugin.setDefaultAlias(DataCacheManagerImpl.class);
- cacheDistributionPolicyPlugin = addPlugin("CacheDistributionPolicy", true);
- aliases = new String[] {
- "default", "org.apache.openjpa.datacache.DefaultCacheDistributionPolicy",
- "type-based", "org.apache.openjpa.datacache.TypeBasedCacheDistributionPolicy"};
- cacheDistributionPolicyPlugin.setAliases(aliases);
- cacheDistributionPolicyPlugin.setDefault(aliases[0]);
- cacheDistributionPolicyPlugin.setString(aliases[0]);
- cacheDistributionPolicyPlugin.setInstantiatingGetter("getCacheDistributionPolicy");
+ cacheDistributionPolicyPlugin = addPlugin(CacheDistributionPolicy.class, true);
+ cacheDistributionPolicyPlugin.setDefaultAlias(DefaultCacheDistributionPolicy.class);
+ cacheDistributionPolicyPlugin.setAlias("type-based", TypeBasedCacheDistributionPolicy.class);
- dataCachePlugin = addPlugin("DataCache", false);
- aliases = new String[] {
- "false", null,
- "true", ConcurrentDataCache.class.getName(),
- "concurrent", ConcurrentDataCache.class.getName(),
- "partitioned", PartitionedDataCache.class.getName(),
- };
- dataCachePlugin.setAliases(aliases);
- dataCachePlugin.setDefault(aliases[0]);
- dataCachePlugin.setString(aliases[0]);
+ dataCachePlugin = addPlugin(DataCache.class);
+ dataCachePlugin.setDefaultAlias("false", null);
+ dataCachePlugin.setAlias("true", ConcurrentDataCache.class);
+ dataCachePlugin.setAlias("concurrent", ConcurrentDataCache.class);
+ dataCachePlugin.setAlias("partitioned", PartitionedDataCache.class);
dataCacheTimeout = addInt("DataCacheTimeout");
dataCacheTimeout.setDefault("-1");
dataCacheTimeout.set(-1);
dataCacheTimeout.setDynamic(true);
- queryCachePlugin = addPlugin("QueryCache", false);
- aliases = new String[] {
- "false", null,
- "true", ConcurrentQueryCache.class.getName(),
- "concurrent", ConcurrentQueryCache.class.getName(),
- };
- queryCachePlugin.setAliases(aliases);
- queryCachePlugin.setDefault(aliases[0]);
- queryCachePlugin.setString(aliases[0]);
+ queryCachePlugin = addPlugin(QueryCache.class);
+ queryCachePlugin.setDefaultAlias("false", null);
+ queryCachePlugin.setAlias("true", ConcurrentQueryCache.class);
+ queryCachePlugin.setAlias("concurrent", ConcurrentQueryCache.class);
refreshFromDataCache = addBoolean("RefreshFromDataCache");
- refreshFromDataCache.setDefault("false");
refreshFromDataCache.set(false);
refreshFromDataCache.setDynamic(true);
dynamicDataStructs = addBoolean("DynamicDataStructs");
- dynamicDataStructs.setDefault("false");
dynamicDataStructs.set(false);
- lockManagerPlugin = addPlugin("LockManager", false);
- aliases =
- new String[] {
- "none", "org.apache.openjpa.kernel.NoneLockManager",
- "version", "org.apache.openjpa.kernel.VersionLockManager", };
- lockManagerPlugin.setAliases(aliases);
- lockManagerPlugin.setDefault(aliases[0]);
- lockManagerPlugin.setString(aliases[0]);
-
- inverseManagerPlugin = addPlugin("InverseManager", false);
- aliases = new String[] {
- "false", null,
- "true", "org.apache.openjpa.kernel.InverseManager", };
- inverseManagerPlugin.setAliases(aliases);
- inverseManagerPlugin.setDefault(aliases[0]);
- inverseManagerPlugin.setString(aliases[0]);
-
- savepointManagerPlugin = addPlugin("SavepointManager", true);
- aliases = new String[] {
- "in-mem", "org.apache.openjpa.kernel.InMemorySavepointManager", };
- savepointManagerPlugin.setAliases(aliases);
- savepointManagerPlugin.setDefault(aliases[0]);
- savepointManagerPlugin.setString(aliases[0]);
- savepointManagerPlugin.setInstantiatingGetter("getSavepointManagerInstance");
-
- orphanedKeyPlugin = addPlugin("OrphanedKeyAction", true);
- aliases = new String[] {
- "log", "org.apache.openjpa.event.LogOrphanedKeyAction",
- "exception", "org.apache.openjpa.event.ExceptionOrphanedKeyAction",
- "none", "org.apache.openjpa.event.NoneOrphanedKeyAction", };
- orphanedKeyPlugin.setAliases(aliases);
- orphanedKeyPlugin.setDefault(aliases[0]);
- orphanedKeyPlugin.setString(aliases[0]);
- orphanedKeyPlugin.setInstantiatingGetter("getOrphanedKeyActionInstance");
+ lockManagerPlugin = addPlugin(LockManager.class);
+ lockManagerPlugin.setDefaultAlias("none", NoneLockManager.class);
+ lockManagerPlugin.setAlias("version", VersionLockManager.class);
+
+ inverseManagerPlugin = addPlugin(InverseManager.class);
+ inverseManagerPlugin.setDefaultAlias("false", null);
+ inverseManagerPlugin.setAlias("true", InverseManager.class);
+
+ savepointManagerPlugin = addPlugin(SavepointManager.class, true);
+ savepointManagerPlugin.setDefaultAlias("in-mem", InMemorySavepointManager.class);
+
+ orphanedKeyPlugin = addPlugin(OrphanedKeyAction.class, true);
+ orphanedKeyPlugin.setDefaultAlias("log", LogOrphanedKeyAction.class);
+ orphanedKeyPlugin.setAlias("exception", ExceptionOrphanedKeyAction.class);
+ orphanedKeyPlugin.setAlias("none", NoneOrphanedKeyAction.class);
- remoteProviderPlugin = new RemoteCommitProviderValue();
- addValue(remoteProviderPlugin);
+ addValue(remoteProviderPlugin = new RemoteCommitProviderValue());
transactionMode = addBoolean("TransactionMode");
aliases = new String[] { "local", "false", "managed", "true", };
transactionMode.setAliases(aliases);
transactionMode.setDefault(aliases[0]);
- managedRuntimePlugin = addPlugin("ManagedRuntime", true);
- aliases = new String[] {
- "auto", "org.apache.openjpa.ee.AutomaticManagedRuntime",
- "jndi", "org.apache.openjpa.ee.JNDIManagedRuntime",
- "invocation", "org.apache.openjpa.ee.InvocationManagedRuntime", };
- managedRuntimePlugin.setAliases(aliases);
- managedRuntimePlugin.setDefault(aliases[0]);
- managedRuntimePlugin.setString(aliases[0]);
- managedRuntimePlugin
- .setInstantiatingGetter("getManagedRuntimeInstance");
+ managedRuntimePlugin = addPlugin(ManagedRuntime.class, true);
+ managedRuntimePlugin.setDefaultAlias("auto", AutomaticManagedRuntime.class);
+ managedRuntimePlugin.setAlias("jndi", JNDIManagedRuntime.class);
+ managedRuntimePlugin.setAlias("invocation", InvocationManagedRuntime.class);
- proxyManagerPlugin = addPlugin("ProxyManager", true);
- aliases = new String[] {
- "default", "org.apache.openjpa.util.ProxyManagerImpl" };
- proxyManagerPlugin.setAliases(aliases);
- proxyManagerPlugin.setDefault(aliases[0]);
- proxyManagerPlugin.setString(aliases[0]);
- proxyManagerPlugin.setInstantiatingGetter("getProxyManagerInstance");
+ proxyManagerPlugin = addPlugin(ProxyManager.class, true);
+ proxyManagerPlugin.setDefaultAlias(ProxyManagerImpl.class);
mapping = addString("Mapping");
- metaFactoryPlugin = addPlugin("MetaDataFactory", false);
+
+ metaFactoryPlugin = addPlugin(MetaDataFactory.class);
- metaRepositoryPlugin = (MetaDataRepositoryValue) addValue(new MetaDataRepositoryValue());
+ metaRepositoryPlugin = new MetaDataRepositoryValue();
+ addValue(metaRepositoryPlugin);
- connectionFactory = addObject("ConnectionFactory");
+ connectionFactory = addObject(Object.class, "ConnectionFactory");
connectionFactory.setInstantiatingGetter("getConnectionFactory");
- connectionFactory2 = addObject("ConnectionFactory2");
+ connectionFactory2 = addObject(Object.class, "ConnectionFactory2");
connectionFactory2.setInstantiatingGetter("getConnectionFactory2");
// This is done because this plug-in may get initialized very lazily
// when the runtime needs it for flush or a sequence. To keep it
@@ -367,7 +327,7 @@ public class OpenJPAConfigurationImpl
connectionPassword.addEquivalentKey("javax.persistence.jdbc.password");
connectionPassword.hide();
- encryptionProvider = addPlugin("EncryptionProvider",true);
+ encryptionProvider = addPlugin(EncryptionProvider.class, true);
connectionURL = addString("ConnectionURL");
connectionURL.addEquivalentKey("javax.persistence.jdbc.url");
@@ -399,9 +359,8 @@ public class OpenJPAConfigurationImpl
autoClear = addInt("AutoClear");
aliases =
- new String[] { "datastore",
- String.valueOf(AutoClear.CLEAR_DATASTORE), "all",
- String.valueOf(AutoClear.CLEAR_ALL), };
+ new String[] { "datastore", String.valueOf(AutoClear.CLEAR_DATASTORE),
+ "all", String.valueOf(AutoClear.CLEAR_ALL), };
autoClear.setAliases(aliases);
autoClear.setDefault(aliases[0]);
autoClear.set(AutoClear.CLEAR_DATASTORE);
@@ -427,16 +386,11 @@ public class OpenJPAConfigurationImpl
autoDetach = new AutoDetachValue();
addValue(autoDetach);
- detachStatePlugin = addPlugin("DetachState", true);
- aliases = new String[] {
- "loaded", DetachOptions.Loaded.class.getName(),
- "fgs", DetachOptions.FetchGroups.class.getName(),
- "fetch-groups", DetachOptions.FetchGroups.class.getName(),
- "all", DetachOptions.All.class.getName(),
- };
- detachStatePlugin.setAliases(aliases);
- detachStatePlugin.setDefault(aliases[0]);
- detachStatePlugin.setString(aliases[0]);
+ detachStatePlugin = addPlugin(DetachOptions.class, "DetachState", true);
+ detachStatePlugin.setDefaultAlias("loaded", DetachOptions.Loaded.class);
+ detachStatePlugin.setAlias("fgs", DetachOptions.FetchGroups.class);
+ detachStatePlugin.setAlias("fetch-groups", DetachOptions.FetchGroups.class);
+ detachStatePlugin.setAlias("all", DetachOptions.All.class);
detachStatePlugin.setInstantiatingGetter("getDetachStateInstance");
ignoreChanges = addBoolean("IgnoreChanges");
@@ -516,28 +470,21 @@ public class OpenJPAConfigurationImpl
connectionRetainMode.setAliasListComprehensive(true);
connectionRetainMode.set(ConnectionRetainModes.CONN_RETAIN_DEMAND);
- filterListenerPlugins = addPluginList("FilterListeners");
+ filterListenerPlugins = addPluginList(FilterListener[].class, "FilterListeners");
filterListenerPlugins.setInstantiatingGetter("getFilterListenerInstances");
- aggregateListenerPlugins = addPluginList("AggregateListeners");
+ aggregateListenerPlugins = addPluginList(AggregateListener[].class, "AggregateListeners");
aggregateListenerPlugins.setInstantiatingGetter("getAggregateListenerInstances");
retryClassRegistration = addBoolean("RetryClassRegistration");
- compatibilityPlugin = addPlugin("Compatibility", true);
- aliases = new String[] { "default", Compatibility.class.getName() };
- compatibilityPlugin.setAliases(aliases);
- compatibilityPlugin.setDefault(aliases[0]);
- compatibilityPlugin.setString(aliases[0]);
- compatibilityPlugin.setInstantiatingGetter("getCompatibilityInstance");
-
- callbackPlugin = addPlugin("Callbacks", true);
- aliases = new String[] { "default", CallbackOptions.class.getName() };
- callbackPlugin.setAliases(aliases);
- callbackPlugin.setDefault(aliases[0]);
- callbackPlugin.setString(aliases[0]);
+ compatibilityPlugin = addPlugin(Compatibility.class, "Compatibility", true);
+ compatibilityPlugin.setDefaultAlias(Compatibility.class);
+
+ callbackPlugin = addPlugin(CallbackOptions.class, "Callbacks", true);
+ callbackPlugin.setDefaultAlias(CallbackOptions.class);
callbackPlugin.setInstantiatingGetter("getCallbackOptionsInstance");
-
+
queryCompilationCachePlugin = new QueryCompilationCacheValue("QueryCompilationCache");
queryCompilationCachePlugin.setInstantiatingGetter("getQueryCompilationCacheInstance");
addValue(queryCompilationCachePlugin);
@@ -564,37 +511,24 @@ public class OpenJPAConfigurationImpl
queryTimeout.setDefault("-1");
queryTimeout.setDynamic(true);
- lifecycleEventManager = addPlugin("LifecycleEventManager", true);
- aliases = new String[] {
- "default", LifecycleEventManager.class.getName(),
- "validating", ValidatingLifecycleEventManager.class.getName(),
- };
- lifecycleEventManager.setAliases(aliases);
- lifecycleEventManager.setDefault(aliases[0]);
- lifecycleEventManager.setString(aliases[0]);
- lifecycleEventManager.setInstantiatingGetter("getLifecycleEventManagerInstance");
+ lifecycleEventManager = addPlugin(LifecycleEventManager.class, true);
+ lifecycleEventManager.setDefaultAlias(LifecycleEventManager.class);
+ lifecycleEventManager.setAlias("validating", ValidatingLifecycleEventManager.class);
dynamicEnhancementAgent = addBoolean("DynamicEnhancementAgent");
dynamicEnhancementAgent.setDefault("true");
dynamicEnhancementAgent.set(true);
- instrumentationManager = addPlugin("InstrumentationManager", true);
- aliases =
- new String[] { "default", InstrumentationManagerImpl.class.getName(), };
- instrumentationManager.setAliases(aliases);
- instrumentationManager.setDefault(aliases[0]);
- instrumentationManager.setString(aliases[0]);
- instrumentationManager.setInstantiatingGetter("getInstrumentationManager");
+ instrumentationManager = addPlugin(InstrumentationManager.class, true);
+ instrumentationManager.setDefaultAlias(InstrumentationManagerImpl.class);
- instrumentationProviders = addPluginList("Instrumentation");
+ instrumentationProviders = addPluginList(InstrumentationProvider[].class, "Instrumentation");
aliases = new String[] { "jmx", "org.apache.openjpa.instrumentation.jmx.JMXProvider" };
instrumentationProviders.setAliases(aliases);
instrumentationProviders.setInstantiatingGetter("getInstrumentationInstances");
- auditorPlugin = addPlugin("Auditor", true);
- aliases = new String[] { "default", AuditLogger.class.getName(), };
- auditorPlugin.setAliases(aliases);
- auditorPlugin.setInstantiatingGetter("getAuditorInstance");
+ auditorPlugin = addPlugin(Auditor.class, true);
+ auditorPlugin.setAlias("default", AuditLogger.class);
// initialize supported options that some runtimes may not support
supportedOptions.add(OPTION_NONTRANS_READ);
@@ -634,7 +568,7 @@ public class OpenJPAConfigurationImpl
}
public Specification getSpecificationInstance() {
- return (Specification)specification.get();
+ return specification.get();
}
/**
@@ -665,8 +599,8 @@ public class OpenJPAConfigurationImpl
public ClassResolver getClassResolverInstance() {
if (classResolverPlugin.get() == null)
- classResolverPlugin.instantiate(ClassResolver.class, this);
- return (ClassResolver) classResolverPlugin.get();
+ classResolverPlugin.instantiate(this);
+ return classResolverPlugin.get();
}
public void setBrokerFactory(String factory) {
@@ -686,7 +620,7 @@ public class OpenJPAConfigurationImpl
}
public BrokerImpl newBrokerInstance(String user, String pass) {
- BrokerImpl broker = (BrokerImpl) brokerPlugin.instantiate(BrokerImpl.class, this);
+ BrokerImpl broker = (BrokerImpl) brokerPlugin.instantiate(this);
if (broker != null)
broker.setAuthentication(user, pass);
return broker;
@@ -707,9 +641,9 @@ public class OpenJPAConfigurationImpl
}
public DataCacheManager getDataCacheManagerInstance() {
- DataCacheManager dcm = (DataCacheManager) dataCacheManagerPlugin.get();
+ DataCacheManager dcm = dataCacheManagerPlugin.get();
if (dcm == null) {
- dcm = (DataCacheManager) dataCacheManagerPlugin.instantiate(DataCacheManager.class, this);
+ dcm = (DataCacheManager) dataCacheManagerPlugin.instantiate(this);
if (dcm != null) {
dcm.initialize(this, dataCachePlugin, queryCachePlugin);
}
@@ -784,8 +718,7 @@ public class OpenJPAConfigurationImpl
// don't validate plugin properties on instantiation because it
// is likely that back ends will override defaults with their
// own subclasses with new properties
- return (LockManager) lockManagerPlugin.instantiate(LockManager.class,
- this, false);
+ return lockManagerPlugin.instantiate(this, false);
}
public void setInverseManager(String inverseManager) {
@@ -797,7 +730,7 @@ public class OpenJPAConfigurationImpl
}
public InverseManager newInverseManagerInstance() {
- return (InverseManager) inverseManagerPlugin.instantiate(InverseManager.class, this);
+ return inverseManagerPlugin.instantiate(this);
}
public void setSavepointManager(String savepointManager) {
@@ -810,8 +743,8 @@ public class OpenJPAConfigurationImpl
public SavepointManager getSavepointManagerInstance() {
if (savepointManagerPlugin.get() == null)
- savepointManagerPlugin.instantiate(SavepointManager.class, this);
- return (SavepointManager) savepointManagerPlugin.get();
+ savepointManagerPlugin.instantiate(this);
+ return savepointManagerPlugin.get();
}
public void setOrphanedKeyAction(String action) {
@@ -824,8 +757,8 @@ public class OpenJPAConfigurationImpl
public OrphanedKeyAction getOrphanedKeyActionInstance() {
if (orphanedKeyPlugin.get() == null)
- orphanedKeyPlugin.instantiate(OrphanedKeyAction.class, this);
- return (OrphanedKeyAction) orphanedKeyPlugin.get();
+ orphanedKeyPlugin.instantiate(this);
+ return orphanedKeyPlugin.get();
}
public void setOrphanedKeyAction(OrphanedKeyAction action) {
@@ -888,8 +821,8 @@ public class OpenJPAConfigurationImpl
public ManagedRuntime getManagedRuntimeInstance() {
if (managedRuntimePlugin.get() == null)
- managedRuntimePlugin.instantiate(ManagedRuntime.class, this);
- return (ManagedRuntime) managedRuntimePlugin.get();
+ managedRuntimePlugin.instantiate(this);
+ return managedRuntimePlugin.get();
}
public void setProxyManager(String proxyManager) {
@@ -906,8 +839,8 @@ public class OpenJPAConfigurationImpl
public ProxyManager getProxyManagerInstance() {
if (proxyManagerPlugin.get() == null)
- proxyManagerPlugin.instantiate(ProxyManager.class, this);
- return (ProxyManager) proxyManagerPlugin.get();
+ proxyManagerPlugin.instantiate(this);
+ return proxyManagerPlugin.get();
}
public void setMapping(String mapping) {
@@ -919,7 +852,7 @@ public class OpenJPAConfigurationImpl
}
public void setMetaDataFactory(String meta) {
- this.metaFactoryPlugin.setString(meta);
+ metaFactoryPlugin.setString(meta);
}
public String getMetaDataFactory() {
@@ -927,12 +860,11 @@ public class OpenJPAConfigurationImpl
}
public MetaDataFactory newMetaDataFactoryInstance() {
- return (MetaDataFactory) metaFactoryPlugin.instantiate(
- MetaDataFactory.class, this);
+ return metaFactoryPlugin.instantiate(this);
}
public void setMetaDataRepository(String meta) {
- this.metaRepositoryPlugin.setString(meta);
+ metaRepositoryPlugin.setString(meta);
}
public String getMetaDataRepository() {
@@ -954,24 +886,23 @@ public class OpenJPAConfigurationImpl
}
public MetaDataRepository newMetaDataRepositoryInstance() {
- return (MetaDataRepository) metaRepositoryPlugin.instantiate(
- MetaDataRepository.class, this);
+ return metaRepositoryPlugin.instantiate(this);
}
- public void setConnectionUserName(String connectionUserName) {
- this.connectionUserName.setString(connectionUserName);
+ public void setConnectionUserName(String userName) {
+ connectionUserName.setString(userName);
}
public String getConnectionUserName() {
return connectionUserName.getString();
}
- public void setConnectionPassword(String connectionPassword) {
- this.connectionPassword.setString(connectionPassword);
+ public void setConnectionPassword(String pwd) {
+ connectionPassword.setString(pwd);
}
public String getConnectionPassword() {
- EncryptionProvider p = getEncryptionProvider();
+ EncryptionProvider p = getEncryptionProviderInstance();
if(p != null) {
return p.decrypt(connectionPassword.getString());
}
@@ -1075,8 +1006,8 @@ public class OpenJPAConfigurationImpl
}
public String getConnection2Password() {
- EncryptionProvider p = getEncryptionProvider();
- if(p != null){
+ EncryptionProvider p = getEncryptionProviderInstance();
+ if (p != null) {
return p.decrypt(connection2Password.getString());
}
return connection2Password.getString();
@@ -1224,8 +1155,8 @@ public class OpenJPAConfigurationImpl
public DetachOptions getDetachStateInstance() {
if (detachStatePlugin.get() == null)
- detachStatePlugin.instantiate(DetachOptions.class, this);
- return (DetachOptions) detachStatePlugin.get();
+ detachStatePlugin.instantiate(this);
+ return detachStatePlugin.get();
}
public void setIgnoreChanges(boolean ignoreChanges) {
@@ -1234,7 +1165,7 @@ public class OpenJPAConfigurationImpl
public void setIgnoreChanges(Boolean ignoreChanges) {
if (ignoreChanges != null)
- setIgnoreChanges(ignoreChanges.booleanValue());
+ setIgnoreChanges(ignoreChanges);
}
public boolean getIgnoreChanges() {
@@ -1405,8 +1336,8 @@ public class OpenJPAConfigurationImpl
public Seq getSequenceInstance() {
if (seqPlugin.get() == null)
- seqPlugin.instantiate(Seq.class, this);
- return (Seq) seqPlugin.get();
+ seqPlugin.instantiate(this);
+ return seqPlugin.get();
}
public void setConnectionRetainMode(String connectionRetainMode) {
@@ -1439,8 +1370,8 @@ public class OpenJPAConfigurationImpl
public FilterListener[] getFilterListenerInstances() {
if (filterListenerPlugins.get() == null)
- filterListenerPlugins.instantiate(FilterListener.class, this);
- return (FilterListener[]) filterListenerPlugins.get();
+ filterListenerPlugins.instantiate(this);
+ return filterListenerPlugins.get();
}
public void setAggregateListeners(String aggregateListeners) {
@@ -1457,8 +1388,8 @@ public class OpenJPAConfigurationImpl
public AggregateListener[] getAggregateListenerInstances() {
if (aggregateListenerPlugins.get() == null)
- aggregateListenerPlugins.instantiate(AggregateListener.class, this);
- return (AggregateListener[]) aggregateListenerPlugins.get();
+ aggregateListenerPlugins.instantiate(this);
+ return aggregateListenerPlugins.get();
}
public void setRetryClassRegistration(boolean retry) {
@@ -1493,11 +1424,11 @@ public class OpenJPAConfigurationImpl
Specification spec = getSpecificationInstance();
Compatibility comp = spec != null ? spec.getCompatibility() : null;
if (comp == null)
- compatibilityPlugin.instantiate(Compatibility.class, this);
+ compatibilityPlugin.instantiate(this);
else
compatibilityPlugin.configure(comp, this);
}
- return (Compatibility) compatibilityPlugin.get();
+ return compatibilityPlugin.get();
}
public String getCallbackOptions() {
@@ -1510,8 +1441,8 @@ public class OpenJPAConfigurationImpl
public CallbackOptions getCallbackOptionsInstance() {
if (callbackPlugin.get() == null)
- callbackPlugin.instantiate(CallbackOptions.class, this);
- return (CallbackOptions) callbackPlugin.get();
+ callbackPlugin.instantiate(this);
+ return callbackPlugin.get();
}
public String getQueryCompilationCache() {
@@ -1524,8 +1455,8 @@ public class OpenJPAConfigurationImpl
public Map getQueryCompilationCacheInstance() {
if (queryCompilationCachePlugin.get() == null)
- queryCompilationCachePlugin.instantiate(Map.class, this);
- return (Map) queryCompilationCachePlugin.get();
+ queryCompilationCachePlugin.instantiate(this);
+ return queryCompilationCachePlugin.get();
}
public StoreFacadeTypeRegistry getStoreFacadeTypeRegistry() {
@@ -1626,8 +1557,8 @@ public class OpenJPAConfigurationImpl
public InstrumentationProvider[] getInstrumentationInstances() {
if (instrumentationProviders.get() == null)
- instrumentationProviders.instantiate(InstrumentationProvider.class, this);
- return (InstrumentationProvider[]) instrumentationProviders.get();
+ instrumentationProviders.instantiate(this);
+ return instrumentationProviders.get();
}
public void setInstrumentationManager(String mgr) {
@@ -1647,7 +1578,7 @@ public class OpenJPAConfigurationImpl
public InstrumentationManager getInstrumentationManagerInstance() {
InstrumentationManager im = (InstrumentationManager) instrumentationManager.get();
if (im == null) {
- im = (InstrumentationManager) instrumentationManager.instantiate(InstrumentationManager.class, this);
+ im = instrumentationManager.instantiate(this);
if (im != null) {
im.initialize(this, instrumentationProviders);
im.start(InstrumentationLevel.IMMEDIATE, this);
@@ -1696,10 +1627,9 @@ public class OpenJPAConfigurationImpl
return null;
if (preparedQueryCachePlugin.get() == null) {
- preparedQueryCachePlugin.instantiate(PreparedQueryCache.class,
- this);
+ preparedQueryCachePlugin.instantiate(this);
}
- return (PreparedQueryCache)preparedQueryCachePlugin.get();
+ return preparedQueryCachePlugin.get();
}
public void setFinderCache(String finderCache) {
@@ -1712,9 +1642,9 @@ public class OpenJPAConfigurationImpl
public FinderCache getFinderCacheInstance() {
if (finderCachePlugin.get() == null) {
- finderCachePlugin.instantiate(FinderCache.class, this);
+ finderCachePlugin.instantiate(this);
}
- return (FinderCache)finderCachePlugin.get();
+ return finderCachePlugin.get();
}
public Object getValidationFactoryInstance() {
@@ -1725,11 +1655,11 @@ public class OpenJPAConfigurationImpl
validationFactory.set(factory);
}
- public Object getValidatorInstance() {
+ public Validator getValidatorInstance() {
return validator.get();
}
- public void setValidatorInstance(Object val) {
+ public void setValidatorInstance(Validator val) {
validator.set(val);
}
@@ -1741,8 +1671,7 @@ public class OpenJPAConfigurationImpl
LifecycleEventManager lem = (LifecycleEventManager)
lifecycleEventManager.get();
if (lem == null) {
- lem = (LifecycleEventManager)lifecycleEventManager
- .instantiate(LifecycleEventManager.class, this);
+ lem = lifecycleEventManager.instantiate(this);
}
return lem;
}
@@ -1773,10 +1702,10 @@ public class OpenJPAConfigurationImpl
encryptionProvider.setString(p);
}
- public EncryptionProvider getEncryptionProvider() {
+ public EncryptionProvider getEncryptionProviderInstance() {
if (encryptionProvider.get() == null)
- encryptionProvider.instantiate(EncryptionProvider.class, this);
- return (EncryptionProvider) encryptionProvider.get();
+ encryptionProvider.instantiate(this);
+ return encryptionProvider.get();
}
public void setDataCacheMode(String mode) {
@@ -1793,10 +1722,9 @@ public class OpenJPAConfigurationImpl
}
public CacheDistributionPolicy getCacheDistributionPolicyInstance() {
- CacheDistributionPolicy policy = (CacheDistributionPolicy) cacheDistributionPolicyPlugin.get();
+ CacheDistributionPolicy policy = cacheDistributionPolicyPlugin.get();
if (policy == null) {
- policy = (CacheDistributionPolicy)
- cacheDistributionPolicyPlugin.instantiate(CacheDistributionPolicy.class, this);
+ policy = cacheDistributionPolicyPlugin.instantiate(this);
}
return policy;
}
@@ -1818,9 +1746,9 @@ public class OpenJPAConfigurationImpl
}
public Auditor getAuditorInstance() {
- Auditor auditor = (Auditor) auditorPlugin.get();
+ Auditor auditor = auditorPlugin.get();
if (auditor == null) {
- auditor = (Auditor) auditorPlugin.instantiate(Auditor.class, this);
+ auditor = auditorPlugin.instantiate(this);
}
return auditor;
}
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/QueryCompilationCacheValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/QueryCompilationCacheValue.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/QueryCompilationCacheValue.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/QueryCompilationCacheValue.java Sat Oct 29 00:44:11 2011
@@ -36,7 +36,7 @@ import org.apache.openjpa.util.CacheMap;
* @nojavadoc
*/
public class QueryCompilationCacheValue
- extends PluginValue {
+ extends PluginValue<Map> {
public static final String[] ALIASES = {
"true", CacheMap.class.getName(),
@@ -45,19 +45,18 @@ public class QueryCompilationCacheValue
};
public QueryCompilationCacheValue(String prop) {
- super(prop, true);
+ super(Map.class, prop, true);
setAliases(ALIASES);
setDefault(ALIASES[0]);
setClassName(ALIASES[1]);
}
- public Object newInstance(String clsName, Class type,
- Configuration conf, boolean fatal) {
+ public Map newInstance(String clsName, Configuration conf, boolean fatal) {
// make sure map handles concurrency
Map map;
try {
- map = (Map) super.newInstance(clsName, type, conf, fatal);
+ map = super.newInstance(clsName, conf, fatal);
} catch (ParseException pe) {
// OPENJPA256: this class differs from most plugins in that
// the plugin type is the standard java interface Map.class (rather
@@ -68,8 +67,7 @@ public class QueryCompilationCacheValue
// the ParseException (which is what we wrap the
// ClassNotFoundException in) and try again, this time using
// this class' ClassLoader.
- map = (Map) super.newInstance(clsName,
- QueryCompilationCacheValue.class, conf, fatal);
+ map = super.newInstance(clsName, conf, fatal);
} catch (IllegalArgumentException iae) {
// OPENJPA256: this class differs from most plugins in that
// the plugin type is the standard java interface Map.class (rather
@@ -80,8 +78,7 @@ public class QueryCompilationCacheValue
// the IllegalArgumentException (which is what we wrap the
// ClassNotFoundException in) and try again, this time using
// this class' ClassLoader.
- map = (Map) super.newInstance(clsName,
- QueryCompilationCacheValue.class, conf, fatal);
+ map = super.newInstance(clsName, conf, fatal);
}
if (map != null && !(map instanceof Hashtable)
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/RemoteCommitProviderValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/RemoteCommitProviderValue.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/RemoteCommitProviderValue.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/RemoteCommitProviderValue.java Sat Oct 29 00:44:11 2011
@@ -35,7 +35,7 @@ import org.apache.openjpa.lib.util.Optio
* @nojavadoc
*/
public class RemoteCommitProviderValue
- extends PluginValue {
+ extends PluginValue<RemoteCommitProvider> {
private static final String[] ALIASES = new String[]{
"sjvm", "org.apache.openjpa.event.SingleJVMRemoteCommitProvider",
@@ -47,7 +47,7 @@ public class RemoteCommitProviderValue
private Boolean _transmitPersIds = null;
public RemoteCommitProviderValue() {
- super("RemoteCommitProvider", true);
+ super(RemoteCommitProvider.class, "RemoteCommitProvider", true);
setAliases(ALIASES);
}
@@ -67,7 +67,7 @@ public class RemoteCommitProviderValue
* The cached provider.
*/
public RemoteCommitProvider getProvider() {
- return (RemoteCommitProvider) get();
+ return get();
}
/**
@@ -101,10 +101,8 @@ public class RemoteCommitProviderValue
/**
* Instantiate the provider.
*/
- public RemoteCommitProvider instantiateProvider(Configuration conf,
- boolean fatal) {
- return (RemoteCommitProvider) instantiate(RemoteCommitProvider.class,
- conf, fatal);
+ public RemoteCommitProvider instantiateProvider(Configuration conf, boolean fatal) {
+ return instantiate(conf, fatal);
}
/**
@@ -119,8 +117,8 @@ public class RemoteCommitProviderValue
/**
* Override to keep decorators out of transport configuration.
*/
- public Object instantiate(Class type, Configuration conf, boolean fatal) {
- Object obj = newInstance(getClassName(), type, conf, fatal);
+ public RemoteCommitProvider instantiate(Configuration conf, boolean fatal) {
+ RemoteCommitProvider obj = newInstance(getClassName(), conf, fatal);
parseOptions();
Configurations.configureInstance(obj, conf, _opts, getProperty());
set(obj, true);
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SeqValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SeqValue.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SeqValue.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SeqValue.java Sat Oct 29 00:44:11 2011
@@ -18,6 +18,7 @@
*/
package org.apache.openjpa.conf;
+import org.apache.openjpa.kernel.Seq;
import org.apache.openjpa.kernel.TimeSeededSeq;
import org.apache.openjpa.lib.conf.PluginValue;
import org.apache.openjpa.meta.SequenceMetaData;
@@ -31,7 +32,7 @@ import org.apache.openjpa.meta.SequenceM
* @nojavadoc
*/
public class SeqValue
- extends PluginValue {
+ extends PluginValue<Seq> {
private static final String[] ALIASES = new String[]{
SequenceMetaData.IMPL_TIME, TimeSeededSeq.class.getName(),
@@ -41,7 +42,7 @@ public class SeqValue
};
public SeqValue(String prop) {
- super(prop, true);
+ super(Seq.class, prop, true);
setAliases(ALIASES);
setDefault(ALIASES[0]);
setClassName(ALIASES[1]);
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SpecificationPlugin.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SpecificationPlugin.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SpecificationPlugin.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/SpecificationPlugin.java Sat Oct 29 00:44:11 2011
@@ -33,22 +33,17 @@ import org.apache.openjpa.util.UserExcep
* @author Pinaki Poddar
*
*/
-public class SpecificationPlugin extends ObjectValue implements ValueListener {
+public class SpecificationPlugin extends ObjectValue<Specification> implements ValueListener {
private Configuration _conf;
protected static final Localizer _loc = Localizer.forPackage
(SpecificationPlugin.class);
public SpecificationPlugin(Configuration conf, String prop) {
- super(prop);
+ super(Specification.class, prop);
_conf = conf;
addListener(this);
}
- @Override
- public Class<?> getValueType() {
- return Specification.class;
- }
-
/**
* Set a value from the given String after validating.
*
@@ -67,16 +62,12 @@ public class SpecificationPlugin extends
* @param obj can be null to set the Specification to null.
*/
@Override
- public void set(Object obj) {
+ public void set(Specification obj) {
if (obj == null) {
super.set(null);
return;
}
- if (obj instanceof Specification == false) {
- throw new UserException(_loc.get("spec-wrong-obj", obj,
- obj.getClass())).setFatal(true);
- }
- validateOverwrite((Specification)obj);
+ validateOverwrite(obj);
super.set(obj);
}
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java Sat Oct 29 00:44:11 2011
@@ -101,11 +101,7 @@ public abstract class AbstractQueryCache
entityTimestampMap = new ConcurrentHashMap<String,Long>();
// Get all persistence types to pre-load the entityTimestamp Map
- Collection perTypes =
- conf.getMetaDataRepositoryInstance().getPersistentTypeNames(
- false,
- AccessController.doPrivileged(J2DoPrivHelper
- .getContextClassLoaderAction()));
+ Collection perTypes = conf.getMetaDataRepositoryInstance().getPersistentTypeNames(false);
// Pre-load all the entity types into the HashMap to handle
// synchronization on the map efficiently
@@ -303,7 +299,7 @@ public abstract class AbstractQueryCache
// ok if no metadata for oid; that just means the pc type
// probably hasn't been loaded into this JVM yet, and therefore
// there's no chance that it's in the cache anyway
- meta = repos.getMetaData(oid, null, false);
+ meta = repos.getMetaData(oid, false);
if (meta != null)
classes.add(meta.getDescribedType());
}
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/Caches.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/Caches.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/Caches.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/Caches.java Sat Oct 29 00:44:11 2011
@@ -36,7 +36,7 @@ class Caches {
if (classNames == null || classNames.isEmpty())
return classes;
- ClassLoader loader = conf.getClassResolverInstance().getClassLoader(null, null);
+ ClassLoader loader = conf.getClassLoader();
Class<?> cls;
for (String className : classNames) {
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManager.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManager.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManager.java Sat Oct 29 00:44:11 2011
@@ -43,8 +43,8 @@ public interface DataCacheManager {
/**
* Initialize the manager, supplying the cache configuration.
*/
- public void initialize(OpenJPAConfiguration conf, ObjectValue dataCache,
- ObjectValue queryCache);
+ public void initialize(OpenJPAConfiguration conf, ObjectValue<DataCache> dataCache,
+ ObjectValue<QueryCache> queryCache);
/**
* Return the system-wide data cache, or null if caching is not enabled.
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManagerImpl.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManagerImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheManagerImpl.java Sat Oct 29 00:44:11 2011
@@ -57,12 +57,13 @@ public class DataCacheManagerImpl
private Set<String> _includedTypes;
private Set<String> _excludedTypes;
- public void initialize(OpenJPAConfiguration conf, ObjectValue dataCache, ObjectValue queryCache) {
+ public void initialize(OpenJPAConfiguration conf, ObjectValue<DataCache> dataCache,
+ ObjectValue<QueryCache> queryCache) {
_conf = conf;
- _queryCache = (QueryCache) queryCache.instantiate(QueryCache.class, conf);
+ _queryCache = queryCache.instantiate(conf);
if (_queryCache != null)
_queryCache.initialize(this);
- _cache = (DataCache) dataCache.instantiate(DataCache.class, conf);
+ _cache = dataCache.instantiate(conf);
if (_cache == null)
return;
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java Sat Oct 29 00:44:11 2011
@@ -112,11 +112,9 @@ public class DataCacheStoreManager
return;
MetaDataRepository mdr = _ctx.getConfiguration().getMetaDataRepositoryInstance();
- ClassLoader loader = _ctx.getClassLoader();
-
DataCache cache;
for (Class<?> cls : classes) {
- cache = mdr.getMetaData(cls, loader, false).getDataCache();
+ cache = mdr.getMetaData(cls, false).getDataCache();
if (cache != null && cache.getEvictOnBulkUpdate())
cache.removeAll(cls, false);
}
@@ -657,7 +655,7 @@ public class DataCacheStoreManager
return unloaded;
}
- public Collection<Exception> flush(Collection<OpenJPAStateManager> states) {
+ public Collection<Exception> flush(Collection<? extends OpenJPAStateManager> states) {
Collection<Exception> exceps = super.flush(states);
// if there were errors evict bad instances and don't record changes
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/PartitionedDataCache.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/PartitionedDataCache.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/PartitionedDataCache.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/PartitionedDataCache.java Sat Oct 29 00:44:11 2011
@@ -86,8 +86,7 @@ public class PartitionedDataCache extend
*/
public void setPartitionType(String type) throws Exception {
Value value = conf.getValue("DataCache");
- ClassLoader ctxLoader = AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction());
- ClassLoader loader = conf.getClassResolverInstance().getClassLoader(null, ctxLoader);
+ ClassLoader loader = conf.getClassLoader();
_type = (Class<? extends DataCache>) AccessController.doPrivileged(
J2DoPrivHelper.getForNameAction(value.unalias(type), true, loader));
}
@@ -101,12 +100,12 @@ public class PartitionedDataCache extend
public void setPartitions(String parts) {
_partProperties.clear();
parsePartitionProperties(parts);
- PluginListValue partitions = new PluginListValue("partitions");
+ PluginListValue<DataCache> partitions = new PluginListValue<DataCache>(DataCache[].class, "partitions");
String[] types = (String[])Array.newInstance(String.class, _partProperties.size());
Arrays.fill(types, _type.getName());
partitions.setClassNames(types);
partitions.setProperties(_partProperties.toArray(new String[_partProperties.size()]));
- DataCache[] array = (DataCache[])partitions.instantiate(_type, conf);
+ DataCache[] array = partitions.instantiate(conf);
for (DataCache part : array) {
if (part.getName() == null)
throw new UserException(_loc.get("partition-cache-null-partition", parts));
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryKey.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryKey.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryKey.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryKey.java Sat Oct 29 00:44:11 2011
@@ -222,7 +222,7 @@ public class QueryKey
// won't find metadata for interfaces.
if (candidateClass.isInterface())
return null;
- meta = repos.getMetaData(candidateClass, ctx.getClassLoader(), true);
+ meta = repos.getMetaData(candidateClass, true);
int timeout = meta.getDataCacheTimeout();
if (subclasses) {
metas = meta.getPCSubclassMetaDatas();
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/InvocationManagedRuntime.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/InvocationManagedRuntime.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/InvocationManagedRuntime.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/ee/InvocationManagedRuntime.java Sat Oct 29 00:44:11 2011
@@ -62,10 +62,8 @@ public class InvocationManagedRuntime ex
public TransactionManager getTransactionManager()
throws Exception {
if (_method == null) {
- ClassLoader loader = _conf.getClassResolverInstance().
- getClassLoader(getClass(), null);
- _method = Class.forName(_clazz, true, loader)
- .getMethod(_methodName, null);
+ ClassLoader loader = _conf.getClassLoader();
+ _method = Class.forName(_clazz, true, loader).getMethod(_methodName, null);
}
return (TransactionManager) _method.invoke(null, null);
}
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java Sat Oct 29 00:44:11 2011
@@ -103,7 +103,7 @@ public class ApplicationIdTool {
repos.setValidate(repos.VALIDATE_NONE);
repos.setSourceMode(repos.MODE_MAPPING, false);
loadObjectIds(repos, true);
- _meta = repos.getMetaData(type, null, false);
+ _meta = repos.getMetaData(type, false);
if (_meta != null) {
_abstract = Modifier.isAbstract(_meta.getDescribedType().
getModifiers());
@@ -1335,16 +1335,13 @@ public class ApplicationIdTool {
}
Configurations.populateConfiguration(conf, opts);
- ClassLoader loader = conf.getClassResolverInstance().
- getClassLoader(ApplicationIdTool.class, null);
- return run(conf, args, flags, loader);
+ return run(conf, args, flags);
}
/**
* Run the tool. Returns false if invalid options were given.
*/
- public static boolean run(OpenJPAConfiguration conf, String[] args,
- Flags flags, ClassLoader loader)
+ public static boolean run(OpenJPAConfiguration conf, String[] args, Flags flags)
throws IOException, ClassNotFoundException {
MetaDataRepository repos = conf.newMetaDataRepositoryInstance();
repos.setValidate(repos.VALIDATE_NONE, true);
@@ -1354,11 +1351,11 @@ public class ApplicationIdTool {
Collection classes;
if (args.length == 0) {
log.info(_loc.get("running-all-classes"));
- classes = repos.loadPersistentTypes(true, loader);
+ classes = repos.loadPersistentTypes(true);
} else {
ClassArgParser cap = conf.getMetaDataRepositoryInstance().
getMetaDataFactory().newClassArgParser();
- cap.setClassLoader(loader);
+ cap.setClassLoader(conf.getClassLoader());
classes = new HashSet();
for (int i = 0; i < args.length; i++)
classes.addAll(Arrays.asList(cap.parseTypes(args[i])));
@@ -1375,7 +1372,7 @@ public class ApplicationIdTool {
cls = (Class) itr.next();
log.info(_loc.get("appid-running", cls));
- meta = repos.getMetaData(cls, null, false);
+ meta = repos.getMetaData(cls, false);
setObjectIdType(meta, flags, bc);
tool = new ApplicationIdTool(conf, cls, meta);
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ClassRedefiner.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ClassRedefiner.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ClassRedefiner.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ClassRedefiner.java Sat Oct 29 00:44:11 2011
@@ -25,6 +25,8 @@ import java.lang.reflect.Method;
import java.security.ProtectionDomain;
import java.util.Map;
+import javax.security.auth.login.Configuration;
+
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.JavaVersions;
@@ -53,13 +55,13 @@ public class ClassRedefiner {
public static void redefineClasses(OpenJPAConfiguration conf,
final Map<Class<?>,byte[]> classes) {
Log log = conf.getLog(OpenJPAConfiguration.LOG_ENHANCE);
- if (classes == null || classes.size() == 0 || !canRedefineClasses(log))
+ if (classes == null || classes.size() == 0 || !canRedefineClasses(conf))
return;
Instrumentation inst = null;
ClassFileTransformer t = null;
try {
- inst = InstrumentationFactory.getInstrumentation(log);
+ inst = InstrumentationFactory.getInstrumentation(conf);
Class<?>[] array = classes.keySet().toArray(new Class[classes.size()]);
if (JavaVersions.VERSION >= 6) {
@@ -87,9 +89,9 @@ public class ClassRedefiner {
log.trace(_loc.get("redefine-types", classes.keySet()));
// in a Java 5 context, we can use class redefinition instead
ClassDefinition[] defs = new ClassDefinition[array.length];
- for (int i = 0; i < defs.length; i++)
- defs[i] = new ClassDefinition(array[i],
- classes.get(array[i]));
+ for (int i = 0; i < defs.length; i++) {
+ defs[i] = new ClassDefinition(array[i], classes.get(array[i]));
+ }
inst.redefineClasses(defs);
}
} catch (Exception e) {
@@ -108,10 +110,10 @@ public class ClassRedefiner {
* only checks whether or not an instrumentation is available and
* if retransformation is possible.
*/
- public static boolean canRedefineClasses(Log log) {
+ public static boolean canRedefineClasses(OpenJPAConfiguration conf) {
if (_canRedefine == null) {
try {
- Instrumentation inst = InstrumentationFactory.getInstrumentation(log);
+ Instrumentation inst = InstrumentationFactory.getInstrumentation(conf);
if (inst == null) {
_canRedefine = Boolean.FALSE;
} else if (JavaVersions.VERSION == 5) {
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/CodeGenerator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/CodeGenerator.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/CodeGenerator.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/CodeGenerator.java Sat Oct 29 00:44:11 2011
@@ -57,8 +57,7 @@ public class CodeGenerator {
* Constructor. Supply configuration and class to generate code for.
*/
public CodeGenerator(OpenJPAConfiguration conf, Class type) {
- this(conf.newMetaDataRepositoryInstance().
- getMetaData(type, null, true));
+ this(conf.newMetaDataRepositoryInstance().getMetaData(type, true));
}
/**
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java Sat Oct 29 00:44:11 2011
@@ -37,6 +37,8 @@ import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
+import org.apache.openjpa.conf.OpenJPAConfiguration;
+import org.apache.openjpa.lib.conf.Configuration;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.JavaVendors;
@@ -53,9 +55,7 @@ import org.apache.openjpa.lib.util.Local
public class InstrumentationFactory {
private static Instrumentation _inst;
private static boolean _dynamicallyInstall = true;
- private static final String _name = InstrumentationFactory.class.getName();
- private static final Localizer _loc = Localizer.forPackage(
- InstrumentationFactory.class);
+ private static final Localizer _loc = Localizer.forPackage(InstrumentationFactory.class);
/**
* This method is not synchronized because when the agent is loaded from
@@ -81,63 +81,48 @@ public class InstrumentationFactory {
* @return null if Instrumentation can not be obtained, or if any
* Exceptions are encountered.
*/
- public static synchronized Instrumentation getInstrumentation(final Log log) {
- if (log.isTraceEnabled() == true) {
- log.trace(_name + ".getInstrumentation() _inst:" + _inst
- + " _dynamicallyInstall:" + _dynamicallyInstall);
- }
+ public static synchronized Instrumentation getInstrumentation(final OpenJPAConfiguration conf) {
+ final Log log = conf.getConfigurationLog();
+ trace(conf, "getInstrumentation()", "_inst:" + _inst + " _dynamicallyInstall:" + _dynamicallyInstall);
if ( _inst != null || !_dynamicallyInstall)
return _inst;
// dynamic loading of the agent is only available in JDK 1.6+
if (JavaVersions.VERSION < 6) {
- if (log.isTraceEnabled() == true) {
- log.trace(_name + ".getInstrumentation() Dynamic loading only supported on Java SE 6 or later");
- }
+ trace(conf, "getInstrumentation()", "Dynamic loading only supported on Java SE 6 or later");
return null;
}
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
- // Dynamic agent enhancement should only occur when the OpenJPA library is
- // loaded using the system class loader. Otherwise, the OpenJPA
- // library may get loaded by separate, disjunct loaders, leading to linkage issues.
- try {
- if (!InstrumentationFactory.class.getClassLoader().equals(
- ClassLoader.getSystemClassLoader())) {
- return null;
- }
- } catch (Throwable t) {
- return null;
- }
JavaVendors vendor = JavaVendors.getCurrentVendor();
File toolsJar = null;
// When running on IBM, the attach api classes are packaged in vm.jar which is a part
// of the default vm classpath.
- if (vendor.isIBM() == false) {
+ if (!vendor.isIBM()) {
// If we can't find the tools.jar and we're not on IBM we can't load the agent.
- toolsJar = findToolsJar(log);
+ toolsJar = findToolsJar(conf);
if (toolsJar == null) {
return null;
}
}
- Class<?> vmClass = loadVMClass(toolsJar, log, vendor);
+ Class<?> vmClass = loadVMClass(toolsJar, conf, vendor);
if (vmClass == null) {
return null;
}
- String agentPath = getAgentJar(log);
+ String agentPath = getAgentJar(conf);
if (agentPath == null) {
return null;
}
- loadAgent(log, agentPath, vmClass);
+ loadAgent(conf, agentPath, vmClass);
return null;
- }// end run()
+ }
});
// If the load(...) agent call was successful, this variable will no
// longer be null.
return _inst;
- }//end getInstrumentation()
+ }
/**
* The method that is called when a jar is added as an agent at runtime.
@@ -176,52 +161,35 @@ public class InstrumentationFactory {
}
/**
- * This private worker method attempts to find [java_home]/lib/tools.jar.
+ * Finds [java_home]/lib/tools.jar.
* Note: The tools.jar is a part of the SDK, it is not present in the JRE.
*
* @return If tools.jar can be found, a File representing tools.jar. <BR>
* If tools.jar cannot be found, null.
*/
- private static File findToolsJar(Log log) {
+ private static File findToolsJar(Configuration conf) {
String javaHome = System.getProperty("java.home");
File javaHomeFile = new File(javaHome);
File toolsJarFile = new File(javaHomeFile, "lib" + File.separator + "tools.jar");
- if (toolsJarFile.exists() == false) {
- if (log.isTraceEnabled() == true) {
- log.trace(_name + ".findToolsJar() -- couldn't find default " + toolsJarFile.getAbsolutePath());
- }
- // If we're on an IBM SDK, then remove /jre off of java.home and try again.
- if (javaHomeFile.getAbsolutePath().endsWith(File.separator + "jre") == true) {
+ if (!toolsJarFile.exists()) {
+ // If we're on an IBM SDK, then remove /jre off of java.home and try again.
+ if (javaHomeFile.getAbsolutePath().endsWith(File.separator + "jre")) {
javaHomeFile = javaHomeFile.getParentFile();
toolsJarFile = new File(javaHomeFile, "lib" + File.separator + "tools.jar");
- if (toolsJarFile.exists() == false) {
- if (log.isTraceEnabled() == true) {
- log.trace(_name + ".findToolsJar() -- for IBM SDK couldn't find " +
- toolsJarFile.getAbsolutePath());
- }
- }
} else if (System.getProperty("os.name").toLowerCase().indexOf("mac") >= 0) {
// If we're on a Mac, then change the search path to use ../Classes/classes.jar.
if (javaHomeFile.getAbsolutePath().endsWith(File.separator + "Home") == true) {
javaHomeFile = javaHomeFile.getParentFile();
toolsJarFile = new File(javaHomeFile, "Classes" + File.separator + "classes.jar");
- if (toolsJarFile.exists() == false) {
- if (log.isTraceEnabled() == true) {
- log.trace(_name + ".findToolsJar() -- for Mac OS couldn't find " +
- toolsJarFile.getAbsolutePath());
- }
- }
}
}
}
- if (toolsJarFile.exists() == false) {
+ if (!toolsJarFile.exists()) {
return null;
} else {
- if (log.isTraceEnabled() == true) {
- log.trace(_name + ".findToolsJar() -- found " + toolsJarFile.getAbsolutePath());
- }
+ trace(conf, ".findToolsJar()", "found " + toolsJarFile.getAbsolutePath());
return toolsJarFile;
}
}
@@ -236,15 +204,14 @@ public class InstrumentationFactory {
* @return absolute path to the agent jar or null if anything unexpected
* happens.
*/
- private static String getAgentJar(Log log) {
+ private static String getAgentJar(Configuration conf) {
File agentJarFile = null;
// Find the name of the File that this class was loaded from. That
// jar *should* be the same location as our agent.
- CodeSource cs =
- InstrumentationFactory.class.getProtectionDomain().getCodeSource();
+ CodeSource cs = InstrumentationFactory.class.getProtectionDomain().getCodeSource();
if (cs != null) {
URL loc = cs.getLocation();
- if(loc!=null){
+ if (loc != null){
agentJarFile = new File(loc.getFile());
}
}
@@ -252,30 +219,27 @@ public class InstrumentationFactory {
// Determine whether the File that this class was loaded from has this
// class defined as the Agent-Class.
boolean createJar = false;
- if (cs == null || agentJarFile == null
- || agentJarFile.isDirectory() == true) {
+ if (cs == null || agentJarFile == null || agentJarFile.isDirectory()) {
createJar = true;
- }else if(validateAgentJarManifest(agentJarFile, log, _name) == false){
+ } else if (!InstrumentationFactory.class.getName().equals(getAgentClassName(agentJarFile, conf))) {
// We have an agentJarFile, but this class isn't the Agent-Class.
- createJar=true;
+ createJar = true;
}
String agentJar;
- if (createJar == true) {
+ if (createJar) {
// This can happen when running in eclipse as an OpenJPA
// developer or for some reason the CodeSource is null. We
// should log a warning here because this will create a jar
// in your temp directory that doesn't always get cleaned up.
try {
agentJar = createAgentJar();
- if (log.isInfoEnabled() == true) {
+ Log log = conf.getConfigurationLog();
+ if (log.isInfoEnabled()) {
log.info(_loc.get("temp-file-creation", agentJar));
}
} catch (IOException ioe) {
- if (log.isTraceEnabled() == true) {
- log.trace(_name + ".getAgentJar() caught unexpected "
- + "exception.", ioe);
- }
+ trace(conf, "getAgentJar()", "caught unexpected exception " + ioe);
agentJar = null;
}
} else {
@@ -283,7 +247,7 @@ public class InstrumentationFactory {
}
return agentJar;
- }//end getAgentJar
+ }
/**
* Attach and load an agent class.
@@ -292,7 +256,7 @@ public class InstrumentationFactory {
* @param agentJar absolute path to the agent jar.
* @param vmClass VirtualMachine.class from tools.jar.
*/
- private static void loadAgent(Log log, String agentJar, Class<?> vmClass) {
+ private static void loadAgent(Configuration conf, String agentJar, Class<?> vmClass) {
try {
// first obtain the PID of the currently-running process
// ### this relies on the undocumented convention of the
@@ -313,18 +277,13 @@ public class InstrumentationFactory {
.invoke(null, new Object[] { pid });
// now deploy the actual agent, which will wind up calling
// agentmain()
- vmClass.getMethod("loadAgent", new Class[] { String.class })
- .invoke(vm, new Object[] { agentJar });
- vmClass.getMethod("detach", new Class[] {}).invoke(vm,
- new Object[] {});
+ vmClass.getMethod("loadAgent", new Class[] { String.class }).invoke(vm, new Object[] { agentJar });
+ vmClass.getMethod("detach", new Class[] {}).invoke(vm, new Object[] {});
} catch (Throwable t) {
- if (log.isTraceEnabled() == true) {
- // Log the message from the exception. Don't log the entire
- // stack as this is expected when running on a JDK that doesn't
- // support the Attach API.
- log.trace(_name + ".loadAgent() caught an exception. Message: "
- + t.getMessage());
- }
+ // Log the message from the exception. Don't log the entire
+ // stack as this is expected when running on a JDK that doesn't
+ // support the Attach API.
+ trace(conf, "loadAgent()", "caught an exception. Message: " + t.getMessage());
}
}
@@ -340,19 +299,16 @@ public class InstrumentationFactory {
* @return The AttachAPI VirtualMachine class <br>
* or null if something unexpected happened.
*/
- private static Class<?> loadVMClass(File toolsJar, Log log, JavaVendors vendor) {
+ private static Class<?> loadVMClass(File toolsJar, Configuration conf, JavaVendors vendor) {
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
String cls = vendor.getVirtualMachineClassName();
- if (vendor.isIBM() == false) {
+ if (!vendor.isIBM()) {
loader = new URLClassLoader(new URL[] { toolsJar.toURI().toURL() }, loader);
}
return loader.loadClass(cls);
} catch (Exception e) {
- if (log.isTraceEnabled()) {
- log.trace(_name
- + ".loadVMClass() failed to load the VirtualMachine class");
- }
+ trace(conf, "loadVMClass()", "failed to load the VirtualMachine class");
}
return null;
}
@@ -370,26 +326,25 @@ public class InstrumentationFactory {
* @return True if the provided agentClassName is defined as the Agent-Class
* in the manifest from the provided agentJarFile. False otherwise.
*/
- private static boolean validateAgentJarManifest(File agentJarFile, Log log,
- String agentClassName) {
+ private static String getAgentClassName(File agentJarFile, Configuration conf) {
try {
JarFile jar = new JarFile(agentJarFile);
Manifest manifest = jar.getManifest();
if (manifest == null) {
- return false;
+ return null;
}
Attributes attributes = manifest.getMainAttributes();
- String ac = attributes.getValue("Agent-Class");
- if (ac != null && ac.equals(agentClassName)) {
- return true;
- }
+ return attributes.getValue("Agent-Class");
} catch (Exception e) {
- if (log.isTraceEnabled() == true) {
- log.trace(_name
- + ".validateAgentJarManifest() caught unexpected "
- + "exception " + e.getMessage());
- }
+ trace(conf, "validateAgentJarManifest()", " caught unexpected exception " + e.getMessage());
}
- return false;
- }// end validateAgentJarManifest
+ return null;
+ }
+
+ private static void trace(Configuration conf, String method, String message) {
+ Log log = conf.getConfigurationLog();
+ if (log.isTraceEnabled()) {
+ log.trace(InstrumentationFactory.class.getName() + "." + method + ":" + message);
+ }
+ }
}
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java?rev=1190716&r1=1190715&r2=1190716&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java Sat Oct 29 00:44:11 2011
@@ -32,9 +32,8 @@ import java.util.Set;
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.BytecodeWriter;
-import org.apache.openjpa.lib.util.JavaVersions;
-import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Files;
+import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Localizer.Message;
import org.apache.openjpa.meta.AccessCode;
import org.apache.openjpa.meta.ClassMetaData;
@@ -46,6 +45,7 @@ import org.apache.openjpa.util.ImplHelpe
import org.apache.openjpa.util.InternalException;
import org.apache.openjpa.util.MetaDataException;
import org.apache.openjpa.util.UserException;
+
import serp.bytecode.BCClass;
/**
@@ -80,8 +80,7 @@ public class ManagedClassSubclasser {
*/
public static List<Class<?>> prepareUnenhancedClasses(
final OpenJPAConfiguration conf,
- final Collection<? extends Class<?>> classes,
- final ClassLoader envLoader) {
+ final Collection<? extends Class<?>> classes) {
if (classes == null)
return null;
if (classes.size() == 0)
@@ -119,7 +118,7 @@ public class ManagedClassSubclasser {
return null;
}
- boolean redefine = ClassRedefiner.canRedefineClasses(log);
+ boolean redefine = ClassRedefiner.canRedefineClasses(conf);
if (redefine) {
log.info(_loc.get("enhance-and-subclass-and-redef-start", classes));
} else {
@@ -176,13 +175,13 @@ public class ManagedClassSubclasser {
ClassRedefiner.redefineClasses(conf, map);
for (Class<?> cls : map.keySet()) {
- setIntercepting(conf, envLoader, cls);
- configureMetaData(conf, envLoader, cls, redefine);
+ setIntercepting(conf, cls);
+ configureMetaData(conf, cls, redefine);
}
for (Class<?> cls : subs)
- configureMetaData(conf, envLoader, cls, redefine);
+ configureMetaData(conf, cls, redefine);
for (Class<?> cls : ints)
- setIntercepting(conf, envLoader, cls);
+ setIntercepting(conf, cls);
return subs;
}
@@ -224,9 +223,8 @@ public class ManagedClassSubclasser {
}
private static void configureMetaData(OpenJPAConfiguration conf,
- ClassLoader envLoader, Class<?> cls, boolean redefineAvailable) {
- ClassMetaData meta = conf.getMetaDataRepositoryInstance()
- .getMetaData(cls, envLoader, true);
+ Class<?> cls, boolean redefineAvailable) {
+ ClassMetaData meta = conf.getMetaDataRepositoryInstance().getMetaData(cls, true);
configureMetaData(meta, conf, redefineAvailable, true);
}
@@ -306,10 +304,9 @@ public class ManagedClassSubclasser {
}
}
- private static void setIntercepting(OpenJPAConfiguration conf,
- ClassLoader envLoader, Class<?> cls) {
+ private static void setIntercepting(OpenJPAConfiguration conf, Class<?> cls) {
ClassMetaData meta = conf.getMetaDataRepositoryInstance()
- .getMetaData(cls, envLoader, true);
+ .getMetaData(cls, true);
meta.setIntercepting(true);
}
|