You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2021/02/15 15:08:28 UTC
[uima-uimafit] branch
feature/UIMA-6312-Better-PEAR-parameter-support created (now 5170999)
This is an automated email from the ASF dual-hosted git repository.
rec pushed a change to branch feature/UIMA-6312-Better-PEAR-parameter-support
in repository https://gitbox.apache.org/repos/asf/uima-uimafit.git.
at 5170999 [UIMA-6312] Better PEAR parameter support
This branch includes the following new commits:
new 5170999 [UIMA-6312] Better PEAR parameter support
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[uima-uimafit] 01/01: [UIMA-6312] Better PEAR parameter support
Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rec pushed a commit to branch feature/UIMA-6312-Better-PEAR-parameter-support
in repository https://gitbox.apache.org/repos/asf/uima-uimafit.git
commit 5170999c383972f54161e8214c25f7b7f0d60e47
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Mon Feb 15 16:08:13 2021 +0100
[UIMA-6312] Better PEAR parameter support
- When fetching parameters from PEARs, fetch legacy parameters as well as the new NameValuePair parameters - latter override former
- When setting parameters, try updating first the modern parameter, then (if present) the legacy ones - if a parameter is not present yet, create a modern NameValuePair parameter
---
.../fit/factory/ConfigurationParameterFactory.java | 49 +++++++++++++++++-----
1 file changed, 39 insertions(+), 10 deletions(-)
diff --git a/uimafit-core/src/main/java/org/apache/uima/fit/factory/ConfigurationParameterFactory.java b/uimafit-core/src/main/java/org/apache/uima/fit/factory/ConfigurationParameterFactory.java
index 067de15..af9a86f 100644
--- a/uimafit-core/src/main/java/org/apache/uima/fit/factory/ConfigurationParameterFactory.java
+++ b/uimafit-core/src/main/java/org/apache/uima/fit/factory/ConfigurationParameterFactory.java
@@ -42,6 +42,7 @@ import org.apache.uima.resource.metadata.ConfigurationParameter;
import org.apache.uima.resource.metadata.NameValuePair;
import org.apache.uima.resource.metadata.ResourceMetaData;
import org.apache.uima.resource.metadata.impl.ConfigurationParameter_impl;
+import org.apache.uima.resource.metadata.impl.NameValuePair_impl;
import org.springframework.beans.SimpleTypeConverter;
import org.springframework.beans.TypeMismatchException;
@@ -548,8 +549,23 @@ public final class ConfigurationParameterFactory {
settings.put(p.getName(), p.getValue());
}
} else if (spec instanceof PearSpecifier) {
- for (Parameter p : ((PearSpecifier) spec).getParameters()) {
- settings.put(p.getName(), p.getValue());
+ PearSpecifier pearSpec = ((PearSpecifier) spec);
+ // Legacy parameters that only support string values.
+ Parameter[] parameters = pearSpec.getParameters();
+
+ if (parameters != null) {
+ for (Parameter parameter : parameters) {
+ settings.put(parameter.getName(), parameter.getValue());
+ }
+ }
+
+ // Parameters supporting arbitrary objects as values
+ NameValuePair[] pearParameters = pearSpec.getPearParameters();
+
+ if (pearParameters != null) {
+ for (NameValuePair pearParameter : pearParameters) {
+ settings.put(pearParameter.getName(), pearParameter.getValue());
+ }
}
} else if (spec instanceof ResourceCreationSpecifier) {
for (NameValuePair p : ((ResourceCreationSpecifier) spec).getMetaData()
@@ -609,23 +625,36 @@ public final class ConfigurationParameterFactory {
} else if (aSpec instanceof PearSpecifier) {
PearSpecifier spec = (PearSpecifier) aSpec;
- // If the parameter is already there, update it
boolean found = false;
- for (Parameter p : spec.getParameters()) {
+
+ // Check modern parameters and if the parameter is present there, update it
+ NameValuePair[] parameters = spec.getPearParameters();
+ for (NameValuePair p : parameters) {
if (p.getName().equals(name)) {
- p.setValue((String) value);
+ p.setValue(value);
found = true;
}
}
+
+ // Check legacy parameters and if the parameter is present there, update it
+ Parameter[] legacyParameters = spec.getParameters();
+ if (legacyParameters != null) {
+ for (Parameter p : legacyParameters) {
+ if (p.getName().equals(name)) {
+ p.setValue((String) value);
+ found = true;
+ }
+ }
+ }
// If the parameter is not there, add it
if (!found) {
- Parameter[] params = new Parameter[spec.getParameters().length + 1];
- System.arraycopy(spec.getParameters(), 0, params, 0, spec.getParameters().length);
- params[params.length - 1] = new Parameter_impl();
+ NameValuePair[] params = new NameValuePair[parameters.length + 1];
+ System.arraycopy(parameters, 0, params, 0, parameters.length);
+ params[params.length - 1] = new NameValuePair_impl();
params[params.length - 1].setName(name);
- params[params.length - 1].setValue((String) value);
- spec.setParameters(params);
+ params[params.length - 1].setValue(value);
+ spec.setPearParameters(params);
}
} else if (aSpec instanceof ResourceCreationSpecifier) {
ResourceMetaData md = ((ResourceCreationSpecifier) aSpec).getMetaData();