writeEndDocument(writer);
}
public void resolve(Composite composite, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
Monitor monitor = context.getMonitor();
try {
monitor.pushContext("Composite: " + composite.getName());
// Resolve includes in the composite
for (int i = 0, n = composite.getIncludes().size(); i < n; i++) {
Composite include = composite.getIncludes().get(i);
if (include != null) {
Composite resolved = resolver.resolveModel(Composite.class, include, context);
if (!resolved.isUnresolved()) {
if ((composite.isLocal() && resolved.isLocal()) || (!composite.isLocal() && !resolved.isLocal())) {
composite.getIncludes().set(i, resolved);
} else {
ContributionResolveException ce =
new ContributionResolveException("[ASM60041] Error: Composite " + composite.getName()
+ " can only include another composite with the identical @local attribute value");
error(monitor, "ContributionResolveException", include, ce);
}
} else {
ContributionResolveException ce =
new ContributionResolveException("[ASM60042] Error: Composite " + include.getName()
+ " is not a valid composite within the domain");
error(monitor, "ContributionResolveException", include, ce);
}
}
}
// Resolve extensions
for (Object extension : composite.getExtensions()) {
if (extension != null) {
extensionProcessor.resolve(extension, resolver, context);
}
}
//Resolve composite services and references
resolveContracts(composite, composite.getServices(), resolver, context);
resolveContracts(composite, composite.getReferences(), resolver, context);
for (Property property : composite.getProperties()){
resolvePropertyType("composite " + composite.getName().toString(),
property,
context.getContribution(), context);
}
// Resolve component implementations, services and references
for (Component component : composite.getComponents()) {
//resolve component services and references
resolveContracts(component, component.getServices(), resolver, context);
resolveContracts(component, component.getReferences(), resolver, context);
for (ComponentProperty componentProperty : component.getProperties()) {
// resolve a reference to a property file
if (componentProperty.getFile() != null) {
Artifact artifact = contributionFactory.createArtifact();
artifact.setURI(componentProperty.getFile());
artifact = resolver.resolveModel(Artifact.class, artifact, context);
if (artifact.getLocation() != null) {
componentProperty.setFile(artifact.getLocation());
}
}
// resolve the reference to a complex property
resolvePropertyType("component " + component.getName(),
componentProperty,
context.getContribution(), context);
}
//resolve component implementation
Implementation implementation = component.getImplementation();
if (implementation != null) {
//now resolve the implementation so that even if there is a shared instance
//for this that is resolved, the specified intents and policysets are safe in the
//component and not lost
List<PolicySet> policySets = new ArrayList<PolicySet>(implementation.getPolicySets());
List<Intent> intents = new ArrayList<Intent>(implementation.getRequiredIntents());
implementation = resolveImplementation(implementation, resolver, context);
// If there are any policy sets on the implementation or component we have to
// ignore policy sets from the component type (policy spec 4.9)
if ( !policySets.isEmpty() || !component.getPolicySets().isEmpty() ) {
implementation.getPolicySets().clear();
implementation.getPolicySets().addAll(policySets);
}
implementation.getRequiredIntents().addAll(intents);
component.setImplementation(implementation);
}
//add model resolver to component
if (component instanceof ResolverExtension) {
((ResolverExtension)component).setModelResolver(resolver);
}
}
// Add model resolver to promoted components
for (Service service : composite.getServices()) {
CompositeService compositeService = (CompositeService)service;
Component promotedComponent = compositeService.getPromotedComponent();
if (promotedComponent instanceof ResolverExtension) {
((ResolverExtension)promotedComponent).setModelResolver(resolver);
}
} // end for
} finally {
// Pop context
monitor.popContext();
} // end try
}