init();
Contribution contribution = contributionFactory.createContribution();
contribution.setURI(systemContribution.getURI());
contribution.setLocation(systemContribution.getLocation());
ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories);
contribution.setModelResolver(modelResolver);
contribution.setUnresolved(true);
DefinitionsFactory definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class);
Definitions definitions = definitionsFactory.createDefinitions();
DefinitionsUtil.aggregate(systemDefinitions, definitions, monitor);
// create an artifact to represent the system defintions and
// add it to the contribution
List<Artifact> artifacts = contribution.getArtifacts();
Artifact artifact = contributionFactory.createArtifact();
artifact.setURI("http://tuscany.apache.org/SystemContribution/Definitions");
artifact.setLocation("Derived");
artifact.setModel(definitions);
artifacts.add(artifact);
// create resolver entries to represent the SCA schema. We don't create artifacts
// in the contribution as the XSD schema are only actually loaded on demand
// so as long as they are in the model resolver we are set. We do it on the clone
// so that every copy of the system contribution has the schema
ProcessorContext context = new ProcessorContext(monitor);
XSDFactory xsdFactory = modelFactories.getFactory(XSDFactory.class);
List<String> scaSchemas = validationSchema.getSchemas();
for (String scaSchemaLocation : scaSchemas){
try {
URL scaSchemaURL = new URL(scaSchemaLocation);
String namespace = staxHelper.readAttribute(scaSchemaURL, XSD, "targetNamespace");
// if this is the SCA schema store it in the system contribution
if (namespace.equals(Constants.SCA11_TUSCANY_NS)){
// add the schema to the model resolver under the Tuscany namespace
XSDefinition scaSchema = xsdFactory.createXSDefinition();
scaSchema.setUnresolved(true);
scaSchema.setNamespace(namespace);
scaSchema.setLocation(IOHelper.toURI(scaSchemaURL));
scaSchema.setUnresolved(false);
// modelResolver.addModel(scaSchema, context);
} else if (namespace.equals(Constants.SCA11_NS)) {
// we know that the SCA schema's are referenced form the Tuscany schemas so
// register the schema under the SCA namespace too
XSDefinition scaSchema = xsdFactory.createXSDefinition();
scaSchema.setUnresolved(true);
scaSchema.setNamespace(Constants.SCA11_NS);
scaSchema.setLocation(IOHelper.toURI(scaSchemaURL));
scaSchema.setUnresolved(false);
modelResolver.addModel(scaSchema, context);
}
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
}