in uimafit-core/src/main/java/org/apache/uima/fit/factory/ConfigurationParameterFactory.java [659:744]
public static void setParameter(ResourceSpecifier aSpec, String name, Object value) {
if (aSpec instanceof CustomResourceSpecifier) {
if (!(value instanceof String || value == null)) {
throw new IllegalArgumentException("Value must be a string");
}
CustomResourceSpecifier spec = (CustomResourceSpecifier) aSpec;
// If the parameter is already there, update it
boolean found = false;
for (Parameter p : spec.getParameters()) {
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();
params[params.length - 1].setName(name);
params[params.length - 1].setValue((String) value);
spec.setParameters(params);
}
} else if (aSpec instanceof PearSpecifier) {
PearSpecifier spec = (PearSpecifier) aSpec;
boolean found = false;
// 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(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) {
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(value);
spec.setPearParameters(params);
}
} else if (aSpec instanceof ResourceCreationSpecifier) {
ResourceMetaData md = ((ResourceCreationSpecifier) aSpec).getMetaData();
ConfigurationParameter param = md.getConfigurationParameterDeclarations()
.getConfigurationParameter(null, name);
if (param == null) {
throw new IllegalArgumentException("Cannot set undeclared parameter [" + name + "]");
}
md.getConfigurationParameterSettings().setParameterValue(name,
convertParameterValue(param, value));
} else if (aSpec instanceof ConfigurableDataResourceSpecifier) {
ResourceMetaData md = ((ConfigurableDataResourceSpecifier) aSpec).getMetaData();
ConfigurationParameter param = md.getConfigurationParameterDeclarations()
.getConfigurationParameter(null, name);
if (param == null) {
throw new IllegalArgumentException("Cannot set undeclared parameter [" + name + "]");
}
md.getConfigurationParameterSettings().setParameterValue(name,
convertParameterValue(param, value));
} else {
throw new IllegalArgumentException(
"Unsupported resource specifier class [" + aSpec.getClass() + "]");
}
}