Utilities for running product derivations.
| Method from org.apache.openjpa.lib.conf.ProductDerivations Detail: |
public static void afterSpecificationSet(Configuration conf) {
for (int i = 0; i < _derivations.length; i++) {
try {
_derivations[i].afterSpecificationSet(conf);
} catch (BootstrapException be) {
if (be.isFatal())
throw be;
} catch (Exception e) {
// logging not configured yet
e.printStackTrace();
}
}
}
|
public static void beforeClose(Configuration conf) {
for (int i = 0; i < _derivations.length; i++) {
try {
_derivations[i].beforeConfigurationClose(conf);
} catch (Exception e) {
conf.getConfigurationLog().warn(_loc.get("before-close-ex"), e);
}
}
}
Called as the first step of a Configuration's close() method.
Exceptions are swallowed. |
public static void beforeConfigurationConstruct(ConfigurationProvider cp) {
for (int i = 0; i < _derivations.length; i++) {
try {
_derivations[i].beforeConfigurationConstruct(cp);
} catch (BootstrapException be) {
if (be.isFatal())
throw be;
} catch (Exception e) {
// can't log; no configuration yet
e.printStackTrace();
}
}
}
|
public static void beforeConfigurationLoad(Configuration conf) {
for (int i = 0; i < _derivations.length; i++) {
try {
_derivations[i].beforeConfigurationLoad(conf);
} catch (BootstrapException be) {
if (be.isFatal())
throw be;
} catch (Exception e) {
// logging not configured yet
e.printStackTrace();
}
}
}
|
public static String getConfigurationKey(String partialKey,
Map map) {
String firstKey = null;
for (int i = 0; map != null && i < _prefixes.length; i++) {
String fullKey = _prefixes[i] + "." + partialKey;
if (map.containsKey(fullKey)) {
if (firstKey == null)
firstKey = fullKey;
else {
// if we've already found a property with a previous
// prefix, then this is a collision.
throw new IllegalStateException(_loc.get(
"dup-with-different-prefixes", firstKey, fullKey)
.getMessage());
}
}
}
if (firstKey == null)
return _prefixes[0] + "." + partialKey;
else
return firstKey;
}
Determine the full key name for key, given the registered
prefixes and the entries in map. This method
computes the appropriate configuration prefix to use by looking
through map for a key starting with any of the known
configuration prefixes and ending with key and, if a
value is found, using the prefix of that key. Otherwise, it uses
the first registered prefix. |
public static String[] getConfigurationPrefixes() {
return _prefixes;
}
Return the recognized prefixes for configuration properties. |
public static List getFullyQualifiedAnchorsInPropertiesLocation(String propertiesLocation) {
List fqAnchors = new ArrayList();
StringBuffer errs = null;
Throwable err = null;
for (int i = _derivations.length - 1; i >= 0; i--) {
try {
if (propertiesLocation == null) {
String loc = _derivations[i].getDefaultResourceLocation();
addAll(fqAnchors, loc,
_derivations[i].getAnchorsInResource(loc));
continue;
}
File f = new File(propertiesLocation);
if (((Boolean) J2DoPrivHelper.isFileAction(f).run())
.booleanValue()) {
addAll(fqAnchors, propertiesLocation,
_derivations[i].getAnchorsInFile(f));
} else {
f = new File("META-INF" + File.separatorChar
+ propertiesLocation);
if (((Boolean) J2DoPrivHelper.isFileAction(f).run())
.booleanValue()) {
addAll(fqAnchors, propertiesLocation,
_derivations[i].getAnchorsInFile(f));
} else {
addAll(fqAnchors, propertiesLocation,
_derivations[i].getAnchorsInResource(
propertiesLocation));
}
}
} catch (Throwable t) {
err = t;
errs = (errs == null) ? new StringBuffer() : errs.append("\n");
errs.append(_derivations[i].getClass().getName() + ":" + t);
}
}
reportErrors(errs, propertiesLocation, err);
return fqAnchors;
}
Return a List of all the fully-qualified anchors specified in
propertiesLocation. The return values must be used in
conjunction with propertiesLocation. If there are no
product derivations or if no product derivations could find anchors,
this returns an empty list. |
public static ProductDerivation[] getProductDerivations() {
ClassLoader l = (ClassLoader) AccessController.doPrivileged(
J2DoPrivHelper.getClassLoaderAction(ProductDerivation.class));
_derivationNames = Services.getImplementors(ProductDerivation.class, l);
_derivationErrors = new Throwable[_derivationNames.length];
List derivations = new ArrayList(_derivationNames.length);
for (int i = 0; i < _derivationNames.length; i++) {
try {
ProductDerivation d = (ProductDerivation)
AccessController.doPrivileged(
J2DoPrivHelper.newInstanceAction(
Class.forName(_derivationNames[i], true, l)));
d.validate();
derivations.add(d);
} catch (Throwable t) {
if (t instanceof PrivilegedActionException)
t = ((PrivilegedActionException) t).getException();
_derivationErrors[i] = t;
}
}
// must be at least one product derivation to define metadata factories,
// etc.
if (derivations.isEmpty()) {
throw new MissingResourceException(_loc.get
("no-product-derivations", ProductDerivation.class.getName(),
derivationErrorsToString()).getMessage(),
ProductDerivations.class.getName(),"derivations");
}
// if some derivations weren't instantiable, warn
for (int i = 0; i < _derivationErrors.length; i++) {
if (_derivationErrors[i] == null)
continue;
System.err.println(_loc.get("bad-product-derivations",
ProductDerivations.class.getName()));
break;
}
Collections.sort(derivations, new ProductDerivationComparator());
_derivations = (ProductDerivation[]) derivations.toArray
(new ProductDerivation[derivations.size()]);
List prefixes = new ArrayList(2);
for (int i = 0; i < _derivations.length; i++) {
if (_derivations[i].getConfigurationPrefix() != null
&& !"openjpa".equals(_derivations[i].getConfigurationPrefix()))
prefixes.add(_derivations[i].getConfigurationPrefix());
}
String[] prefixArray = new String[1 + prefixes.size()];
prefixArray[0] = "openjpa";
for (int i = 0; i < prefixes.size(); i++)
prefixArray[i + 1] = (String) prefixes.get(i);
setConfigurationPrefixes(prefixArray);
return _derivations;
}
Return all the product derivations registered in the current classloader |
public static ConfigurationProvider load(String resource,
String anchor,
ClassLoader loader) {
if (StringUtils.isEmpty(resource))
return null;
if (loader == null)
loader = (ClassLoader) AccessController.doPrivileged(
J2DoPrivHelper.getContextClassLoaderAction());
ConfigurationProvider provider = null;
StringBuffer errs = null;
// most specific to least
Throwable err = null;
for (int i = _derivations.length - 1; i >= 0; i--) {
try {
provider = _derivations[i].load(resource, anchor, loader);
if (provider != null)
return provider;
} catch (Throwable t) {
err = t;
errs = (errs == null) ? new StringBuffer() : errs.append("\n");
errs.append(_derivations[i].getClass().getName() + ":" + t);
}
}
reportErrors(errs, resource, err);
String rsrc = resource + "#" + anchor;
throw (MissingResourceException) JavaVersions.initCause
(new MissingResourceException(rsrc,
ProductDerivations.class.getName(), rsrc), err);
}
Load the given given resource, or return false if it is not a resource
this provider understands. The given class loader may be null. |
public static ConfigurationProvider load(File file,
String anchor,
ClassLoader loader) {
if (file == null)
return null;
if (loader == null)
loader = (ClassLoader) AccessController.doPrivileged(
J2DoPrivHelper.getContextClassLoaderAction());
ConfigurationProvider provider = null;
StringBuffer errs = null;
Throwable err = null;
// most specific to least
for (int i = _derivations.length - 1; i >= 0; i--) {
try {
provider = _derivations[i].load(file, anchor);
if (provider != null)
return provider;
} catch (Throwable t) {
err = t;
errs = (errs == null) ? new StringBuffer() : errs.append("\n");
errs.append(_derivations[i].getClass().getName() + ":" + t);
}
}
String aPath = (String) AccessController.doPrivileged(
J2DoPrivHelper.getAbsolutePathAction(file));
reportErrors(errs, aPath, err);
String rsrc = aPath + "#" + anchor;
throw (MissingResourceException) JavaVersions.initCause
(new MissingResourceException(rsrc,
ProductDerivations.class.getName(), rsrc), err);
}
Load given file, or return false if it is not a file this provider
understands. |
public static ConfigurationProvider loadDefaults(ClassLoader loader) {
return load(loader, false);
}
|
public static ConfigurationProvider loadGlobals(ClassLoader loader) {
return load(loader, true);
}
|
public static void main(String[] args) {
System.err.println(derivationErrorsToString());
}
Prints product derivation information. |
static void setConfigurationPrefixes(String[] prefixes) {
_prefixes = prefixes;
}
Set the configuration prefix array. This is package-visible for
testing purposes. |