* @throws SimpleServerException
* Content parsing error.
*/
public static ServerSpec readServerSpec(InputStream is) throws IOException, XmlException,
SimpleServerException {
UimaSimpleServerSpec specBean = UimaSimpleServerSpecDocument.Factory.parse(is)
.getUimaSimpleServerSpec();
// Do validation. If XML is not valid, throw first error.
ArrayList<XmlError> validationErrors = new ArrayList<XmlError>();
XmlOptions validationOptions = new XmlOptions();
validationOptions.setErrorListener(validationErrors);
boolean isValid = specBean.validate(validationOptions);
if (!isValid) {
Iterator<XmlError> iter = validationErrors.iterator();
if (iter.hasNext()) {
throw new XmlException(iter.next());
}
}
// TODO: recompile XML beans code from XSD. While doing this: check if the number of jars for
// xml parsing (3) can be reduced. This is all Apache code, so legally this should be ok.
// Also create ant build script for this.
// TEMPORARY:
final boolean doOutputAll = false;
// Create new server spec from XML beans.
ServerSpec spec = ConfigFactory.newServerSpec(specBean.getShortDescription(), specBean
.getLongDescription(), doOutputAll);
TypeElementType[] typeMaps = specBean.getTypeArray();
for (int i = 0; i < typeMaps.length; i++) {
spec.addTypeMap(readTypeMap(typeMaps[i]));
}
return spec;
}