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.



git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@427229 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
A. Abram White 2006-07-31 19:36:46 +00:00
parent 696cbee04b
commit 2fd7381e53
5 changed files with 43 additions and 4 deletions

View File

@ -19,8 +19,10 @@ import java.util.ArrayList;
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 @@ public class ProductDerivations {
// 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()]);

View File

@ -34,7 +34,6 @@ public class QueryLanguages {
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(

View File

@ -536,3 +536,9 @@ no-named-cf: use a DataSource bound to JNDI
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?

View File

@ -434,11 +434,16 @@ public class Configurations {
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 @@ public class Configurations {
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 @@ public class Configurations {
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 @@ public class Configurations {
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);

View File

@ -46,6 +46,12 @@ loaded-via-provider: Configuration information loaded via "{0}".
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() \