* if the value is not of a supported type for the given specifier.
*/
public static void setParameter(ResourceSpecifier aSpec, String name, Object value) {
if (aSpec instanceof CustomResourceSpecifier) {
if (!(value instanceof String || value == null)) {
throw new IllegalClassException(String.class, value);
}
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 ResourceCreationSpecifier) {
ResourceMetaData md = ((ResourceCreationSpecifier) aSpec).getMetaData();
if (md.getConfigurationParameterDeclarations().getConfigurationParameter(null, name) == null) {
throw new IllegalArgumentException("Cannot set undeclared parameter [" + name + "]");
}
md.getConfigurationParameterSettings().setParameterValue(name, value);
} else if (aSpec instanceof ConfigurableDataResourceSpecifier) {
ResourceMetaData md = ((ConfigurableDataResourceSpecifier) aSpec).getMetaData();
if (md.getConfigurationParameterDeclarations().getConfigurationParameter(null, name) == null) {
throw new IllegalArgumentException("Cannot set undeclared parameter [" + name + "]");
}
md.getConfigurationParameterSettings().setParameterValue(name, value);
} else {
throw new IllegalClassException("Unsupported resource specifier class [" + aSpec.getClass()
+ "]");
}
}