Package org.apache.tuscany.sca.policy

Examples of org.apache.tuscany.sca.policy.PolicySetAttachPoint


     */
    private void readPolicySets(Object attachPoint, Operation operation, XMLStreamReader reader) {
        if (!(attachPoint instanceof PolicySetAttachPoint)) {
            return;
        }
        PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint;
        String value = reader.getAttributeValue(null, POLICY_SETS);
        if (value != null) {
            List<PolicySet> policySets = policySetAttachPoint.getPolicySets();
            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
                QName qname = getQNameValue(reader, tokens.nextToken());
                PolicySet policySet = policyFactory.createPolicySet();
                policySet.setName(qname);
                if (operation != null) {
                    //FIXME Don't we need to handle policySet specification
                    // on an operation basis?
                    //policySet.getOperations().add(operation);
                }
                policySets.add(policySet);
            }
        }
       
        value = reader.getAttributeValue(SCA10_TUSCANY_NS, APPLICABLE_POLICY_SETS);
        if (value != null) {
            List<PolicySet> applicablePolicySets = policySetAttachPoint.getApplicablePolicySets();
            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
                QName qname = getQNameValue(reader, tokens.nextToken());
                PolicySet policySet = policyFactory.createPolicySet();
                policySet.setName(qname);
                if (operation != null) {
View Full Code Here


     */
    private XAttr writePolicySets(Object attachPoint, Operation operation) {
        if (!(attachPoint instanceof PolicySetAttachPoint)) {
            return null;
        }
        PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint;
        List<QName> qnames = new ArrayList<QName>();
        for (PolicySet policySet: policySetAttachPoint.getPolicySets()) {
            qnames.add(policySet.getName());
        }
        return new XAttr(Constants.POLICY_SETS, qnames);
    }
View Full Code Here

        return new XAttr(Constants.POLICY_SETS, qnames);
    }
   
    public void resolvePolicies(Object attachPoint, ModelResolver resolver) {
        if ( attachPoint instanceof PolicySetAttachPoint ) {
            PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint;
           
            List<Intent> requiredIntents = new ArrayList<Intent>();
            Intent resolvedIntent = null;
           
            if ( policySetAttachPoint.getRequiredIntents() != null && policySetAttachPoint.getRequiredIntents().size() > 0 ) {
                for ( Intent intent : policySetAttachPoint.getRequiredIntents() ) {
                    resolvedIntent = resolver.resolveModel(Intent.class, intent);
                    requiredIntents.add(resolvedIntent);
                }
                policySetAttachPoint.getRequiredIntents().clear();
                policySetAttachPoint.getRequiredIntents().addAll(requiredIntents);
            }
           
            if ( policySetAttachPoint.getPolicySets() != null && policySetAttachPoint.getPolicySets().size() > 0 ) {
                List<PolicySet> resolvedPolicySets = new ArrayList<PolicySet>();
                PolicySet resolvedPolicySet = null;
                for ( PolicySet policySet : policySetAttachPoint.getPolicySets() ) {
                    resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet);
                    resolvedPolicySets.add(resolvedPolicySet);
                }
                policySetAttachPoint.getPolicySets().clear();
                policySetAttachPoint.getPolicySets().addAll(resolvedPolicySets);
            }
        }
    }
View Full Code Here

                if (implementation.isUnresolved()) {
                    extensionProcessor.resolve(implementation, resolver);
                    if (!implementation.isUnresolved()) {
                        //resolve policies
                        if ( implementation instanceof PolicySetAttachPoint ) {
                            PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)implementation;
                            resolveIntents(policiedImpl.getRequiredIntents(), resolver);
                            PolicyValidationUtils.validateIntents(policiedImpl, policiedImpl.getType());
                           
                            resolvePolicySets(policiedImpl.getPolicySets(), resolver);
                            PolicyValidationUtils.validatePolicySets(policiedImpl);
                           
                            if ( implementation instanceof OperationsConfigurator ) {
                                OperationsConfigurator opsConfigurator = (OperationsConfigurator)implementation;
                                for ( ConfiguredOperation implOp : opsConfigurator.getConfiguredOperations() ) {
                                    resolveIntents(implOp.getRequiredIntents(), resolver);
                                    PolicyValidationUtils.validateIntents(implOp, policiedImpl.getType());
                                   
                                    resolvePolicySets(implOp.getPolicySets(), resolver);
                                    PolicyValidationUtils.validatePolicySets(implOp,
                                                                             policiedImpl.getType(),
                                                                             policiedImpl.getApplicablePolicySets());
                                }
                            }
                           
                            for ( Service service : implementation.getServices() ) {
                                resolveIntents(service.getRequiredIntents(), resolver);
View Full Code Here

                        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;
View Full Code Here

                                                 List<PolicySet> inheritedApplicablePolicySets,
                                                 ModelResolver resolver) throws ContributionResolveException,
                                                                                 PolicyValidationException
                                                        {
        if ( implementation instanceof PolicySetAttachPoint ) {
            PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)implementation;
           
            policiedImpl.getApplicablePolicySets().addAll(inheritedApplicablePolicySets);
           
            resolveIntents(policiedImpl.getRequiredIntents(), resolver);
            PolicyValidationUtils.validateIntents(policiedImpl, policiedImpl.getType());
           
            resolvePolicySets(policiedImpl.getPolicySets(), resolver);
            resolvePolicySets(policiedImpl.getApplicablePolicySets(), resolver);
           
            PolicyValidationUtils.validatePolicySets(policiedImpl);
           
            if ( implementation instanceof OperationsConfigurator ) {
                for ( ConfiguredOperation implConfOp : ((OperationsConfigurator)implementation).getConfiguredOperations() ) {
                    resolveIntents(implConfOp.getRequiredIntents(), resolver);
                    PolicyValidationUtils.validateIntents(implConfOp, policiedImpl.getType());
                   
                    resolvePolicySets(implConfOp.getPolicySets(), resolver);
                    resolvePolicySets(implConfOp.getApplicablePolicySets(), resolver);
                    //add the inherited applicablePolicysets
                    addInheritedPolicySets(policiedImpl.getApplicablePolicySets(), implConfOp.getApplicablePolicySets());
                   
                    PolicyValidationUtils.validatePolicySets(implConfOp, policiedImpl.getType());
                   
                    PolicyComputationUtils.addDefaultPolicies(
                                            ((PolicySetAttachPoint)implementation).getRequiredIntents(),
                                            ((PolicySetAttachPoint)implementation).getPolicySets(),
                                            implConfOp.getRequiredIntents(),
View Full Code Here

                        implementation.getProperties().addAll(componentType.getProperties());
                        implementation.setConstrainingType(componentType.getConstrainingType());
                       
                        if (implementation instanceof PolicySetAttachPoint &&
                                componentType instanceof PolicySetAttachPoint ) {
                            PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)implementation;
                            PolicySetAttachPoint policiedCompType = (PolicySetAttachPoint)componentType;
                           
                            if ( policiedImpl.getPolicySets() != null) {
                                policiedImpl.getPolicySets().addAll(policiedCompType.getPolicySets());
                            }
                            if (policiedImpl.getRequiredIntents() != null) {
                                policiedImpl.getRequiredIntents().addAll(policiedCompType.getRequiredIntents());
                            }
                        }
                    }
                }
            }
View Full Code Here

    }

    static void computeBindingIntentsAndPolicySets(Contract contractthrows PolicyValidationException {
        for (Binding binding : contract.getBindings()) {
            if (binding instanceof PolicySetAttachPoint) {
                PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
                computeIntents((IntentAttachPoint)binding, contract.getRequiredIntents());
               
                aggregateAndPruneApplicablePolicySets(contract.getApplicablePolicySets(),
                                                      policiedBinding.getApplicablePolicySets());
   
                computePolicySets(policiedBinding, contract.getPolicySets());
   
                PolicyComputationUtils.checkForMutuallyExclusiveIntents(
                    policiedBinding.getRequiredIntents(),
                    policiedBinding.getPolicySets(),
                    policiedBinding.getType(),
                    contract.getName());
   
                if ( binding instanceof OperationsConfigurator &&
                        contract instanceof OperationsConfigurator ) {
                    //add or merge service operations to the binding
                    addInheritedOpConfOnBindings((OperationsConfigurator)contract,
                                                 (OperationsConfigurator)binding,
                                                 (PolicySetAttachPoint)binding);
               
                    computeIntentsForOperations((IntentAttachPoint)binding);
                    computePolicySetsForOperations(contract.getApplicablePolicySets(),
                                                   policiedBinding);
   
                    for ( ConfiguredOperation confOp : ((OperationsConfigurator)binding).getConfiguredOperations() ) {
                        PolicyComputationUtils.checkForMutuallyExclusiveIntents(
                            confOp.getRequiredIntents(),
                            confOp.getPolicySets(),
                            policiedBinding.getType(),
                            contract.getName() + "." + confOp.getName());
                    }
   
                }
            }
        }
       
        if ( contract.getCallback() != null ) {
            for (Binding binding : contract.getCallback().getBindings()) {
                if (binding instanceof PolicySetAttachPoint) {
                    PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
                    computeIntents((IntentAttachPoint)binding, contract.getCallback().getRequiredIntents());
           
                    aggregateAndPruneApplicablePolicySets(contract.getApplicablePolicySets(),
                                                          policiedBinding.getApplicablePolicySets());
   
                    computePolicySets(policiedBinding, contract.getCallback().getPolicySets());
   
                    PolicyComputationUtils.checkForMutuallyExclusiveIntents(
                        policiedBinding.getRequiredIntents(),
                        policiedBinding.getPolicySets(),
                        policiedBinding.getType(),
                        contract.getName() + " callback");
   
                }
            }
        }
View Full Code Here

    static void determineApplicableBindingPolicySets(Contract source, Contract target) throws PolicyConfigurationException {
        List<Intent> intentsCopy = null;
        for (Binding aBinding : source.getBindings()) {
            if (aBinding instanceof PolicySetAttachPoint) {
                PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)aBinding;
                IntentAttachPointType bindingType = policiedBinding.getType();
   
               
                intentsCopy = new ArrayList<Intent>(policiedBinding.getRequiredIntents());
                // add the target component's intents to the reference binding
                if (target != null) {
                    for (Intent intent : target.getRequiredIntents()) {
                        if (!policiedBinding.getRequiredIntents().contains(intent)) {
                            for (QName constrained : intent.getConstrains()) {
                                if (bindingType != null && bindingType.getName().getNamespaceURI()
                                    .equals(constrained.getNamespaceURI())
                                    && bindingType.getName().getLocalPart().startsWith(constrained
                                        .getLocalPart())) {
                                    policiedBinding.getRequiredIntents().add(intent);
                                    break;
                                }
                            }
                        }
                    }
                }
               
                //trim intents specified in operations.  First check for policysets specified on the operation
                //and then in the parent implementation
                if ( aBinding instanceof OperationsConfigurator ) {
                    OperationsConfigurator opConfigurator = (OperationsConfigurator)aBinding;
                   
                    for ( ConfiguredOperation confOp : opConfigurator.getConfiguredOperations() ) {
                        List<Intent> opsIntentsCopy = new ArrayList<Intent>(confOp.getRequiredIntents());
                       
                        trimInherentlyProvidedIntents(policiedBinding.getType(),
                                                      confOp.getRequiredIntents());
                        trimProvidedIntents(confOp.getRequiredIntents(), confOp.getPolicySets());
                        trimProvidedIntents(confOp.getRequiredIntents(), policiedBinding.getPolicySets());
                       
                        determineApplicableDomainPolicySets(policiedBinding.getApplicablePolicySets(),
                                                            confOp,
                                                            policiedBinding.getType());
   
                        if (confOp.getRequiredIntents().size() > 0) {
                            throw new PolicyConfigurationException("The following are unfulfilled intents for operations configured in "
                                    + "binding - " + aBinding.getName() + "\nUnfulfilled Intents = " +
                                    confOp.getRequiredIntents());
                        }
                       
                        //the intents list could have been trimmed when matching for policysets
                        //since the bindings may need the original set of intents we copy that back
                        confOp.getRequiredIntents().clear();
                        confOp.getRequiredIntents().addAll(opsIntentsCopy);
                       
                    }
                }
   
                trimInherentlyProvidedIntents(policiedBinding.getType(),
                                              policiedBinding.getRequiredIntents());
                trimProvidedIntents(policiedBinding.getRequiredIntents(), policiedBinding
                    .getPolicySets());
   
                // determine additional policysets that match remaining intents
                // TODO: resolved to domain policy registry and attach suitable
                // policy sets to the binding
                // for now using the SCA Definitions instead of registry
                // if there are intents that are not provided by any policy set
                // throw a warning
                determineApplicableDomainPolicySets(source, policiedBinding);
               
                //the intents list could have been trimmed when matching for policysets
                //since the bindings may need the original set of intents we copy that back
                policiedBinding.getRequiredIntents().clear();
                policiedBinding.getRequiredIntents().addAll(intentsCopy);
               
            }
        }
    }
View Full Code Here

    }

    static void computeImplementationIntentsAndPolicySets(Implementation implementation, Component parent
                                                                throws PolicyValidationException, PolicyConfigurationException {
        if ( implementation instanceof PolicySetAttachPoint ) {
            PolicySetAttachPoint policiedImplementation = (PolicySetAttachPoint)implementation;
            //since for an implementation the component has its policy intents and policysets its possible
            //that there are some intents there that does not constrain the implementation.. so prune
            List<Intent> prunedIntents = computeInheritableIntents(policiedImplementation.getType(),
                                                                   parent.getRequiredIntents());
            parent.getRequiredIntents().clear();
            parent.getRequiredIntents().addAll(prunedIntents);
            normalizeIntents(parent);
   
            computeIntentsForOperations((OperationsConfigurator)parent,
                                        (IntentAttachPoint)implementation,
                                        parent.getRequiredIntents());
           
           
            List<PolicySet> prunedPolicySets = computeInheritablePolicySets(parent.getPolicySets(),
                                                                            parent.getApplicablePolicySets());
            parent.getPolicySets().clear();
            parent.getPolicySets().addAll(prunedPolicySets);
            normalizePolicySets(parent);
   
            PolicyComputationUtils.checkForMutuallyExclusiveIntents(
                parent.getRequiredIntents(),
                parent.getPolicySets(),
                policiedImplementation.getType(),
                parent.getName());
   
            computePolicySetsForOperations(parent.getApplicablePolicySets(),
                                           (OperationsConfigurator)parent,
                                           (PolicySetAttachPoint)implementation);
   
            for ( ConfiguredOperation confOp : ((OperationsConfigurator)parent).getConfiguredOperations() ) {
                PolicyComputationUtils.checkForMutuallyExclusiveIntents(
                    confOp.getRequiredIntents(),
                    confOp.getPolicySets(),
                    policiedImplementation.getType(),
                    parent.getName() + "." + confOp.getName());
            }
           
            determineApplicableImplementationPolicySets(parent);
   
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.policy.PolicySetAttachPoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.