You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sv...@apache.org on 2007/12/08 21:07:59 UTC

svn commit: r602541 [1/3] - in /incubator/tuscany/java/sca/modules: assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ assembly-xml/src/test/resources/org/apache/tuscany/sca/a...

Author: svkrish
Date: Sat Dec  8 12:07:56 2007
New Revision: 602541

URL: http://svn.apache.org/viewvc?rev=602541&view=rev
Log:
fix implementation policies for sharing of implementation model instances across components (cleaned up earlier hacks)

Added:
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingPolicyComputer.java
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ImplementationPolicyComputer.java
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyComputationException.java
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyComputer.java
    incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationException.java
    incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationUtils.java
Modified:
    incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java
    incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
    incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java
    incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java
    incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java
    incubator/tuscany/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/definitions.xml
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeWireBuilderImpl.java
    incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java
    incubator/tuscany/java/sca/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java
    incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPoint.java
    incubator/tuscany/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetAttachPoint.java

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java?rev=602541&r1=602540&r2=602541&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java Sat Dec  8 12:07:56 2007
@@ -40,6 +40,7 @@
 import org.apache.tuscany.sca.assembly.AbstractProperty;
 import org.apache.tuscany.sca.assembly.AbstractReference;
 import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Base;
 import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.assembly.ComponentService;
 import org.apache.tuscany.sca.assembly.ComponentType;
@@ -60,9 +61,11 @@
 import org.apache.tuscany.sca.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.policy.Intent;
 import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
 import org.apache.tuscany.sca.policy.PolicyFactory;
 import org.apache.tuscany.sca.policy.PolicySet;
 import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.apache.tuscany.sca.policy.util.PolicyValidationUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
@@ -244,15 +247,43 @@
         }
         return implementation;
     }
-
+    
     /**
      * Resolve interface, callback interface and bindings on a list of contracts.
      * @param contracts the list of contracts
      * @param resolver the resolver to use to resolve models
      */
     protected <C extends Contract> void resolveContracts(List<C> contracts, ModelResolver resolver)
+    throws ContributionResolveException {
+        resolveContracts(null, contracts, resolver);
+    }
+
+
+    /**
+     * Resolve interface, callback interface and bindings on a list of contracts.
+     * @param parent element for the contracts
+     * @param contracts the list of contracts
+     * @param resolver the resolver to use to resolve models
+     */
+    protected <C extends Contract> void resolveContracts(Base parent, List<C> contracts, ModelResolver resolver)
         throws ContributionResolveException {
         for (Contract contract : contracts) {
+            //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);
+            
+            //inherit the composite / component level policy intents and policysets
+            if ( parent != null && parent instanceof PolicySetAttachPoint )  {
+                addInheritedIntents(((PolicySetAttachPoint)parent).getRequiredIntents(), contract.getRequiredIntents());
+                addInheritedPolicySets(((PolicySetAttachPoint)parent).getPolicySets(), contract.getPolicySets());
+            }
+            
+            for ( ConfiguredOperation confOp : contract.getConfiguredOperations() ) {
+                resolveIntents(confOp.getRequiredIntents(), resolver);
+                resolvePolicySets(confOp.getPolicySets(), resolver);
+            }
+                            
             // Resolve the interface contract
             InterfaceContract interfaceContract = contract.getInterfaceContract();
             if (interfaceContract != null) {
@@ -270,6 +301,8 @@
                 if (binding instanceof PolicySetAttachPoint) {
                     PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
                     resolvePolicySets(policiedBinding.getPolicySets(), resolver);
+                    //validate if attached policysets apply to the binding
+                    validatePolicySets(contract, policiedBinding);
                 }
                 if (binding instanceof OperationsConfigurator) {
                     OperationsConfigurator opConfigurator = (OperationsConfigurator)binding;
@@ -284,6 +317,10 @@
             if (contract.getCallback() != null) {
                 resolveIntents(contract.getCallback().getRequiredIntents(), resolver);
                 resolvePolicySets(contract.getCallback().getPolicySets(), resolver);
+                //inherit the contract's policy intents and policysets
+                addInheritedIntents(contract.getRequiredIntents(), contract.getCallback().getRequiredIntents());
+                addInheritedPolicySets(contract.getPolicySets(), contract.getCallback().getPolicySets());
+                
                 for (int i = 0, n = contract.getCallback().getBindings().size(); i < n; i++) {
                     Binding binding = contract.getCallback().getBindings().get(i);
                     extensionProcessor.resolve(binding, resolver);
@@ -295,6 +332,7 @@
                     if (binding instanceof PolicySetAttachPoint) {
                         PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
                         resolvePolicySets(policiedBinding.getPolicySets(), resolver);
+                        validatePolicySets(contract.getCallback(), policiedBinding);
                     }
                     if (binding instanceof OperationsConfigurator) {
                         OperationsConfigurator opConfigurator = (OperationsConfigurator)binding;
@@ -305,13 +343,6 @@
                     }
                 }
             }
-
-            resolveIntents(contract.getRequiredIntents(), resolver);
-            resolvePolicySets(contract.getPolicySets(), resolver);
-            for (ConfiguredOperation confOp : contract.getConfiguredOperations()) {
-                resolveIntents(confOp.getRequiredIntents(), resolver);
-                resolvePolicySets(confOp.getPolicySets(), resolver);
-            }
         }
     }
 
@@ -610,5 +641,41 @@
             }
         }
     }
+    
+    protected void addInheritedIntents(List<Intent> sourceList, List<Intent> targetList) {
+        if (sourceList != null) {
+            targetList.addAll(sourceList);
+        }
+    }
+    
+    protected  void addInheritedPolicySets(List<PolicySet> sourceList, List<PolicySet> targetList) {
+        if (sourceList != null) {
+            targetList.addAll(sourceList);
+        }
+    }
+    
+    protected void validatePolicySets(Base parent, PolicySetAttachPoint policySetAttachPoint) throws ContributionResolveException {
+        String appliesTo = null;
+        IntentAttachPointType attachPointType = policySetAttachPoint.getType();
+        String scdlFragment = ""; //need to write the 'parent' as scdl xml string
+        
+        //validate policysets specified for the attachPoint
+        for (PolicySet policySet : policySetAttachPoint.getPolicySets()) {
+            appliesTo = policySet.getAppliesTo();
+            if ( !policySet.isUnresolved() ) {
+                if (!PolicyValidationUtils.isPolicySetApplicable(scdlFragment, appliesTo, attachPointType)) {
+                    throw new ContributionResolveException("Policy Set '" + policySet.getName()
+                        + "' does not apply to binding type  "
+                        + attachPointType.getName());
+     
+                } }
+            else {
+                throw new ContributionResolveException("Policy Set '" + policySet.getName()
+                       + "' is not defined in this domain  ");
+                
+            }
+        }
+    }
+
 
 }

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java?rev=602541&r1=602540&r2=602541&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java Sat Dec  8 12:07:56 2007
@@ -60,13 +60,14 @@
 import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
 import org.apache.tuscany.sca.interfacedef.InterfaceContract;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
-import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.policy.Intent;
 import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
 import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
 import org.w3c.dom.Document;
 
 /**
- * A composite processor.
+ * A composite processor. 
  * 
  * @version $Rev$ $Date$
  */
@@ -731,6 +732,24 @@
                 extensionProcessor.resolve(extension, resolver);
             }
         }
+        
+        //resolve intents and policysets first as they are going to be copied over
+        //to child elements as and when the child elements are being resolved
+        List<Intent> compositeIntents = null;
+        List<PolicySet> compositePolicySets = null;
+        if (composite instanceof PolicySetAttachPoint) { 
+            resolveIntents(((PolicySetAttachPoint)composite).getRequiredIntents(), resolver);
+            resolvePolicySets(((PolicySetAttachPoint)composite).getPolicySets(), resolver);
+            compositeIntents = ((PolicySetAttachPoint)composite).getRequiredIntents();
+            compositePolicySets = ((PolicySetAttachPoint)composite).getPolicySets();
+        } else {
+            compositeIntents = new ArrayList<Intent>();
+            compositePolicySets = new ArrayList<PolicySet>();
+        }
+        
+        //Resolve composite services and references
+        resolveContracts(composite, composite.getServices(), resolver);
+        resolveContracts(composite, composite.getReferences(), resolver);
 
         // Resolve component implementations, services and references
         for (Component component : composite.getComponents()) {
@@ -739,20 +758,50 @@
                 constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType);
                 component.setConstrainingType(constrainingType);
             }
-
+            
+            //resolve intents and policysets first as they are going to be copied over
+            //to child elements as and when the child elements are being resolved
+            resolveIntents(component.getRequiredIntents(), resolver);
+            resolvePolicySets(component.getPolicySets(), resolver);
+            
+            //inherit composite intents and policysets
+            addInheritedIntents(compositeIntents, component.getRequiredIntents());
+            addInheritedPolicySets(compositePolicySets, component.getPolicySets());
+
+            //resolve component services and references 
+            resolveContracts(component, component.getServices(), resolver);
+            resolveContracts(component, component.getReferences(), resolver);
+            
+            for (ComponentProperty componentProperty : component.getProperties()) {
+                if (componentProperty.getFile() != null) {
+                    DeployedArtifact deployedArtifact = contributionFactory.createDeployedArtifact();
+                    deployedArtifact.setURI(componentProperty.getFile());
+                    deployedArtifact = resolver.resolveModel(DeployedArtifact.class, deployedArtifact);
+                    if (deployedArtifact.getLocation() != null) {
+                        componentProperty.setFile(deployedArtifact.getLocation());
+                    }
+                }
+            }
+            
+            //resolve component implemenation
             Implementation implementation = component.getImplementation();
             if (implementation != null) {
-                implementation = resolveImplementation(implementation, resolver);
-                component.setImplementation(implementation);
-                
-                //do a getImplementation to resolve policy intents and policysets
-                //that the implementation is configured with under this component
-                implementation = component.getImplementation();
                 if (implementation instanceof PolicySetAttachPoint) {
                     resolveIntents(((PolicySetAttachPoint)implementation).getRequiredIntents(), resolver);
                     resolvePolicySets(((PolicySetAttachPoint)implementation).getPolicySets(), resolver);
+                    validatePolicySets(component, (PolicySetAttachPoint)implementation);
+                    //add implementation policies into component... since implementation instance are 
+                    //reused and its likely that this implementation instance will not hold after its resolution
+                    component.getRequiredIntents().addAll(((PolicySetAttachPoint)implementation).getRequiredIntents());
+                    component.getPolicySets().addAll(((PolicySetAttachPoint)implementation).getPolicySets());
                 }
                 
+                implementation = resolveImplementation(implementation, resolver);
+                component.setImplementation(implementation);
+                
+                //need to do this so that component can set the configured 
+                //operations to the implementation instance
+                implementation = component.getImplementation();
                 if ( implementation instanceof OperationsConfigurator ) {
                     OperationsConfigurator opConfigurator = (OperationsConfigurator)implementation;
                     for ( ConfiguredOperation op : opConfigurator.getConfiguredOperations() ) {
@@ -761,32 +810,9 @@
                     }
                 }
             }
-
-            for (ComponentProperty componentProperty : component.getProperties()) {
-                if (componentProperty.getFile() != null) {
-                    DeployedArtifact deployedArtifact = contributionFactory.createDeployedArtifact();
-                    deployedArtifact.setURI(componentProperty.getFile());
-                    deployedArtifact = resolver.resolveModel(DeployedArtifact.class, deployedArtifact);
-                    if (deployedArtifact.getLocation() != null) {
-                        componentProperty.setFile(deployedArtifact.getLocation());
-                    }
-                }
-            }
-            resolveIntents(component.getRequiredIntents(), resolver);
-            resolvePolicySets(component.getPolicySets(), resolver);
-            resolveContracts(component.getServices(), resolver);
-            resolveContracts(component.getReferences(), resolver);
-        }
-
-        // Resolve composite services and references
-        resolveContracts(composite.getServices(), resolver);
-        resolveContracts(composite.getReferences(), resolver);
-        if (composite instanceof PolicySetAttachPoint) {
-            resolveIntents(((PolicySetAttachPoint)composite).getRequiredIntents(), resolver);
-            resolvePolicySets(((PolicySetAttachPoint)composite).getPolicySets(), resolver);
         }
     }
-
+    
     public QName getArtifactType() {
         return COMPOSITE_QNAME;
     }

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java?rev=602541&r1=602540&r2=602541&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java Sat Dec  8 12:07:56 2007
@@ -138,8 +138,8 @@
         assertEquals(policiedComposite.getRequiredIntents().size(), 1);
         assertEquals(policiedComposite.getRequiredIntents().get(0).getName(), new QName(namespaceUri, "tuscanyIntent_1"));
         
-        //1 defined for composite, 2 defined for the service, 1 defined for the promoted service (4)
-        assertEquals(composite.getServices().get(0).getRequiredIntents().size(), 4);
+        //1 defined for composite, 2 defined for the service, 1 defined and 3 inherited for the promoted service (4)
+        assertEquals(composite.getServices().get(0).getRequiredIntents().size(), 7);
         //1 from the operation defined in this service and 2 from the operation defined in the promoted service 
         assertEquals(composite.getServices().get(0).getConfiguredOperations().get(0).getRequiredIntents().size(), 5);
         assertEquals(composite.getServices().get(0).getRequiredIntents().get(3).getName(), new QName(namespaceUri, "tuscanyIntent_3"));
@@ -148,11 +148,11 @@
         assertEquals(((OperationsConfigurator)composite.getServices().get(0).getBindings().get(0)).getConfiguredOperations().size(), 1);
         assertEquals(((OperationsConfigurator)composite.getServices().get(0).getBindings().get(0)).getConfiguredOperations().get(0).getRequiredIntents().size(), 5);
         
-        assertEquals(composite.getReferences().get(0).getRequiredIntents().size(), 2);
+        assertEquals(composite.getReferences().get(0).getRequiredIntents().size(), 5);
         assertEquals(composite.getReferences().get(0).getConfiguredOperations().size(), 1);
-        assertEquals(composite.getReferences().get(0).getConfiguredOperations().get(0).getRequiredIntents().size(), 3);
+        assertEquals(composite.getReferences().get(0).getConfiguredOperations().get(0).getRequiredIntents().size(), 4);
         assertEquals(composite.getReferences().get(0).getRequiredIntents().get(1).getName(), new QName(namespaceUri, "tuscanyIntent_1"));
-        assertEquals(((IntentAttachPoint)composite.getReferences().get(0).getBindings().get(0)).getRequiredIntents().size(), 2);
+        assertEquals(((IntentAttachPoint)composite.getReferences().get(0).getBindings().get(0)).getRequiredIntents().size(), 3);
 
         assertEquals(composite.getComponents().get(0).getRequiredIntents().size(), 3);
         assertEquals(composite.getComponents().get(0).getRequiredIntents().get(2).getName(), new QName(namespaceUri, "tuscanyIntent_1"));

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java?rev=602541&r1=602540&r2=602541&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java Sat Dec  8 12:07:56 2007
@@ -20,6 +20,8 @@
 package org.apache.tuscany.sca.assembly.xml;
 
 import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
 
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLOutputFactory;
@@ -37,6 +39,8 @@
 import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl;
 import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
 import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.definitions.xml.SCADefinitionsDocumentProcessor;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
 import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
 import org.apache.tuscany.sca.policy.DefaultIntentAttachPointTypeFactory;
@@ -58,6 +62,7 @@
     private SCABindingFactory scaBindingFactory;
     private PolicyFactory policyFactory;
     private InterfaceContractMapper mapper;
+    private SCADefinitionsDocumentProcessor scaDefnDocProcessor;
 
     @Override
     public void setUp() throws Exception {
@@ -69,6 +74,9 @@
         scaBindingFactory = new TestSCABindingFactoryImpl();
         policyFactory = new DefaultPolicyFactory();
         mapper = new InterfaceContractMapperImpl();
+        
+        scaDefnDocProcessor = new SCADefinitionsDocumentProcessor(staxProcessors, staxProcessor, inputFactory, policyFactory);
+        
     }
 
     @Override
@@ -91,6 +99,13 @@
         is.close();
         assertNotNull(composite);
         
+        URL url = getClass().getResource("definitions.xml");
+        URI uri = URI.create("definitions.xml");
+        SCADefinitions scaDefns = (SCADefinitions)scaDefnDocProcessor.read(null, uri, url);
+        assertNotNull(scaDefns);
+        
+        scaDefnDocProcessor.resolve(scaDefns, resolver);
+        
         compositeReader.resolve(composite, resolver);
         CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, new DefaultIntentAttachPointTypeFactory(), mapper, null, null);
         compositeUtil.build(composite);
@@ -113,6 +128,13 @@
         reader = inputFactory.createXMLStreamReader(is);
         Composite composite = compositeReader.read(reader);
         is.close();
+        
+        URL url = getClass().getResource("definitions.xml");
+        URI uri = URI.create("definitions.xml");
+        SCADefinitions scaDefns = (SCADefinitions)scaDefnDocProcessor.read(null, uri, url);
+        assertNotNull(scaDefns);
+        
+        scaDefnDocProcessor.resolve(scaDefns, resolver);
         
         compositeReader.resolve(composite, resolver);
         CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, new DefaultIntentAttachPointTypeFactory(), mapper, null, null);

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java?rev=602541&r1=602540&r2=602541&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java Sat Dec  8 12:07:56 2007
@@ -22,6 +22,8 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLInputFactory;
@@ -40,6 +42,8 @@
 import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl;
 import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
 import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.definitions.xml.SCADefinitionsDocumentProcessor;
 import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
 import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
 import org.apache.tuscany.sca.policy.DefaultIntentAttachPointTypeFactory;
@@ -60,6 +64,7 @@
     private PolicyFactory policyFactory;
     private InterfaceContractMapper mapper;
     private CompositeBuilderImpl compositeUtil;
+    private SCADefinitionsDocumentProcessor scaDefnDocProcessor;
 
 
     @Override
@@ -75,6 +80,7 @@
         staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(assemblyFactory, policyFactory, staxProcessor));
         staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(assemblyFactory, policyFactory, staxProcessor));
         resolver = new TestModelResolver();
+        scaDefnDocProcessor = new SCADefinitionsDocumentProcessor(staxProcessors, staxProcessor, XMLInputFactory.newInstance(), policyFactory);
     }
 
     @Override
@@ -101,6 +107,13 @@
     public void testReadWireWriteComposite() throws Exception {
         InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite");
         Composite composite = staxProcessor.read(is, Composite.class);
+        
+        URL url = getClass().getResource("definitions.xml");
+        URI uri = URI.create("definitions.xml");
+        SCADefinitions scaDefns = (SCADefinitions)scaDefnDocProcessor.read(null, uri, url);
+        assertNotNull(scaDefns);
+        scaDefnDocProcessor.resolve(scaDefns, resolver);
+        
         staxProcessor.resolve(composite, resolver);
         compositeUtil.build(composite);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/definitions.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/definitions.xml?rev=602541&r1=602540&r2=602541&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/definitions.xml (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/definitions.xml Sat Dec  8 12:07:56 2007
@@ -30,7 +30,7 @@
  <!-- POLICY SETS -->
   <sca:policySet name="SecureReliablePolicy"
  	provides="confidentiality.transport integrity"
- 	appliesTo="sca:binding.ws"
+ 	appliesTo="sca:binding.ws sca:binding.sca"
  	xmlns="http://test"
  	xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
  		<wsp:PolicyAttachment>
@@ -50,15 +50,15 @@
  	 xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
      <sca:intentMap provides="confidentiality" default="transport">
         <sca:qualifier name="transport">
-            <wsp:PolicyAttachment>
+            <wsp:Policy>
                 <!-- policy expression and policy subject for "transport" alternative -->
-                </wsp:PolicyAttachment>
-            <wsp:PolicyAttachment>...</wsp:PolicyAttachment>
+                </wsp:Policy>
+            <wsp:Policy>...</wsp:Policy>
         </sca:qualifier>
         <sca:qualifier name="message">
-            <wsp:PolicyAttachment>
+            <wsp:Policy>
                 <!-- policy expression and policy subject for "message" alternative" -->
-            </wsp:PolicyAttachment>
+            </wsp:Policy>
         </sca:qualifier>
     </sca:intentMap>
 </sca:policySet>
@@ -70,21 +70,21 @@
         <sca:qualifier name="message">
             <sca:intentMap provides="message" default="whole">
                 <sca:qualifier name="body">
-                	<wsp:PolicyAttachment>
+                	<wsp:Policy>
                 		<!-- policy attachment for body encryption --> 
-               		</wsp:PolicyAttachment>
+               		</wsp:Policy>
            		</sca:qualifier>
                 <sca:qualifier name="whole">
-                	<wsp:PolicyAttachment>
+                	<wsp:Policy>
                 		<!-- policy attachment for whole message encryption --> 
-               		</wsp:PolicyAttachment>
+               		</wsp:Policy>
              	</sca:qualifier>
             </sca:intentMap>
         </sca:qualifier>
         <sca:qualifier name="transport">
-        	<wsp:PolicyAttachment>
+        	<wsp:Policy>
         		<!-- policy attachment for transport encryption --> 
-       		</wsp:PolicyAttachment>
+       		</wsp:Policy>
         </sca:qualifier>
     </sca:intentMap>
 </sca:policySet>
@@ -115,17 +115,17 @@
     xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
     <sca:intentMap provides="confidentiality"  default="transport">
         <sca:qualifier name="transport">
-            <wsp:PolicyAttachment>
+            <wsp:Policy>
                 <!-- policy expression and policy subject for "transport"
                 alternative -->
-            </wsp:PolicyAttachment>
-            <wsp:PolicyAttachment>...</wsp:PolicyAttachment>
+            </wsp:Policy>
+            <wsp:Policy>...</wsp:Policy>
         </sca:qualifier>
         <sca:qualifier name="message">
-            <wsp:PolicyAttachment>
+            <wsp:Policy>
                 <!-- policy expression and policy subject for "message"
                 alternative" -->...
-            </wsp:PolicyAttachment>
+            </wsp:Policy>
         </sca:qualifier>
     </sca:intentMap>
 </sca:policySet>

Modified: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java?rev=602541&r1=602540&r2=602541&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java (original)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java Sat Dec  8 12:07:56 2007
@@ -28,7 +28,7 @@
  * 
  * @version $Rev$ $Date$
  */
-public interface Callback extends Extensible, IntentAttachPoint, PolicySetAttachPoint {
+public interface Callback extends Base, Extensible, IntentAttachPoint, PolicySetAttachPoint {
 
     /**
      * Returns the bindings supported for callbacks.

Added: incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingPolicyComputer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingPolicyComputer.java?rev=602541&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingPolicyComputer.java (added)
+++ incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingPolicyComputer.java Sat Dec  8 12:07:56 2007
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.apache.tuscany.sca.policy.util.PolicyValidationException;
+
+/**
+ * Policy computation methods pertaining to computing Binding policies
+ */
+public class BindingPolicyComputer extends PolicyComputer {
+    
+    public BindingPolicyComputer(List<PolicySet> domainPolicySets) {
+        super(domainPolicySets);
+    }
+    
+    public void computeBindingIntentsAndPolicySets(Contract contract)  throws PolicyValidationException {
+        computeIntents(contract.getBindings(), contract.getRequiredIntents());
+        computePolicySets(contract, contract.getBindings(), contract.getPolicySets());
+        
+        for ( Binding binding : contract.getBindings() ) {
+            if ( binding instanceof IntentAttachPoint ) {
+                computeIntentsForOperations((IntentAttachPoint)binding);
+            }
+            
+            if ( binding instanceof PolicySetAttachPoint ) {
+                computePolicySetsForOperations(contract, (PolicySetAttachPoint)binding);
+            }
+        }
+        
+        if ( contract.getCallback() != null ) {
+            computeIntents(contract.getCallback().getBindings(), 
+                           contract.getCallback().getRequiredIntents());
+            computePolicySets(contract, 
+                              contract.getCallback().getBindings(), 
+                              contract.getCallback().getPolicySets());
+        }
+    }
+    
+    private void computeIntents(List<Binding> bindings, List<Intent> inheritedIntents) throws PolicyValidationException {
+        for (Binding binding : bindings) {
+            if (binding instanceof IntentAttachPoint) {
+                IntentAttachPoint policiedBinding = (IntentAttachPoint)binding;
+                //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(policiedBinding.getType(), 
+                                                                       inheritedIntents);
+                policiedBinding.getRequiredIntents().addAll(prunedIntents);
+                
+                computeIntents(policiedBinding);
+                trimInherentlyProvidedIntents(policiedBinding.getType(), 
+                                              policiedBinding.getRequiredIntents());
+                
+                computeIntentsForOperations((IntentAttachPoint)policiedBinding);
+            }
+        }
+    }
+    
+    private void computePolicySets(Base parent,
+                                   List<Binding> bindings,
+                                   List<PolicySet> inheritedPolicySets) throws PolicyValidationException {
+        for (Binding binding : bindings) {
+            if ( binding instanceof PolicySetAttachPoint ) {
+                PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
+                
+                List<PolicySet> prunedPolicySets = computeInheritablePolicySets(parent, 
+                                                                                policiedBinding.getType(), 
+                                                                                inheritedPolicySets);
+                policiedBinding.getPolicySets().addAll(prunedPolicySets);
+                computePolicySets(policiedBinding);
+                computePolicySetsForOperations(parent, policiedBinding);
+
+            }
+        }
+    }
+    
+    public void determineApplicableBindingPolicySets(Contract source, Contract target) throws PolicyComputationException {
+        for (Binding aBinding : source.getBindings()) {
+            if (aBinding instanceof PolicySetAttachPoint) {
+                PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)aBinding;
+                IntentAttachPointType bindingType = policiedBinding.getType();
+
+                // 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() ) {
+                        trimProvidedIntents(confOp.getRequiredIntents(), confOp.getPolicySets());
+                        trimProvidedIntents(confOp.getRequiredIntents(), policiedBinding.getPolicySets());
+                    }
+                }
+
+                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);
+            }
+        }
+    }
+    
+    private void determineApplicableDomainPolicySets(Contract contract, 
+                                                     PolicySetAttachPoint policiedBinding) 
+                                                            throws PolicyComputationException {
+        if ( domainPolicySets != null) {
+            determineApplicableDomainPolicySets(contract, 
+                                                policiedBinding,
+                                                policiedBinding.getType());
+            
+            if ( policiedBinding.getRequiredIntents().size() > 0 ) {
+                if ( contract instanceof Service ) {
+                    throw new PolicyComputationException("There are unfulfilled intents for " +
+                            "binding in service - " + contract.getName());
+                } else {
+                    throw new PolicyComputationException("There are unfulfilled intents for " +
+                            "binding in reference - " + contract.getName());
+                }
+            }
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org