tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sl...@apache.org
Subject svn commit: r657881 [8/9] - in /incubator/tuscany/java/sca: modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ modules/assembly-xml/src/main/resources/ modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ modules...
Date Mon, 19 May 2008 17:49:08 GMT
Modified: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java?rev=657881&r1=657880&r2=657881&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java Mon May 19 10:49:04 2008
@@ -1,416 +1,465 @@
-/*
- * 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.xml;
-
-import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
-import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
-
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
-import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
-import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.contribution.service.ContributionReadException;
-import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
-import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
-import org.apache.tuscany.sca.policy.Intent;
-import org.apache.tuscany.sca.policy.PolicyFactory;
-import org.apache.tuscany.sca.policy.PolicySet;
-
-
-/**
- * Processor for handling XML models of PolicySet definitions
- *
- * @version $Rev$ $Date$
- */
-public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<PolicySet>, PolicyConstants {
-
-    private PolicyFactory policyFactory;
-    private StAXArtifactProcessor<Object> extensionProcessor;
-    private XPathFactory xpathFactory = XPathFactory.newInstance();
-    
-    public PolicySetProcessor(ModelFactoryExtensionPoint modelFactories, StAXArtifactProcessor<Object> extensionProcessor) {
-        this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
-        this.extensionProcessor = extensionProcessor;
-    }
-    
-    public PolicySetProcessor(PolicyFactory policyFactory, StAXArtifactProcessor<Object> extensionProcessor) {
-        this.policyFactory = policyFactory;
-        this.extensionProcessor = extensionProcessor;
-    }
-
-    public PolicySet read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
-        String policySetName = reader.getAttributeValue(null, NAME);
-        
-        PolicySet policySet = policyFactory.createPolicySet();
-        policySet.setName(new QName(policySetName));
-        String appliesTo = reader.getAttributeValue(null, APPLIES_TO);
-        String alwaysAppliesTo = reader.getAttributeValue(TUSCANY_NS, ALWAYS_APPLIES_TO);
-        
-        //TODO: with 1.0 version of specs the applies to xpath is given related to the immediate
-        //parent whereas the runtime evaluates the xpath aginst the composite element.  What the runtime
-        //is doing is what the future version of the specs could be tending towards.  When that happens
-        //this 'if' must be deleted
-        if ( appliesTo != null && !appliesTo.startsWith("/") ) {
-            appliesTo = "//" + appliesTo;
-        }
-        
-        if ( alwaysAppliesTo != null && !alwaysAppliesTo.startsWith("/") ) {
-            alwaysAppliesTo = "//" + alwaysAppliesTo;
-        }
-        
-        policySet.setAppliesTo(appliesTo);
-        policySet.setAlwaysAppliesTo(alwaysAppliesTo);
-
-        XPath path = xpathFactory.newXPath(); 
-        path.setNamespaceContext(reader.getNamespaceContext());
-        try {
-            if (appliesTo != null) {
-                policySet.setAppliesToXPathExpression(path.compile(appliesTo));
-            }
-            if (alwaysAppliesTo != null) {
-                policySet.setAlwaysAppliesToXPathExpression(path.compile(alwaysAppliesTo));
-            }
-        } catch (XPathExpressionException e) {
-            throw new ContributionReadException(e);
-        }  
-        
-        readProvidedIntents(policySet, reader);
-        
-        int event = reader.getEventType();
-        QName name = null;
-        reader.next();
-        while (reader.hasNext()) {
-            event = reader.getEventType();
-            switch (event) {
-                case START_ELEMENT : {
-                    name = reader.getName();
-                    if ( POLICY_INTENT_MAP_QNAME.equals(name) ) {
-                        Intent mappedIntent = policyFactory.createIntent();
-                        mappedIntent.setName(getQName(reader, PROVIDES));
-                        if ( policySet.getProvidedIntents().contains(mappedIntent) ) {
-                            readIntentMap(reader, policySet, mappedIntent);
-                        } else {
-                            throw new ContributionReadException("Intent Map provides for Intent not spcified as provided by parent PolicySet - " + policySetName);
-                        }
-                    } else if ( POLICY_SET_REFERENCE_QNAME.equals(name) )  {
-                        PolicySet referredPolicySet = policyFactory.createPolicySet();
-                        referredPolicySet.setName(getQName(reader, NAME));
-                        policySet.getReferencedPolicySets().add(referredPolicySet);
-                    } /*else if ( WS_POLICY_QNAME.equals(name) )  {
-                        OMElement policyElement = loadElement(reader);
-                        org.apache.neethi.Policy wsPolicy = PolicyEngine.getPolicy(policyElement);
-                        policySet.getPolicies().add(wsPolicy);
-                    } */ else {
-                        Object extension = extensionProcessor.read(reader);
-                        if ( extension != null ) {
-                            policySet.getPolicies().add(extension);
-                        }
-                    }
-                    break;
-                }
-            }
-            if ( event == END_ELEMENT ) {
-                if ( POLICY_SET_QNAME.equals(reader.getName()) ) {
-                    break;
-                } 
-            }
-            
-            //Read the next element
-            if (reader.hasNext()) {
-                reader.next();
-            }
-        }
-        return policySet;
-    }
-    
-    
-    public void readIntentMap(XMLStreamReader reader, PolicySet policySet, Intent mappedIntent) throws ContributionReadException {
-        QName name = reader.getName();
-        Map<Intent, List<Object>> mappedPolicies = policySet.getMappedPolicies();
-        if ( POLICY_INTENT_MAP_QNAME.equals(name) ) {
-            //Intent mappedIntent = policyFactory.createIntent();
-            //mappedIntent.setName(getQName(reader, PROVIDES));
-            String defaultQualifier = getString(reader, DEFAULT);
-            
-            String qualifierName = null;
-            String qualfiedIntentName = null;
-            Intent qualifiedIntent = null;
-        
-            int event = reader.getEventType();
-            try {
-                reader.next();
-                while (reader.hasNext()) {
-                    event = reader.getEventType();
-                    switch (event) {
-                        case START_ELEMENT : {
-                            name = reader.getName();
-                            if ( POLICY_INTENT_MAP_QUALIFIER_QNAME.equals(name)) {
-                                qualifierName = getString(reader, NAME);
-                                qualfiedIntentName = mappedIntent.getName().getLocalPart() + 
-                                                            QUALIFIER + qualifierName;
-                                qualifiedIntent = policyFactory.createIntent();
-                                qualifiedIntent.setName(new QName(mappedIntent.getName().getNamespaceURI(),
-                                                                  qualfiedIntentName)); 
-                            } else if ( POLICY_INTENT_MAP_QNAME.equals(name) ) {
-                                QName providedIntent = getQName(reader, PROVIDES);
-                                if ( qualifierName.equals(providedIntent.getLocalPart()) ) {
-                                    readIntentMap(reader, policySet, qualifiedIntent);
-                                } else {
-                                    throw new ContributionReadException("Intent provided by IntentMap " + 
-                                                                    providedIntent + " does not match parent qualifier " + qualifierName +
-                                                                    " in policyset - " + policySet);
-                                }
-                            }/* else if ( WS_POLICY_QNAME.equals(name) )  {
-                                OMElement policyElement = loadElement(reader);
-                                Policy wsPolicy = PolicyEngine.getPolicy(policyElement);
-                                policySet.getPolicies().add(wsPolicy);
-                                
-                                List<Object> policyList = mappedPolicies.get(qualifiedIntent);
-                                if ( policyList == null ) {
-                                    policyList = new ArrayList<Object>();
-                                    mappedPolicies.put(qualifiedIntent, policyList);
-                                    
-                                    if (qualifierName.equals(defaultQualifier)) {
-                                        mappedPolicies.put(mappedIntent, policyList);
-                                    }
-                                }
-                                policyList.add((Policy)wsPolicy);
-                            }*/ else {
-                                Object extension = extensionProcessor.read(reader);
-                                if ( extension != null ) {
-                                    List<Object> policyList = mappedPolicies.get(qualifiedIntent);
-                                    if ( policyList == null ) {
-                                        policyList = new ArrayList<Object>();
-                                        mappedPolicies.put(qualifiedIntent, policyList);
-                                        
-                                        if (qualifierName.equals(defaultQualifier)) {
-                                            mappedPolicies.put(mappedIntent, policyList);
-                                        }
-                                    }
-                                    policyList.add(extension);
-                                }
-                            }
-                            break;
-                        }
-                        case END_ELEMENT : {
-                            if ( POLICY_INTENT_MAP_QNAME.equals(reader.getName()) ) {
-                                if ( defaultQualifier != null ) {
-                                    String qualifiedIntentName = mappedIntent.getName().getLocalPart() + QUALIFIER + defaultQualifier;
-                                    Intent defaultQualifiedIntent = policyFactory.createIntent();
-                                    defaultQualifiedIntent.setName(new QName(mappedIntent.getName().getNamespaceURI(),
-                                                                             qualifiedIntentName));
-                                    List<Object> policyList = mappedPolicies.get(defaultQualifiedIntent);
-                                    if ( policyList != null ) {
-                                        mappedPolicies.put(mappedIntent, policyList);
-                                    } else {
-                                        throw new ContributionReadException("Unable to map policies for default qualifier in IntentMap for - " +
-                                                                            mappedIntent + " in policy set - " + policySet);
-                                    }
-                                    defaultQualifier = null;
-                                }
-                            } 
-                            break;
-                        }
-                    }
-                    if ( event == END_ELEMENT && POLICY_INTENT_MAP_QNAME.equals(reader.getName()) ) {
-                        break;
-                    }
-                    //Read the next element
-                    if (reader.hasNext()) {
-                        reader.next();
-                    }
-                }
-            }  catch (XMLStreamException e) {
-                throw new ContributionReadException(e);
-            }
-        }
-    }
-    
-    public void write(PolicySet policySet, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
-
-        // Write an <sca:policySet>
-        writer.writeStartElement(SCA10_NS, POLICY_SET);
-        writer.writeNamespace(policySet.getName().getPrefix(), policySet.getName().getNamespaceURI());
-        writer.writeAttribute(NAME, 
-                              policySet.getName().getPrefix() + COLON + policySet.getName().getLocalPart());
-        writer.writeAttribute(APPLIES_TO, policySet.getAppliesTo());
-        writer.writeAttribute(TUSCANY_NS, ALWAYS_APPLIES_TO, policySet.getAlwaysAppliesTo());
-        
-        writeProvidedIntents(policySet, writer);
-        
-        writer.writeEndElement();
-    }
-    
-    private void readProvidedIntents(PolicySet policySet, XMLStreamReader reader) {
-        String value = reader.getAttributeValue(null, PROVIDES);
-        if (value != null) {
-            List<Intent> providedIntents = policySet.getProvidedIntents();
-            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
-                QName qname = getQNameValue(reader, tokens.nextToken());
-                Intent intent = policyFactory.createIntent();
-                intent.setName(qname);
-                providedIntents.add(intent);
-            }
-        }
-    }
-    
-    private void writeProvidedIntents(PolicySet policySet, XMLStreamWriter writer) throws XMLStreamException {
-        if (policySet.getProvidedIntents() != null && 
-            policySet.getProvidedIntents().size() > 0) {
-            StringBuffer sb = new StringBuffer();
-            for (Intent providedIntents : policySet.getProvidedIntents()) {
-                sb.append(providedIntents.getName());
-                sb.append(" ");
-            }
-            writer.writeAttribute(PolicyConstants.PROVIDES, sb.toString());
-        }
-    }
-
-   private void resolvePolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
-       boolean unresolved = false;
-       for ( Object o : policySet.getPolicies() ) {
-           extensionProcessor.resolve(o, resolver);
-           /*if ( o instanceof Policy && ((Policy)o).isUnresolved() ) {
-              unresolved = true;
-           }*/
-       }
-       policySet.setUnresolved(unresolved);
-   }
-   
-   
-    
-    public QName getArtifactType() {
-        return POLICY_SET_QNAME;
-    }
-    
-    public Class<PolicySet> getModelType() {
-        return PolicySet.class;
-    }
-    
-    private void resolveProvidedIntents(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
-        if (policySet != null) {
-            //resolve all provided intents
-            List<Intent> providedIntents = new ArrayList<Intent>();
-            for (Intent providedIntent : policySet.getProvidedIntents()) {
-                if (providedIntent.isUnresolved()) {
-                    Intent resolvedProvidedIntent = resolver.resolveModel(Intent.class, providedIntent);
-                    if (resolvedProvidedIntent != null) {
-                        providedIntents.add(resolvedProvidedIntent);
-                    } else {
-                        throw new ContributionResolveException("Provided Intent - " + providedIntent
-                            + " not found for PolicySet "
-                            + policySet);
-
-                    }
-                } else {
-                    providedIntents.add(providedIntent);
-                }
-            }
-            policySet.getProvidedIntents().clear();
-            policySet.getProvidedIntents().addAll(providedIntents);
-        }
-     }
-    
-    private void resolveIntentsInMappedPolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
-        Map<Intent, List<Object>> mappedPolicies = new Hashtable<Intent, List<Object>>();
-        for (Map.Entry<Intent, List<Object>> entry : policySet.getMappedPolicies().entrySet()) {
-            Intent mappedIntent = entry.getKey();
-            if (mappedIntent.isUnresolved()) {
-                Intent resolvedMappedIntent = resolver.resolveModel(Intent.class, mappedIntent);
-    
-                if (resolvedMappedIntent != null) {
-                    mappedPolicies.put(resolvedMappedIntent, entry.getValue());
-                } else {
-                    throw new ContributionResolveException("Mapped Intent - " + mappedIntent
-                        + " not found for PolicySet "
-                        + policySet);
-    
-                }
-            } else {
-                mappedPolicies.put(mappedIntent, entry.getValue());
-            }
-        }
-
-        policySet.getMappedPolicies().clear();
-        policySet.getMappedPolicies().putAll(mappedPolicies);
-    }
-    
-    private void resolveReferredPolicySets(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
-    
-        List<PolicySet> referredPolicySets = new ArrayList<PolicySet>();
-        for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) {
-            if (referredPolicySet.isUnresolved()) {
-                PolicySet resolvedReferredPolicySet = resolver.resolveModel(PolicySet.class, referredPolicySet);
-                if (resolvedReferredPolicySet != null) {
-                    referredPolicySets.add(resolvedReferredPolicySet);
-                } else {
-                    throw new ContributionResolveException("Referred PolicySet - " + referredPolicySet
-                        + "not found for PolicySet - "
-                        + policySet);
-                }
-            } else {
-                referredPolicySets.add(referredPolicySet);
-            }
-        }
-        policySet.getReferencedPolicySets().clear();
-        policySet.getReferencedPolicySets().addAll(referredPolicySets);
-    }
-    
-    private void includeReferredPolicySets(PolicySet policySet, PolicySet referredPolicySet) {
-        for (PolicySet furtherReferredPolicySet : referredPolicySet.getReferencedPolicySets()) {
-            includeReferredPolicySets(referredPolicySet, furtherReferredPolicySet);
-        }
-        policySet.getPolicies().addAll(referredPolicySet.getPolicies());
-        policySet.getMappedPolicies().putAll(referredPolicySet.getMappedPolicies());
-    }
-    
-    public void resolve(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
-        resolveProvidedIntents(policySet, resolver);
-        resolveIntentsInMappedPolicies(policySet, resolver);
-        resolveReferredPolicySets(policySet, resolver);
-        
-        for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) {
-            includeReferredPolicySets(policySet, referredPolicySet);
-        }
-        
-        if ( policySet.isUnresolved() ) {
-            //resolve the policy attachments
-            resolvePolicies(policySet, resolver);
-             
-            if ( !policySet.isUnresolved() ) {
-                 resolver.addModel(policySet);
-            }
-        }
-     }   
- }
+/*
+ * 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.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+
+/**
+ * Processor for handling XML models of PolicySet definitions
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<PolicySet>, PolicyConstants {
+
+    private PolicyFactory policyFactory;
+    private StAXArtifactProcessor<Object> extensionProcessor;
+    private XPathFactory xpathFactory = XPathFactory.newInstance();
+    private Monitor monitor;
+    
+    public PolicySetProcessor(ModelFactoryExtensionPoint modelFactories, 
+    						  StAXArtifactProcessor<Object> extensionProcessor,
+    						  Monitor monitor) {
+        this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
+        this.extensionProcessor = extensionProcessor;
+        this.monitor = monitor;
+    }
+    
+    public PolicySetProcessor(PolicyFactory policyFactory, 
+    						  StAXArtifactProcessor<Object> extensionProcessor,
+    						  Monitor monitor) {
+        this.policyFactory = policyFactory;
+        this.extensionProcessor = extensionProcessor;
+        this.monitor = monitor;
+    }
+    
+    /**
+     * Report a exception.
+     * 
+     * @param problems
+     * @param message
+     * @param model
+     */
+     private void error(String message, Object model, Exception ex) {
+    	 if (monitor != null) {
+    		 Problem problem = new ProblemImpl(this.getClass().getName(), "policy-xml-validation-messages", Severity.ERROR, model, message, ex);
+    	     monitor.problem(problem);
+    	 }        
+     }
+    
+    /**
+     * Report a error.
+     * 
+     * @param problems
+     * @param message
+     * @param model
+     */
+     private void error(String message, Object model, Object... messageParameters) {
+    	 if (monitor != null) {
+    		 Problem problem = new ProblemImpl(this.getClass().getName(), "policy-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+    	     monitor.problem(problem);
+    	 }        
+     }
+
+    public PolicySet read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+        String policySetName = reader.getAttributeValue(null, NAME);
+        
+        PolicySet policySet = policyFactory.createPolicySet();
+        policySet.setName(new QName(policySetName));
+        String appliesTo = reader.getAttributeValue(null, APPLIES_TO);
+        String alwaysAppliesTo = reader.getAttributeValue(TUSCANY_NS, ALWAYS_APPLIES_TO);
+        
+        //TODO: with 1.0 version of specs the applies to xpath is given related to the immediate
+        //parent whereas the runtime evaluates the xpath aginst the composite element.  What the runtime
+        //is doing is what the future version of the specs could be tending towards.  When that happens
+        //this 'if' must be deleted
+        if ( appliesTo != null && !appliesTo.startsWith("/") ) {
+            appliesTo = "//" + appliesTo;
+        }
+        
+        if ( alwaysAppliesTo != null && !alwaysAppliesTo.startsWith("/") ) {
+            alwaysAppliesTo = "//" + alwaysAppliesTo;
+        }
+        
+        policySet.setAppliesTo(appliesTo);
+        policySet.setAlwaysAppliesTo(alwaysAppliesTo);
+
+        XPath path = xpathFactory.newXPath(); 
+        path.setNamespaceContext(reader.getNamespaceContext());
+        try {
+            if (appliesTo != null) {
+                policySet.setAppliesToXPathExpression(path.compile(appliesTo));
+            }
+            if (alwaysAppliesTo != null) {
+                policySet.setAlwaysAppliesToXPathExpression(path.compile(alwaysAppliesTo));
+            }
+        } catch (XPathExpressionException e) {
+        	ContributionReadException ce = new ContributionReadException(e);
+        	error("ContributionReadException", policySet, ce);
+            throw ce;
+        }  
+        
+        readProvidedIntents(policySet, reader);
+        
+        int event = reader.getEventType();
+        QName name = null;
+        reader.next();
+        while (reader.hasNext()) {
+            event = reader.getEventType();
+            switch (event) {
+                case START_ELEMENT : {
+                    name = reader.getName();
+                    if ( POLICY_INTENT_MAP_QNAME.equals(name) ) {
+                        Intent mappedIntent = policyFactory.createIntent();
+                        mappedIntent.setName(getQName(reader, PROVIDES));
+                        if ( policySet.getProvidedIntents().contains(mappedIntent) ) {
+                            readIntentMap(reader, policySet, mappedIntent);
+                        } else {
+                        	error("IntentNotSpecified", policySet, policySetName);
+                            throw new ContributionReadException("Intent Map provides for Intent not specified as provided by parent PolicySet - " + policySetName);
+                        }
+                    } else if ( POLICY_SET_REFERENCE_QNAME.equals(name) )  {
+                        PolicySet referredPolicySet = policyFactory.createPolicySet();
+                        referredPolicySet.setName(getQName(reader, NAME));
+                        policySet.getReferencedPolicySets().add(referredPolicySet);
+                    } /*else if ( WS_POLICY_QNAME.equals(name) )  {
+                        OMElement policyElement = loadElement(reader);
+                        org.apache.neethi.Policy wsPolicy = PolicyEngine.getPolicy(policyElement);
+                        policySet.getPolicies().add(wsPolicy);
+                    } */ else {
+                        Object extension = extensionProcessor.read(reader);
+                        if ( extension != null ) {
+                            policySet.getPolicies().add(extension);
+                        }
+                    }
+                    break;
+                }
+            }
+            if ( event == END_ELEMENT ) {
+                if ( POLICY_SET_QNAME.equals(reader.getName()) ) {
+                    break;
+                } 
+            }
+            
+            //Read the next element
+            if (reader.hasNext()) {
+                reader.next();
+            }
+        }
+        return policySet;
+    }
+    
+    
+    public void readIntentMap(XMLStreamReader reader, PolicySet policySet, Intent mappedIntent) throws ContributionReadException {
+        QName name = reader.getName();
+        Map<Intent, List<Object>> mappedPolicies = policySet.getMappedPolicies();
+        if ( POLICY_INTENT_MAP_QNAME.equals(name) ) {
+            //Intent mappedIntent = policyFactory.createIntent();
+            //mappedIntent.setName(getQName(reader, PROVIDES));
+            String defaultQualifier = getString(reader, DEFAULT);
+            
+            String qualifierName = null;
+            String qualfiedIntentName = null;
+            Intent qualifiedIntent = null;
+        
+            int event = reader.getEventType();
+            try {
+                reader.next();
+                while (reader.hasNext()) {
+                    event = reader.getEventType();
+                    switch (event) {
+                        case START_ELEMENT : {
+                            name = reader.getName();
+                            if ( POLICY_INTENT_MAP_QUALIFIER_QNAME.equals(name)) {
+                                qualifierName = getString(reader, NAME);
+                                qualfiedIntentName = mappedIntent.getName().getLocalPart() + 
+                                                            QUALIFIER + qualifierName;
+                                qualifiedIntent = policyFactory.createIntent();
+                                qualifiedIntent.setName(new QName(mappedIntent.getName().getNamespaceURI(),
+                                                                  qualfiedIntentName)); 
+                            } else if ( POLICY_INTENT_MAP_QNAME.equals(name) ) {
+                                QName providedIntent = getQName(reader, PROVIDES);
+                                if ( qualifierName.equals(providedIntent.getLocalPart()) ) {
+                                    readIntentMap(reader, policySet, qualifiedIntent);
+                                } else {
+                                	error("IntentMapDoesNotMatch", providedIntent, providedIntent, qualifierName, policySet);
+                                    throw new ContributionReadException("Intent provided by IntentMap " + 
+                                                                    providedIntent + " does not match parent qualifier " + qualifierName +
+                                                                    " in policyset - " + policySet);
+                                }
+                            }/* else if ( WS_POLICY_QNAME.equals(name) )  {
+                                OMElement policyElement = loadElement(reader);
+                                Policy wsPolicy = PolicyEngine.getPolicy(policyElement);
+                                policySet.getPolicies().add(wsPolicy);
+                                
+                                List<Object> policyList = mappedPolicies.get(qualifiedIntent);
+                                if ( policyList == null ) {
+                                    policyList = new ArrayList<Object>();
+                                    mappedPolicies.put(qualifiedIntent, policyList);
+                                    
+                                    if (qualifierName.equals(defaultQualifier)) {
+                                        mappedPolicies.put(mappedIntent, policyList);
+                                    }
+                                }
+                                policyList.add((Policy)wsPolicy);
+                            }*/ else {
+                                Object extension = extensionProcessor.read(reader);
+                                if ( extension != null ) {
+                                    List<Object> policyList = mappedPolicies.get(qualifiedIntent);
+                                    if ( policyList == null ) {
+                                        policyList = new ArrayList<Object>();
+                                        mappedPolicies.put(qualifiedIntent, policyList);
+                                        
+                                        if (qualifierName.equals(defaultQualifier)) {
+                                            mappedPolicies.put(mappedIntent, policyList);
+                                        }
+                                    }
+                                    policyList.add(extension);
+                                }
+                            }
+                            break;
+                        }
+                        case END_ELEMENT : {
+                            if ( POLICY_INTENT_MAP_QNAME.equals(reader.getName()) ) {
+                                if ( defaultQualifier != null ) {
+                                    String qualifiedIntentName = mappedIntent.getName().getLocalPart() + QUALIFIER + defaultQualifier;
+                                    Intent defaultQualifiedIntent = policyFactory.createIntent();
+                                    defaultQualifiedIntent.setName(new QName(mappedIntent.getName().getNamespaceURI(),
+                                                                             qualifiedIntentName));
+                                    List<Object> policyList = mappedPolicies.get(defaultQualifiedIntent);
+                                    if ( policyList != null ) {
+                                        mappedPolicies.put(mappedIntent, policyList);
+                                    } else {
+                                    	error("UnableToMapPolicies", mappedPolicies, mappedIntent, policySet);
+                                        throw new ContributionReadException("Unable to map policies for default qualifier in IntentMap for - " +
+                                                                            mappedIntent + " in policy set - " + policySet);
+                                    }
+                                    defaultQualifier = null;
+                                }
+                            } 
+                            break;
+                        }
+                    }
+                    if ( event == END_ELEMENT && POLICY_INTENT_MAP_QNAME.equals(reader.getName()) ) {
+                        break;
+                    }
+                    //Read the next element
+                    if (reader.hasNext()) {
+                        reader.next();
+                    }
+                }
+            }  catch (XMLStreamException e) {
+            	ContributionReadException ce = new ContributionReadException(e);
+            	error("ContributionReadException", reader, ce);
+                throw ce;
+            }
+        }
+    }
+    
+    public void write(PolicySet policySet, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+        // Write an <sca:policySet>
+        writer.writeStartElement(SCA10_NS, POLICY_SET);
+        writer.writeNamespace(policySet.getName().getPrefix(), policySet.getName().getNamespaceURI());
+        writer.writeAttribute(NAME, 
+                              policySet.getName().getPrefix() + COLON + policySet.getName().getLocalPart());
+        writer.writeAttribute(APPLIES_TO, policySet.getAppliesTo());
+        writer.writeAttribute(TUSCANY_NS, ALWAYS_APPLIES_TO, policySet.getAlwaysAppliesTo());
+        
+        writeProvidedIntents(policySet, writer);
+        
+        writer.writeEndElement();
+    }
+    
+    private void readProvidedIntents(PolicySet policySet, XMLStreamReader reader) {
+        String value = reader.getAttributeValue(null, PROVIDES);
+        if (value != null) {
+            List<Intent> providedIntents = policySet.getProvidedIntents();
+            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+                QName qname = getQNameValue(reader, tokens.nextToken());
+                Intent intent = policyFactory.createIntent();
+                intent.setName(qname);
+                providedIntents.add(intent);
+            }
+        }
+    }
+    
+    private void writeProvidedIntents(PolicySet policySet, XMLStreamWriter writer) throws XMLStreamException {
+        if (policySet.getProvidedIntents() != null && 
+            policySet.getProvidedIntents().size() > 0) {
+            StringBuffer sb = new StringBuffer();
+            for (Intent providedIntents : policySet.getProvidedIntents()) {
+                sb.append(providedIntents.getName());
+                sb.append(" ");
+            }
+            writer.writeAttribute(PolicyConstants.PROVIDES, sb.toString());
+        }
+    }
+
+   private void resolvePolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
+       boolean unresolved = false;
+       for ( Object o : policySet.getPolicies() ) {
+           extensionProcessor.resolve(o, resolver);
+           /*if ( o instanceof Policy && ((Policy)o).isUnresolved() ) {
+              unresolved = true;
+           }*/
+       }
+       policySet.setUnresolved(unresolved);
+   }
+   
+   
+    
+    public QName getArtifactType() {
+        return POLICY_SET_QNAME;
+    }
+    
+    public Class<PolicySet> getModelType() {
+        return PolicySet.class;
+    }
+    
+    private void resolveProvidedIntents(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
+        if (policySet != null) {
+            //resolve all provided intents
+            List<Intent> providedIntents = new ArrayList<Intent>();
+            for (Intent providedIntent : policySet.getProvidedIntents()) {
+                if (providedIntent.isUnresolved()) {
+                    Intent resolvedProvidedIntent = resolver.resolveModel(Intent.class, providedIntent);
+                    if (resolvedProvidedIntent != null) {
+                        providedIntents.add(resolvedProvidedIntent);
+                    } else {
+                    	error("ProvidedIntentNotFound", policySet, providedIntent, policySet);
+                        throw new ContributionResolveException("Provided Intent - " + providedIntent
+                            + " not found for PolicySet "
+                            + policySet);
+
+                    }
+                } else {
+                    providedIntents.add(providedIntent);
+                }
+            }
+            policySet.getProvidedIntents().clear();
+            policySet.getProvidedIntents().addAll(providedIntents);
+        }
+     }
+    
+    private void resolveIntentsInMappedPolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
+        Map<Intent, List<Object>> mappedPolicies = new Hashtable<Intent, List<Object>>();
+        for (Map.Entry<Intent, List<Object>> entry : policySet.getMappedPolicies().entrySet()) {
+            Intent mappedIntent = entry.getKey();
+            if (mappedIntent.isUnresolved()) {
+                Intent resolvedMappedIntent = resolver.resolveModel(Intent.class, mappedIntent);
+    
+                if (resolvedMappedIntent != null) {
+                    mappedPolicies.put(resolvedMappedIntent, entry.getValue());
+                } else {
+                	error("MappedIntentNotFound", policySet, mappedIntent, policySet);
+                    throw new ContributionResolveException("Mapped Intent - " + mappedIntent
+                        + " not found for PolicySet "
+                        + policySet);
+    
+                }
+            } else {
+                mappedPolicies.put(mappedIntent, entry.getValue());
+            }
+        }
+
+        policySet.getMappedPolicies().clear();
+        policySet.getMappedPolicies().putAll(mappedPolicies);
+    }
+    
+    private void resolveReferredPolicySets(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
+    
+        List<PolicySet> referredPolicySets = new ArrayList<PolicySet>();
+        for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) {
+            if (referredPolicySet.isUnresolved()) {
+                PolicySet resolvedReferredPolicySet = resolver.resolveModel(PolicySet.class, referredPolicySet);
+                if (resolvedReferredPolicySet != null) {
+                    referredPolicySets.add(resolvedReferredPolicySet);
+                } else {
+                	error("ReferredPolicySetNotFound", policySet, referredPolicySet, policySet);
+                    throw new ContributionResolveException("Referred PolicySet - " + referredPolicySet
+                        + "not found for PolicySet - "
+                        + policySet);
+                }
+            } else {
+                referredPolicySets.add(referredPolicySet);
+            }
+        }
+        policySet.getReferencedPolicySets().clear();
+        policySet.getReferencedPolicySets().addAll(referredPolicySets);
+    }
+    
+    private void includeReferredPolicySets(PolicySet policySet, PolicySet referredPolicySet) {
+        for (PolicySet furtherReferredPolicySet : referredPolicySet.getReferencedPolicySets()) {
+            includeReferredPolicySets(referredPolicySet, furtherReferredPolicySet);
+        }
+        policySet.getPolicies().addAll(referredPolicySet.getPolicies());
+        policySet.getMappedPolicies().putAll(referredPolicySet.getMappedPolicies());
+    }
+    
+    public void resolve(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
+        resolveProvidedIntents(policySet, resolver);
+        resolveIntentsInMappedPolicies(policySet, resolver);
+        resolveReferredPolicySets(policySet, resolver);
+        
+        for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) {
+            includeReferredPolicySets(policySet, referredPolicySet);
+        }
+        
+        if ( policySet.isUnresolved() ) {
+            //resolve the policy attachments
+            resolvePolicies(policySet, resolver);
+             
+            if ( !policySet.isUnresolved() ) {
+                 resolver.addModel(policySet);
+            }
+        }
+     }   
+ }

Modified: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java?rev=657881&r1=657880&r2=657881&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java Mon May 19 10:49:04 2008
@@ -1,44 +1,45 @@
-/*
- * 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.xml;
-
-import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
-import org.apache.tuscany.sca.policy.PolicyFactory;
-import org.apache.tuscany.sca.policy.ProfileIntent;
-
-/**
- * Processor for handling XML models of PolicyIntent definitions that are ProfileIntents
- *
- * @version $Rev$ $Date$
- */
-public class ProfileIntentProcessor extends PolicyIntentProcessor<ProfileIntent> {
-
-    public ProfileIntentProcessor(PolicyFactory policyFactory) {
-        super(policyFactory);
-    }
-    
-    public ProfileIntentProcessor(ModelFactoryExtensionPoint modelFactories) {
-        super(modelFactories);
-    }
-
-    public Class<ProfileIntent> getModelType() {
-        return ProfileIntent.class;
-    }
-}
+/*
+ * 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.xml;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.ProfileIntent;
+
+/**
+ * Processor for handling XML models of PolicyIntent definitions that are ProfileIntents
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProfileIntentProcessor extends PolicyIntentProcessor<ProfileIntent> {
+
+    public ProfileIntentProcessor(PolicyFactory policyFactory, Monitor monitor) {
+        super(policyFactory, monitor);
+    }
+    
+    public ProfileIntentProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+        super(modelFactories, monitor);
+    }
+
+    public Class<ProfileIntent> getModelType() {
+        return ProfileIntent.class;
+    }
+}

Modified: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java?rev=657881&r1=657880&r2=657881&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java Mon May 19 10:49:04 2008
@@ -1,44 +1,45 @@
-/*
- * 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.xml;
-
-import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
-import org.apache.tuscany.sca.policy.PolicyFactory;
-import org.apache.tuscany.sca.policy.QualifiedIntent;
-
-/**
- * Processor for handling XML models of PolicyIntent definitions that are QualifiedIntents
- *
- * @version $Rev$ $Date$
- */
-public class QualifiedIntentProcessor extends PolicyIntentProcessor<QualifiedIntent> {
-
-    public QualifiedIntentProcessor(ModelFactoryExtensionPoint modelFactories) {
-        super(modelFactories);
-    }
-    
-    public QualifiedIntentProcessor(PolicyFactory policyFactory) {
-        super(policyFactory);
-    }
-
-    public Class<QualifiedIntent> getModelType() {
-        return QualifiedIntent.class;
-    }
-}
+/*
+ * 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.xml;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.QualifiedIntent;
+
+/**
+ * Processor for handling XML models of PolicyIntent definitions that are QualifiedIntents
+ *
+ * @version $Rev$ $Date$
+ */
+public class QualifiedIntentProcessor extends PolicyIntentProcessor<QualifiedIntent> {
+	
+    public QualifiedIntentProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+        super(modelFactories, monitor);
+    }
+    
+    public QualifiedIntentProcessor(PolicyFactory policyFactory, Monitor monitor) {
+        super(policyFactory, monitor);
+    }
+
+    public Class<QualifiedIntent> getModelType() {
+        return QualifiedIntent.class;
+    }
+}

Modified: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java?rev=657881&r1=657880&r2=657881&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java Mon May 19 10:49:04 2008
@@ -1,44 +1,45 @@
-/*
- * 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.xml;
-
-import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
-import org.apache.tuscany.sca.policy.Intent;
-import org.apache.tuscany.sca.policy.PolicyFactory;
-
-/**
- * Processor for handling XML models of PolicyIntent definitions
- *
- * @version $Rev$ $Date$
- */
-public class SimpleIntentProcessor extends PolicyIntentProcessor<Intent> {
-
-    public SimpleIntentProcessor(PolicyFactory policyFactory) {
-        super(policyFactory);
-    }
-
-    public SimpleIntentProcessor(ModelFactoryExtensionPoint modelFactories) {
-        super(modelFactories);
-    }
-
-    public Class<Intent> getModelType() {
-        return Intent.class;
-    }
-}
+/*
+ * 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.xml;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+
+/**
+ * Processor for handling XML models of PolicyIntent definitions
+ *
+ * @version $Rev$ $Date$
+ */
+public class SimpleIntentProcessor extends PolicyIntentProcessor<Intent> {
+
+    public SimpleIntentProcessor(PolicyFactory policyFactory, Monitor monitor) {
+        super(policyFactory, monitor);
+    }
+
+    public SimpleIntentProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+        super(modelFactories, monitor);
+    }
+
+    public Class<Intent> getModelType() {
+        return Intent.class;
+    }
+}

Added: incubator/tuscany/java/sca/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties?rev=657881&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties Mon May 19 10:49:04 2008
@@ -0,0 +1,35 @@
+#
+#
+#    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.
+#
+#
+ReferredPolicySetNotFound = Referred PolicySet - {0} not found for PolicySet - {1}
+MappedIntentNotFound = Mapped Intent - {0} not found for PolicySet {1}
+ProvidedIntentNotFound = Provided Intent - {0} not found for PolicySet {1}
+UnableToMapPolicies = Unable to map policies for default qualifier in IntentMap for - {0} in policy set - {1}
+IntentMapDoesNotMatch = Intent provided by IntentMap {0} does not match parent qualifier {1} in policyset - {2}
+IntentNotSpecified = Intent Map provides for Intent not specified as provided by parent PolicySet - {0}
+ContrainsAttributeMissing = Contrains attribute missing from Policy Intent Definition {0}
+RequiredIntentNotFound = Required Intent - {0} not found for ProfileIntent {1}
+QualifiableIntentNotFound = Qualifiable Intent - {0} not found for QualifiedIntent {1}
+ErrorInPolicyIntentDefinition = Error in PolicyIntent Definition - {0} {1}
+ExcludedIntentNotFound = Excluded Intent {0} not found for intent {1}
+UnrecognizedIntentAttachPointType = Unrecognized IntentAttachPointType - {0}
+RequiredAttributeMissing = Required attribute '{0}' missing from BindingType Definition
+AlwaysProvidedIntentNotFound = Always Provided Intent - {0} not found for ExtensionType {1}
+MayProvideIntentNotFound = May Provide Intent - {0} not found for ExtensionType {1}
\ No newline at end of file

Propchange: incubator/tuscany/java/sca/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/tuscany/java/sca/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java?rev=657881&r1=657880&r2=657881&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java Mon May 19 10:49:04 2008
@@ -1,235 +1,235 @@
-/*
- * 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.xml;
-
-import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Hashtable;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamReader;
-
-import junit.framework.TestCase;
-
-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.contribution.resolver.DefaultModelResolver;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
-import org.apache.tuscany.sca.policy.Intent;
-import org.apache.tuscany.sca.policy.IntentAttachPointType;
-import org.apache.tuscany.sca.policy.PolicySet;
-import org.apache.tuscany.sca.policy.ProfileIntent;
-import org.apache.tuscany.sca.policy.QualifiedIntent;
-import org.apache.tuscany.sca.policy.impl.BindingTypeImpl;
-import org.apache.tuscany.sca.policy.impl.ImplementationTypeImpl;
-
-/**
- * Test reading SCA XML assembly documents.
- * 
- * @version $Rev: 551296 $ $Date: 2007-06-28 01:18:35 +0530 (Thu, 28 Jun 2007) $
- */
-public class ReadDocumentTestCase extends TestCase {
-
-    private ModelResolver resolver;
-    private StAXArtifactProcessor<Object> staxProcessor;
-    
-        
-    private Map<QName, Intent> intentTable = new Hashtable<QName, Intent>();
-    private Map<QName, PolicySet> policySetTable = new Hashtable<QName, PolicySet>();
-    private Map<QName, IntentAttachPointType> bindingTypesTable = new Hashtable<QName, IntentAttachPointType>();
-    private Map<QName, IntentAttachPointType> implTypesTable = new Hashtable<QName, IntentAttachPointType>();
-    private static final String scaNamespace = "http://www.osoa.org/xmlns/sca/1.0";
-    private static final String namespace = "http://test";
-    
-    private static final QName confidentiality = new QName(namespace, "confidentiality");
-    private static final QName integrity = new QName(namespace, "integrity");
-    private static final QName messageProtection = new QName(namespace, "messageProtection");
-    private static final QName confidentiality_transport = new QName(namespace, "confidentiality.transport");   
-    private static final QName confidentiality_message = new QName(namespace, "confidentiality.message");
-    private static final QName secureReliablePolicy = new QName(namespace, "SecureReliablePolicy");
-    private static final QName secureMessagingPolicies = new QName(namespace, "SecureMessagingPolicies");
-    private static final QName securityPolicy = new QName(namespace, "SecurityPolicy");
-    private static final QName basicAuthMsgProtSecurity = new QName(namespace, "BasicAuthMsgProtSecurity");
-    private static final QName wsBinding = new QName(scaNamespace, "binding.ws");
-    private static final QName javaImpl = new QName(scaNamespace, "implementation.java");
-    
-
-    @Override
-    public void setUp() throws Exception {
-        DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
-        resolver = new DefaultModelResolver();
-        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
-        StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
-        staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
-        staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
-        
-        URL url = getClass().getResource("test_definitions.xml");
-        InputStream urlStream = url.openStream();
-        XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream);
-        reader.next();
-        while ( true ) {
-            int event = reader.getEventType();
-            switch (event) {
-                case START_ELEMENT: {
-                    Object artifact = staxProcessor.read(reader);
-                    if ( artifact instanceof PolicySet ) {
-                        PolicySet policySet = (PolicySet)artifact;
-                        policySet.setName(new QName(namespace, policySet.getName().getLocalPart()));
-                        policySetTable.put(policySet.getName(), policySet);
-                    } else if ( artifact instanceof Intent ) {
-                        Intent intent = (Intent)artifact;
-                        intent.setName(new QName(namespace, intent.getName().getLocalPart()));
-                        if ( intent instanceof QualifiedIntent ) {
-                            ((QualifiedIntent)intent).getQualifiableIntent().
-                                    setName(new QName(namespace, 
-                                                      ((QualifiedIntent)intent).getQualifiableIntent().getName().getLocalPart()));
-                        }
-                        intentTable.put(intent.getName(), intent);
-                    } else if ( artifact instanceof BindingTypeImpl ) {
-                        IntentAttachPointType bindingType = (IntentAttachPointType)artifact;
-                        bindingTypesTable.put(bindingType.getName(), bindingType);
-                    } else if ( artifact instanceof ImplementationTypeImpl ) {
-                        IntentAttachPointType implType = (IntentAttachPointType)artifact;
-                        implTypesTable.put(implType.getName(), implType);
-                    }
-                    
-                    if ( artifact != null ) {
-                        resolver.addModel(artifact);
-                    }
-                    
-                    break;
-                }
-            }
-            if ( reader.hasNext() ) {
-                reader.next();
-            } else {
-                break;
-            }
-        }
-        urlStream.close();
-    }
-
-    @Override
-    public void tearDown() throws Exception {
-    }
-
-    public void testReadSCADefinitions() throws Exception {
-        assertNotNull(intentTable.get(confidentiality));
-        assertNotNull(intentTable.get(messageProtection));
-        assertNotNull(intentTable.get(confidentiality_transport));
-        assertTrue(intentTable.get(confidentiality).getDescription().length() > 0 );
-        
-        assertNotNull(policySetTable.get(secureReliablePolicy));
-        assertTrue(policySetTable.get(secureReliablePolicy).getProvidedIntents().size() == 2);
-        assertTrue(policySetTable.get(secureReliablePolicy).getPolicies().size() == 2);
-        
-        assertNotNull(policySetTable.get(secureMessagingPolicies));
-        assertEquals(policySetTable.get(secureMessagingPolicies).getMappedPolicies().size(), 3);
-        
-        assertEquals(bindingTypesTable.size(), 1);
-        assertNotNull(bindingTypesTable.get(wsBinding));
-        assertEquals(implTypesTable.size(), 1);
-        assertNotNull(implTypesTable.get(javaImpl));
-    }
-    
-    public void testResolution() throws Exception {
-        assertTrue(intentTable.get(messageProtection) instanceof ProfileIntent);
-        ProfileIntent profileIntent = (ProfileIntent)intentTable.get(new QName(namespace, "messageProtection"));
-        assertNull(profileIntent.getRequiredIntents().get(0).getDescription());
-        
-        QName confidentiality_transport = new QName(namespace, "confidentiality.transport"); 
-        assertTrue(intentTable.get(confidentiality_transport) instanceof QualifiedIntent);
-        QualifiedIntent qualifiedIntent = (QualifiedIntent)intentTable.get(new QName(namespace, "confidentiality.transport"));
-        assertNull(qualifiedIntent.getQualifiableIntent().getDescription());
-        
-        PolicySet secureReliablePolicySet = policySetTable.get(secureReliablePolicy);
-        PolicySet secureMessagingPolicySet = policySetTable.get(secureMessagingPolicies);
-        PolicySet securityPolicySet = policySetTable.get(securityPolicy);
-        
-        assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity);
-        assertNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription());
-        assertTrue(secureMessagingPolicySet.isUnresolved());
-        assertEquals(securityPolicySet.getMappedPolicies().size(), 5);
-        
-        //testing to ensure that inclusion of referred policy sets has not happened
-        PolicySet basicAuthMsgProtSecurityPolicySet = policySetTable.get(basicAuthMsgProtSecurity);
-        assertTrue(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty());
-        assertTrue(basicAuthMsgProtSecurityPolicySet.getMappedPolicies().isEmpty());
-        
-        IntentAttachPointType wsBindingType = bindingTypesTable.get(wsBinding);
-        assertNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription());
-        assertNull(wsBindingType.getMayProvideIntents().get(0).getDescription());
-        
-        IntentAttachPointType javaImplType = implTypesTable.get(javaImpl);
-        assertNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription());
-        assertNull(javaImplType.getMayProvideIntents().get(0).getDescription());
-        
-        for ( Intent intent : intentTable.values() ) {
-            staxProcessor.resolve(intent, resolver);
-        }
-        
-        for ( PolicySet policySet : policySetTable.values() ) {
-            staxProcessor.resolve(policySet, resolver);
-        }
-        
-        for (  IntentAttachPointType bindingType : bindingTypesTable.values() ) {
-            staxProcessor.resolve(bindingType, resolver);
-        }
-        
-        for ( IntentAttachPointType implType : implTypesTable.values() ) {
-            staxProcessor.resolve(implType, resolver);
-        }
-        
-        
-        
-        //testing if policy intents have been linked have property been linked up 
-        assertNotNull(profileIntent.getRequiredIntents().get(0).getDescription());
-        assertNotNull(qualifiedIntent.getQualifiableIntent().getDescription());
-        assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity);
-        assertNotNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription());
-        
-        //testing if policysets have been properly linked up with intents
-        assertFalse(secureMessagingPolicySet.isUnresolved());
-        assertNotNull(secureMessagingPolicySet.getMappedPolicies().get(intentTable.get(confidentiality)));
-        assertNotNull(secureMessagingPolicySet.getMappedPolicies().get(intentTable.get(confidentiality_transport)));
-        
-        //testing if intent maps have been properly mapped to policies
-        assertFalse(securityPolicySet.isUnresolved());
-        assertNotNull(securityPolicySet.getMappedPolicies().get(intentTable.get(confidentiality)));
-        assertNotNull(securityPolicySet.getMappedPolicies().get(intentTable.get(confidentiality_message)));
-        
-        //testing for inclusion of referred policysets
-        assertFalse(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty());
-        assertFalse(basicAuthMsgProtSecurityPolicySet.getMappedPolicies().isEmpty());
-        assertNotNull(basicAuthMsgProtSecurityPolicySet.getMappedPolicies().get(intentTable.get(confidentiality_transport)));
-        
-        assertNotNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription());
-        assertNotNull(wsBindingType.getMayProvideIntents().get(0).getDescription());
-        
-        assertNotNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription());
-        assertNotNull(javaImplType.getMayProvideIntents().get(0).getDescription());
-    }
-}
+/*
+ * 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.xml;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+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.contribution.resolver.DefaultModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.ProfileIntent;
+import org.apache.tuscany.sca.policy.QualifiedIntent;
+import org.apache.tuscany.sca.policy.impl.BindingTypeImpl;
+import org.apache.tuscany.sca.policy.impl.ImplementationTypeImpl;
+
+/**
+ * Test reading SCA XML assembly documents.
+ * 
+ * @version $Rev: 551296 $ $Date: 2007-06-28 01:18:35 +0530 (Thu, 28 Jun 2007) $
+ */
+public class ReadDocumentTestCase extends TestCase {
+
+    private ModelResolver resolver;
+    private StAXArtifactProcessor<Object> staxProcessor;
+    
+        
+    private Map<QName, Intent> intentTable = new Hashtable<QName, Intent>();
+    private Map<QName, PolicySet> policySetTable = new Hashtable<QName, PolicySet>();
+    private Map<QName, IntentAttachPointType> bindingTypesTable = new Hashtable<QName, IntentAttachPointType>();
+    private Map<QName, IntentAttachPointType> implTypesTable = new Hashtable<QName, IntentAttachPointType>();
+    private static final String scaNamespace = "http://www.osoa.org/xmlns/sca/1.0";
+    private static final String namespace = "http://test";
+    
+    private static final QName confidentiality = new QName(namespace, "confidentiality");
+    private static final QName integrity = new QName(namespace, "integrity");
+    private static final QName messageProtection = new QName(namespace, "messageProtection");
+    private static final QName confidentiality_transport = new QName(namespace, "confidentiality.transport");   
+    private static final QName confidentiality_message = new QName(namespace, "confidentiality.message");
+    private static final QName secureReliablePolicy = new QName(namespace, "SecureReliablePolicy");
+    private static final QName secureMessagingPolicies = new QName(namespace, "SecureMessagingPolicies");
+    private static final QName securityPolicy = new QName(namespace, "SecurityPolicy");
+    private static final QName basicAuthMsgProtSecurity = new QName(namespace, "BasicAuthMsgProtSecurity");
+    private static final QName wsBinding = new QName(scaNamespace, "binding.ws");
+    private static final QName javaImpl = new QName(scaNamespace, "implementation.java");
+    
+
+    @Override
+    public void setUp() throws Exception {
+        DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+        resolver = new DefaultModelResolver();
+        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+        StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+        staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+        staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
+        
+        URL url = getClass().getResource("test_definitions.xml");
+        InputStream urlStream = url.openStream();
+        XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream);
+        reader.next();
+        while ( true ) {
+            int event = reader.getEventType();
+            switch (event) {
+                case START_ELEMENT: {
+                    Object artifact = staxProcessor.read(reader);
+                    if ( artifact instanceof PolicySet ) {
+                        PolicySet policySet = (PolicySet)artifact;
+                        policySet.setName(new QName(namespace, policySet.getName().getLocalPart()));
+                        policySetTable.put(policySet.getName(), policySet);
+                    } else if ( artifact instanceof Intent ) {
+                        Intent intent = (Intent)artifact;
+                        intent.setName(new QName(namespace, intent.getName().getLocalPart()));
+                        if ( intent instanceof QualifiedIntent ) {
+                            ((QualifiedIntent)intent).getQualifiableIntent().
+                                    setName(new QName(namespace, 
+                                                      ((QualifiedIntent)intent).getQualifiableIntent().getName().getLocalPart()));
+                        }
+                        intentTable.put(intent.getName(), intent);
+                    } else if ( artifact instanceof BindingTypeImpl ) {
+                        IntentAttachPointType bindingType = (IntentAttachPointType)artifact;
+                        bindingTypesTable.put(bindingType.getName(), bindingType);
+                    } else if ( artifact instanceof ImplementationTypeImpl ) {
+                        IntentAttachPointType implType = (IntentAttachPointType)artifact;
+                        implTypesTable.put(implType.getName(), implType);
+                    }
+                    
+                    if ( artifact != null ) {
+                        resolver.addModel(artifact);
+                    }
+                    
+                    break;
+                }
+            }
+            if ( reader.hasNext() ) {
+                reader.next();
+            } else {
+                break;
+            }
+        }
+        urlStream.close();
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+    }
+
+    public void testReadSCADefinitions() throws Exception {
+        assertNotNull(intentTable.get(confidentiality));
+        assertNotNull(intentTable.get(messageProtection));
+        assertNotNull(intentTable.get(confidentiality_transport));
+        assertTrue(intentTable.get(confidentiality).getDescription().length() > 0 );
+        
+        assertNotNull(policySetTable.get(secureReliablePolicy));
+        assertTrue(policySetTable.get(secureReliablePolicy).getProvidedIntents().size() == 2);
+        assertTrue(policySetTable.get(secureReliablePolicy).getPolicies().size() == 2);
+        
+        assertNotNull(policySetTable.get(secureMessagingPolicies));
+        assertEquals(policySetTable.get(secureMessagingPolicies).getMappedPolicies().size(), 3);
+        
+        assertEquals(bindingTypesTable.size(), 1);
+        assertNotNull(bindingTypesTable.get(wsBinding));
+        assertEquals(implTypesTable.size(), 1);
+        assertNotNull(implTypesTable.get(javaImpl));
+    }
+    
+    public void testResolution() throws Exception {
+        assertTrue(intentTable.get(messageProtection) instanceof ProfileIntent);
+        ProfileIntent profileIntent = (ProfileIntent)intentTable.get(new QName(namespace, "messageProtection"));
+        assertNull(profileIntent.getRequiredIntents().get(0).getDescription());
+        
+        QName confidentiality_transport = new QName(namespace, "confidentiality.transport"); 
+        assertTrue(intentTable.get(confidentiality_transport) instanceof QualifiedIntent);
+        QualifiedIntent qualifiedIntent = (QualifiedIntent)intentTable.get(new QName(namespace, "confidentiality.transport"));
+        assertNull(qualifiedIntent.getQualifiableIntent().getDescription());
+        
+        PolicySet secureReliablePolicySet = policySetTable.get(secureReliablePolicy);
+        PolicySet secureMessagingPolicySet = policySetTable.get(secureMessagingPolicies);
+        PolicySet securityPolicySet = policySetTable.get(securityPolicy);
+        
+        assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity);
+        assertNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription());
+        assertTrue(secureMessagingPolicySet.isUnresolved());
+        assertEquals(securityPolicySet.getMappedPolicies().size(), 5);
+        
+        //testing to ensure that inclusion of referred policy sets has not happened
+        PolicySet basicAuthMsgProtSecurityPolicySet = policySetTable.get(basicAuthMsgProtSecurity);
+        assertTrue(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty());
+        assertTrue(basicAuthMsgProtSecurityPolicySet.getMappedPolicies().isEmpty());
+        
+        IntentAttachPointType wsBindingType = bindingTypesTable.get(wsBinding);
+        assertNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription());
+        assertNull(wsBindingType.getMayProvideIntents().get(0).getDescription());
+        
+        IntentAttachPointType javaImplType = implTypesTable.get(javaImpl);
+        assertNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription());
+        assertNull(javaImplType.getMayProvideIntents().get(0).getDescription());
+        
+        for ( Intent intent : intentTable.values() ) {
+            staxProcessor.resolve(intent, resolver);
+        }
+        
+        for ( PolicySet policySet : policySetTable.values() ) {
+            staxProcessor.resolve(policySet, resolver);
+        }
+        
+        for (  IntentAttachPointType bindingType : bindingTypesTable.values() ) {
+            staxProcessor.resolve(bindingType, resolver);
+        }
+        
+        for ( IntentAttachPointType implType : implTypesTable.values() ) {
+            staxProcessor.resolve(implType, resolver);
+        }
+        
+        
+        
+        //testing if policy intents have been linked have property been linked up 
+        assertNotNull(profileIntent.getRequiredIntents().get(0).getDescription());
+        assertNotNull(qualifiedIntent.getQualifiableIntent().getDescription());
+        assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity);
+        assertNotNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription());
+        
+        //testing if policysets have been properly linked up with intents
+        assertFalse(secureMessagingPolicySet.isUnresolved());
+        assertNotNull(secureMessagingPolicySet.getMappedPolicies().get(intentTable.get(confidentiality)));
+        assertNotNull(secureMessagingPolicySet.getMappedPolicies().get(intentTable.get(confidentiality_transport)));
+        
+        //testing if intent maps have been properly mapped to policies
+        assertFalse(securityPolicySet.isUnresolved());
+        assertNotNull(securityPolicySet.getMappedPolicies().get(intentTable.get(confidentiality)));
+        assertNotNull(securityPolicySet.getMappedPolicies().get(intentTable.get(confidentiality_message)));
+        
+        //testing for inclusion of referred policysets
+        assertFalse(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty());
+        assertFalse(basicAuthMsgProtSecurityPolicySet.getMappedPolicies().isEmpty());
+        assertNotNull(basicAuthMsgProtSecurityPolicySet.getMappedPolicies().get(intentTable.get(confidentiality_transport)));
+        
+        assertNotNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription());
+        assertNotNull(wsBindingType.getMayProvideIntents().get(0).getDescription());
+        
+        assertNotNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription());
+        assertNotNull(javaImplType.getMayProvideIntents().get(0).getDescription());
+    }
+}



Mime
View raw message