private XSDefinition aggregate(List<XSDefinition> definitions) throws IOException {
if (definitions == null || definitions.size() == 0) {
return null;
}
if (definitions.size() == 1) {
XSDefinition d = definitions.get(0);
loadOnDemand(d);
return d;
}
XSDefinition aggregated = factory.createXSDefinition();
for (XSDefinition d : definitions) {
loadOnDemand(d);
}
String ns = definitions.get(0).getNamespace();
XmlSchema facade = new XmlSchema(ns, schemaCollection);
for (XmlSchema d : schemaCollection.getXmlSchemas()) {
if (ns.equals(d.getTargetNamespace())) {
XmlSchemaInclude include = new XmlSchemaInclude();
include.setSchema(d);
include.setSourceURI(d.getSourceURI());
include.setSchemaLocation(d.getSourceURI());
facade.getIncludes().add(include);
facade.getItems().add(include);
}
}
aggregated.setUnresolved(true);
aggregated.setSchema(facade);
aggregated.setNamespace(ns);
aggregated.setUnresolved(false);
// FIXME: [rfeng] This is hacky
definitions.clear();
definitions.add(aggregated);
return aggregated;