// Javadoc inherited.
public Object startElement(
DynamicProcess dynamicProcess, ExpandedName element,
Attributes attributes) throws SAXException {
final TemplateModel model = getModel(dynamicProcess);
model.startElement(TemplateSchema.PARAMETER);
final String name = attributes.getValue("name");
// Convert the type attribute value into an enumeration.
String type = attributes.getValue("type");
Complexity complexity;
if (type == null) {
complexity = Complexity.SIMPLE;
} else {
complexity = Complexity.literal(type);
if (complexity == null) {
throw forwardFatalError(dynamicProcess,
"Unknown type '" + type + "'");
}
}
// Convert the use attribute value into an enumeration.
String useAsString = attributes.getValue("use");
Use use;
if (useAsString == null) {
use = Use.REQUIRED;
} else {
use = Use.literal(useAsString);
if (use == null) {
throw forwardFatalError(dynamicProcess,
"Unknown use '" + useAsString + "'");
}
}
String defaultValue = attributes.getValue("default");
String variable = attributes.getValue("expressionVariable");
EndElementAction action;
if (name == null) {
throw forwardFatalError(dynamicProcess,
"A name must be provided for a parameter");
} else if (use == Use.REQUIRED && defaultValue != null) {
throw forwardFatalError(dynamicProcess,
"Default values cannot be specified for " +
"mandatory parameter '" + name + "'");
} else {
ParameterBlock parameters = model.getParameterBlock();
TValue boundValue = parameters.query(name);
if (boundValue != null) {
if (boundValue.getComplexity() == Complexity.COMPLEX &&
complexity == Complexity.SIMPLE) {
throw forwardFatalError(dynamicProcess,
"A complex binding has been provided for the " +
"simple parameter " + name);
} else {
model.transition(TemplateSchema.VALUE_START);
dynamicProcess.getPipelineContext()
.getFlowControlManager().exitCurrentElement();
// Record the fact that the existing binding value is
// "good"
boundValue.verify();
model.transition(TemplateSchema.VALUE_END);
action = new EndParameterAction(model);
}
} else if (use == Use.REQUIRED) {
throw forwardFatalError(dynamicProcess,
"No binding has been provided for required " +
"parameter " + name);
} else {
// The parameter is optional and has no existing binding
if (defaultValue != null) {
TValue value = model.createSimpleValue(defaultValue);
model.addDefaultValue(name, value);
action = new EndParameterAction(model);
} else {
model.setValueSetter(new TemplateValueSetter() {
public void setTemplateValue(TValue value)
throws SAXException {
model.addDefaultValue(name, value);
}
});
action = new EndParameterAction(model);
}
}