mirror of https://github.com/apache/openjpa.git
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:
parent
696cbee04b
commit
2fd7381e53
|
@ -19,8 +19,10 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.MissingResourceException;
|
||||||
|
|
||||||
import org.apache.openjpa.lib.conf.ConfigurationProvider;
|
import org.apache.openjpa.lib.conf.ConfigurationProvider;
|
||||||
|
import org.apache.openjpa.lib.util.Localizer;
|
||||||
import org.apache.openjpa.lib.util.Services;
|
import org.apache.openjpa.lib.util.Services;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,6 +45,16 @@ public class ProductDerivations {
|
||||||
// invalid service
|
// 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());
|
Collections.sort(derivations, new ProductDerivationComparator());
|
||||||
_derivations = (ProductDerivation[]) derivations.toArray
|
_derivations = (ProductDerivation[]) derivations.toArray
|
||||||
(new ProductDerivation[derivations.size()]);
|
(new ProductDerivation[derivations.size()]);
|
||||||
|
|
|
@ -34,7 +34,6 @@ public class QueryLanguages {
|
||||||
public static final String LANG_METHODQL = "org.apache.openjpa.MethodQL";
|
public static final String LANG_METHODQL = "org.apache.openjpa.MethodQL";
|
||||||
|
|
||||||
private static Map _expressionParsers = new HashMap();
|
private static Map _expressionParsers = new HashMap();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Load and cache all the query languages available in the system.
|
// Load and cache all the query languages available in the system.
|
||||||
Class[] classes = Services.getImplementorClasses(
|
Class[] classes = Services.getImplementorClasses(
|
||||||
|
|
|
@ -536,3 +536,9 @@ no-named-cf: use a DataSource bound to JNDI
|
||||||
diff-specs: Attempt to configure for multiple specifications. Was configured \
|
diff-specs: Attempt to configure for multiple specifications. Was configured \
|
||||||
for "{0}". Attempt to now configure for "{1}". This attempt will be \
|
for "{0}". Attempt to now configure for "{1}". This attempt will be \
|
||||||
ignored.
|
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?
|
||||||
|
|
|
@ -434,11 +434,16 @@ public class Configurations {
|
||||||
Class[] impls = Services.getImplementorClasses
|
Class[] impls = Services.getImplementorClasses
|
||||||
(ConfigurationProvider.class, loader);
|
(ConfigurationProvider.class, loader);
|
||||||
ConfigurationProvider provider = null;
|
ConfigurationProvider provider = null;
|
||||||
|
int providerCount = 0;
|
||||||
StringBuffer errs = null;
|
StringBuffer errs = null;
|
||||||
for (int i = 0; i < impls.length; i++) {
|
for (int i = 0; i < impls.length; i++) {
|
||||||
provider = newProvider(impls[i]);
|
provider = newProvider(impls[i]);
|
||||||
|
if (provider == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
providerCount++;
|
||||||
try {
|
try {
|
||||||
if (provider != null && provider.loadDefaults(loader))
|
if (provider.loadDefaults(loader))
|
||||||
return provider;
|
return provider;
|
||||||
} catch (MissingResourceException mre) {
|
} catch (MissingResourceException mre) {
|
||||||
throw mre;
|
throw mre;
|
||||||
|
@ -453,7 +458,10 @@ public class Configurations {
|
||||||
if (errs != null)
|
if (errs != null)
|
||||||
throw new MissingResourceException(errs.toString(),
|
throw new MissingResourceException(errs.toString(),
|
||||||
Configurations.class.getName(), "defaults");
|
Configurations.class.getName(), "defaults");
|
||||||
|
if (providerCount == 0)
|
||||||
|
throw new MissingResourceException(_loc.get ("no-providers",
|
||||||
|
ConfigurationProvider.class.getName()),
|
||||||
|
Configurations.class.getName(), "defaults");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,11 +492,16 @@ public class Configurations {
|
||||||
Class[] impls = Services.getImplementorClasses
|
Class[] impls = Services.getImplementorClasses
|
||||||
(ConfigurationProvider.class, loader);
|
(ConfigurationProvider.class, loader);
|
||||||
ConfigurationProvider provider = null;
|
ConfigurationProvider provider = null;
|
||||||
|
int providerCount = 0;
|
||||||
StringBuffer errs = null;
|
StringBuffer errs = null;
|
||||||
for (int i = 0; i < impls.length; i++) {
|
for (int i = 0; i < impls.length; i++) {
|
||||||
provider = newProvider(impls[i]);
|
provider = newProvider(impls[i]);
|
||||||
|
if (provider == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
providerCount++;
|
||||||
try {
|
try {
|
||||||
if (provider != null && provider.load(resource, loader))
|
if (provider.load(resource, loader))
|
||||||
return provider;
|
return provider;
|
||||||
} catch (MissingResourceException mre) {
|
} catch (MissingResourceException mre) {
|
||||||
throw mre;
|
throw mre;
|
||||||
|
@ -503,6 +516,9 @@ public class Configurations {
|
||||||
String msg;
|
String msg;
|
||||||
if (errs != null)
|
if (errs != null)
|
||||||
msg = errs.toString();
|
msg = errs.toString();
|
||||||
|
else if (providerCount == 0)
|
||||||
|
msg = _loc.get("no-providers",
|
||||||
|
ConfigurationProvider.class.getName());
|
||||||
else
|
else
|
||||||
msg = _loc.get("no-provider", resource);
|
msg = _loc.get("no-provider", resource);
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,12 @@ loaded-via-provider: Configuration information loaded via "{0}".
|
||||||
no-default-providers: Default configuration information couldn''t be loaded \
|
no-default-providers: Default configuration information couldn''t be loaded \
|
||||||
from any configuration provider.
|
from any configuration provider.
|
||||||
no-provider: No registered configuration provider could load "{0}".
|
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() \
|
hook-before: An exception occurred while invoking beforeConfigurationLoad() \
|
||||||
on "{0}". This exception will be consumed.
|
on "{0}". This exception will be consumed.
|
||||||
hook-after: An exception occurred while invoking afterConfigurationLoad() \
|
hook-after: An exception occurred while invoking afterConfigurationLoad() \
|
||||||
|
|
Loading…
Reference in New Issue