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 [3/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/conf/OpenJPAConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java?rev=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -28,23 +28,13 @@ 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;
@@ -53,25 +43,20 @@ 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;
@@ -87,13 +72,10 @@ 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.
@@ -114,16 +96,16 @@ public class OpenJPAConfigurationImpl
     protected RemoteCommitEventManager remoteEventManager = null;
 
     // openjpa properties
-    public ObjectValue<ClassResolver> classResolverPlugin;
+    public ObjectValue classResolverPlugin;
     public BrokerValue brokerPlugin;
-    public ObjectValue<DataCache> dataCachePlugin;
-    public ObjectValue<DataCacheManager> dataCacheManagerPlugin;
-    public ObjectValue<Auditor> auditorPlugin;
-    public ObjectValue<CacheDistributionPolicy> cacheDistributionPolicyPlugin;
+    public ObjectValue dataCachePlugin;
+    public ObjectValue dataCacheManagerPlugin;
+    public ObjectValue auditorPlugin;
+    public ObjectValue cacheDistributionPolicyPlugin;
     public IntValue dataCacheTimeout;
-    public ObjectValue<QueryCache> queryCachePlugin;
+    public ObjectValue queryCachePlugin;
     public BooleanValue dynamicDataStructs;
-    public ObjectValue<ManagedRuntime> managedRuntimePlugin;
+    public ObjectValue managedRuntimePlugin;
     public BooleanValue transactionMode;
     public IntValue connectionRetainMode;
     public IntValue fetchBatchSize;
@@ -134,17 +116,17 @@ public class OpenJPAConfigurationImpl
     public IntValue queryTimeout;
     public IntValue readLockLevel;
     public IntValue writeLockLevel;
-    public ObjectValue<Seq> seqPlugin;
-    public PluginListValue<FilterListener> filterListenerPlugins;
-    public PluginListValue<AggregateListener> aggregateListenerPlugins;
+    public ObjectValue seqPlugin;
+    public PluginListValue filterListenerPlugins;
+    public PluginListValue aggregateListenerPlugins;
     public BooleanValue retryClassRegistration;
-    public ObjectValue<ProxyManager> proxyManagerPlugin;
+    public ObjectValue proxyManagerPlugin;
     public StringValue connectionUserName;
     public StringValue connectionPassword;
-    public PluginValue<EncryptionProvider> encryptionProvider;
+    public PluginValue encryptionProvider;
     public StringValue connectionURL;
     public StringValue connectionDriverName;
-    public ObjectValue<Object> connectionFactory;
+    public ObjectValue connectionFactory;
     public StringValue connectionFactoryName;
     public StringValue connectionProperties;
     public StringValue connectionFactoryProperties;
@@ -154,46 +136,46 @@ public class OpenJPAConfigurationImpl
     public StringValue connection2URL;
     public StringValue connection2DriverName;
     public StringValue connection2Properties;
-    public ObjectValue<Object> connectionFactory2;
+    public ObjectValue connectionFactory2;
     public StringValue connectionFactory2Name;
     public StringValue connectionFactory2Properties;
     public BooleanValue optimistic;
     public IntValue autoClear;
     public BooleanValue retainState;
     public IntValue restoreState;
-    public ObjectValue<DetachOptions> detachStatePlugin;
+    public ObjectValue detachStatePlugin;
     public BooleanValue ignoreChanges;
     public BooleanValue nontransactionalRead;
     public BooleanValue nontransactionalWrite;
     public BooleanValue refreshFromDataCache;
     public BooleanValue multithreaded;
     public StringValue mapping;
-    public PluginValue<MetaDataFactory> metaFactoryPlugin;
+    public PluginValue metaFactoryPlugin;
     public MetaDataRepositoryValue metaRepositoryPlugin;
-    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 ObjectValue lockManagerPlugin;
+    public ObjectValue inverseManagerPlugin;
+    public ObjectValue savepointManagerPlugin;
+    public ObjectValue orphanedKeyPlugin;
+    public ObjectValue compatibilityPlugin;
+    public ObjectValue callbackPlugin;
     public QueryCompilationCacheValue queryCompilationCachePlugin;
     public IntValue runtimeUnenhancedClasses;
     public CacheMarshallersValue cacheMarshallerPlugins;
     public BooleanValue eagerInitialization;
-    public PluginValue<PreparedQueryCache> preparedQueryCachePlugin;
-    public PluginValue<FinderCache> finderCachePlugin;
-    public ObjectValue<Specification> specification;
+    public PluginValue preparedQueryCachePlugin;
+    public PluginValue finderCachePlugin;
+    public ObjectValue specification;
     public StringValue validationMode;
-    public ObjectValue<Object> validationFactory;
-    public ObjectValue<Validator> validator;
-    public ObjectValue<LifecycleEventManager> lifecycleEventManager;
+    public ObjectValue validationFactory;
+    public ObjectValue validator;
+    public ObjectValue lifecycleEventManager;
     public StringValue validationGroupPrePersist;
     public StringValue validationGroupPreUpdate;
     public StringValue validationGroupPreRemove;
     public StringValue dataCacheMode; 
     public BooleanValue dynamicEnhancementAgent;
-    public ObjectValue<InstrumentationManager> instrumentationManager;
-    public PluginListValue<InstrumentationProvider> instrumentationProviders;
+    public ObjectValue instrumentationManager;
+    public PluginListValue instrumentationProviders;
     
     // custom values
     public BrokerFactoryValue brokerFactoryPlugin;
@@ -231,87 +213,145 @@ public class OpenJPAConfigurationImpl
         super(false);
         String[] aliases;
 
-        classResolverPlugin = addPlugin(ClassResolver.class, true);
-        classResolverPlugin.setDefaultAlias(ClassResolverImpl.class);
-        // deprecated alias
-        classResolverPlugin.setAlias("spec", ClassResolverImpl.class);
+        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");
 
-        addValue(brokerFactoryPlugin = new BrokerFactoryValue());
+        brokerFactoryPlugin = new BrokerFactoryValue();
+        addValue(brokerFactoryPlugin);
 
-        addValue(brokerPlugin = new BrokerValue());
+        brokerPlugin = new BrokerValue();
+        addValue(brokerPlugin);
 
-        dataCacheManagerPlugin = addPlugin(DataCacheManager.class, true);
-        dataCacheManagerPlugin.setDefaultAlias(DataCacheManagerImpl.class);
+        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");
 
-        cacheDistributionPolicyPlugin = addPlugin(CacheDistributionPolicy.class, true);
-        cacheDistributionPolicyPlugin.setDefaultAlias(DefaultCacheDistributionPolicy.class);
-        cacheDistributionPolicyPlugin.setAlias("type-based", TypeBasedCacheDistributionPolicy.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");
         
-        dataCachePlugin = addPlugin(DataCache.class);
-        dataCachePlugin.setDefaultAlias("false", null);
-        dataCachePlugin.setAlias("true", ConcurrentDataCache.class);
-        dataCachePlugin.setAlias("concurrent", ConcurrentDataCache.class);
-        dataCachePlugin.setAlias("partitioned", PartitionedDataCache.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]);
 
         dataCacheTimeout = addInt("DataCacheTimeout");
         dataCacheTimeout.setDefault("-1");
         dataCacheTimeout.set(-1);
         dataCacheTimeout.setDynamic(true);
 
-        queryCachePlugin = addPlugin(QueryCache.class);
-        queryCachePlugin.setDefaultAlias("false", null);
-        queryCachePlugin.setAlias("true", ConcurrentQueryCache.class);
-        queryCachePlugin.setAlias("concurrent", ConcurrentQueryCache.class);
+        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]);
         
         refreshFromDataCache = addBoolean("RefreshFromDataCache");
+        refreshFromDataCache.setDefault("false");
         refreshFromDataCache.set(false);
         refreshFromDataCache.setDynamic(true);
         
         dynamicDataStructs = addBoolean("DynamicDataStructs");
+        dynamicDataStructs.setDefault("false");
         dynamicDataStructs.set(false);
 
-        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);        
+        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");
 
-        addValue(remoteProviderPlugin = new RemoteCommitProviderValue());
+        remoteProviderPlugin = new RemoteCommitProviderValue();
+        addValue(remoteProviderPlugin);
 
         transactionMode = addBoolean("TransactionMode");
         aliases = new String[] { "local", "false", "managed", "true", };
         transactionMode.setAliases(aliases);
         transactionMode.setDefault(aliases[0]);
 
-        managedRuntimePlugin = addPlugin(ManagedRuntime.class, true);
-        managedRuntimePlugin.setDefaultAlias("auto", AutomaticManagedRuntime.class);
-        managedRuntimePlugin.setAlias("jndi", JNDIManagedRuntime.class);
-        managedRuntimePlugin.setAlias("invocation", InvocationManagedRuntime.class);
+        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");
 
-        proxyManagerPlugin = addPlugin(ProxyManager.class, true);
-        proxyManagerPlugin.setDefaultAlias(ProxyManagerImpl.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");
 
         mapping = addString("Mapping");
-        
-        metaFactoryPlugin = addPlugin(MetaDataFactory.class);
+        metaFactoryPlugin = addPlugin("MetaDataFactory", false);
 
-        metaRepositoryPlugin = new MetaDataRepositoryValue();
-        addValue(metaRepositoryPlugin);
+        metaRepositoryPlugin = (MetaDataRepositoryValue) addValue(new MetaDataRepositoryValue());
 
-        connectionFactory = addObject(Object.class, "ConnectionFactory");
+        connectionFactory = addObject("ConnectionFactory");
         connectionFactory.setInstantiatingGetter("getConnectionFactory");
 
-        connectionFactory2 = addObject(Object.class, "ConnectionFactory2");
+        connectionFactory2 = addObject("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
@@ -327,7 +367,7 @@ public class OpenJPAConfigurationImpl
         connectionPassword.addEquivalentKey("javax.persistence.jdbc.password");
         connectionPassword.hide();
         
-        encryptionProvider = addPlugin(EncryptionProvider.class, true);
+        encryptionProvider = addPlugin("EncryptionProvider",true);
 
         connectionURL = addString("ConnectionURL");
         connectionURL.addEquivalentKey("javax.persistence.jdbc.url");
@@ -359,8 +399,9 @@ 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);
@@ -386,11 +427,16 @@ public class OpenJPAConfigurationImpl
         autoDetach = new AutoDetachValue();
         addValue(autoDetach);
 
-        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 = 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.setInstantiatingGetter("getDetachStateInstance");
 
         ignoreChanges = addBoolean("IgnoreChanges");
@@ -470,21 +516,28 @@ public class OpenJPAConfigurationImpl
         connectionRetainMode.setAliasListComprehensive(true);
         connectionRetainMode.set(ConnectionRetainModes.CONN_RETAIN_DEMAND);
 
-        filterListenerPlugins = addPluginList(FilterListener[].class, "FilterListeners");
+        filterListenerPlugins = addPluginList("FilterListeners");
         filterListenerPlugins.setInstantiatingGetter("getFilterListenerInstances");
 
-        aggregateListenerPlugins = addPluginList(AggregateListener[].class, "AggregateListeners");
+        aggregateListenerPlugins = addPluginList("AggregateListeners");
         aggregateListenerPlugins.setInstantiatingGetter("getAggregateListenerInstances");
 
         retryClassRegistration = addBoolean("RetryClassRegistration");
 
-        compatibilityPlugin = addPlugin(Compatibility.class, "Compatibility", true);
-        compatibilityPlugin.setDefaultAlias(Compatibility.class);
-        
-        callbackPlugin = addPlugin(CallbackOptions.class, "Callbacks", true);
-        callbackPlugin.setDefaultAlias(CallbackOptions.class);
+        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]);
         callbackPlugin.setInstantiatingGetter("getCallbackOptionsInstance");
-        
+           
         queryCompilationCachePlugin = new QueryCompilationCacheValue("QueryCompilationCache");
         queryCompilationCachePlugin.setInstantiatingGetter("getQueryCompilationCacheInstance");
         addValue(queryCompilationCachePlugin);
@@ -511,24 +564,37 @@ public class OpenJPAConfigurationImpl
         queryTimeout.setDefault("-1");
         queryTimeout.setDynamic(true);
       
-        lifecycleEventManager = addPlugin(LifecycleEventManager.class, true);
-        lifecycleEventManager.setDefaultAlias(LifecycleEventManager.class);
-        lifecycleEventManager.setAlias("validating", ValidatingLifecycleEventManager.class);
+        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");
 
         dynamicEnhancementAgent  = addBoolean("DynamicEnhancementAgent");
         dynamicEnhancementAgent.setDefault("true");
         dynamicEnhancementAgent.set(true);
         
-        instrumentationManager = addPlugin(InstrumentationManager.class, true);
-        instrumentationManager.setDefaultAlias(InstrumentationManagerImpl.class);
+        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");
 
-        instrumentationProviders = addPluginList(InstrumentationProvider[].class, "Instrumentation");
+        instrumentationProviders = addPluginList("Instrumentation");
         aliases = new String[] { "jmx", "org.apache.openjpa.instrumentation.jmx.JMXProvider" };
         instrumentationProviders.setAliases(aliases);
         instrumentationProviders.setInstantiatingGetter("getInstrumentationInstances");
         
-        auditorPlugin = addPlugin(Auditor.class, true);
-        auditorPlugin.setAlias("default", AuditLogger.class);
+        auditorPlugin = addPlugin("Auditor", true);
+        aliases = new String[] { "default", AuditLogger.class.getName(), };
+        auditorPlugin.setAliases(aliases);
+        auditorPlugin.setInstantiatingGetter("getAuditorInstance");
         
         // initialize supported options that some runtimes may not support
         supportedOptions.add(OPTION_NONTRANS_READ);
@@ -568,7 +634,7 @@ public class OpenJPAConfigurationImpl
     }
     
     public Specification getSpecificationInstance() {
-        return specification.get();
+        return (Specification)specification.get();
     }
 
     /**
@@ -599,8 +665,8 @@ public class OpenJPAConfigurationImpl
 
     public ClassResolver getClassResolverInstance() {
         if (classResolverPlugin.get() == null)
-            classResolverPlugin.instantiate(this);
-        return classResolverPlugin.get();
+            classResolverPlugin.instantiate(ClassResolver.class, this);
+        return (ClassResolver) classResolverPlugin.get();
     }
 
     public void setBrokerFactory(String factory) {
@@ -620,7 +686,7 @@ public class OpenJPAConfigurationImpl
     }
 
     public BrokerImpl newBrokerInstance(String user, String pass) {
-        BrokerImpl broker = (BrokerImpl) brokerPlugin.instantiate(this);
+        BrokerImpl broker = (BrokerImpl) brokerPlugin.instantiate(BrokerImpl.class, this);
         if (broker != null)
             broker.setAuthentication(user, pass);
         return broker;
@@ -641,9 +707,9 @@ public class OpenJPAConfigurationImpl
     }
 
     public DataCacheManager getDataCacheManagerInstance() {
-        DataCacheManager dcm = dataCacheManagerPlugin.get();
+        DataCacheManager dcm = (DataCacheManager) dataCacheManagerPlugin.get();
         if (dcm == null) {
-            dcm = (DataCacheManager) dataCacheManagerPlugin.instantiate(this);
+            dcm = (DataCacheManager) dataCacheManagerPlugin.instantiate(DataCacheManager.class, this);
             if (dcm != null) {
                 dcm.initialize(this, dataCachePlugin, queryCachePlugin);
             }
@@ -718,7 +784,8 @@ 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 lockManagerPlugin.instantiate(this, false);
+        return (LockManager) lockManagerPlugin.instantiate(LockManager.class,
+            this, false);
     }
 
     public void setInverseManager(String inverseManager) {
@@ -730,7 +797,7 @@ public class OpenJPAConfigurationImpl
     }
 
     public InverseManager newInverseManagerInstance() {
-        return inverseManagerPlugin.instantiate(this);
+        return (InverseManager) inverseManagerPlugin.instantiate(InverseManager.class, this);
     }
 
     public void setSavepointManager(String savepointManager) {
@@ -743,8 +810,8 @@ public class OpenJPAConfigurationImpl
 
     public SavepointManager getSavepointManagerInstance() {
         if (savepointManagerPlugin.get() == null)
-            savepointManagerPlugin.instantiate(this);
-        return savepointManagerPlugin.get();
+            savepointManagerPlugin.instantiate(SavepointManager.class, this);
+        return (SavepointManager) savepointManagerPlugin.get();
     }
 
     public void setOrphanedKeyAction(String action) {
@@ -757,8 +824,8 @@ public class OpenJPAConfigurationImpl
 
     public OrphanedKeyAction getOrphanedKeyActionInstance() {
         if (orphanedKeyPlugin.get() == null)
-            orphanedKeyPlugin.instantiate(this);
-        return orphanedKeyPlugin.get();
+            orphanedKeyPlugin.instantiate(OrphanedKeyAction.class, this);
+        return (OrphanedKeyAction) orphanedKeyPlugin.get();
     }
 
     public void setOrphanedKeyAction(OrphanedKeyAction action) {
@@ -821,8 +888,8 @@ public class OpenJPAConfigurationImpl
 
     public ManagedRuntime getManagedRuntimeInstance() {
         if (managedRuntimePlugin.get() == null)
-            managedRuntimePlugin.instantiate(this);
-        return managedRuntimePlugin.get();
+            managedRuntimePlugin.instantiate(ManagedRuntime.class, this);
+        return (ManagedRuntime) managedRuntimePlugin.get();
     }
 
     public void setProxyManager(String proxyManager) {
@@ -839,8 +906,8 @@ public class OpenJPAConfigurationImpl
 
     public ProxyManager getProxyManagerInstance() {
         if (proxyManagerPlugin.get() == null)
-            proxyManagerPlugin.instantiate(this);
-        return proxyManagerPlugin.get();
+            proxyManagerPlugin.instantiate(ProxyManager.class, this);
+        return (ProxyManager) proxyManagerPlugin.get();
     }
 
     public void setMapping(String mapping) {
@@ -852,7 +919,7 @@ public class OpenJPAConfigurationImpl
     }
 
     public void setMetaDataFactory(String meta) {
-        metaFactoryPlugin.setString(meta);
+        this.metaFactoryPlugin.setString(meta);
     }
 
     public String getMetaDataFactory() {
@@ -860,11 +927,12 @@ public class OpenJPAConfigurationImpl
     }
 
     public MetaDataFactory newMetaDataFactoryInstance() {
-        return metaFactoryPlugin.instantiate(this);
+        return (MetaDataFactory) metaFactoryPlugin.instantiate(
+            MetaDataFactory.class, this);
     }
 
     public void setMetaDataRepository(String meta) {
-        metaRepositoryPlugin.setString(meta);
+        this.metaRepositoryPlugin.setString(meta);
     }
 
     public String getMetaDataRepository() {
@@ -886,23 +954,24 @@ public class OpenJPAConfigurationImpl
     }
 
     public MetaDataRepository newMetaDataRepositoryInstance() {
-        return metaRepositoryPlugin.instantiate(this);
+        return (MetaDataRepository) metaRepositoryPlugin.instantiate(
+            MetaDataRepository.class, this);
     }
 
-    public void setConnectionUserName(String userName) {
-        connectionUserName.setString(userName);
+    public void setConnectionUserName(String connectionUserName) {
+        this.connectionUserName.setString(connectionUserName);
     }
 
     public String getConnectionUserName() {
         return connectionUserName.getString();
     }
 
-    public void setConnectionPassword(String pwd) {
-        connectionPassword.setString(pwd);
+    public void setConnectionPassword(String connectionPassword) {
+        this.connectionPassword.setString(connectionPassword);
     }
 
     public String getConnectionPassword() {
-    	EncryptionProvider p = getEncryptionProviderInstance();
+    	EncryptionProvider p = getEncryptionProvider();
     	if(p != null) {
     		return p.decrypt(connectionPassword.getString());
     	}
@@ -1006,8 +1075,8 @@ public class OpenJPAConfigurationImpl
     }
 
     public String getConnection2Password() {
-    	EncryptionProvider p = getEncryptionProviderInstance();
-    	if (p != null) {
+    	EncryptionProvider p = getEncryptionProvider();
+    	if(p != null){
     		return p.decrypt(connection2Password.getString());
     	}
         return connection2Password.getString();
@@ -1155,8 +1224,8 @@ public class OpenJPAConfigurationImpl
 
     public DetachOptions getDetachStateInstance() {
         if (detachStatePlugin.get() == null)
-            detachStatePlugin.instantiate(this);
-        return detachStatePlugin.get();
+            detachStatePlugin.instantiate(DetachOptions.class, this);
+        return (DetachOptions) detachStatePlugin.get();
     }
 
     public void setIgnoreChanges(boolean ignoreChanges) {
@@ -1165,7 +1234,7 @@ public class OpenJPAConfigurationImpl
 
     public void setIgnoreChanges(Boolean ignoreChanges) {
         if (ignoreChanges != null)
-            setIgnoreChanges(ignoreChanges);
+            setIgnoreChanges(ignoreChanges.booleanValue());
     }
 
     public boolean getIgnoreChanges() {
@@ -1336,8 +1405,8 @@ public class OpenJPAConfigurationImpl
 
     public Seq getSequenceInstance() {
         if (seqPlugin.get() == null)
-            seqPlugin.instantiate(this);
-        return seqPlugin.get();
+            seqPlugin.instantiate(Seq.class, this);
+        return (Seq) seqPlugin.get();
     }
 
     public void setConnectionRetainMode(String connectionRetainMode) {
@@ -1370,8 +1439,8 @@ public class OpenJPAConfigurationImpl
 
     public FilterListener[] getFilterListenerInstances() {
         if (filterListenerPlugins.get() == null)
-            filterListenerPlugins.instantiate(this);
-        return filterListenerPlugins.get();
+            filterListenerPlugins.instantiate(FilterListener.class, this);
+        return (FilterListener[]) filterListenerPlugins.get();
     }
 
     public void setAggregateListeners(String aggregateListeners) {
@@ -1388,8 +1457,8 @@ public class OpenJPAConfigurationImpl
 
     public AggregateListener[] getAggregateListenerInstances() {
         if (aggregateListenerPlugins.get() == null)
-            aggregateListenerPlugins.instantiate(this);
-        return aggregateListenerPlugins.get();
+            aggregateListenerPlugins.instantiate(AggregateListener.class, this);
+        return (AggregateListener[]) aggregateListenerPlugins.get();
     }
 
     public void setRetryClassRegistration(boolean retry) {
@@ -1424,11 +1493,11 @@ public class OpenJPAConfigurationImpl
             Specification spec = getSpecificationInstance();
             Compatibility comp = spec != null ? spec.getCompatibility() : null;
             if (comp == null)
-                compatibilityPlugin.instantiate(this);
+                compatibilityPlugin.instantiate(Compatibility.class, this);
             else 
                 compatibilityPlugin.configure(comp, this);
         }
-        return compatibilityPlugin.get();
+        return (Compatibility) compatibilityPlugin.get();
     }
     
     public String getCallbackOptions() {
@@ -1441,8 +1510,8 @@ public class OpenJPAConfigurationImpl
     
     public CallbackOptions getCallbackOptionsInstance() {
         if (callbackPlugin.get() == null)
-            callbackPlugin.instantiate(this);
-        return callbackPlugin.get();
+            callbackPlugin.instantiate(CallbackOptions.class, this);
+        return (CallbackOptions) callbackPlugin.get();
     }
 
     public String getQueryCompilationCache() {
@@ -1455,8 +1524,8 @@ public class OpenJPAConfigurationImpl
     
     public Map getQueryCompilationCacheInstance() {
         if (queryCompilationCachePlugin.get() == null)
-            queryCompilationCachePlugin.instantiate(this);
-        return queryCompilationCachePlugin.get();
+            queryCompilationCachePlugin.instantiate(Map.class, this);
+        return (Map) queryCompilationCachePlugin.get();
     }
 
     public StoreFacadeTypeRegistry getStoreFacadeTypeRegistry() {
@@ -1557,8 +1626,8 @@ public class OpenJPAConfigurationImpl
     
     public InstrumentationProvider[] getInstrumentationInstances() {
         if (instrumentationProviders.get() == null)
-            instrumentationProviders.instantiate(this);
-        return instrumentationProviders.get();
+            instrumentationProviders.instantiate(InstrumentationProvider.class, this);
+        return (InstrumentationProvider[]) instrumentationProviders.get();
     }
     
     public void setInstrumentationManager(String mgr) {
@@ -1578,7 +1647,7 @@ public class OpenJPAConfigurationImpl
     public InstrumentationManager getInstrumentationManagerInstance() {
         InstrumentationManager im = (InstrumentationManager) instrumentationManager.get();
         if (im == null) {
-            im = instrumentationManager.instantiate(this);
+            im = (InstrumentationManager) instrumentationManager.instantiate(InstrumentationManager.class, this);
             if (im != null) {
                 im.initialize(this, instrumentationProviders);
                 im.start(InstrumentationLevel.IMMEDIATE, this);
@@ -1627,9 +1696,10 @@ public class OpenJPAConfigurationImpl
             return null;
         
         if (preparedQueryCachePlugin.get() == null) {
-            preparedQueryCachePlugin.instantiate(this);
+            preparedQueryCachePlugin.instantiate(PreparedQueryCache.class,
+                    this);
         }
-        return preparedQueryCachePlugin.get();
+        return (PreparedQueryCache)preparedQueryCachePlugin.get();
     }
 
     public void setFinderCache(String finderCache) {
@@ -1642,9 +1712,9 @@ public class OpenJPAConfigurationImpl
     
     public FinderCache getFinderCacheInstance() {
         if (finderCachePlugin.get() == null) {
-            finderCachePlugin.instantiate(this);
+            finderCachePlugin.instantiate(FinderCache.class, this);
         }
-        return finderCachePlugin.get();
+        return (FinderCache)finderCachePlugin.get();
     }
 
     public Object getValidationFactoryInstance() {
@@ -1655,11 +1725,11 @@ public class OpenJPAConfigurationImpl
         validationFactory.set(factory);                            
     }
 
-    public Validator getValidatorInstance() {
+    public Object getValidatorInstance() {
         return validator.get();
     }
 
-    public void setValidatorInstance(Validator val) {
+    public void setValidatorInstance(Object val) {
         validator.set(val);                            
     }
 
@@ -1671,7 +1741,8 @@ public class OpenJPAConfigurationImpl
         LifecycleEventManager lem = (LifecycleEventManager)
             lifecycleEventManager.get();
         if (lem == null) {
-            lem = lifecycleEventManager.instantiate(this);
+            lem = (LifecycleEventManager)lifecycleEventManager
+                .instantiate(LifecycleEventManager.class, this);
         }
         return lem;
     }
@@ -1702,10 +1773,10 @@ public class OpenJPAConfigurationImpl
         encryptionProvider.setString(p);
     }
     
-    public EncryptionProvider getEncryptionProviderInstance() {
+    public EncryptionProvider getEncryptionProvider() {
         if (encryptionProvider.get() == null)
-            encryptionProvider.instantiate(this);
-        return encryptionProvider.get();
+            encryptionProvider.instantiate(EncryptionProvider.class, this);
+        return (EncryptionProvider) encryptionProvider.get();
     }
 
     public void setDataCacheMode(String mode) {
@@ -1722,9 +1793,10 @@ public class OpenJPAConfigurationImpl
     }
 
     public CacheDistributionPolicy getCacheDistributionPolicyInstance() {
-        CacheDistributionPolicy policy = cacheDistributionPolicyPlugin.get();
+        CacheDistributionPolicy policy = (CacheDistributionPolicy) cacheDistributionPolicyPlugin.get();
         if (policy == null) {
-            policy =  cacheDistributionPolicyPlugin.instantiate(this);
+            policy =  (CacheDistributionPolicy) 
+                cacheDistributionPolicyPlugin.instantiate(CacheDistributionPolicy.class, this);
         }
         return policy;
     }
@@ -1746,9 +1818,9 @@ public class OpenJPAConfigurationImpl
     }
     
     public Auditor getAuditorInstance() {
-    	Auditor auditor = auditorPlugin.get();
+    	Auditor auditor = (Auditor) auditorPlugin.get();
         if (auditor == null) {
-            auditor = auditorPlugin.instantiate(this);
+            auditor = (Auditor) auditorPlugin.instantiate(Auditor.class, 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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -36,7 +36,7 @@ import org.apache.openjpa.util.CacheMap;
  * @nojavadoc
  */
 public class QueryCompilationCacheValue
-    extends PluginValue<Map> {
+    extends PluginValue {
 
     public static final String[] ALIASES = {
         "true", CacheMap.class.getName(),
@@ -45,18 +45,19 @@ public class QueryCompilationCacheValue
     };
 
     public QueryCompilationCacheValue(String prop) {
-        super(Map.class, prop, true);
+        super(prop, true);
         setAliases(ALIASES);
         setDefault(ALIASES[0]);
         setClassName(ALIASES[1]);
     }
 
-    public Map newInstance(String clsName, Configuration conf, boolean fatal) {
+    public Object newInstance(String clsName, Class type,
+        Configuration conf, boolean fatal) {
         // make sure map handles concurrency
         Map map;
         
         try {
-            map = super.newInstance(clsName, conf, fatal);
+            map = (Map) super.newInstance(clsName, type, 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
@@ -67,7 +68,8 @@ public class QueryCompilationCacheValue
             // the ParseException (which is what we wrap the
             // ClassNotFoundException in) and try again, this time using
             // this class' ClassLoader.
-            map = super.newInstance(clsName, conf, fatal);
+            map = (Map) super.newInstance(clsName,
+                QueryCompilationCacheValue.class, 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
@@ -78,7 +80,8 @@ public class QueryCompilationCacheValue
             // the IllegalArgumentException (which is what we wrap the
             // ClassNotFoundException in) and try again, this time using
             // this class' ClassLoader.
-            map = super.newInstance(clsName, conf, fatal);
+            map = (Map) super.newInstance(clsName,
+                QueryCompilationCacheValue.class, 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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -35,7 +35,7 @@ import org.apache.openjpa.lib.util.Optio
  * @nojavadoc
  */
 public class RemoteCommitProviderValue
-    extends PluginValue<RemoteCommitProvider> {
+    extends PluginValue {
 
     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.class, "RemoteCommitProvider", true);
+        super("RemoteCommitProvider", true);
         setAliases(ALIASES);
     }
 
@@ -67,7 +67,7 @@ public class RemoteCommitProviderValue
      * The cached provider.
      */
     public RemoteCommitProvider getProvider() {
-        return get();
+        return (RemoteCommitProvider) get();
     }
 
     /**
@@ -101,8 +101,10 @@ public class RemoteCommitProviderValue
     /**
      * Instantiate the provider.
      */
-    public RemoteCommitProvider instantiateProvider(Configuration conf, boolean fatal) {
-        return instantiate(conf, fatal);
+    public RemoteCommitProvider instantiateProvider(Configuration conf,
+        boolean fatal) {
+        return (RemoteCommitProvider) instantiate(RemoteCommitProvider.class,
+            conf, fatal);
     }
 
     /**
@@ -117,8 +119,8 @@ public class RemoteCommitProviderValue
     /**
      * Override to keep decorators out of transport configuration.
      */
-    public RemoteCommitProvider instantiate(Configuration conf, boolean fatal) {
-    	RemoteCommitProvider obj = newInstance(getClassName(), conf, fatal);
+    public Object instantiate(Class type, Configuration conf, boolean fatal) {
+        Object obj = newInstance(getClassName(), type, 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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -18,7 +18,6 @@
  */
 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;
@@ -32,7 +31,7 @@ import org.apache.openjpa.meta.SequenceM
  * @nojavadoc
  */
 public class SeqValue
-    extends PluginValue<Seq> {
+    extends PluginValue {
 
     private static final String[] ALIASES = new String[]{
         SequenceMetaData.IMPL_TIME, TimeSeededSeq.class.getName(),
@@ -42,7 +41,7 @@ public class SeqValue
     };
 
     public SeqValue(String prop) {
-        super(Seq.class, prop, true);
+        super(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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -33,17 +33,22 @@ import org.apache.openjpa.util.UserExcep
  * @author Pinaki Poddar
  *
  */
-public class SpecificationPlugin extends ObjectValue<Specification> implements ValueListener {
+public class SpecificationPlugin extends ObjectValue implements ValueListener {
     private Configuration _conf;
     protected static final Localizer _loc = Localizer.forPackage
         (SpecificationPlugin.class);
     
     public SpecificationPlugin(Configuration conf, String prop) {
-        super(Specification.class, prop);
+        super(prop);
         _conf = conf;
         addListener(this);
     }
     
+    @Override
+    public Class<?> getValueType() {
+        return Specification.class;
+    }
+    
     /**
      * Set a value from the given String after validating.
      * 
@@ -62,12 +67,16 @@ public class SpecificationPlugin extends
      * @param obj can be null to set the Specification to null.
      */
     @Override
-    public void set(Specification obj) {
+    public void set(Object obj) {
         if (obj == null) {
             super.set(null);
             return;
         }
-        validateOverwrite(obj);
+        if (obj instanceof Specification == false) {
+            throw new UserException(_loc.get("spec-wrong-obj", obj, 
+                obj.getClass())).setFatal(true);
+        }
+        validateOverwrite((Specification)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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -101,7 +101,11 @@ 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);
+            Collection perTypes =
+                conf.getMetaDataRepositoryInstance().getPersistentTypeNames(
+                    false,
+                    AccessController.doPrivileged(J2DoPrivHelper
+                        .getContextClassLoaderAction()));
             
             // Pre-load all the entity types into the HashMap to handle 
             // synchronization on the map efficiently
@@ -299,7 +303,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, false);
+                meta = repos.getMetaData(oid, null, 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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -36,7 +36,7 @@ class Caches {
         if (classNames == null || classNames.isEmpty())
             return classes;
 
-        ClassLoader loader = conf.getClassLoader();
+        ClassLoader loader = conf.getClassResolverInstance().getClassLoader(null, null);
 
         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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -43,8 +43,8 @@ public interface DataCacheManager {
     /**
      * Initialize the manager, supplying the cache configuration.
      */
-    public void initialize(OpenJPAConfiguration conf, ObjectValue<DataCache> dataCache,
-        ObjectValue<QueryCache> queryCache);
+    public void initialize(OpenJPAConfiguration conf, ObjectValue dataCache,
+        ObjectValue 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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -57,13 +57,12 @@ public class DataCacheManagerImpl
     private Set<String> _includedTypes;
     private Set<String> _excludedTypes;
     
-    public void initialize(OpenJPAConfiguration conf, ObjectValue<DataCache> dataCache, 
-    		ObjectValue<QueryCache> queryCache) {
+    public void initialize(OpenJPAConfiguration conf, ObjectValue dataCache, ObjectValue queryCache) {
         _conf = conf;        
-        _queryCache = queryCache.instantiate(conf);
+        _queryCache = (QueryCache) queryCache.instantiate(QueryCache.class, conf);
         if (_queryCache != null)
             _queryCache.initialize(this);
-        _cache = dataCache.instantiate(conf);
+        _cache = (DataCache) dataCache.instantiate(DataCache.class, 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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -112,9 +112,11 @@ public class DataCacheStoreManager
             return;
 
         MetaDataRepository mdr = _ctx.getConfiguration().getMetaDataRepositoryInstance();
+        ClassLoader loader = _ctx.getClassLoader();
+
         DataCache cache;
         for (Class<?> cls : classes) {
-            cache = mdr.getMetaData(cls, false).getDataCache();
+            cache = mdr.getMetaData(cls, loader, false).getDataCache();
             if (cache != null && cache.getEvictOnBulkUpdate())
                 cache.removeAll(cls, false);
         }
@@ -655,7 +657,7 @@ public class DataCacheStoreManager
         return unloaded;
     }
 
-    public Collection<Exception> flush(Collection<? extends OpenJPAStateManager> states) {
+    public Collection<Exception> flush(Collection<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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -86,7 +86,8 @@ public class PartitionedDataCache extend
      */
     public void setPartitionType(String type) throws Exception {
         Value value = conf.getValue("DataCache");
-        ClassLoader loader = conf.getClassLoader();
+        ClassLoader ctxLoader = AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction());
+        ClassLoader loader = conf.getClassResolverInstance().getClassLoader(null, ctxLoader);
         _type = (Class<? extends DataCache>) AccessController.doPrivileged(
                 J2DoPrivHelper.getForNameAction(value.unalias(type), true, loader));
     }
@@ -100,12 +101,12 @@ public class PartitionedDataCache extend
     public void setPartitions(String parts) {
         _partProperties.clear();
         parsePartitionProperties(parts);
-        PluginListValue<DataCache> partitions = new PluginListValue<DataCache>(DataCache[].class, "partitions");
+        PluginListValue partitions = new PluginListValue("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 = partitions.instantiate(conf);
+        DataCache[] array = (DataCache[])partitions.instantiate(_type, 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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -222,7 +222,7 @@ public class QueryKey
         // won't find metadata for interfaces.
         if (candidateClass.isInterface())
             return null;
-        meta = repos.getMetaData(candidateClass, true);
+        meta = repos.getMetaData(candidateClass, ctx.getClassLoader(), 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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -62,8 +62,10 @@ public class InvocationManagedRuntime ex
     public TransactionManager getTransactionManager()
         throws Exception {
         if (_method == null) {
-            ClassLoader loader = _conf.getClassLoader();
-            _method = Class.forName(_clazz, true, loader).getMethod(_methodName, null);
+            ClassLoader loader = _conf.getClassResolverInstance().
+                getClassLoader(getClass(), null);
+            _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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 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, false);
+        _meta = repos.getMetaData(type, null, false);
         if (_meta != null) {
             _abstract = Modifier.isAbstract(_meta.getDescribedType().
                 getModifiers());
@@ -1335,13 +1335,16 @@ public class ApplicationIdTool {
         }
 
         Configurations.populateConfiguration(conf, opts);
-        return run(conf, args, flags);
+        ClassLoader loader = conf.getClassResolverInstance().
+            getClassLoader(ApplicationIdTool.class, null);
+        return run(conf, args, flags, loader);
     }
 
     /**
      * Run the tool. Returns false if invalid options were given.
      */
-    public static boolean run(OpenJPAConfiguration conf, String[] args, Flags flags)
+    public static boolean run(OpenJPAConfiguration conf, String[] args,
+        Flags flags, ClassLoader loader)
         throws IOException, ClassNotFoundException {
         MetaDataRepository repos = conf.newMetaDataRepositoryInstance();
         repos.setValidate(repos.VALIDATE_NONE, true);
@@ -1351,11 +1354,11 @@ public class ApplicationIdTool {
         Collection classes;
         if (args.length == 0) {
             log.info(_loc.get("running-all-classes"));
-            classes = repos.loadPersistentTypes(true);
+            classes = repos.loadPersistentTypes(true, loader);
         } else {
             ClassArgParser cap = conf.getMetaDataRepositoryInstance().
                 getMetaDataFactory().newClassArgParser();
-            cap.setClassLoader(conf.getClassLoader());
+            cap.setClassLoader(loader);
             classes = new HashSet();
             for (int i = 0; i < args.length; i++)
                 classes.addAll(Arrays.asList(cap.parseTypes(args[i])));
@@ -1372,7 +1375,7 @@ public class ApplicationIdTool {
             cls = (Class) itr.next();
             log.info(_loc.get("appid-running", cls));
 
-            meta = repos.getMetaData(cls, false);
+            meta = repos.getMetaData(cls, null, 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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -25,8 +25,6 @@ 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;
@@ -55,13 +53,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(conf))
+        if (classes == null || classes.size() == 0 || !canRedefineClasses(log))
             return;
 
         Instrumentation inst = null;
         ClassFileTransformer t = null;
         try {
-            inst = InstrumentationFactory.getInstrumentation(conf);
+            inst = InstrumentationFactory.getInstrumentation(log);
 
             Class<?>[] array = classes.keySet().toArray(new Class[classes.size()]);
             if (JavaVersions.VERSION >= 6) {
@@ -89,9 +87,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) {
@@ -110,10 +108,10 @@ public class ClassRedefiner {
      * only checks whether or not an instrumentation is available and
      * if retransformation is possible.
      */
-    public static boolean canRedefineClasses(OpenJPAConfiguration conf) {
+    public static boolean canRedefineClasses(Log log) {
         if (_canRedefine == null) {
             try {
-                Instrumentation inst = InstrumentationFactory.getInstrumentation(conf);
+                Instrumentation inst = InstrumentationFactory.getInstrumentation(log);
                 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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -57,7 +57,8 @@ public class CodeGenerator {
      * Constructor. Supply configuration and class to generate code for.
      */
     public CodeGenerator(OpenJPAConfiguration conf, Class type) {
-        this(conf.newMetaDataRepositoryInstance().getMetaData(type, true));
+        this(conf.newMetaDataRepositoryInstance().
+            getMetaData(type, null, 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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -37,8 +37,6 @@ 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;
@@ -55,7 +53,9 @@ import org.apache.openjpa.lib.util.Local
 public class InstrumentationFactory {
     private static Instrumentation _inst;
     private static boolean _dynamicallyInstall = true;
-    private static final Localizer _loc = Localizer.forPackage(InstrumentationFactory.class);
+    private static final String _name = InstrumentationFactory.class.getName();
+    private static final Localizer _loc = Localizer.forPackage(
+        InstrumentationFactory.class);
 
     /**
      * This method is not synchronized because when the agent is loaded from
@@ -81,48 +81,63 @@ public class InstrumentationFactory {
      * @return null if Instrumentation can not be obtained, or if any 
      * Exceptions are encountered.
      */
-    public static synchronized Instrumentation getInstrumentation(final OpenJPAConfiguration conf) {
-    	final Log log = conf.getConfigurationLog();
-        trace(conf, "getInstrumentation()", "_inst:" + _inst + " _dynamicallyInstall:" + _dynamicallyInstall);
+    public static synchronized Instrumentation getInstrumentation(final Log log) {
+        if (log.isTraceEnabled() == true) {
+            log.trace(_name + ".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) {
-            trace(conf, "getInstrumentation()", "Dynamic loading only supported on Java SE 6 or later");
+            if (log.isTraceEnabled() == true) {
+                log.trace(_name + ".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()) {
+                if (vendor.isIBM() == false) {
                     // If we can't find the tools.jar and we're not on IBM we can't load the agent. 
-                    toolsJar = findToolsJar(conf);
+                    toolsJar = findToolsJar(log);
                     if (toolsJar == null) {
                         return null;
                     }
                 }
 
-                Class<?> vmClass = loadVMClass(toolsJar, conf, vendor);
+                Class<?> vmClass = loadVMClass(toolsJar, log, vendor);
                 if (vmClass == null) {
                     return null;
                 }
-                String agentPath = getAgentJar(conf);
+                String agentPath = getAgentJar(log);
                 if (agentPath == null) {
                     return null;
                 }
-                loadAgent(conf, agentPath, vmClass);
+                loadAgent(log, 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.
@@ -161,35 +176,52 @@ public class InstrumentationFactory {
     }
 
     /**
-     * Finds [java_home]/lib/tools.jar.
+     * This private worker method attempts to find [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(Configuration conf) {
+    private static File findToolsJar(Log log) {
         String javaHome = System.getProperty("java.home");
         File javaHomeFile = new File(javaHome);
 
         File toolsJarFile = new File(javaHomeFile, "lib" + File.separator + "tools.jar");
-        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")) {
+        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) {
                 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()) {
+        if (toolsJarFile.exists() == false) {
             return null;
         } else {
-            trace(conf, ".findToolsJar()", "found " + toolsJarFile.getAbsolutePath());
+            if (log.isTraceEnabled() == true) {
+                log.trace(_name + ".findToolsJar() -- found " + toolsJarFile.getAbsolutePath());
+            }
             return toolsJarFile;
         }
     }
@@ -204,14 +236,15 @@ public class InstrumentationFactory {
      * @return absolute path to the agent jar or null if anything unexpected
      * happens.
      */
-    private static String getAgentJar(Configuration conf) {
+    private static String getAgentJar(Log log) {
         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());
             }
         }
@@ -219,27 +252,30 @@ 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()) {
+        if (cs == null || agentJarFile == null
+            || agentJarFile.isDirectory() == true) {
             createJar = true;
-        } else if (!InstrumentationFactory.class.getName().equals(getAgentClassName(agentJarFile, conf))) {
+        }else if(validateAgentJarManifest(agentJarFile, log, _name) == false){
             // We have an agentJarFile, but this class isn't the Agent-Class.
-            createJar = true;           
+            createJar=true;           
         }
         
         String agentJar;
-        if (createJar) {
+        if (createJar == true) {
             // 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();
-                Log log = conf.getConfigurationLog();
-                if (log.isInfoEnabled()) {
+                if (log.isInfoEnabled() == true) {
                     log.info(_loc.get("temp-file-creation", agentJar));
                 }
             } catch (IOException ioe) {
-                trace(conf, "getAgentJar()",  "caught unexpected exception " + ioe);
+                if (log.isTraceEnabled() == true) {
+                    log.trace(_name + ".getAgentJar() caught unexpected "
+                        + "exception.", ioe);
+                }
                 agentJar = null;
             }
         } else {
@@ -247,7 +283,7 @@ public class InstrumentationFactory {
         }
 
         return agentJar;
-    }
+    }//end getAgentJar
 
     /**
      * Attach and load an agent class. 
@@ -256,7 +292,7 @@ public class InstrumentationFactory {
      * @param agentJar absolute path to the agent jar.
      * @param vmClass VirtualMachine.class from tools.jar.
      */
-    private static void loadAgent(Configuration conf, String agentJar, Class<?> vmClass) {
+    private static void loadAgent(Log log, String agentJar, Class<?> vmClass) {
         try {
             // first obtain the PID of the currently-running process
             // ### this relies on the undocumented convention of the
@@ -277,13 +313,18 @@ 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) {
-            // 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());
+            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());
+            }
         }
     }
 
@@ -299,16 +340,19 @@ public class InstrumentationFactory {
      * @return The AttachAPI VirtualMachine class <br>
      *         or null if something unexpected happened.
      */
-    private static Class<?> loadVMClass(File toolsJar, Configuration conf, JavaVendors vendor) {
+    private static Class<?> loadVMClass(File toolsJar, Log log, JavaVendors vendor) {
         try {
             ClassLoader loader = Thread.currentThread().getContextClassLoader();
             String cls = vendor.getVirtualMachineClassName();
-            if (!vendor.isIBM()) {
+            if (vendor.isIBM() == false) {
                 loader = new URLClassLoader(new URL[] { toolsJar.toURI().toURL() }, loader);
             }
             return loader.loadClass(cls);
         } catch (Exception e) {
-           trace(conf, "loadVMClass()", "failed to load the VirtualMachine class");
+            if (log.isTraceEnabled()) {
+                log.trace(_name
+                    + ".loadVMClass() failed to load the VirtualMachine class");
+            }
         }
         return null;
     }
@@ -326,25 +370,26 @@ 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 String getAgentClassName(File agentJarFile, Configuration conf) {
+    private static boolean validateAgentJarManifest(File agentJarFile, Log log,
+        String agentClassName) {
         try {
             JarFile jar = new JarFile(agentJarFile);
             Manifest manifest = jar.getManifest();
             if (manifest == null) {
-                return null;
+                return false;
             }
             Attributes attributes = manifest.getMainAttributes();
-            return attributes.getValue("Agent-Class");
+            String ac = attributes.getValue("Agent-Class");
+            if (ac != null && ac.equals(agentClassName)) {
+                return true;
+            }
         } catch (Exception e) {
-            trace(conf, "validateAgentJarManifest()",  " caught unexpected exception " + e.getMessage());
+            if (log.isTraceEnabled() == true) {
+                log.trace(_name
+                    + ".validateAgentJarManifest() caught unexpected "
+                    + "exception " + e.getMessage());
+            }
         }
-        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);
-    	}
-    }
+        return false;
+    }// end validateAgentJarManifest   
 }

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=1197994&r1=1197993&r2=1197994&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 Nov  5 17:17:26 2011
@@ -32,8 +32,9 @@ 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.Files;
+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.Message;
 import org.apache.openjpa.meta.AccessCode;
 import org.apache.openjpa.meta.ClassMetaData;
@@ -45,7 +46,6 @@ 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,7 +80,8 @@ public class ManagedClassSubclasser {
      */
     public static List<Class<?>> prepareUnenhancedClasses(
         final OpenJPAConfiguration conf,
-        final Collection<? extends Class<?>> classes) {
+        final Collection<? extends Class<?>> classes,
+        final ClassLoader envLoader) {
         if (classes == null)
             return null;
         if (classes.size() == 0)
@@ -93,7 +94,7 @@ public class ManagedClassSubclasser {
                 if (!PersistenceCapable.class.isAssignableFrom(cls))
                     unenhanced.add(cls);
             if (unenhanced.size() > 0) {
-                if (PCEnhancerAgent.getLoadSuccessful()) {
+                if (PCEnhancerAgent.getLoadSuccessful() == true) {
                     // This means that the enhancer has been ran but we
                     // have some unenhanced classes. This can happen if an
                     // entity is loaded by the JVM before the EntityManger
@@ -118,7 +119,7 @@ public class ManagedClassSubclasser {
             return null;
         }
 
-        boolean redefine = ClassRedefiner.canRedefineClasses(conf);
+        boolean redefine = ClassRedefiner.canRedefineClasses(log);
         if (redefine) {
             log.info(_loc.get("enhance-and-subclass-and-redef-start", classes));
         } else {
@@ -175,13 +176,13 @@ public class ManagedClassSubclasser {
 
         ClassRedefiner.redefineClasses(conf, map);
         for (Class<?> cls : map.keySet()) {
-            setIntercepting(conf, cls);
-            configureMetaData(conf, cls, redefine);
+            setIntercepting(conf, envLoader, cls);
+            configureMetaData(conf, envLoader, cls, redefine);
         }
         for (Class<?> cls : subs)
-            configureMetaData(conf, cls, redefine);
+            configureMetaData(conf, envLoader, cls, redefine);
         for (Class<?> cls : ints)
-            setIntercepting(conf, cls);
+            setIntercepting(conf, envLoader, cls);
 
         return subs;
     }
@@ -223,8 +224,9 @@ public class ManagedClassSubclasser {
     }
 
     private static void configureMetaData(OpenJPAConfiguration conf,
-        Class<?> cls, boolean redefineAvailable) {
-        ClassMetaData meta = conf.getMetaDataRepositoryInstance().getMetaData(cls, true);
+        ClassLoader envLoader, Class<?> cls, boolean redefineAvailable) {
+        ClassMetaData meta = conf.getMetaDataRepositoryInstance()
+            .getMetaData(cls, envLoader, true);
         configureMetaData(meta, conf, redefineAvailable, true);
     }
 
@@ -304,9 +306,10 @@ public class ManagedClassSubclasser {
         }
     }
 
-    private static void setIntercepting(OpenJPAConfiguration conf, Class<?> cls) {
+    private static void setIntercepting(OpenJPAConfiguration conf,
+        ClassLoader envLoader, Class<?> cls) {
         ClassMetaData meta = conf.getMetaDataRepositoryInstance()
-            .getMetaData(cls, true);
+            .getMetaData(cls, envLoader, true);
         meta.setIntercepting(true);
     }