Package org.apache.tuscany.sca.policy

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


        return new XAttr(Constants.POLICY_SETS, qnames);
    }
   
    public void resolvePolicies(Object subject, ModelResolver resolver, ProcessorContext context) {
        if ( subject instanceof PolicySubject ) {
            PolicySubject policySetAttachPoint = (PolicySubject)subject;
           
            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, context);
                    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, context);
                    resolvedPolicySets.add(resolvedPolicySet);
                }
                policySetAttachPoint.getPolicySets().clear();
                policySetAttachPoint.getPolicySets().addAll(resolvedPolicySets);
            }
        }
    }
View Full Code Here


            }
           
         
            // The node can be a component, implementation, service, reference or binding
            String index = getStructuralURI(node);
            PolicySubject subject = lookup(composite, index);
            if (subject != null) {
              ps.setIsExternalAttachment(true);
              // Remove any PolicySets with the same name that may have been added
              List<PolicySet> subjectPSCopy = new ArrayList<PolicySet>(subject.getPolicySets());
              for ( PolicySet existingPS : subjectPSCopy ) {
                if ( existingPS.getName().equals(ps.getName()) ) {
                  subject.getPolicySets().remove(existingPS);
                }
              }
              subject.getPolicySets().add(ps);
            } else {
              // raise a warning that the XPath node didn't match a node in the
              // models
              Monitor.warning(monitor,
                  this,
View Full Code Here

    @Test
    @Ignore("There are so many errors with this composite the builder doesn't have enough to go on")
    public void testPolicyIntentInheritance() throws Exception {
        String namespaceUri = "http://test";

        PolicySubject policiedComposite = composite;
        assertEquals(policiedComposite.getRequiredIntents().size(), 1);
        assertEquals(policiedComposite.getRequiredIntents().get(0).getName(),
                     new QName(namespaceUri, "tuscanyIntent_1"));

        Component component = composite.getComponents().get(0);
        Endpoint ep = component.getServices().get(0).getEndpoints().get(0);
        EndpointReference epr = component.getReferences().get(0).getEndpointReferences().get(0);
View Full Code Here

            binding.setURI(scaBinding.getURI());
            binding.setOperationSelector(scaBinding.getOperationSelector());
            binding.setRequestWireFormat(scaBinding.getRequestWireFormat());
            binding.setResponseWireFormat(scaBinding.getResponseWireFormat());
            if (binding instanceof PolicySubject && scaBinding instanceof PolicySubject) {
                PolicySubject subject1 = (PolicySubject)binding;
                PolicySubject subject2 = (PolicySubject)scaBinding;
                subject1.getPolicySets().addAll(subject2.getPolicySets());
                subject1.getRequiredIntents().addAll(subject2.getRequiredIntents());
            }
            return binding;
        } catch (Throwable e) {
            throw new ServiceRuntimeException(e);
        }
View Full Code Here

     * @param models - the subjects from which intents will be copied
     */
    protected void inherit(PolicySubject policySubject, Intent.Type intentType, boolean ignoreExclusiveIntents, Object... models) {
        for (Object model : models) {
            if (model instanceof PolicySubject) {
                PolicySubject subject = (PolicySubject)model;

                if (!ignoreExclusiveIntents) {
                    // The intents are merged and the exclusion check will be done after
                    for (Intent intent : subject.getRequiredIntents()) {
                        if (!policySubject.getRequiredIntents().contains(intent)){
                            if ((intent.getType() != null) && (intentType != null) ) {
                                if (intent.getType().equals(intentType)){
                                    policySubject.getRequiredIntents().add(intent);
                                }
                            } else {
                                policySubject.getRequiredIntents().add(intent);
                            }
                        }
                    }
                } else {
                    Set<Intent> intents = new HashSet<Intent>();
                    for (Intent i1 : subject.getRequiredIntents()) {
                        boolean exclusive = false;
                        for (Intent i2 : policySubject.getRequiredIntents()) {
                            if (i1.getExcludedIntents().contains(i2) || i2.getExcludedIntents().contains(i1)) {
                                exclusive = true;
                                break;
                            }
                        }
                        if (!exclusive) {
                            if (!intents.contains(i1)){
                                if (intentType != null) {
                                    if (i1.getType().equals(intentType)){
                                        intents.add(i1);
                                    }
                                } else {
                                    intents.add(i1);
                                }
                            }
                        }
                    }
                    policySubject.getRequiredIntents().addAll(intents);
                }
                //FIXME this duplicates the intents for a implementation
                //e.g <implementation.java requires="managedTransaction.local managedTransaction.local"
                //becomes twice
                //[{http://docs.oasis-open.org/ns/opencsa/sca/200912}managedTransaction.local,
                //{http://docs.oasis-open.org/ns/opencsa/sca/200912}managedTransaction.local]
                for (PolicySet policySet : subject.getPolicySets()){
                    if (!policySubject.getPolicySets().contains(policySet)){
                        policySubject.getPolicySets().add(policySet);
                    }
                }
            }
View Full Code Here

            }
                   
            for (int i = 0; i < nodes.getLength(); i++) {
              Node node = nodes.item(i);
              String index = getStructuralURI(node);
              PolicySubject subject = lookup(composite, index);
              if ( subject != null )
                subjects.add(subject);
            }
          }
        }
View Full Code Here

     * @param models
     */
    private void inherit(PolicySubject policySubject, Object... models) {
        for (Object model : models) {
            if (model instanceof PolicySubject) {
                PolicySubject subject = (PolicySubject)model;
                policySubject.getRequiredIntents().addAll(subject.getRequiredIntents());
                policySubject.getPolicySets().addAll(subject.getPolicySets());
            }
        }
    }
View Full Code Here

                        implementation.getProperties().addAll(componentType.getProperties());
                        implementation.setConstrainingType(componentType.getConstrainingType());

                        if (implementation instanceof PolicySubject &&
                                componentType instanceof PolicySubject ) {
                            PolicySubject policiedImpl = (PolicySubject)implementation;
                            PolicySubject policiedCompType = (PolicySubject)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 PolicySubject) {
                PolicySubject policiedBinding = (PolicySubject)binding;
                computeIntents((PolicySubject)binding, contract.getRequiredIntents());
               
                computePolicySets(policiedBinding, contract.getPolicySets());
   
                PolicyComputationUtils.checkForMutuallyExclusiveIntents(
                    policiedBinding.getRequiredIntents(),
                    policiedBinding.getPolicySets(),
                    policiedBinding.getType(),
                    contract.getName());
            }
        }
       
        if ( contract.getCallback() != null ) {
            for (Binding binding : contract.getCallback().getBindings()) {
                if (binding instanceof PolicySubject) {
                    PolicySubject policiedBinding = (PolicySubject)binding;
                    computeIntents((PolicySubject)binding, contract.getCallback().getRequiredIntents());
           
                    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 PolicySubject) {
                PolicySubject policiedBinding = (PolicySubject)aBinding;
                ExtensionType 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 (ExtensionType constrained : intent.getConstrainedTypes()) {
                                if (bindingType != null && bindingType.getType().getNamespaceURI()
                                    .equals(constrained.getType().getNamespaceURI())
                                    && bindingType.getType().getLocalPart().startsWith(constrained
                                        .getType().getLocalPart())) {
                                    policiedBinding.getRequiredIntents().add(intent);
                                    break;
                                }
                            }
                        }
                    }
                }
   
                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

TOP

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

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.