in modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java [981:1125]
protected void computePolicies(Composite composite) {
// compute policies recursively
for (Component component : composite.getComponents()) {
Implementation implementation = component.getImplementation();
if (implementation instanceof Composite) {
computePolicies((Composite)implementation);
}
}
for (Component component : composite.getComponents()) {
// Inherit default policies from the component to component-level contracts.
// This must be done BEFORE computing implementation policies because the
// implementation policy computer removes from the component any
// intents and policy sets that don't apply to implementations.
PolicyConfigurationUtil.inheritDefaultPolicies(component, component.getServices());
PolicyConfigurationUtil.inheritDefaultPolicies(component, component.getReferences());
Implementation implemenation = component.getImplementation();
try {
PolicyConfigurationUtil.computeImplementationIntentsAndPolicySets(implemenation, component);
} catch ( Exception e ) {
error("PolicyRelatedException", implemenation, e);
//throw new RuntimeException(e);
}
for (ComponentService componentService : component.getServices()) {
Service service = componentService.getService();
if (service != null) {
// reconcile intents and policysets from componentType
PolicyComputationUtils.addInheritedIntents(service.getRequiredIntents(), componentService.getRequiredIntents());
PolicyComputationUtils.addInheritedPolicySets(service.getPolicySets(), componentService.getPolicySets(), true);
//reconcile intents and policysets for operations
boolean notFound;
List<ConfiguredOperation> opsFromComponentType = new ArrayList<ConfiguredOperation>();
for ( ConfiguredOperation ctsConfOp : service.getConfiguredOperations() ) {
notFound = true;
for ( ConfiguredOperation csConfOp : componentService.getConfiguredOperations() ) {
if ( csConfOp.getName().equals(ctsConfOp.getName()) ) {
PolicyComputationUtils.addInheritedIntents(ctsConfOp.getRequiredIntents(), csConfOp.getRequiredIntents());
PolicyComputationUtils.addInheritedPolicySets(ctsConfOp.getPolicySets(), csConfOp.getPolicySets(), true);
notFound = false;
}
}
if ( notFound ) {
opsFromComponentType.add(ctsConfOp);
}
}
componentService.getConfiguredOperations().addAll(opsFromComponentType);
}
try {
//compute the intents for operations under service element
PolicyConfigurationUtil.computeIntentsForOperations(componentService);
//compute intents and policyset for each binding
//addInheritedOpConfOnBindings(componentService);
PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(componentService);
PolicyConfigurationUtil.determineApplicableBindingPolicySets(componentService, null);
} catch ( Exception e ) {
error("PolicyRelatedException", componentService, e);
//throw new RuntimeException(e);
}
}
for (ComponentReference componentReference : component.getReferences()) {
Reference reference = componentReference.getReference();
if (reference != null) {
// reconcile intents and policysets
PolicyComputationUtils.addInheritedIntents(reference.getRequiredIntents(), componentReference.getRequiredIntents());
PolicyComputationUtils.addInheritedPolicySets(reference.getPolicySets(), componentReference.getPolicySets(), true);
}
try {
//compute the intents for operations under reference element
PolicyConfigurationUtil.computeIntentsForOperations(componentReference);
//compute intents and policyset for each binding
//addInheritedOpConfOnBindings(componentReference);
PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(componentReference);
PolicyConfigurationUtil.determineApplicableBindingPolicySets(componentReference, null);
if ( componentReference.getCallback() != null ) {
PolicyComputationUtils.addInheritedIntents(componentReference.getRequiredIntents(),
componentReference.getCallback().getRequiredIntents());
PolicyComputationUtils.addInheritedPolicySets(componentReference.getPolicySets(),
componentReference.getCallback().getPolicySets(),
false);
}
} catch ( Exception e ) {
error("PolicyRelatedException", componentReference, e);
//throw new RuntimeException(e);
}
}
}
PolicyConfigurationUtil.inheritDefaultPolicies(composite, composite.getServices());
PolicyConfigurationUtil.inheritDefaultPolicies(composite, composite.getReferences());
//compute policies for composite service bindings
for (Service service : composite.getServices()) {
addPoliciesFromPromotedService((CompositeService)service);
try {
//compute the intents for operations under service element
PolicyConfigurationUtil.computeIntentsForOperations(service);
//add or merge service operations to the binding
//addInheritedOpConfOnBindings(service);
PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(service);
PolicyConfigurationUtil.determineApplicableBindingPolicySets(service, null);
} catch ( Exception e ) {
error("PolicyRelatedException", service, e);
//throw new RuntimeException(e);
}
}
for (Reference reference : composite.getReferences()) {
CompositeReference compReference = (CompositeReference)reference;
addPoliciesFromPromotedReference(compReference);
try {
//compute the intents for operations under service element
PolicyConfigurationUtil.computeIntentsForOperations(reference);
//addInheritedOpConfOnBindings(reference);
if (compReference.getCallback() != null) {
PolicyComputationUtils.addInheritedIntents(compReference.getRequiredIntents(),
compReference.getCallback().getRequiredIntents());
PolicyComputationUtils.addInheritedPolicySets(compReference.getPolicySets(),
compReference.getCallback().getPolicySets(),
false);
}
PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(reference);
PolicyConfigurationUtil.determineApplicableBindingPolicySets(reference, null);
} catch ( Exception e ) {
error("PolicyRelatedException", reference, e);
//throw new RuntimeException(e);
}
}
}