You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by aw...@apache.org on 2006/07/31 21:36:47 UTC

svn commit: r427229 - in /incubator/openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/conf/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/resources/org/apache/openjpa/conf/ openjpa-lib/src/main/java/org/ap...

Author: awhite
Date: Mon Jul 31 12:36:46 2006
New Revision: 427229

URL: http://svn.apache.org/viewvc?rev=427229&view=rev
Log:
Throw good error message about META-INF/services if we can't find any 
configuration providers or product derivations.  This has the downside of
mandating that there must be at least one valid product derivation and one
valid configuration provider available (theoretically someone using brokers
directly together with a simpl store like the sample XML store wouldn't need 
either), but otherwise the final error message to the user is often meaningless.


Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryLanguages.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java
    incubator/openjpa/trunk/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java?rev=427229&r1=427228&r2=427229&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java (original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java Mon Jul 31 12:36:46 2006
@@ -19,8 +19,10 @@
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.MissingResourceException;
 
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.Services;
 
 /**
@@ -43,6 +45,16 @@
                 // invalid service
             }
         }
+
+        // there must be some product derivation to define metadata factories,
+        // etc. 
+        if (derivations.isEmpty()) {
+            Localizer loc = Localizer.forPackage(ProductDerivations.class);
+            throw new MissingResourceException(loc.get("no-product-derivations",
+                ProductDerivation.class.getName()),
+                ProductDerivations.class.getName(), "derivations");
+        }
+
         Collections.sort(derivations, new ProductDerivationComparator());
         _derivations = (ProductDerivation[]) derivations.toArray
             (new ProductDerivation[derivations.size()]);

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryLanguages.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryLanguages.java?rev=427229&r1=427228&r2=427229&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryLanguages.java (original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryLanguages.java Mon Jul 31 12:36:46 2006
@@ -34,7 +34,6 @@
     public static final String LANG_METHODQL = "org.apache.openjpa.MethodQL";
 
     private static Map _expressionParsers = new HashMap();
-
     static {
         // Load and cache all the query languages available in the system.
         Class[] classes = Services.getImplementorClasses(

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties?rev=427229&r1=427228&r2=427229&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties (original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/conf/localizer.properties Mon Jul 31 12:36:46 2006
@@ -536,3 +536,9 @@
 diff-specs: Attempt to configure for multiple specifications.  Was configured \
 	for "{0}".  Attempt to now configure for "{1}".  This attempt will be \
 	ignored.
+no-product-derivations: Your system is missing product derivations.  Product \
+    derivations provide configuration options for supported data stores and \
+    specifications.  You must have a META-INF/services/{0} file in your \
+    classpath listing the available derivation classes, and some listed class \
+    must be instantiable.  Typically this file is bundled as part of the \
+    distribution.  Have you unbundled it, or unbundled its listed classes?

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?rev=427229&r1=427228&r2=427229&view=diff
==============================================================================
--- 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 Jul 31 12:36:46 2006
@@ -434,11 +434,16 @@
         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 != null && provider.loadDefaults(loader))
+                if (provider.loadDefaults(loader))
                     return provider;
             } catch (MissingResourceException mre) {
                 throw mre;
@@ -453,7 +458,10 @@
         if (errs != null)
             throw new MissingResourceException(errs.toString(),
                 Configurations.class.getName(), "defaults");
-
+        if (providerCount == 0)
+            throw new MissingResourceException(_loc.get ("no-providers", 
+                ConfigurationProvider.class.getName()),
+                Configurations.class.getName(), "defaults"); 
         return null;
     }
 
@@ -484,11 +492,16 @@
         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 != null && provider.load(resource, loader))
+                if (provider.load(resource, loader))
                     return provider;
             } catch (MissingResourceException mre) {
                 throw mre;
@@ -503,6 +516,9 @@
         String msg;
         if (errs != null)
             msg = errs.toString();
+        else if (providerCount == 0)
+            msg = _loc.get("no-providers", 
+                ConfigurationProvider.class.getName());
         else
             msg = _loc.get("no-provider", resource);
         

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties?rev=427229&r1=427228&r2=427229&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties Mon Jul 31 12:36:46 2006
@@ -46,6 +46,12 @@
 no-default-providers: Default configuration information couldn''t be loaded \
 	from any configuration provider.
 no-provider: No registered configuration provider could load "{0}".
+no-providers: Your system is missing configuration providers. \
+    Configuration providers load configuration information for supported \
+    specifications.  You must have a META-INF/services/{0} file in your \
+    classpath listing the available provider classes, and some listed class \
+    must be instantiable.  Typically this file is bundled as part of the \
+    distribution.  Have you unbundled it, or unbundled its listed classes?
 hook-before: An exception occurred while invoking beforeConfigurationLoad() \
 	on "{0}". This exception will be consumed.
 hook-after: An exception occurred while invoking afterConfigurationLoad() \