You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by bu...@apache.org on 2012/04/24 19:34:18 UTC
svn commit: r1329878 - in /uima/uimaj/trunk/uimaj-core/src/main:
java/org/apache/uima/resource/ java/org/apache/uima/resource/impl/
java/org/apache/uima/resource/metadata/
java/org/apache/uima/resource/metadata/impl/ resources/org/apache/uima/
Author: burn
Date: Tue Apr 24 17:34:18 2012
New Revision: 1329878
URL: http://svn.apache.org/viewvc?rev=1329878&view=rev
Log:
[UIMA-2378] -DUimaExternalOverrides now accepts a comma-separated list of files.
Throw ResourceConfigurationException if a property value contains a reference to an undefined variable.
Modified:
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceConfigurationException.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurationManagerImplBase.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurationManager_impl.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/ExternalOverrideSettings.java
uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/ExternalOverrideSettings_impl.java
uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceConfigurationException.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceConfigurationException.java?rev=1329878&r1=1329877&r2=1329878&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceConfigurationException.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/ResourceConfigurationException.java Tue Apr 24 17:34:18 2012
@@ -90,6 +90,11 @@ public class ResourceConfigurationExcept
* component "{1}" -- directory "{2}" does not exist.
*/
public static final String DIRECTORY_NOT_FOUND = "directory_not_found";
+
+ /**
+ * Message key for a standard UIMA exception message: An external override references the undefined variable "{0}"
+ */
+ public static final String EXTERNAL_OVERRIDE_INVALID = "external_override_invalid";
/**
* Creates a new exception with a null message.
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurationManagerImplBase.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurationManagerImplBase.java?rev=1329878&r1=1329877&r2=1329878&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurationManagerImplBase.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurationManagerImplBase.java Tue Apr 24 17:34:18 2012
@@ -341,9 +341,11 @@ public abstract class ConfigurationManag
* name of context containing this parameter
* @param aParentContextName
* name of parent context, null if none
+ * @throws ResourceConfigurationException
*/
protected void declareParameters(String aGroupName, ConfigurationParameter[] aParams,
- ConfigurationParameterSettings aSettings, String aContextName, String aParentContextName) {
+ ConfigurationParameterSettings aSettings, String aContextName, String aParentContextName)
+ throws ResourceConfigurationException {
// iterate over config. param _declarations_
if (aParams != null) {
for (int i = 0; i < aParams.length; i++) {
@@ -356,10 +358,8 @@ public abstract class ConfigurationManag
// no explicit override. Check for implicit override (a parameter with same
// name declared in parent aggregate with no explicit overrides)
// Note: any type mismatch will generate an error later
- String nameInParentContext = makeQualifiedName(aParentContextName, param.getName(),
- aGroupName);
- if (lookup(nameInParentContext) != null
- && !mExplicitlyOverridingParameters.contains(nameInParentContext)) {
+ String nameInParentContext = makeQualifiedName(aParentContextName, param.getName(), aGroupName);
+ if (lookup(nameInParentContext) != null && !mExplicitlyOverridingParameters.contains(nameInParentContext)) {
// create a link (but collapse multiple links)
// String parentLink = getLink(nameInParentContext);
// overriddenBy = parentLink != null ? parentLink : nameInParentContext;
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurationManager_impl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurationManager_impl.java?rev=1329878&r1=1329877&r2=1329878&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurationManager_impl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurationManager_impl.java Tue Apr 24 17:34:18 2012
@@ -79,12 +79,12 @@ public class ConfigurationManager_impl e
* (non-Javadoc)
*
* @see org.apache.uima.resource.impl.ConfigurationManagerImplBase#declareParameters(java.lang.String,
- * org.apache.uima.resource.metadata.ConfigurationParameter[],
- * org.apache.uima.resource.metadata.ConfigurationParameterSettings, java.lang.String,
- * java.lang.String)
+ * org.apache.uima.resource.metadata.ConfigurationParameter[],
+ * org.apache.uima.resource.metadata.ConfigurationParameterSettings, java.lang.String, java.lang.String)
*/
protected void declareParameters(String aGroupName, ConfigurationParameter[] aParams,
- ConfigurationParameterSettings aSettings, String aContextName, String aParentContextName) {
+ ConfigurationParameterSettings aSettings, String aContextName, String aParentContextName)
+ throws ResourceConfigurationException {
super.declareParameters(aGroupName, aParams, aSettings, aContextName, aParentContextName);
// iterate over config. param _declarations_ and build mSharedParamNap
if (aParams != null) {
@@ -105,11 +105,12 @@ public class ConfigurationManager_impl e
if (propValue != null) {
Object result = createParam(propValue, aParams[i].getType(), aParams[i].isMultiValued());
if (result == null) {
- throw new NumberFormatException("Array mismatch assigning value of " + extName + " ('" + propValue + "') to " + aParams[i].getName());
+ throw new NumberFormatException("Array mismatch assigning value of " + extName + " ('" + propValue
+ + "') to " + aParams[i].getName());
}
paramValue = result;
mLinkMap.remove(qname);
- from = "(overridden from " + extName + ")";
+ from = "(overridden from " + extName + ")";
}
}
mSharedParamMap.put(qname, paramValue);
@@ -133,8 +134,8 @@ public class ConfigurationManager_impl e
Object[] array = (Object[]) realValue;
realValue = Arrays.toString(array);
}
- UIMAFramework.getLogger(this.getClass()).logrb(Level.CONFIG, this.getClass().getName(),
- "declareParameters", LOG_RESOURCE_BUNDLE, "UIMA_parameter_set__CONFIG",
+ UIMAFramework.getLogger(this.getClass()).logrb(Level.CONFIG, this.getClass().getName(), "declareParameters",
+ LOG_RESOURCE_BUNDLE, "UIMA_parameter_set__CONFIG",
new Object[] { aParams[i].getName(), aContextName, realValue, from });
}
}
@@ -315,9 +316,20 @@ public class ConfigurationManager_impl e
return mSettingsMap.get(aContextName);
}
+ /**
+ * Convenience method for direct access to string variables
+ *
+ * @param context - UIMA Context
+ * @param name - variable to look up
+ * @return - value of variable OR an exception message if definition is invalid
+ */
public String getExternalParameter(String context, String name) {
ExternalOverrideSettings settings = getExternalOverrideSettings(context);
- String value = settings == null ? null : settings.resolveExternalName(name);
- return value == null ? null : escape(value);
+ try {
+ String value = settings == null ? null : settings.resolveExternalName(name);
+ return value == null ? null : escape(value);
+ } catch (ResourceConfigurationException e) {
+ return "*ERROR* " + e.getMessage();
+ }
}
}
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/ExternalOverrideSettings.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/ExternalOverrideSettings.java?rev=1329878&r1=1329877&r2=1329878&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/ExternalOverrideSettings.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/ExternalOverrideSettings.java Tue Apr 24 17:34:18 2012
@@ -70,7 +70,7 @@ public interface ExternalOverrideSetting
/* (non-Javadoc)
* Look up value for external name from the external override settings
*/
- public String resolveExternalName(String name);
+ public String resolveExternalName(String name) throws ResourceConfigurationException;
/**
* Resolves an imported ExternalOverrideSettings specifier, if there is one.
Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/ExternalOverrideSettings_impl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/ExternalOverrideSettings_impl.java?rev=1329878&r1=1329877&r2=1329878&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/ExternalOverrideSettings_impl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/metadata/impl/ExternalOverrideSettings_impl.java Tue Apr 24 17:34:18 2012
@@ -96,14 +96,15 @@ public class ExternalOverrideSettings_im
/*
* Look up value for external name from the external override settings.
- * Perform one substitution pass on ${key} substrings. Undefined keys get the empty string.
+ * Perform one substitution pass on ${key} substrings. If key is undefined throw an exception.
* Recursively evaluate the value to be substituted. NOTE: infinite loops not detected!
* To avoid evaluation and get ${key} in the output use a property to generate the $, e.g.
* $ = $
* key = ${$}{key}
- * The Properties class processes the \ escape character so it must be doubled to survive
+ * or escape the $
+ * key = \${key}
*/
- public String resolveExternalName(String name) {
+ public String resolveExternalName(String name) throws ResourceConfigurationException {
String value;
if (mProperties == null || (value = mProperties.getProperty(name)) == null) {
return null;
@@ -113,16 +114,19 @@ public class ExternalOverrideSettings_im
int lastEnd = 0;
while (matcher.find()) {
// Check if the $ is escaped
- if (mProperties.isEscaped(value,matcher.start())) {
+ if (mProperties.isEscaped(value, matcher.start())) {
result.append(value.substring(lastEnd, matcher.start() + 1));
- lastEnd = matcher.start() + 1; // copy the escaped $ and restart after it
+ lastEnd = matcher.start() + 1; // copy the escaped $ and restart after it
} else {
result.append(value.substring(lastEnd, matcher.start()));
lastEnd = matcher.end();
- String val = resolveExternalName(value.substring(matcher.start() + 2, lastEnd - 1));
- if (val != null) { // If variable is undefined replace with nothing
- result.append(val);
+ String key = value.substring(matcher.start() + 2, lastEnd - 1);
+ String val = resolveExternalName(key);
+ if (val == null) { // External override variable "{0}" references the undefined variable "{1}"
+ throw new ResourceConfigurationException(ResourceConfigurationException.EXTERNAL_OVERRIDE_INVALID,
+ new Object[] { name, key });
}
+ result.append(val);
}
}
if (lastEnd == 0) {
@@ -155,13 +159,15 @@ public class ExternalOverrideSettings_im
// Also supports UTF-8 and lets first entry found override later entries.
mProperties = new Settings_impl();
- // First see if an import specified on the command line
- String fname = System.getProperty("UimaExternalOverrides");
- if (fname != null) {
- mProperties.load(new FileInputStream(fname));
- UIMAFramework.getLogger(this.getClass()).logrb(Level.CONFIG, this.getClass().getName(),
- "resolveImports", LOG_RESOURCE_BUNDLE, "UIMA_external_overrides_loaded__CONFIG",
- new Object[] {"cmdline file", fname} );
+ // First see if a comma-separated list of imports has been specified on the command line
+ String fnames = System.getProperty("UimaExternalOverrides");
+ if (fnames != null) {
+ for (String fname : fnames.split(",")) {
+ mProperties.load(new FileInputStream(fname));
+ UIMAFramework.getLogger(this.getClass())
+ .logrb(Level.CONFIG, this.getClass().getName(), "resolveImports", LOG_RESOURCE_BUNDLE,
+ "UIMA_external_overrides_loaded__CONFIG", new Object[] { "cmdline file", fname });
+ }
}
// Load settings first to override any imports
Modified: uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties?rev=1329878&r1=1329877&r2=1329878&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/resources/org/apache/uima/UIMAException_Messages.properties Tue Apr 24 17:34:18 2012
@@ -124,6 +124,8 @@ properties_file_not_found = Could not lo
directory_not_found = Invalid value for parameter "{0}" in component "{1}" -- \
directory "{2}" does not exist.
+external_override_invalid = External override variable "{0}" references the undefined variable "{1}"
+
#--------------------------------
#ResourceProcessException
#--------------------------------