Perl5Compiler compiler = new Perl5Compiler();
Pattern pattern;
try {
pattern = compiler.compile(patternString, Perl5Compiler.READ_ONLY_MASK);
} catch (MalformedPatternException e) {
throw new FormsException("Invalid regular expression '" + patternString + "'.",
e, DomHelper.getLocationObject(splitElement));
}
definition.setSplitPattern(pattern, patternString);
}
// read split mappings
Element[] mapElements = DomHelper.getChildElements(splitElement, FormsConstants.DEFINITION_NS, "map");
for (int i = 0; i < mapElements.length; i++) {
int group = DomHelper.getAttributeAsInteger(mapElements[i], "group");
String field = DomHelper.getAttribute(mapElements[i], "field");
// check that this field exists
if (!definition.hasWidget(field)) {
throw new FormsException("Unknown widget id '" + field + "' referenced.",
DomHelper.getLocationObject(mapElements[i]));
}
try {
definition.addSplitMapping(group, field);
} catch(RuntimeException e) {
throw new FormsException("Two groups are mapped to the same widget id '" + field + "'.",
DomHelper.getLocationObject(mapElements[i]));
}
}
// read split fail message (if any)
Element failMessageElement = DomHelper.getChildElement(splitElement, FormsConstants.DEFINITION_NS, "failmessage");
if (failMessageElement != null) {
XMLizable failMessage = DomHelper.compileElementContent(failMessageElement);
definition.setSplitFailMessage(failMessage);
}
// compile combine expression
Element combineElement = DomHelper.getChildElement(widgetElement, FormsConstants.DEFINITION_NS, "combine", true);
if(combineElement!=null) {
String combineExprString = DomHelper.getAttribute(combineElement, "expression");
Expression combineExpr;
try {
combineExpr = expressionManager.parse(combineExprString);
} catch (Exception e) {
throw new FormsException("Invalid combine expression '" + combineExprString + "'.",
e, DomHelper.getLocationObject(combineElement));
}
Class clazz = definition.getDatatype().getTypeClass();
if (combineExpr.getResultType() != null && !clazz.isAssignableFrom(combineExpr.getResultType())) {
throw new FormsException("The result of the combine expression should be '" + clazz.getName() + "', not '" + combineExpr.getResultType().getName() + "'.",
DomHelper.getLocationObject(combineElement));
}
definition.setCombineExpression(combineExpr);
}
}