openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r447664 - in /incubator/openjpa/trunk: openjpa-all/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/resources/META-INF/services/ openjpa-kernel/src/ma...
Date Tue, 19 Sep 2006 00:50:59 GMT
Author: ppoddar
Date: Mon Sep 18 17:50:57 2006
New Revision: 447664

URL: http://svn.apache.org/viewvc?view=rev&rev=447664
Log:
1. Refactoring ConfigurationProvider/ProductDerivation subsystem.
2. Extensibility of OpenJPA via ProductDerivation

Primary modifications are
a) The configuration information resources are located/parsed/loaded via dynamically discovered ProductDerivation services
(instead of ConfigurationProviders). ConfigurationProvider is not enlisted as a service any more.
b) Tools are modified to use ProductDerivations instead of Configurations 
c) ProductDerivation has moved to lib from kernel.
d) ProductDerivation types that are STORE specific are no more defined in lib version.
OpenJPAProductDerivation in kernel package defines them. The type constants have holes. 
e) One test is modified
f) pom.xml is modified as ProductDerivation has moved to lib from kernel 

Added:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAProductDerivation.java
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java
      - copied, changed from r442075, incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivation.java
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
      - copied, changed from r442075, incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java
    incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/ConfigurationTestProductDerivation.java
    incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryValue.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation
Removed:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/META-INF/services/org.apache.openjpa.conf.ProductDerivation
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivation.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java
    incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/services/org.apache.openjpa.lib.conf.ConfigurationProvider
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/META-INF/services/org.apache.openjpa.conf.ProductDerivation
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderExtension.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/resources/META-INF/services/org.apache.openjpa.conf.ProductDerivation
    incubator/openjpa/trunk/openjpa-persistence/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ConfigurationProvider
Modified:
    incubator/openjpa/trunk/openjpa-all/pom.xml
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ClassTableJDBCSeq.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java
    incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/TestConfigurationImpl.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
    incubator/openjpa/trunk/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLConfiguration.java

Modified: incubator/openjpa/trunk/openjpa-all/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-all/pom.xml?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-all/pom.xml (original)
+++ incubator/openjpa/trunk/openjpa-all/pom.xml Mon Sep 18 17:50:57 2006
@@ -50,10 +50,9 @@
                                     </sequential>
                                 </macrodef>
 
-                                <aggregate-file servicename="org.apache.openjpa.conf.ProductDerivation"/>
+                                <aggregate-file servicename="org.apache.openjpa.lib.conf.ProductDerivation"/>
                                 <aggregate-file servicename="javax.persistence.spi.PersistenceProvider"/>
                                 <aggregate-file servicename="org.apache.openjpa.kernel.exps.ExpressionParser"/>
-                                <aggregate-file servicename="org.apache.openjpa.lib.conf.ConfigurationProvider"/>
                             </tasks>
                         </configuration>
                         <goals>

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java Mon Sep 18 17:50:57 2006
@@ -20,7 +20,6 @@
 import javax.sql.DataSource;
 
 import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
-import org.apache.openjpa.conf.ProductDerivations;
 import org.apache.openjpa.jdbc.kernel.EagerFetchModes;
 import org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory;
 import org.apache.openjpa.jdbc.kernel.LRSSizes;
@@ -39,6 +38,7 @@
 import org.apache.openjpa.lib.conf.IntValue;
 import org.apache.openjpa.lib.conf.ObjectValue;
 import org.apache.openjpa.lib.conf.PluginValue;
+import org.apache.openjpa.lib.conf.ProductDerivations;
 import org.apache.openjpa.lib.conf.StringListValue;
 import org.apache.openjpa.lib.conf.StringValue;
 import org.apache.openjpa.lib.jdbc.ConnectionDecorator;

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCProductDerivation.java Mon Sep 18 17:50:57 2006
@@ -16,16 +16,16 @@
 package org.apache.openjpa.jdbc.conf;
 
 import org.apache.openjpa.conf.BrokerFactoryValue;
-import org.apache.openjpa.conf.OpenJPAConfiguration;
-import org.apache.openjpa.conf.ProductDerivation;
+import org.apache.openjpa.conf.OpenJPAProductDerivation;
 import org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory;
+import org.apache.openjpa.lib.conf.AbstractProductDerivation;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
 
 /**
  * Sets JDBC as default store.
  */
-public class JDBCProductDerivation
-    implements ProductDerivation {
+public class JDBCProductDerivation extends AbstractProductDerivation
+    implements OpenJPAProductDerivation {
 
     static {
         BrokerFactoryValue.addDefaultAlias("jdbc",
@@ -36,17 +36,17 @@
         return TYPE_STORE;
     }
 
-    public void beforeConfigurationConstruct(ConfigurationProvider cp) {
+    public boolean beforeConfigurationConstruct(ConfigurationProvider cp) {
         // default to JDBC when no broker factory set
         if (BrokerFactoryValue.get(cp) == null) {
             cp.addProperty(BrokerFactoryValue.getKey(cp),
                 JDBCBrokerFactory.class.getName());
+            return true;
         }
+        return false;
     }
-
-    public void beforeConfigurationLoad(OpenJPAConfiguration c) {
-    }
-
-    public void afterSpecificationSet(OpenJPAConfiguration c) {
+    
+    public ConfigurationProvider newConfigurationProvider() {
+        return null;
     }
 }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ClassTableJDBCSeq.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ClassTableJDBCSeq.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ClassTableJDBCSeq.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ClassTableJDBCSeq.java Mon Sep 18 17:50:57 2006
@@ -29,6 +29,7 @@
 import org.apache.openjpa.jdbc.schema.Table;
 import org.apache.openjpa.jdbc.sql.DBDictionary;
 import org.apache.openjpa.lib.conf.Configurations;
+import org.apache.openjpa.lib.conf.ProductDerivations;
 import org.apache.openjpa.lib.meta.ClassArgParser;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.Options;

Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation?view=auto&rev=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation Mon Sep 18 17:50:57 2006
@@ -0,0 +1 @@
+org.apache.openjpa.jdbc.conf.JDBCProductDerivation

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java (original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfiguration.java Mon Sep 18 17:50:57 2006
@@ -209,7 +209,7 @@
      * A configuration can be set with defaults for a specific specification.
      */
     public String getSpecification();
-
+    
     /**
      * Set the specification that this configuration should use for the
      * various properties that need to have different defaults for different

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java (original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java Mon Sep 18 17:50:57 2006
@@ -15,8 +15,12 @@
  */
 package org.apache.openjpa.conf;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 import org.apache.openjpa.datacache.ConcurrentDataCache;
 import org.apache.openjpa.datacache.ConcurrentQueryCache;
@@ -38,15 +42,7 @@
 import org.apache.openjpa.kernel.Seq;
 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.IntValue;
-import org.apache.openjpa.lib.conf.ObjectValue;
-import org.apache.openjpa.lib.conf.PluginListValue;
-import org.apache.openjpa.lib.conf.PluginValue;
-import org.apache.openjpa.lib.conf.StringListValue;
-import org.apache.openjpa.lib.conf.StringValue;
+import org.apache.openjpa.lib.conf.*;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.MetaDataFactory;
@@ -140,7 +136,6 @@
 
     private Collection supportedOptions = new HashSet(33);
     private String spec = null;
-    
     private final StoreFacadeTypeRegistry _storeFacadeRegistry =
         new StoreFacadeTypeRegistry();
 
@@ -531,7 +526,6 @@
                     spec));
             return false;
         }
-
         this.spec = spec;
         ProductDerivations.afterSpecificationSet(this);
         return true;

Added: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAProductDerivation.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAProductDerivation.java?view=auto&rev=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAProductDerivation.java (added)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAProductDerivation.java Mon Sep 18 17:50:57 2006
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.conf;
+
+import org.apache.openjpa.lib.conf.ProductDerivation;
+
+/**
+ * 
+ * Adds datastore based extension to ProductDerivation.  
+ *
+ * @since 0.4.1
+ * @author Pinaki Poddar
+ *
+ */
+public interface OpenJPAProductDerivation extends ProductDerivation {
+    public static final int TYPE_STORE = 200;
+    public static final int TYPE_SPEC_STORE = 300;
+    public static final int TYPE_PRODUCT_STORE = 400;
+}

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java (original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java Mon Sep 18 17:50:57 2006
@@ -19,9 +19,9 @@
 import java.lang.reflect.Method;
 
 import org.apache.openjpa.conf.BrokerFactoryValue;
-import org.apache.openjpa.conf.ProductDerivations;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
 import org.apache.openjpa.lib.conf.MapConfigurationProvider;
+import org.apache.openjpa.lib.conf.ProductDerivations;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.util.InternalException;
 import org.apache.openjpa.util.OpenJPAException;

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java Mon Sep 18 17:50:57 2006
@@ -29,7 +29,7 @@
 import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.conf.ConfigurationImpl;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
-import org.apache.openjpa.lib.conf.Configurations;
+import org.apache.openjpa.lib.conf.ProductDerivations;
 import org.apache.openjpa.lib.util.Localizer;
 
 /**
@@ -155,7 +155,7 @@
         if (_conf == null)
             _conf = newConfiguration();
         if (_conf.getPropertiesResource() == null) {
-            ConfigurationProvider cp = Configurations.loadDefaults
+            ConfigurationProvider cp = ProductDerivations.loadDefaults
                 (_conf.getClass().getClassLoader());
             if (cp != null)
                 cp.setInto(_conf);

Added: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java?view=auto&rev=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/AbstractProductDerivation.java Mon Sep 18 17:50:57 2006
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf;
+
+import java.io.File;
+import java.util.Map;
+
+/**
+ * Abstract implementation of ProductDerivation loads configuration data using
+ * ConfigurationProvider supplied by concrete implementation via 
+ * {@link #newConfigurationProvider()} method.<p>
+ * This abstract implementation does <em>not</em> provide a concrete 
+ * ConfigurationProvider and hence all its loadXXX() methods would return null
+ * by default. When the concrete subclass supplies a ConfigurationProvider,
+ * this abstratct implementation will use it to load the configuration data. 
+ *
+ * @author Pinaki Poddar
+ * @since 0.4.1
+ */
+
+public abstract class AbstractProductDerivation
+    implements ProductDerivation {
+
+    public ConfigurationProvider loadGlobals(ClassLoader loader)
+            throws Exception {
+        ConfigurationProvider provider = newConfigurationProvider();
+        if (provider != null && provider.loadGlobals(loader))
+            return provider;
+        return null;
+    }
+
+    public ConfigurationProvider loadDefaults(ClassLoader loader)
+            throws Exception {
+        ConfigurationProvider provider = newConfigurationProvider();
+        if (provider != null && provider.loadDefaults(loader))
+            return provider;
+        return null;
+    }
+
+    public ConfigurationProvider load(String resource, String anchor,
+            ClassLoader loader)  throws Exception {
+        ConfigurationProvider provider = newConfigurationProvider();
+        if (provider != null && provider.load(resource, anchor, loader))
+            return provider;
+        return null;
+    }
+    
+    public ConfigurationProvider load(String resource, String anchor,
+            Map map) throws Exception {
+        ConfigurationProvider provider = newConfigurationProvider();
+        if (provider != null && provider.load(resource, anchor, map))
+            return provider;
+        return null;
+    }
+
+    public ConfigurationProvider load(File file, String anchor)
+            throws Exception {
+        ConfigurationProvider provider = newConfigurationProvider();
+        if (provider != null && provider.load(file, anchor))
+            return provider;
+        return null;
+    }
+
+    public boolean beforeConfigurationConstruct(ConfigurationProvider cp) {
+        return false;
+    }
+
+    public boolean beforeConfigurationLoad(Configuration conf) {
+        return false;
+    }
+
+    public boolean afterSpecificationSet(Configuration conf) {
+        return false;
+    }
+    
+    public abstract ConfigurationProvider newConfigurationProvider();
+}

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java Mon Sep 18 17:50:57 2006
@@ -120,7 +120,7 @@
 
     /**
      * Default constructor. Attempts to load default properties through
-     * system's configured {@link ConfigurationProvider}s.
+     * system's configured {@link ProductDerivation}s.
      */
     public ConfigurationImpl() {
         this(true);
@@ -153,10 +153,10 @@
 
     /**
      * Automatically load global values from the system's
-     * {@link ConfigurationProvider}s, and from System properties.
+     * {@link ProductDerivation}s, and from System properties.
      */
     public boolean loadGlobals() {
-        ConfigurationProvider provider = Configurations.loadGlobals
+        ConfigurationProvider provider = ProductDerivations.loadGlobals
             (getClass().getClassLoader());
         if (provider != null)
             provider.setInto(this);
@@ -752,8 +752,8 @@
      * <code>properties</code> value with the name of a resource.
      */
     public void setProperties(String resourceName) throws IOException {
-        Configurations.load(resourceName, getClass().getClassLoader()).
-            setInto(this);
+        ProductDerivations.load(resourceName, null, 
+                getClass().getClassLoader()).setInto(this);
         _auto = resourceName;
     }
 
@@ -763,7 +763,8 @@
      * <code>propertiesFile</code> value with the name of a file.
      */
     public void setPropertiesFile(File file) throws IOException {
-        Configurations.load(file, getClass().getClassLoader()).setInto(this);
+        ProductDerivations.load(file, null, 
+                getClass().getClassLoader()).setInto(this);
         _auto = file.toString();
     }
 

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java Mon Sep 18 17:50:57 2006
@@ -30,34 +30,6 @@
 public interface ConfigurationProvider {
 
     /**
-     * Load globals, or return false if no globals for this provider found.
-     */
-    public boolean loadGlobals(ClassLoader loader) throws Exception;
-
-    /**
-     * Load defaults, or return false if no defaults for this provider found.
-     */
-    public boolean loadDefaults(ClassLoader loader) throws Exception;
-
-    /**
-     * Load the given given resource, or return false if it is not a resource
-     * this provider understands. The given class loader may be null.
-     *
-     * @param anchor optional named anchor within a multiple-configuration
-     * resource
-     */
-    public boolean load(String resource, String anchor, ClassLoader loader) 
-        throws Exception;
-
-    /**
-     * Load given file, or return false if it is not a file this provider
-     * understands.
-     *
-     * @param anchor optional named anchor within a multiple-configuration file
-     */
-    public boolean load(File file, String anchor) throws Exception;
-
-    /**
      * Return properties loaded thus far, or empty map if none.
      */
     public Map getProperties();
@@ -78,4 +50,48 @@
      * Set loaded information into the given configuration.
      */
     public void setInto(Configuration conf);
+    
+    /**
+     * Loads the global resource. The meaning of <em>global</em> is specific
+     * to concrte implementaion. 
+     * @param loader used to locate the resource. If null uses the current
+     * thread's loader.
+     * @return true if located and loaded global configuration 
+     */
+    public boolean loadGlobals(ClassLoader loader) throws Exception;
+
+    /**
+     * Loads the default resource. The meaning of <em>default</em> is specific
+     * to concrte implementaion. 
+     * @param loader used to locate the resource. If null uses the current
+     * thread's loader.
+     * @return true if located and loaded default configuration 
+     */
+    public boolean loadDefaults(ClassLoader loader) throws Exception;
+    
+    /**
+     * Loads the given resource. 
+     * @param resource name of the resource
+     * @param anchor optional named anchor within a resource containing multiple
+     * configuration
+     * @param loader used to locate the resource. If null uses the current
+     * thread's loader.
+     * @return true if located and loaded configuration 
+     */
+    public boolean load(String resource, String anchor, ClassLoader loader) 
+        throws Exception;
+    
+    public boolean load(String resource, String anchor, Map map) 
+        throws Exception;
+
+    /**
+     * Loads the given resource. 
+     * @param file name of the file to load from
+     * @param anchor optional named anchor within a file containing multiple
+     * configuration
+     * @return true if located and loaded configuration 
+     */
+    public boolean load(File file, String anchor) throws Exception;
+
+
 }

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java Mon Sep 18 17:50:57 2006
@@ -163,6 +163,50 @@
     }
 
     /**
+     * Set the given {@link Configuration} instance from the command line
+     * options provided. All property names of the given configuration are
+     * recognized; additionally, if a <code>properties</code> or
+     * <code>p</code> argument exists, the resource it
+     * points to will be loaded and set into the given configuration instance.
+     * It can point to either a file or a resource name.
+     */
+    public static void populateConfiguration(Configuration conf, Options opts) {
+        String props = opts.removeProperty("properties", "p", null);
+        ConfigurationProvider provider;
+        if (props != null && props.length() > 0) {
+            String path = props;
+            String anchor = null;
+            int idx = path.lastIndexOf('#');
+            if (idx != -1) {
+                if (idx < path.length() - 1)
+                    anchor = path.substring(idx + 1);
+                path = path.substring(0, idx);
+                if (path.length() == 0)
+                    throw new MissingResourceException(_loc.get("anchor-only",
+                        props).getMessage(), Configurations.class.getName(), 
+                        props);
+            }
+
+            File file = new File(path);
+            if (file.isFile())
+                provider = ProductDerivations.load(file, anchor, null);
+            else {
+                file = new File("META-INF" + File.separatorChar + path);
+                if (file.isFile())
+                    provider = ProductDerivations.load(file, anchor, null);
+                else
+                    provider = ProductDerivations.load(path, anchor, (Map)null);
+            }
+            provider.setInto(conf);
+        } else {
+            provider = ProductDerivations.loadDefaults(null);
+            if (provider != null)
+                provider.setInto(conf);
+        }
+        opts.setInto(conf);
+    }
+
+    /**
      * Helper method to throw an informative description on instantiation error.
      */
     private static RuntimeException getCreateException(String clsName,
@@ -398,261 +442,6 @@
         } catch (RuntimeException re) {
             throw new ParseException(_loc.get("prop-parse", properties), re);
         }
-    }
-
-    /**
-     * Set the given {@link Configuration} instance from the command line
-     * options provided. All property names of the given configuration are
-     * recognized; additionally, if a <code>properties</code> or
-     * <code>p</code> argument exists, the resource it
-     * points to will be loaded and set into the given configuration instance.
-     * It can point to either a file or a resource name.
-     */
-    public static void populateConfiguration(Configuration conf, Options opts) {
-        String props = opts.removeProperty("properties", "p", null);
-        if (props != null && props.length() > 0) {
-            String path = props;
-            String anchor = null;
-            int idx = path.lastIndexOf('#');
-            if (idx != -1) {
-                if (idx < path.length() - 1)
-                    anchor = path.substring(idx + 1);
-                path = path.substring(0, idx);
-                if (path.length() == 0)
-                    throw new MissingResourceException(_loc.get("anchor-only",
-                        props).getMessage(), Configurations.class.getName(), 
-                        props);
-            }
-
-            File file = new File(path);
-            ConfigurationProvider provider;
-            if (file.isFile())
-                provider = load(file, anchor, null);
-            else {
-                file = new File("META-INF" + File.separatorChar + path);
-                if (file.isFile())
-                    provider = load(file, anchor, null);
-                else
-                    provider = load(path, anchor, null);
-            }
-            provider.setInto(conf);
-        } else {
-            ConfigurationProvider provider = loadDefaults(null);
-            if (provider != null)
-                provider.setInto(conf);
-        }
-        opts.setInto(conf);
-    }
-
-    /**
-     * Return a {@link ConfigurationProvider} that has parsed system defaults.
-     */
-    public static ConfigurationProvider loadDefaults(ClassLoader loader) {
-        return load(loader, false);
-    }
-
-    /**
-     * Return a {@link ConfigurationProvider} that has parsed system globals.
-     */
-    static ConfigurationProvider loadGlobals(ClassLoader loader) {
-        return load(loader, true);
-    }
-
-    /**
-     * Load globals or defaults.
-     */
-    private static ConfigurationProvider load(ClassLoader loader, 
-        boolean globals) {
-        if (loader == null)
-            loader = Thread.currentThread().getContextClassLoader();
-        Class[] impls = Services.getImplementorClasses
-            (ConfigurationProvider.class, loader);
-        ConfigurationProvider provider = null;
-        int providerCount = 0;
-        List errs = null;
-        for (int i = 0; i < impls.length; i++) {
-            try {
-                provider = (ConfigurationProvider) impls[i].newInstance();
-                if (provider == null)
-                    continue;
-
-                providerCount++;
-
-                if ((globals && provider.loadGlobals(loader))
-                    || (!globals && provider.loadDefaults(loader)))
-                    return provider;
-            } catch (MissingResourceException mre) {
-                throw mre;
-            } catch (Throwable t) {
-                (errs == null ? errs = new ArrayList() : errs).add(t);
-            }
-        }
-
-        String type = (globals) ? "globals" : "defaults";
-        MissingResourceException ex = null;
-
-        if (errs != null)
-            ex = new MissingResourceException(errs.toString(),
-                Configurations.class.getName(), type);
-        else if (providerCount == 0)
-            ex = new MissingResourceException(_loc.get ("no-providers", 
-                ConfigurationProvider.class.getName()).getMessage(),
-                Configurations.class.getName(), type);
-
-        if (ex != null)
-            throw (MissingResourceException) JavaVersions.initCause(ex,
-                errs.size() == 0 ? null : (Throwable) errs.get(0));
-
-        return null;
-    }
-
-    /**
-     * Return a new new configuration provider instance of the given class,
-     * or null if the class cannot be instantiated.
-     */
-    private static ConfigurationProvider newProvider(Class cls) {
-        try {
-            return (ConfigurationProvider) cls.newInstance();
-        } catch (Throwable e) {
-            return null;
-        }
-    }
-
-    /**
-     * Return a {@link ConfigurationProvider} that has parsed the given
-     * resource. Throws {@link MissingResourceException} if resource does
-     * not exist.
-     */
-    public static ConfigurationProvider load(String resource, 
-        ClassLoader loader) {
-        if (resource == null || resource.length() == 0)
-            return null;
-
-        String path = resource;
-        String anchor = null;
-        int idx = path.indexOf('#');
-        if (idx != -1) {
-            if (idx < path.length() - 1)
-                anchor = path.substring(idx + 1);
-            path = path.substring(0, idx);
-            if (path.length() == 0)
-                throw new MissingResourceException(_loc.get("anchor-only", 
-                    resource).getMessage(), Configurations.class.getName(), 
-                    resource);
-        }
-        return load(path, anchor, loader);
-    }
-
-    /**
-     * Return a {@link ConfigurationProvider} that has parsed the given
-     * resource. Throws {@link MissingResourceException} if resource does
-     * not exist.
-     */
-    public static ConfigurationProvider load(String resource, String anchor, 
-        ClassLoader loader) {
-        if (resource == null || resource.length() == 0)
-            return null;
-
-        if (loader == null)
-            loader = Thread.currentThread().getContextClassLoader();
-        Class[] impls = Services.getImplementorClasses
-            (ConfigurationProvider.class, loader);
-        ConfigurationProvider provider = null;
-        int providerCount = 0;
-        StringBuffer errs = null;
-        for (int i = 0; i < impls.length; i++) {
-            provider = newProvider(impls[i]);
-            if (provider == null)
-                continue;
-
-            providerCount++;
-            try {
-                if (provider.load(resource, anchor, loader))
-                    return provider;
-            } catch (MissingResourceException mre) {
-                throw mre;
-            } catch (Exception e) {
-                if (errs == null)
-                    errs = new StringBuffer();
-                else
-                    errs.append(", ");
-                errs.append(e.toString());
-            }
-        }
-        String msg;
-        if (errs != null)
-            msg = errs.toString();
-        else if (providerCount == 0)
-            msg = _loc.get("no-providers", 
-                ConfigurationProvider.class.getName()).getMessage();
-        else
-            msg = _loc.get("no-provider", resource).getMessage();
-        
-        throw new MissingResourceException(msg,
-            Configurations.class.getName(), resource);
-    }
-
-    /**
-     * Return a {@link ConfigurationProvider} that has parsed the given
-     * file. Throws {@link MissingResourceException} if file does not exist.
-     */
-    public static ConfigurationProvider load(File file, ClassLoader loader) {
-        if (file == null)
-            return null;
-
-        String anchor = null;
-        try {
-            String path = file.getCanonicalPath();
-            int idx = path.indexOf('#');
-            if (idx != -1) {
-                if (idx < path.length() - 1)
-                    anchor = path.substring(idx + 1);
-                path = path.substring(0, idx);
-                if (path.length() == 0)
-                    throw new MissingResourceException(_loc.get("anchor-only",
-                        file).getMessage(), Configurations.class.getName(), 
-                        file.toString());
-                file = new File(path);
-            }
-        } catch (IOException ioe) {
-            // ignore
-        }
-        return load(file, anchor, loader);
-    }
-
-    /**
-     * Return a {@link ConfigurationProvider} that has parsed the given
-     * file. Throws {@link MissingResourceException} if file does not exist.
-     */
-    public static ConfigurationProvider load(File file, String anchor, 
-        ClassLoader loader) {
-        if (file == null)
-            return null;
-
-        if (loader == null)
-            loader = Thread.currentThread().getContextClassLoader();
-        Class[] impls = Services.getImplementorClasses
-            (ConfigurationProvider.class, loader);
-        ConfigurationProvider provider = null;
-        StringBuffer errs = null;
-        for (int i = 0; i < impls.length; i++) {
-            provider = newProvider(impls[i]);
-            try {
-                if (provider != null && provider.load(file, anchor))
-                    return provider;
-            } catch (MissingResourceException mre) {
-                throw mre;
-            } catch (Exception e) {
-                if (errs == null)
-                    errs = new StringBuffer();
-                else
-                    errs.append(", ");
-                errs.append(e.toString());
-            }
-        }
-        String msg = (errs == null) ? file.toString() : errs.toString();
-        throw new MissingResourceException(msg,
-            Configurations.class.getName(), file.toString());
     }
 
     /**

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/MapConfigurationProvider.java Mon Sep 18 17:50:57 2006
@@ -68,6 +68,16 @@
         return false;
     }
 
+    /**
+     * Loads only if the given map is non-null.
+     * Always returns false.
+     */
+    public boolean load(String rsrc, String anchor, Map m) throws Exception {
+        if (m != null)
+            addProperties(m);
+        return false;
+    }
+
     public Map getProperties() {
         return (_props == null) ? Collections.EMPTY_MAP : _props;
     }

Copied: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java (from r442075, incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivation.java)
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java?view=diff&rev=447664&p1=incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivation.java&r1=442075&p2=incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivation.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivation.java Mon Sep 18 17:50:57 2006
@@ -13,29 +13,31 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.openjpa.conf;
+package org.apache.openjpa.lib.conf;
 
-import org.apache.openjpa.lib.conf.Configuration;
-import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import java.io.File;
+import java.util.Map;
 
 /**
  * Hooks for deriving products with additional functionality.
+ * The specific implementation uses corresponding {@link ConfigurationProvider}
+ * to locate and parse configuration information from global, default or
+ * explictly-specified resources.
  * All implementations of this interface will have a chance to mutate
  * a {@link Configuration} both before and after the user-specified
- * configuration data is loaded. The order in which the
- * derivations are evaluated is determined by the specificity of the
- * derivation type.
+ * configuration data is loaded. 
+ * The order in which the product derivations are evaluated is determined by the 
+ * specificity of the derivation type.
  *
+ * @author Abe White
+ * @author Pinaki Poddar
  * @since 0.4.1
  */
 public interface ProductDerivation {
 
     public static final int TYPE_SPEC = 0;
-    public static final int TYPE_PRODUCT = 1;
-    public static final int TYPE_STORE = 2;
-    public static final int TYPE_SPEC_STORE = 3;
-    public static final int TYPE_PRODUCT_STORE = 4;
-    public static final int TYPE_FEATURE = 5;
+    public static final int TYPE_PRODUCT = 100;
+    public static final int TYPE_FEATURE = 1000;
 
     /**
      * Return the type of derivation.
@@ -43,21 +45,69 @@
     public int getType();
 
     /**
+     * Load globals via the returned ConfigurationProvider, or return null if 
+     * no globals is found.
+     */
+    public ConfigurationProvider loadGlobals(ClassLoader loader) 
+        throws Exception;
+
+    /**
+     * Load defaults via the returned ConfigurationProvider, or return null if 
+     * no defaults is found.
+     */
+    public ConfigurationProvider loadDefaults(ClassLoader loader) 
+        throws Exception;
+
+    /**
+     * Load the given given resource via the returned ConfigurationProvider, or 
+     * return null if it is not a resource this receiver understands. 
+     * The given class loader may be null.
+     *
+     * @param anchor optional named anchor within a multiple-configuration
+     * resource
+     */
+    public ConfigurationProvider load(String resource, String anchor, 
+        ClassLoader loader) throws Exception;
+
+    /**
+     * Load given file, or return null if it is not a file this receiver
+     * understands.
+     *
+     * @param anchor optional named anchor within a multiple-configuration file
+     */
+    public ConfigurationProvider load(File file, String anchor) 
+        throws Exception;
+    
+    /**
+     * Load given resource overriding with the given map <code>m</code>, or 
+     * return null if it is not a resource this receiver* understands.
+     *
+     * @param anchor optional named anchor within a multiple-configuration file
+     * @param m optional properties to override the content of the resource.
+     */
+    public ConfigurationProvider load(String rsrc, String anchor, Map m) 
+        throws Exception;
+
+    
+    /**
      * Provides the instance with a callback to mutate the initial properties
      * of the {@link ConfigurationProvider}. This is primarily to alter or
      * add properties that determine what type of configuration is constructed,
      * and therefore is typically used at runtime only.
+     * @return true if given ConfigurationProvider has been mutated.
      */
-    public void beforeConfigurationConstruct(ConfigurationProvider cp);
+    public boolean beforeConfigurationConstruct(ConfigurationProvider cp);
 
     /**
      * Provides the instance with the opportunity to mutate
      * <code>conf</code> before the user configuration is applied.
+     * @return true if given Configuration has been mutated.
      */
-    public void beforeConfigurationLoad(OpenJPAConfiguration conf);
+    public boolean beforeConfigurationLoad(Configuration conf);
 
     /**
      * Called after the specification has been set.
+     * @return true if given Configuration has been mutated.
      */
-    public void afterSpecificationSet(OpenJPAConfiguration conf);
+    public boolean afterSpecificationSet(Configuration conf);
 }

Copied: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java (from r442075, incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java)
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java?view=diff&rev=447664&p1=incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java&r1=442075&p2=incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java Mon Sep 18 17:50:57 2006
@@ -13,16 +13,19 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.openjpa.conf;
+package org.apache.openjpa.lib.conf;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Map;
 import java.util.MissingResourceException;
 
-import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import org.apache.openjpa.lib.util.JavaVersions;
 import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.lib.util.Options;
 import org.apache.openjpa.lib.util.Services;
 
 /**
@@ -48,7 +51,7 @@
             }
         }
 
-        // there must be some product derivation to define metadata factories,
+        // must be at least one product derivation to define metadata factories,
         // etc. 
         if (derivations.isEmpty()) {
             Localizer loc = Localizer.forPackage(ProductDerivations.class);
@@ -69,7 +72,7 @@
     public static void beforeConfigurationConstruct(ConfigurationProvider cp) {
         for (int i = 0; i < _derivations.length; i++) {
             try {
-                _derivations[i].beforeConfigurationConstruct(cp);
+                boolean ret = _derivations[i].beforeConfigurationConstruct(cp);
             } catch (Exception e) {
                 // can't log; no configuration yet
                 e.printStackTrace();
@@ -81,10 +84,10 @@
      * Apply {@link ProductDerivation#beforeConfigurationLoad} callbacks
      * to the the given instance. Exceptions are swallowed.
      */
-    public static void beforeConfigurationLoad(OpenJPAConfiguration conf) {
+    public static void beforeConfigurationLoad(Configuration conf) {
         for (int i = 0; i < _derivations.length; i++) {
             try {
-                _derivations[i].beforeConfigurationLoad(conf);
+                boolean ret = _derivations[i].beforeConfigurationLoad(conf);
             } catch (Exception e) {
                 // logging not configured yet
                 e.printStackTrace();
@@ -96,10 +99,10 @@
      * Apply {@link ProductDerivation#afterSpecificationSet} callbacks
      * to the the given instance. Exceptions are swallowed.
      */
-    public static void afterSpecificationSet(OpenJPAConfiguration conf) {
+    public static void afterSpecificationSet(Configuration conf) {
         for (int i = 0; i < _derivations.length; i++) {
             try {
-                _derivations[i].afterSpecificationSet(conf);
+                boolean ret = _derivations[i].afterSpecificationSet(conf);
             } catch (Exception e) {
                 // logging not configured yet
                 e.printStackTrace();
@@ -107,6 +110,133 @@
         }
     }
 
+    /**
+     * Load the given given resource, or return false if it is not a resource
+     * this provider understands. The given class loader may be null.
+     *
+     * @param anchor optional named anchor within a multiple-configuration
+     * resource
+     */
+    public static ConfigurationProvider load(String resource, String anchor, 
+        ClassLoader loader) {
+        if (resource == null || resource.length() == 0)
+            return null;
+        if (loader == null)
+            loader = Thread.currentThread().getContextClassLoader();
+        ConfigurationProvider provider = null;
+        StringBuffer errs = null;
+        for (int i = 0; i < _derivations.length; i++) {
+            try {
+                provider = _derivations[i].load(resource, anchor, loader);
+                if (provider != null) {
+                    return provider;
+                }
+            } catch (Throwable t) {
+                errs = (errs == null) ? new StringBuffer() 
+                        : errs.append("\r\n");
+                errs.append(_derivations[i].getClass().getName() + ":" + t);
+            }
+        }
+        reportError(errs, resource);
+        return null;
+    }
+
+    /**
+     * Load given file, or return false if it is not a file this provider
+     * understands.
+     *
+     * @param anchor optional named anchor within a multiple-configuration file
+     */
+    public static ConfigurationProvider load(File file, String anchor, 
+        ClassLoader loader) {
+        if (file == null)
+            return null;
+        if (loader == null)
+            loader = Thread.currentThread().getContextClassLoader();
+        ConfigurationProvider provider = null;
+        StringBuffer errs = null;
+        for (int i = 0; i < _derivations.length; i++) {
+            try {
+                provider = _derivations[i].load(file, anchor);
+                if (provider != null) {
+                    return provider;
+                }
+            } catch (Throwable t) {
+                errs = (errs == null) ? new StringBuffer() 
+                        : errs.append("\r\n");
+                errs.append(_derivations[i].getClass().getName() + ":" + t);
+            }
+        }
+        reportError(errs, file.getAbsolutePath());
+        return null;
+    }
+    
+    public static ConfigurationProvider load(String rsrc, String anchor, 
+        Map m) {
+        ConfigurationProvider provider = null;
+        StringBuffer errs = null;
+        for (int i = 0; i < _derivations.length; i++) {
+            try {
+                provider = _derivations[i].load(rsrc, anchor, m);
+                if (provider != null) {
+                    return provider;
+                }
+            } catch (Throwable t) {
+                errs = (errs == null) ? new StringBuffer() 
+                        : errs.append("\r\n");
+                errs.append(_derivations[i].getClass().getName() + ":" + t);
+            }
+        }
+        reportError(errs, rsrc);
+        return null;
+    }
+        
+    public static ConfigurationProvider load(ClassLoader loader, 
+       boolean globals) {
+        if (loader == null)
+            loader = Thread.currentThread().getContextClassLoader();
+        
+        ConfigurationProvider provider = null;
+        StringBuffer errs = null;
+        String type = (globals) ? "globals" : "defaults";
+        for (int i = 0; i < _derivations.length; i++) {
+            try {
+                provider = (globals) ? _derivations[i].loadGlobals(loader) 
+                        : _derivations[i].loadDefaults(loader);
+                if (provider != null) {
+                   return provider;
+                }
+            } catch (Throwable t) {
+                errs = (errs == null) ? new StringBuffer() 
+                        : errs.append("\r\n");
+                errs.append(_derivations[i].getClass().getName() + ":" + t);
+            }
+        }
+        reportError(errs, type);
+        return null;
+    }
+    
+    private static void reportError(StringBuffer errs, String resource) {
+        if (errs == null)
+            return;
+        throw new MissingResourceException(
+                errs.toString(), ProductDerivations.class.getName(), resource);
+    }
+
+    /**
+     * Return a {@link ConfigurationProvider} that has parsed system defaults.
+     */
+    public static ConfigurationProvider loadDefaults(ClassLoader loader) {
+        return load(loader, false);
+    }
+
+    /**
+     * Return a {@link ConfigurationProvider} that has parsed system globals.
+     */
+    public static ConfigurationProvider loadGlobals(ClassLoader loader) {
+        return load(loader, true);
+    }
+    
     /**
      * Compare {@link ProductDerivation}s.
      */

Added: incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/ConfigurationTestProductDerivation.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/ConfigurationTestProductDerivation.java?view=auto&rev=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/ConfigurationTestProductDerivation.java (added)
+++ incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/ConfigurationTestProductDerivation.java Mon Sep 18 17:50:57 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.lib.conf.test;
+
+import org.apache.openjpa.lib.conf.AbstractProductDerivation;
+import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import org.apache.openjpa.lib.conf.ProductDerivation;
+
+/**
+ * A Product Derivation to test loading of global and default configuration with
+ * System settings. This provider uses 
+ * {@link ConfigurationTestConfigurationProvider} which reads its global from
+ * a file specified by <code>"openjpatest.properties"</code> system property.
+ *
+ * @author Pinaki Poddar
+ */
+public class ConfigurationTestProductDerivation 
+    extends AbstractProductDerivation {
+    
+    public int getType() {
+        return ProductDerivation.TYPE_PRODUCT;
+    }
+    
+    public ConfigurationProvider newConfigurationProvider() {
+        return new ConfigurationTestConfigurationProvider();
+    }
+    
+}
+

Modified: incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/TestConfigurationImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/TestConfigurationImpl.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/TestConfigurationImpl.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/TestConfigurationImpl.java Mon Sep 18 17:50:57 2006
@@ -18,11 +18,7 @@
 import java.util.MissingResourceException;
 import java.util.Properties;
 
-import org.apache.openjpa.lib.conf.ConfigurationImpl;
-import org.apache.openjpa.lib.conf.ObjectValue;
-import org.apache.openjpa.lib.conf.PluginValue;
-import org.apache.openjpa.lib.conf.StringValue;
-import org.apache.openjpa.lib.conf.Value;
+import org.apache.openjpa.lib.conf.*;
 import org.apache.openjpa.lib.test.AbstractTestCase;
 
 /**
@@ -30,8 +26,16 @@
  * in a sub-package so that it can have its own localizer.properties
  * properties, which are required for the bean descriptors used by the
  * configuration framework {@link Value}.
+ * 
+ * This test has been modified to test the same functionality of 
+ * ConfigurationProvider but now invoked via ProductDerivation.
+ * 
+ * This test assumes a <code>"test.properties"</code> file available in
+ * classpath and also system property <code>"openjpatest.properties"</code>
+ * is set to <code>"test.properties"</code>.
  *
  * @author Abe White
+ * @author Pinaki Poddar
  */
 public class TestConfigurationImpl extends AbstractTestCase {
 

Added: incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation?view=auto&rev=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation (added)
+++ incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation Mon Sep 18 17:50:57 2006
@@ -0,0 +1 @@
+org.apache.openjpa.lib.conf.test.ConfigurationTestProductDerivation

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java Mon Sep 18 17:50:57 2006
@@ -16,9 +16,11 @@
 package org.apache.openjpa.persistence.jdbc;
 
 import org.apache.openjpa.conf.OpenJPAConfiguration;
-import org.apache.openjpa.conf.ProductDerivation;
+import org.apache.openjpa.conf.OpenJPAProductDerivation;
 import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
 import org.apache.openjpa.jdbc.kernel.JDBCStoreManager;
+import org.apache.openjpa.lib.conf.AbstractProductDerivation;
+import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
 import org.apache.openjpa.persistence.FetchPlan;
 import org.apache.openjpa.persistence.PersistenceProductDerivation;
@@ -29,21 +31,20 @@
  * @author Abe White
  * @nojavadoc
  */
-public class JDBCPersistenceProductDerivation
-    implements ProductDerivation {
-
+public class JDBCPersistenceProductDerivation extends AbstractProductDerivation 
+    implements OpenJPAProductDerivation {
+    
     public int getType() {
         return TYPE_SPEC_STORE;
     }
 
-    public void beforeConfigurationConstruct(ConfigurationProvider cp) {
-    }
-
-    public void beforeConfigurationLoad(OpenJPAConfiguration c) {
-        c.getStoreFacadeTypeRegistry().registerImplementation(FetchPlan.class, 
-            JDBCStoreManager.class, JDBCFetchPlanImpl.class);
+    public boolean beforeConfigurationLoad(Configuration c) {
+        if (c instanceof OpenJPAConfiguration) 
+        ((OpenJPAConfiguration)c).getStoreFacadeTypeRegistry().
+            registerImplementation(FetchPlan.class, JDBCStoreManager.class, 
+            JDBCFetchPlanImpl.class);
         if (!(c instanceof JDBCConfigurationImpl))
-            return;
+            return false;
 
         JDBCConfigurationImpl conf = (JDBCConfigurationImpl) c;
         String jpa = PersistenceProductDerivation.SPEC_JPA;
@@ -63,16 +64,24 @@
             PersistenceMappingDefaults.class.getName());
         conf.mappingDefaultsPlugin.setAlias(jpa,
             PersistenceMappingDefaults.class.getName());
+        return true;
     }
 
-    public void afterSpecificationSet(OpenJPAConfiguration c) {
+    public boolean afterSpecificationSet(Configuration c) {
         String jpa = PersistenceProductDerivation.SPEC_JPA;
-        if (!(c instanceof JDBCConfigurationImpl)
-            || !jpa.equals(c.getSpecification()))
-            return;
-
+        if (!(c instanceof JDBCConfigurationImpl))
+            return false;
         JDBCConfigurationImpl conf = (JDBCConfigurationImpl) c;
+        
+         if (!jpa.equals(conf.getSpecification()))
+            return false;
+        
         conf.mappingDefaultsPlugin.setDefault(jpa);
         conf.mappingDefaultsPlugin.setString(jpa);
+        return true;
+    }
+    
+    public ConfigurationProvider newConfigurationProvider() {
+        return null;
     }
 }

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation?view=auto&rev=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation Mon Sep 18 17:50:57 2006
@@ -0,0 +1 @@
+org.apache.openjpa.persistence.jdbc.JDBCPersistenceProductDerivation

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java Mon Sep 18 17:50:57 2006
@@ -85,7 +85,12 @@
 
     /**
      * Load configuration from the given persistence unit with the specified
-     * user properties.
+     * user properties in <code>m</code>.
+     * Checks if this receiver's PersistenceProvider matches with the 
+     * PersistenceProvider specified in the given PersistenceUnitInfo.
+     * @return false if PersistenceUnitInfo is null.
+     * false if this receiver's PersistenceProvider does not matche with the 
+     * PersistenceProvider specified in the given PersistenceUnitInfo. 
      */
     public boolean load(PersistenceUnitInfo pinfo, Map m)
         throws IOException {
@@ -93,9 +98,9 @@
             return false;
         String providerName = pinfo.getPersistenceProviderClassName();
         if (!StringUtils.isEmpty(providerName)
-            && !getPersistenceProviderName().equals(providerName))
+            && !getPersistenceProviderName().equals(providerName)) {
             return false;
-        
+        }
         addProperties(PersistenceUnitInfoImpl.toOpenJPAProperties(pinfo));
         if (m != null)
             addProperties(m);
@@ -244,14 +249,14 @@
     @Override
     public boolean load(String rsrc, String anchor, ClassLoader loader)
         throws IOException {
-        if (!rsrc.endsWith(".xml"))
+        if (rsrc != null && !rsrc.endsWith(".xml"))
             return false;
         return load(rsrc, anchor, null, loader, true) == Boolean.TRUE;
     }
 
     @Override
     public boolean load(File file, String anchor) {
-        if (!file.getName().endsWith(".xml"))
+        if (file != null && !file.getName().endsWith(".xml"))
             return false;
 
         try {

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java Mon Sep 18 17:50:57 2006
@@ -61,7 +61,7 @@
     /**
      * Constructor. Delegate must be provided on construction.
      */
-    protected EntityManagerFactoryImpl(BrokerFactory factory) {
+    public EntityManagerFactoryImpl(BrokerFactory factory) {
         _factory = new DelegatingBrokerFactory(factory,
             PersistenceExceptions.TRANSLATOR);
     }
@@ -175,7 +175,7 @@
         // regardless of PersistenceContextType
         broker.setAutoDetach(AutoDetach.DETACH_CLOSE);
         broker.setDetachedNew(false);
-        OpenJPAEntityManager em = OpenJPAPersistence.toEntityManager(broker);
+        OpenJPAEntityManager em = new EntityManagerImpl(this, broker);
 
         // allow setting of other bean properties of EM
         List<RuntimeException> errs = null;

Added: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryValue.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryValue.java?view=auto&rev=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryValue.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryValue.java Mon Sep 18 17:50:57 2006
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.persistence;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+
+import org.apache.openjpa.abstractstore.AbstractStoreBrokerFactory;
+import org.apache.openjpa.kernel.BrokerFactory;
+import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import org.apache.openjpa.lib.conf.PluginValue;
+
+/**
+ * Value type used to represent the {@link EntityManagerFactory}. 
+ *
+ * @nojavadoc
+ */
+public class EntityManagerFactoryValue
+    extends PluginValue {
+
+    public static final String KEY = "EntityManagerFactory";
+
+    private static final List _prefixes = new ArrayList(2);
+    static {
+        _prefixes.add("openjpa");
+    }
+    
+    /**
+     * Add <code>prefix</code> to the list of prefixes under which configuration
+     * properties may be scoped.
+     */
+    public static void addPropertyPrefix(String prefix) {
+        if (!_prefixes.contains(prefix))
+            _prefixes.add(prefix);
+    }
+    
+    /**
+     * Extract the value of this property if set in the given provider.
+     */
+    public static Object get(ConfigurationProvider cp) {
+        Map props = cp.getProperties();
+        Object bf;
+        for (int i = 0; i < _prefixes.size (); i++) {
+            bf = props.get(_prefixes.get(i) + "." + KEY);
+            if (bf != null)
+                return  bf;
+        }
+        return null;
+    }
+
+    /**
+     * Return the key to use for this property.
+     */
+    public static String getKey(ConfigurationProvider cp) {
+        return _prefixes.get(0) + "." + KEY;
+    }
+
+    public EntityManagerFactoryValue() {
+        super(KEY, false);
+    }
+}

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java Mon Sep 18 17:50:57 2006
@@ -15,6 +15,9 @@
  */
 package org.apache.openjpa.persistence;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -28,24 +31,17 @@
 import javax.persistence.Query;
 import javax.rmi.PortableRemoteObject;
 
+import org.apache.openjpa.conf.BrokerFactoryValue;
 import org.apache.openjpa.enhance.PersistenceCapable;
 import org.apache.openjpa.kernel.Bootstrap;
 import org.apache.openjpa.kernel.Broker;
 import org.apache.openjpa.kernel.BrokerFactory;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
 import org.apache.openjpa.lib.conf.MapConfigurationProvider;
+import org.apache.openjpa.lib.conf.ProductDerivations;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
-import org.apache.openjpa.util.ByteId;
-import org.apache.openjpa.util.CharId;
-import org.apache.openjpa.util.Id;
-import org.apache.openjpa.util.ImplHelper;
-import org.apache.openjpa.util.IntId;
-import org.apache.openjpa.util.LongId;
-import org.apache.openjpa.util.ObjectId;
-import org.apache.openjpa.util.OpenJPAId;
-import org.apache.openjpa.util.ShortId;
-import org.apache.openjpa.util.StringId;
+import org.apache.openjpa.util.*;
 
 /**
  * Static helper method for JPA users, including switching
@@ -66,20 +62,26 @@
     private static Localizer _loc =
         Localizer.forPackage(OpenJPAPersistence.class);
 
+    
+    public static OpenJPAEntityManagerFactory toEntityManagerFactory
+       (BrokerFactory factory) {
+        return toEntityManagerFactory(factory, null);
+    }
+    
     /**
      * Return an entity manager factory facade to the given broker factory.
      */
     public static OpenJPAEntityManagerFactory toEntityManagerFactory
-        (BrokerFactory factory) {
+        (BrokerFactory factory, ConfigurationProvider cp) {
         if (factory == null)
             return null;
-
         factory.lock();
+        
         try {
             OpenJPAEntityManagerFactory emf = (OpenJPAEntityManagerFactory)
                 factory.getUserObject(EMF_KEY);
             if (emf == null) {
-                emf = newEntityManagerFactory(factory);
+                emf = newEntityManagerFactory(factory, cp, null);
                 factory.putUserObject(EMF_KEY, emf);
             }
             return emf;
@@ -89,10 +91,6 @@
             factory.unlock();
         }
     }
-
-    protected static OpenJPAEntityManagerFactory newEntityManagerFactory(BrokerFactory factory) {
-		return new EntityManagerFactoryImpl(factory);
-	}
     
     /**
      * Return the underlying broker factory for the given persistence manager
@@ -443,4 +441,49 @@
 			return String.class;
 		return oidClass;
 	}
+    
+    private static OpenJPAEntityManagerFactory newEntityManagerFactory (
+        BrokerFactory brokerFactory, ConfigurationProvider conf, 
+        ClassLoader loader) {
+            if (conf == null)
+                conf = new MapConfigurationProvider();
+            ProductDerivations.beforeConfigurationConstruct(conf);
+
+            Class cls = getFactoryClass(conf, loader);
+            Constructor ctr;
+            try {
+                ctr = cls.getConstructor(BrokerFactory.class); 
+                return (OpenJPAEntityManagerFactory)ctr
+                   .newInstance(brokerFactory);
+            } catch (Exception e) {
+                throw PersistenceExceptions.toPersistenceException(e);
+            }
+        }
+
+    /**
+     * Instantiate the factory class designated in properties.
+     */
+    private static Class getFactoryClass(ConfigurationProvider conf,
+        ClassLoader loader) {
+        if (loader == null)
+            loader = Thread.currentThread().getContextClassLoader();
+
+        Object cls = EntityManagerFactoryValue.get(conf);
+        if (cls instanceof Class)
+            return (Class) cls;
+
+        EntityManagerFactoryValue value = new EntityManagerFactoryValue();
+        value.setString((String) cls);
+        String clsName = value.getClassName();
+        if (clsName == null)
+            throw new UserException(_loc.get("no-emf", 
+                conf.getProperties())).setFatal(true);
+
+        try {
+            return Class.forName(clsName, true, loader);
+        } catch (Exception e) {
+            throw new UserException(_loc.get("bad-emf-class",
+                clsName), e).setFatal(true);
+        }
+    }
 }

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java Mon Sep 18 17:50:57 2006
@@ -15,10 +15,15 @@
  */
 package org.apache.openjpa.persistence;
 
+import java.util.Map;
+
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
-import org.apache.openjpa.conf.ProductDerivation;
+import org.apache.openjpa.conf.OpenJPAProductDerivation;
+import org.apache.openjpa.lib.conf.AbstractProductDerivation;
+import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import org.apache.openjpa.lib.conf.PluginValue;
 
 /**
  * Sets JPA specification defaults.
@@ -26,8 +31,9 @@
  * @author Abe White
  * @nojavadoc
  */
-public class PersistenceProductDerivation
-    implements ProductDerivation {
+public class PersistenceProductDerivation 
+    extends AbstractProductDerivation
+    implements OpenJPAProductDerivation {
 
     public static final String SPEC_JPA = "jpa";
     public static final String ALIAS_EJB = "ejb";
@@ -36,25 +42,55 @@
         return TYPE_SPEC;
     }
 
-    public void beforeConfigurationConstruct(ConfigurationProvider cp) {
+    @Override
+    public ConfigurationProvider newConfigurationProvider() {
+        return new ConfigurationProviderImpl();
     }
 
-    public void beforeConfigurationLoad(OpenJPAConfiguration c) {
+    @Override
+    public ConfigurationProvider load(String rsrc, String anchor,
+            ClassLoader loader)  throws Exception {
+        if (rsrc != null && !rsrc.endsWith(".xml"))
+            return null;
+        return super.load(rsrc, anchor, loader);
+    }
+    
+    public ConfigurationProvider load(String rsrc, String anchor,
+            Map map) throws Exception {
+        if (rsrc != null && !rsrc.endsWith(".xml"))
+            return null;
+        return super.load(rsrc, anchor, map);
+    }
+    
+    public boolean beforeConfigurationConstruct(ConfigurationProvider cp) {
+        if (EntityManagerFactoryValue.get(cp) == null) {
+            cp.addProperty(EntityManagerFactoryValue.getKey(cp),
+                EntityManagerFactoryImpl.class.getName());
+            return true;
+        }
+        return false;
+    }
+    
+    public boolean beforeConfigurationLoad(Configuration c) {
         if (!(c instanceof OpenJPAConfigurationImpl))
-            return;
-
+            return false;
+        
         OpenJPAConfigurationImpl conf = (OpenJPAConfigurationImpl) c;
         conf.metaFactoryPlugin.setAlias(ALIAS_EJB,
             PersistenceMetaDataFactory.class.getName());
         conf.metaFactoryPlugin.setAlias(SPEC_JPA,
             PersistenceMetaDataFactory.class.getName());
+        
+        PluginValue emfPlugin = new EntityManagerFactoryValue();
+        conf.addValue(emfPlugin);
+        return true;
     }
 
-    public void afterSpecificationSet(OpenJPAConfiguration c) {
-        if (!(c instanceof OpenJPAConfigurationImpl)
-            || !SPEC_JPA.equals(c.getSpecification()))
-            return;
-
+    public boolean afterSpecificationSet(Configuration c) {
+      if (!(c instanceof OpenJPAConfigurationImpl)
+         || !SPEC_JPA.equals(((OpenJPAConfiguration)c).getSpecification()))
+          return false;
+ 
         OpenJPAConfigurationImpl conf = (OpenJPAConfigurationImpl) c;
         conf.metaFactoryPlugin.setDefault(SPEC_JPA);
         conf.metaFactoryPlugin.setString(SPEC_JPA);
@@ -62,5 +98,6 @@
         conf.lockManagerPlugin.setString("version");
         conf.nontransactionalWrite.setDefault("true");
         conf.nontransactionalWrite.set(true);
+        return true;
     }
 }

Modified: incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java (original)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java Mon Sep 18 17:50:57 2006
@@ -35,6 +35,8 @@
 import org.apache.openjpa.kernel.BrokerFactory;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
 import org.apache.openjpa.lib.conf.Configurations;
+import org.apache.openjpa.lib.conf.ProductDerivation;
+import org.apache.openjpa.lib.conf.ProductDerivations;
 import org.apache.openjpa.meta.MetaDataModes;
 import org.apache.openjpa.meta.MetaDataRepository;
 
@@ -46,7 +48,7 @@
  * @see Persistence#createEntityManagerFactory(String,Map)
  */
 public class PersistenceProviderImpl
-    implements PersistenceProvider, PersistenceProviderExtension {
+    implements PersistenceProvider {
 
     static final String CLASS_TRANSFORMER_OPTIONS =
         "openjpa.ClassTransformerOptions";
@@ -63,11 +65,13 @@
      */
     public EntityManagerFactory createEntityManagerFactory(String name,
         String resource, Map m) {
-        ConfigurationProviderImpl cp = newConfigurationProviderImpl();
         try {
-            if (cp.load(resource, name, m))
-            	return toEntityManagerFactory(
-            		Bootstrap.newBrokerFactory(cp, cp.getClassLoader()));
+            ConfigurationProvider cp = ProductDerivations.load(resource, name, 
+                 m);
+            if (cp != null) {
+                BrokerFactory factory = Bootstrap.newBrokerFactory(cp, null);
+            	return OpenJPAPersistence.toEntityManagerFactory(factory, cp);
+            }
             else
                  return null;
         } catch (Exception e) {
@@ -81,11 +85,13 @@
 
     public EntityManagerFactory createContainerEntityManagerFactory(
         PersistenceUnitInfo pui, Map map) {
-        ConfigurationProviderImpl cp = newConfigurationProviderImpl();
+        ConfigurationProviderImpl cp = newConfigurationProvider();
         try {
             if (cp.load(pui, map)) {
-                OpenJPAEntityManagerFactory emf = toEntityManagerFactory(
-                        Bootstrap.newBrokerFactory(cp, cp.getClassLoader()));
+                BrokerFactory factory = Bootstrap.newBrokerFactory(cp, 
+                     cp.getClassLoader());
+                OpenJPAEntityManagerFactory emf = 
+                    OpenJPAPersistence.toEntityManagerFactory(factory);
                 Properties p = pui.getProperties();
                 String ctOpts = null;
                 if (p != null)
@@ -101,14 +107,14 @@
         }
     }
     
-    public ConfigurationProviderImpl newConfigurationProviderImpl() {
-    	return new ConfigurationProviderImpl();
-    }
-    
-    public OpenJPAEntityManagerFactory toEntityManagerFactory(BrokerFactory factory) {
-    	return OpenJPAPersistence.toEntityManagerFactory(factory);
+    /**
+     * Gets the configuration provider to locate and load configuration data.
+     * An implementation is returned rather than the interface.
+      */
+    protected ConfigurationProviderImpl newConfigurationProvider() {
+        return new ConfigurationProviderImpl();
     }
-    
+            
     /**
      * Java EE 5 class transformer.
      */

Added: incubator/openjpa/trunk/openjpa-persistence/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation?view=auto&rev=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation (added)
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/resources/META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation Mon Sep 18 17:50:57 2006
@@ -0,0 +1 @@
+org.apache.openjpa.persistence.PersistenceProductDerivation

Modified: incubator/openjpa/trunk/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLConfiguration.java?view=diff&rev=447664&r1=447663&r2=447664
==============================================================================
--- incubator/openjpa/trunk/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLConfiguration.java (original)
+++ incubator/openjpa/trunk/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLConfiguration.java Mon Sep 18 17:50:57 2006
@@ -16,9 +16,9 @@
 package org.apache.openjpa.xmlstore;
 
 import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
-import org.apache.openjpa.conf.ProductDerivations;
 import org.apache.openjpa.kernel.Broker;
 import org.apache.openjpa.kernel.BrokerFactory;
+import org.apache.openjpa.lib.conf.ProductDerivations;
 
 /**
  * Configuration implementation for the XML file store. Each unique



Mime
View raw message