You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2009/09/15 00:57:47 UTC

svn commit: r814899 - in /tuscany/java/sca/modules/policy-builder: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/sca/ src/main/java/org/apache/...

Author: rfeng
Date: Mon Sep 14 22:57:46 2009
New Revision: 814899

URL: http://svn.apache.org/viewvc?rev=814899&view=rev
Log:
Add a module to hold the builder for external policy attachment

Added:
    tuscany/java/sca/modules/policy-builder/   (with props)
    tuscany/java/sca/modules/policy-builder/META-INF/
    tuscany/java/sca/modules/policy-builder/META-INF/MANIFEST.MF
    tuscany/java/sca/modules/policy-builder/pom.xml   (with props)
    tuscany/java/sca/modules/policy-builder/src/
    tuscany/java/sca/modules/policy-builder/src/main/
    tuscany/java/sca/modules/policy-builder/src/main/java/
    tuscany/java/sca/modules/policy-builder/src/main/java/org/
    tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/
    tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/
    tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/
    tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/
    tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/
    tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/
    tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java   (with props)
    tuscany/java/sca/modules/policy-builder/src/main/resources/
    tuscany/java/sca/modules/policy-builder/src/main/resources/META-INF/
    tuscany/java/sca/modules/policy-builder/src/main/resources/META-INF/services/
    tuscany/java/sca/modules/policy-builder/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.CompositeBuilder
    tuscany/java/sca/modules/policy-builder/src/test/
    tuscany/java/sca/modules/policy-builder/src/test/java/
    tuscany/java/sca/modules/policy-builder/src/test/java/org/
    tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/
    tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/
    tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/
    tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/
    tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/
    tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/
    tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/MockPolicy.java   (with props)
    tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentTestCase.java   (with props)
    tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/TestPolicyProcessor.java   (with props)
    tuscany/java/sca/modules/policy-builder/src/test/resources/
    tuscany/java/sca/modules/policy-builder/src/test/resources/org/
    tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/
    tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/
    tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/
    tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/
    tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/
    tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/
    tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Calculator.composite   (with props)
    tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/test_definitions.xml   (with props)

Propchange: tuscany/java/sca/modules/policy-builder/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Sep 14 22:57:46 2009
@@ -0,0 +1,15 @@
+target
+*.iws
+*.ipr
+*.iml
+.project
+.classpath
+maven.log
+velocity.log*
+junit*.properties
+surefire*.properties
+.settings
+.deployables
+.wtpmodules
+.externalToolBuilders
+maven-eclipse.xml

Added: tuscany/java/sca/modules/policy-builder/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-builder/META-INF/MANIFEST.MF?rev=814899&view=auto
==============================================================================
--- tuscany/java/sca/modules/policy-builder/META-INF/MANIFEST.MF (added)
+++ tuscany/java/sca/modules/policy-builder/META-INF/MANIFEST.MF Mon Sep 14 22:57:46 2009
@@ -0,0 +1,26 @@
+Manifest-Version: 1.0
+Bundle-Name: Apache Tuscany SCA Policy Attachment Builder
+Created-By: 1.6.0_07 (Sun Microsystems Inc.)
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bnd-LastModified: 1225397097203
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Assembly Model
+Import-Package: javax.xml.namespace,
+ javax.xml.xpath,
+ org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.assembly.builder;version="2.0.0",
+ org.apache.tuscany.sca.common.xml.dom;version="2.0.0",
+ org.apache.tuscany.sca.common.xml.stax;version="2.0.0",
+ org.apache.tuscany.sca.common.xml.xpath;version="2.0.0",
+ org.apache.tuscany.sca.contribution.processor;version="2.0.0",
+ org.apache.tuscany.sca.contribution.resolver;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.definitions;version="2.0.0",
+ org.apache.tuscany.sca.monitor;version="2.0.0",
+ org.apache.tuscany.sca.policy;version="2.0.0",
+ org.w3c.dom
+Bundle-SymbolicName: org.apache.tuscany.sca.policy.builder
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6

Added: tuscany/java/sca/modules/policy-builder/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-builder/pom.xml?rev=814899&view=auto
==============================================================================
--- tuscany/java/sca/modules/policy-builder/pom.xml (added)
+++ tuscany/java/sca/modules/policy-builder/pom.xml Mon Sep 14 22:57:46 2009
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<project>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.tuscany.sca</groupId>
+        <artifactId>tuscany-modules</artifactId>
+        <version>2.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <artifactId>tuscany-policy-builder</artifactId>
+    <name>Apache Tuscany SCA Policy Attachment Builder</name>
+
+    <dependencies>
+      
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-assembly</artifactId>
+            <version>2.0-SNAPSHOT</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-assembly-xml</artifactId>
+            <version>2.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-definitions-xml</artifactId>
+            <version>2.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-implementation-java</artifactId>
+            <version>2.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+                
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-contribution</artifactId>
+            <version>2.0-SNAPSHOT</version>
+        </dependency>
+        
+                
+    </dependencies>
+
+</project>

Propchange: tuscany/java/sca/modules/policy-builder/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/policy-builder/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java?rev=814899&view=auto
==============================================================================
--- tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java (added)
+++ tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java Mon Sep 14 22:57:46 2009
@@ -0,0 +1,117 @@
+/*
+ * 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.policy.builder.impl;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
+import org.apache.tuscany.sca.common.xml.stax.StAXHelper;
+import org.apache.tuscany.sca.common.xml.xpath.XPathHelper;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.definitions.Definitions;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySubject;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * A composite builder that computes policy sets based on attached intents and policy sets.
+ * Useful if you want to build the model without making any runtime decisions such as
+ * reference/services matching
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyAttachmentBuilderImpl implements CompositeBuilder {
+    private XMLOutputFactory xmlOutputFactory;
+    private StAXHelper staxHelper;
+    private DOMHelper domHelper;
+    private XPathHelper xpathHelper;
+    private StAXArtifactProcessor processor;
+
+    public PolicyAttachmentBuilderImpl(ExtensionPointRegistry registry) {
+        xmlOutputFactory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(XMLOutputFactory.class);
+        domHelper = DOMHelper.getInstance(registry);
+        xpathHelper = XPathHelper.getInstance(registry);
+        staxHelper = StAXHelper.getInstance(registry);
+        StAXArtifactProcessorExtensionPoint processors =
+            registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+        processor = processors.getProcessor(Composite.class);
+    }
+
+    public String getID() {
+        return "org.apache.tuscany.sca.policy.builder.PolicyAttachmentBuilder";
+    }
+
+    public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException {
+        try {
+            applyXPath(composite, definitions, monitor);
+        } catch (Exception e) {
+            throw new CompositeBuilderException(e);
+        }
+    }
+
+    private void applyXPath(Composite composite, Definitions definitions, Monitor monitor) throws Exception {
+        // First write the composite into a DOM document so that we can apply the xpath
+        StringWriter sw = new StringWriter();
+        XMLStreamWriter writer = staxHelper.createXMLStreamWriter(sw);
+        // Write the composite into a DOM document
+        processor.write(composite, writer);
+        writer.close();
+
+        Document document = domHelper.load(sw.toString());
+
+        for (PolicySet ps : definitions.getPolicySets()) {
+            XPathExpression exp = ps.getAttachToXPathExpression();
+            if (exp != null) {
+                NodeList nodes = (NodeList)exp.evaluate(document, XPathConstants.NODESET);
+                for (int i = 0; i < nodes.getLength(); i++) {
+                    Node node = nodes.item(i);
+                    // The node can be a component, service, reference or binding
+                    node.getNamespaceURI();
+                    // Use the node to find the corresponding element in the java model
+                }
+            }
+        }
+    }
+
+    /**
+     * Look up the corresponding Java model within the composite based on the DOM node
+     * @param composite
+     * @param node
+     * @return
+     */
+    private PolicySubject lookup(Composite composite, Node node) {
+        return null;
+    }
+
+}

Propchange: tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/policy-builder/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.CompositeBuilder
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-builder/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.CompositeBuilder?rev=814899&view=auto
==============================================================================
--- tuscany/java/sca/modules/policy-builder/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.CompositeBuilder (added)
+++ tuscany/java/sca/modules/policy-builder/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.CompositeBuilder Mon Sep 14 22:57:46 2009
@@ -0,0 +1,17 @@
+# 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. 
+org.apache.tuscany.sca.policy.builder.impl.PolicyAttachmentBuilderImpl;id=org.apache.tuscany.sca.policy.builder.PolicyAttachmentBuilder

Added: tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/MockPolicy.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/MockPolicy.java?rev=814899&view=auto
==============================================================================
--- tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/MockPolicy.java (added)
+++ tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/MockPolicy.java Mon Sep 14 22:57:46 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.policy.builder.impl;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Mocked Policy
+ */
+public class MockPolicy {
+    public QName getName() {
+        return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+    }
+
+    public boolean isUnresolved() {
+        return false;
+    }
+
+    public void setUnresolved(boolean unresolved) {
+    }
+
+}

Propchange: tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/MockPolicy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/MockPolicy.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentTestCase.java?rev=814899&view=auto
==============================================================================
--- tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentTestCase.java (added)
+++ tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentTestCase.java Mon Sep 14 22:57:46 2009
@@ -0,0 +1,92 @@
+/*
+ * 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.policy.builder.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.definitions.Definitions;
+import org.apache.tuscany.sca.monitor.DefaultMonitorFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.junit.Test;
+
+/**
+ * Test reading SCA XML assembly documents.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class PolicyAttachmentTestCase {
+
+    private StAXArtifactProcessor<Object> staxProcessor;
+    private Monitor monitor;
+
+    @Test
+    public void testBuild() throws FactoryConfigurationError, IOException, XMLStreamException,
+        ContributionReadException, CompositeBuilderException {
+        DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+        // Create a monitor
+        UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+        MonitorFactory monitorFactory = new DefaultMonitorFactory();
+        if (monitorFactory != null) {
+            monitor = monitorFactory.createMonitor();
+            utilities.addUtility(monitorFactory);
+        }
+        StAXArtifactProcessorExtensionPoint staxProcessors =
+            extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+        staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor);
+        staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
+
+        URL url = getClass().getResource("test_definitions.xml");
+        InputStream urlStream = url.openStream();
+        XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream);
+        reader.nextTag();
+
+        Definitions definitions = (Definitions)staxProcessor.read(reader);
+        reader.close();
+
+        url = getClass().getResource("Calculator.composite");
+        urlStream = url.openStream();
+        reader = inputFactory.createXMLStreamReader(urlStream);
+        reader.nextTag();
+
+        Composite composite = (Composite)staxProcessor.read(reader);
+        reader.close();
+
+        PolicyAttachmentBuilderImpl builder = new PolicyAttachmentBuilderImpl(extensionPoints);
+        builder.build(composite, definitions, monitor);
+    }
+
+}

Propchange: tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/TestPolicyProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/TestPolicyProcessor.java?rev=814899&view=auto
==============================================================================
--- tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/TestPolicyProcessor.java (added)
+++ tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/TestPolicyProcessor.java Mon Sep 14 22:57:46 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.policy.builder.impl;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * A PolicyProcessor used for testing.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestPolicyProcessor implements StAXArtifactProcessor<MockPolicy> {
+    public QName getArtifactType() {
+        return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+    }
+
+    public MockPolicy read(XMLStreamReader arg0) throws ContributionReadException, XMLStreamException {
+        return new MockPolicy();
+    }
+
+    public void write(MockPolicy arg0, XMLStreamWriter arg1) throws ContributionWriteException, XMLStreamException {
+    }
+
+    public Class<MockPolicy> getModelType() {
+        return MockPolicy.class;
+    }
+
+    public void resolve(MockPolicy arg0, ModelResolver arg1) throws ContributionResolveException {
+
+    }
+
+}

Propchange: tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/TestPolicyProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/TestPolicyProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Calculator.composite
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Calculator.composite?rev=814899&view=auto
==============================================================================
--- tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Calculator.composite (added)
+++ tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Calculator.composite Mon Sep 14 22:57:46 2009
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+           targetNamespace="http://sample"
+           xmlns:sample="http://sample"
+           name="Calculator">
+
+    <component name="CalculatorServiceComponent" requires="confidentiality">
+		<implementation.java class="calculator.CalculatorServiceImpl" xmlns:test="http://test" requiers="test:TestIntentOne"/>
+        <reference name="addService" target="AddServiceComponent" />
+        <reference name="subtractService" target="SubtractServiceComponent" />
+        <reference name="multiplyService" target="MultiplyServiceComponent" />
+        <reference name="divideService" target="DivideServiceComponent" />
+    </component>
+
+    <component name="AddServiceComponent">
+        <implementation.java class="calculator.AddServiceImpl"/>
+    </component>
+
+    <component name="SubtractServiceComponent">
+        <implementation.java class="calculator.SubtractServiceImpl"/>
+    </component>
+
+    <component name="MultiplyServiceComponent">
+        <implementation.java class="calculator.MultiplyServiceImpl"/>
+    </component>
+
+    <component name="DivideServiceComponent">
+        <implementation.java class="calculator.DivideServiceImpl"/>
+    </component>
+
+</composite>

Propchange: tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Calculator.composite
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Calculator.composite
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/test_definitions.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/test_definitions.xml?rev=814899&view=auto
==============================================================================
--- tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/test_definitions.xml (added)
+++ tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/test_definitions.xml Mon Sep 14 22:57:46 2009
@@ -0,0 +1,207 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * 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.    
+-->
+<definitions xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" targetNamespace="http://test"
+    xmlns:test="http://test" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903">
+
+    <!-- Extension Types Metadata -->
+    <implementationType type="sca:implementation.java" alwaysProvides="test:logging" mayProvide="test:tracing" />
+    <bindingType type="sca:binding.ws" alwaysProvides="test:confidentiality" mayProvide="test:integrity" />
+
+    <!-- Intents and Policysets to assume targetnamespace -->
+    <intent name="TestIntentOne" constrains="sca:binding">
+        <description>
+            Test Intent
+             </description>
+    </intent>
+
+    <intent name="TestIntentTwo" constrains="sca:binding" requires="test:TestIntentOne">
+        <description>
+            Protect messages from unauthorized reading or modification
+             </description>
+    </intent>
+
+    <policySet name="TestPolicySetOne" provides="test:TestIntentOne" appliesTo="sca:binding.ws"
+        attachTo = "//sca:component[@name='CalculatorServiceComponent']/sca:reference[@name='addService']"
+        xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+        <wsp:PolicyAttachment>
+            <!-- policy expression and policy subject for
+                 "basic authentication" -->
+        </wsp:PolicyAttachment>
+        <wsp:PolicyAttachment>
+            <!-- policy expression and policy subject for
+                "reliability" -->
+        </wsp:PolicyAttachment>
+    </policySet>
+
+    <!-- POLICY SETS -->
+    <policySet name="SecureReliablePolicy" provides="test:confidentiality.transport test:integrity" appliesTo="sca:binding.ws"
+        xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+        <wsp:PolicyAttachment>
+            <!-- policy expression and policy subject for
+                 "basic authentication" -->
+        </wsp:PolicyAttachment>
+        <wsp:PolicyAttachment>
+            <!-- policy expression and policy subject for
+                "reliability" -->
+        </wsp:PolicyAttachment>
+    </policySet>
+
+    <policySet name="SecureMessagingPolicies" provides="test:confidentiality" appliesTo="binding.ws"
+        xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+        <intentMap provides="test:confidentiality">
+            <qualifier name="transport">
+                <wsp:PolicyAttachment>
+                    <!-- policy expression and policy subject for "transport" alternative -->
+                </wsp:PolicyAttachment>
+                <wsp:PolicyAttachment>...</wsp:PolicyAttachment>
+            </qualifier>
+            <qualifier name="message">
+                <wsp:PolicyAttachment>
+                    <!-- policy expression and policy subject for "message" alternative" -->
+                </wsp:PolicyAttachment>
+            </qualifier>
+        </intentMap>
+    </policySet>
+
+    <policySet name="SecurityPolicy" provides="test:confidentiality" appliesTo="binding.ws"
+        xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+        <intentMap provides="test:confidentiality">
+            <qualifier name="message">
+                <wsp:PolicyAttachment>
+                    <!-- policy attachment for body encryption -->
+                </wsp:PolicyAttachment>
+                <wsp:PolicyAttachment>
+                    <!-- policy attachment for whole message encryption -->
+                </wsp:PolicyAttachment>
+            </qualifier>
+            <qualifier name="transport">
+                <wsp:PolicyAttachment>
+                    <!-- policy attachment for transport encryption -->
+                </wsp:PolicyAttachment>
+            </qualifier>
+        </intentMap>
+    </policySet>
+
+    <policySet name="BasicAuthMsgProtSecurity" provides="test:authentication test:confidentiality" appliesTo="binding.ws"
+        xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903">
+        <policySetReference name="test:AuthenticationPolicies" />
+        <policySetReference name="test:ConfidentialityPolicies" />
+    </policySet>
+
+    <policySet name="AuthenticationPolicies" provides="test:authentication" appliesTo="binding.ws"
+        xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+        <wsp:PolicyAttachment>
+            <!-- policy expression and policy subject for "basic
+        authentication" -->
+        </wsp:PolicyAttachment>
+    </policySet>
+
+    <policySet name="ConfidentialityPolicies" provides="test:confidentiality" appliesTo="binding.ws"
+        xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+        <intentMap provides="test:confidentiality">
+            <qualifier name="transport">
+                <wsp:PolicyAttachment>
+                    <!-- policy expression and policy subject for "transport"
+                alternative -->
+                </wsp:PolicyAttachment>
+                <wsp:PolicyAttachment>...</wsp:PolicyAttachment>
+            </qualifier>
+            <qualifier name="message">
+                <wsp:PolicyAttachment>
+                    <!-- policy expression and policy subject for "message"
+                alternative" -->
+                    ...
+                </wsp:PolicyAttachment>
+            </qualifier>
+        </intentMap>
+    </policySet>
+
+    <policySet name="SecureWSPolicy" provides="test:confidentiality" appliesTo="sca:binding.ws"
+        xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:sp="http://schemas.xmlsoap.org/ws/2002/12/secext"
+        xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+        <wsp:Policy>
+            <wsp:ExactlyOne>
+                <wsp:All>
+                    <sp:SecurityToken>
+                        <sp:TokenType>sp:X509v3</sp:TokenType>
+                    </sp:SecurityToken>
+                    <sp:UsernameToken />
+                    <sp:SignedParts />
+                    <sp:EncryptedParts>
+                        <sp:Body />
+                    </sp:EncryptedParts>
+                    <sp:TransportBinding>
+                        <sp:IncludeTimeStamp />
+                    </sp:TransportBinding>
+                </wsp:All>
+            </wsp:ExactlyOne>
+        </wsp:Policy>
+    </policySet>
+
+    <!-- profile intent -->
+    <intent name="reliableMessageProtection" constrains="sca:binding" requires="test:messageProtection">
+        <description>
+            Protect messages from unauthorized reading or modification
+             </description>
+    </intent>
+
+    <intent name="messageProtection" constrains="sca:binding" requires="test:confidentiality test:integrity">
+        <description>
+            Protect messages from unauthorized reading or modification
+             </description>
+    </intent>
+
+    <!-- simple intent -->
+    <intent name="confidentiality" constrains="sca:binding">
+        <description>
+            Communitcation thro this binding must prevent
+            unauthorized users from reading the messages.
+        </description>
+        <qualifier name="transport" />
+        <qualifier name="message" default="true" />
+    </intent>
+
+    <intent name="integrity" constrains="sca:binding">
+        <description>
+            Communitcation thro this binding must prevent
+            unauthorized modification of the messages.
+             </description>
+    </intent>
+
+    <intent name="authentication" constrains="sca:binding">
+        <description>
+            Communitcation thro this binding required
+            Authentication.
+             </description>
+    </intent>
+
+    <intent name="logging" constrains="sca:implementation">
+        <description>
+            All messages to and from this implementation must be logged
+             </description>
+    </intent>
+
+    <intent name="tracing" constrains="sca:implementation.java">
+        <description>
+            Need to figure out some description for this 
+             </description>
+    </intent>
+
+</definitions>
\ No newline at end of file

Propchange: tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/test_definitions.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/test_definitions.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date