protected void resolveContracts()

in modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java [413:554]


    protected <C extends Contract> void resolveContracts(Base parent, List<C> contracts, ModelResolver resolver)
        throws ContributionResolveException {

        String parentName = (parent instanceof Composite) ? ((Composite)parent).getName().toString() :
            (parent instanceof Component) ? ((Component)parent).getName() : "UNKNOWN";

        for (Contract contract : contracts) {
            try {
                //resolve the intents and policysets as they need to be copied over into the
                //child binding elements
                resolveIntents(contract.getRequiredIntents(), resolver);
                resolvePolicySets(contract.getPolicySets(), resolver);
                resolvePolicySets(contract.getApplicablePolicySets(), resolver);

                // Inherit the composite / component level applicable policy sets.
                if ( parent != null && parent instanceof PolicySetAttachPoint )  {
                    addInheritedPolicySets(((PolicySetAttachPoint)parent).getApplicablePolicySets(), contract.getApplicablePolicySets());
                }

                for ( ConfiguredOperation confOp : contract.getConfiguredOperations() ) {
                    resolveIntents(confOp.getRequiredIntents(), resolver);
                    resolvePolicySets(confOp.getPolicySets(), resolver);
                    resolvePolicySets(confOp.getApplicablePolicySets(), resolver);

                    //inherit applicable policy sets from parent contract
                    addInheritedPolicySets(contract.getApplicablePolicySets(), confOp.getApplicablePolicySets());
                }

                // Resolve the interface contract
                InterfaceContract interfaceContract = contract.getInterfaceContract();
                if (interfaceContract != null) {
                    extensionProcessor.resolve(interfaceContract, resolver);
                }

                // Resolve bindings
                for (int i = 0, n = contract.getBindings().size(); i < n; i++) {
                    Binding binding = contract.getBindings().get(i);
                    extensionProcessor.resolve(binding, resolver);

                    if (binding instanceof IntentAttachPoint) {
                        IntentAttachPoint policiedBinding = (IntentAttachPoint)binding;

                        if ( policiedBinding.getType() != null && policiedBinding.getType().isUnresolved() ) {
                            IntentAttachPointType resolved =
                                resolver.resolveModel(IntentAttachPointType.class,
                                                      policiedBinding.getType());
                            policiedBinding.setType(resolved);
                        }

                        resolveIntents(policiedBinding.getRequiredIntents(), resolver);
                        PolicyValidationUtils.validateIntents(policiedBinding, policiedBinding.getType());
                    }

                    if (binding instanceof PolicySetAttachPoint) {
                        PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
                        resolvePolicySets(policiedBinding.getPolicySets(), resolver);
                        //validate if attached policysets apply to the binding
                        resolvePolicySets(policiedBinding.getApplicablePolicySets(), resolver);
                        //inherit the applicable policysets from parent contract as whatever applies to that
                        //applies to the binding as well
                        addInheritedPolicySets(contract.getApplicablePolicySets(), policiedBinding.getApplicablePolicySets());
                        PolicyValidationUtils.validatePolicySets(policiedBinding);
                    }

                    if (binding instanceof OperationsConfigurator) {
                        OperationsConfigurator opConfigurator = (OperationsConfigurator)binding;
                        for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations()) {
                            resolveIntents(confOp.getRequiredIntents(), resolver);
                            PolicyValidationUtils.validateIntents(confOp, ((PolicySetAttachPoint)binding).getType());

                            resolvePolicySets(confOp.getPolicySets(), resolver);
                            resolvePolicySets(confOp.getApplicablePolicySets(), resolver);
                            //inherit the applicable policysets from parent binding as whatever applies to that
                            //applies to the binding as well
                            addInheritedPolicySets(((PolicySetAttachPoint)binding).getApplicablePolicySets(),
                                                   confOp.getApplicablePolicySets());
                            PolicyValidationUtils.validatePolicySets(confOp, ((PolicySetAttachPoint)binding).getType());
                        }
                    }
                }

                // Resolve callback bindings
                if (contract.getCallback() != null) {
                    resolveIntents(contract.getCallback().getRequiredIntents(), resolver);
                    resolvePolicySets(contract.getCallback().getPolicySets(), resolver);
                    resolvePolicySets(contract.getCallback().getApplicablePolicySets(), resolver);
                    //inherit the contract's policy intents and policysets
                    addInheritedPolicySets(contract.getApplicablePolicySets(), contract.getCallback().getApplicablePolicySets());

                    for (int i = 0, n = contract.getCallback().getBindings().size(); i < n; i++) {
                        Binding binding = contract.getCallback().getBindings().get(i);
                        extensionProcessor.resolve(binding, resolver);

                        if (binding instanceof IntentAttachPoint) {
                            IntentAttachPoint policiedBinding = (IntentAttachPoint)binding;

                            if ( policiedBinding.getType().isUnresolved() ) {
                                IntentAttachPointType resolved =
                                    resolver.resolveModel(IntentAttachPointType.class,
                                                          policiedBinding.getType());
                                policiedBinding.setType(resolved);
                            }

                            resolveIntents(policiedBinding.getRequiredIntents(), resolver);
                            PolicyValidationUtils.validateIntents(policiedBinding, policiedBinding.getType());
                        }

                        if (binding instanceof PolicySetAttachPoint) {
                            PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
                            resolvePolicySets(policiedBinding.getPolicySets(), resolver);
                            //validate if attached policysets apply to the binding
                            resolvePolicySets(policiedBinding.getApplicablePolicySets(), resolver);
                            //inherit the applicable policysets from parent contract as whatever applies to that
                            //applies to the binding as well
                            addInheritedPolicySets(contract.getApplicablePolicySets(), policiedBinding.getApplicablePolicySets());
                            PolicyValidationUtils.validatePolicySets(policiedBinding);
                        }

                        if (binding instanceof OperationsConfigurator) {
                            OperationsConfigurator opConfigurator = (OperationsConfigurator)binding;
                            for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations()) {
                                resolveIntents(confOp.getRequiredIntents(), resolver);
                                PolicyValidationUtils.validateIntents(confOp, ((PolicySetAttachPoint)binding).getType());

                                resolvePolicySets(confOp.getPolicySets(), resolver);
                                resolvePolicySets(confOp.getApplicablePolicySets(), resolver);
                                //inherit the applicable policysets from parent binding as whatever applies to that
                                //applies to the binding as well
                                addInheritedPolicySets(((PolicySetAttachPoint)binding).getApplicablePolicySets(),
                                                       confOp.getApplicablePolicySets());
                                PolicyValidationUtils.validatePolicySets(confOp, ((PolicySetAttachPoint)binding).getType());
                            }
                        }
                    }
                }
            } catch ( PolicyValidationException e ) {
            	error("PolicyServiceValidationException", contract, contract.getName(), parentName, e.getMessage());
                //throw new ContributionResolveException("PolicyValidation exceptions when processing service/reference '"
                                                       //+ contract.getName() + "' in '" + parentName + "'");
            }
        }
    }