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

svn commit: r555688 - in /incubator/tuscany/java/sca/modules/policy-xml: ./ 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/tusc...

Author: svkrish
Date: Thu Jul 12 09:29:23 2007
New Revision: 555688

URL: http://svn.apache.org/viewvc?view=rev&rev=555688
Log:
adding artifact processors for policy intents

Added:
    incubator/tuscany/java/sca/modules/policy-xml/
    incubator/tuscany/java/sca/modules/policy-xml/DISCLAIMER
    incubator/tuscany/java/sca/modules/policy-xml/LICENSE
    incubator/tuscany/java/sca/modules/policy-xml/NOTICE
    incubator/tuscany/java/sca/modules/policy-xml/pom.xml
    incubator/tuscany/java/sca/modules/policy-xml/src/
    incubator/tuscany/java/sca/modules/policy-xml/src/main/
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsDocumentProcessor.java
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsProcessor.java
    incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/XAttr.java
    incubator/tuscany/java/sca/modules/policy-xml/src/test/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/java/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java
    incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestModelResolver.java
    incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/
    incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/definitions.xml

Added: incubator/tuscany/java/sca/modules/policy-xml/DISCLAIMER
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/DISCLAIMER?view=auto&rev=555688
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/DISCLAIMER (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/DISCLAIMER Thu Jul 12 09:29:23 2007
@@ -0,0 +1,8 @@
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+

Added: incubator/tuscany/java/sca/modules/policy-xml/LICENSE
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/LICENSE?view=auto&rev=555688
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/LICENSE (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/LICENSE Thu Jul 12 09:29:23 2007
@@ -0,0 +1,205 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+
+
+

Added: incubator/tuscany/java/sca/modules/policy-xml/NOTICE
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/NOTICE?view=auto&rev=555688
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/NOTICE (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/NOTICE Thu Jul 12 09:29:23 2007
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2007 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+

Added: incubator/tuscany/java/sca/modules/policy-xml/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/pom.xml?view=auto&rev=555688
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/pom.xml (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/pom.xml Thu Jul 12 09:29:23 2007
@@ -0,0 +1,57 @@
+<?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>1.0-incubating-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <artifactId>tuscany-policy-xml</artifactId>
+    <name>Apache Tuscany Policy - XML Model Support</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-policy</artifactId>
+            <version>1.0-incubating-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-contribution</artifactId>
+            <version>1.0-incubating-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>stax</groupId>
+            <artifactId>stax-api</artifactId>
+            <version>1.0.1</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.codehaus.woodstox</groupId>
+            <artifactId>wstx-asl</artifactId>
+            <version>3.2.0</version>
+            <scope>runtime</scope>
+        </dependency>
+    </dependencies>
+</project>

Added: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java?view=auto&rev=555688
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java Thu Jul 12 09:29:23 2007
@@ -0,0 +1,55 @@
+/*
+ * 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 javax.xml.namespace.QName;
+
+/**
+ * constants related to policy framework
+ *
+ */
+public interface PolicyConstants {
+    String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+    String INTENT = "intent";
+    String INTENT_MAP = "intentMap";
+    String NAME = "name";
+    String TARGET_NAMESPACE = "targetNamespace";
+    String SCA_DEFINITIONS = "definitions";
+    String CONSTRAINS = "constrains";
+    String DESCRIPTION = "description";
+    String PROVIDES = "provides";
+    String APPLIES_TO = "appliesTo";
+    String QUALIFIER = ".";
+    String REQUIRES = "requires";
+    
+    
+    QName POLICY_INTENT_QNAME = new QName(SCA10_NS, INTENT);
+    QName POLICY_SET_QNAME = new QName(SCA10_NS, "policySet");
+    QName POLICY_INTENT_MAP_QNAME = new QName(SCA10_NS, INTENT_MAP); 
+    QName SCA_DEFNS_QNAME = new QName(SCA10_NS, SCA_DEFINITIONS);
+    QName DESCRIPTION_QNAME = new QName(SCA10_NS, DESCRIPTION);
+    QName POLICY_INTENT_MAP_QUALIFIER_QNAME = new QName(SCA10_NS, QUALIFIER);
+    
+    String QUALIFIED_INTENT_CONSTRAINS_ERROR = " - Qualified Intents must not specify 'constrains' attribute";
+    
+    
+    
+    
+    
+}

Added: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java?view=auto&rev=555688
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java Thu Jul 12 09:29:23 2007
@@ -0,0 +1,266 @@
+/*
+ * 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.List;
+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 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.ProfileIntent;
+import org.apache.tuscany.sca.policy.QualifiedIntent;
+
+public class PolicyIntentProcessor implements StAXArtifactProcessor<Intent>, PolicyConstants {
+
+    private PolicyFactory policyFactory;
+
+    public PolicyIntentProcessor(PolicyFactory policyFactory) {
+        this.policyFactory = policyFactory;
+    }
+
+    public Intent read(XMLStreamReader reader) throws ContributionReadException {
+        try {
+            Intent policyIntent = null;
+            String policyIntentName = reader.getAttributeValue(null, NAME);
+            // Read an <sca:intent>
+            if (reader.getAttributeValue(null, REQUIRES) != null) {
+                policyIntent = policyFactory.createProfileIntent();
+            } else if ( policyIntentName != null && policyIntentName.indexOf(QUALIFIER) != -1) {
+                policyIntent = policyFactory.createQualifiedIntent();
+                
+                int qualifierIndex = policyIntentName.lastIndexOf(QUALIFIER);
+                Intent qualifiableIntent = policyFactory.createIntent();
+                qualifiableIntent.setName(getQNameValue(reader, 
+                                                        policyIntentName.substring(0, qualifierIndex)));
+                
+                ((QualifiedIntent)policyIntent).setQualifiableIntent(qualifiableIntent);
+            } else {
+                policyIntent = policyFactory.createIntent();
+            }
+            policyIntent.setName(getQNameValue(reader, policyIntentName));
+            
+            if ( policyIntent instanceof ProfileIntent ) {
+                readRequiredIntents((ProfileIntent)policyIntent, reader);
+            }
+            
+            readConstrainedArtifacts(policyIntent, reader);
+            
+            int event = reader.getEventType();
+            QName name = null;
+            while (reader.hasNext()) {
+                event = reader.getEventType();
+                switch (event) {
+                    case START_ELEMENT : {
+                        name = reader.getName();
+                        if (DESCRIPTION_QNAME.equals(name)) {
+                            policyIntent.setDescription(reader.getElementText());
+                        }
+                        break;
+                    }
+                }
+                if (event == END_ELEMENT && POLICY_INTENT_QNAME.equals(reader.getName())) {
+                    break;
+                }
+                
+                //Read the next element
+                if (reader.hasNext()) {
+                    reader.next();
+                }
+            }
+            return policyIntent;
+            
+        } catch (XMLStreamException e) {
+            throw new ContributionReadException(e);
+        }
+    }
+    
+    public void write(Intent policyIntent, XMLStreamWriter writer) throws ContributionWriteException {
+        try {
+            // Write an <sca:intent>
+            writer.writeStartElement(PolicyConstants.SCA10_NS, INTENT);
+            if (policyIntent instanceof ProfileIntent) {
+                ProfileIntent profileIntent = (ProfileIntent)policyIntent;
+                if (profileIntent.getRequiredIntents() != null && 
+                    profileIntent.getRequiredIntents().size() > 0) {
+                    StringBuffer sb = new StringBuffer();
+                    for (Intent requiredIntents : profileIntent.getRequiredIntents()) {
+                        sb.append(requiredIntents.getName());
+                        sb.append(" ");
+                    }
+                    writer.writeAttribute(PolicyConstants.REQUIRES, sb.toString());
+                }
+            }
+            
+            if (!(policyIntent instanceof QualifiedIntent) ) {
+                if (policyIntent.getConstrains() != null && 
+                    policyIntent.getConstrains().size() > 0) {
+                    StringBuffer sb = new StringBuffer();
+                    for (QName contrainedArtifact : policyIntent.getConstrains()) {
+                        sb.append(contrainedArtifact.toString());
+                        sb.append(" ");
+                    }
+                    writer.writeAttribute(CONSTRAINS, sb.toString());
+                } else {
+                    throw new ContributionWriteException("Contrains attribute missing from " +
+                                    "Policy Intent Definition" + policyIntent.getName());
+                }
+            }
+            
+            if ( policyIntent.getDescription() != null && policyIntent.getDescription().length() > 0) {
+                writer.writeStartElement(PolicyConstants.SCA10_NS, DESCRIPTION);
+                writer.writeCData(policyIntent.getDescription());
+                writer.writeEndElement();
+            }
+            
+            writer.writeEndElement();
+            
+        } catch (XMLStreamException e) {
+            throw new ContributionWriteException(e);
+        }
+    }
+    
+    private Intent resolveRequiredIntents(ProfileIntent policyIntent, ModelResolver resolver) throws ContributionResolveException {
+        boolean isUnresolved = false;
+        //FIXME: Need to check for cyclic references first i.e an A requiring B and then B requiring A... 
+        if (policyIntent != null && policyIntent.isUnresolved()) {
+            
+            //resolve all required intents
+            List<Intent> requiredIntents = new ArrayList<Intent>(); 
+            for (Intent requiredIntent : policyIntent.getRequiredIntents()) {
+                if ( requiredIntent.isUnresolved() ) {
+                    //policyIntent.getRequiredIntents().remove(requiredIntent);
+                    requiredIntent = resolver.resolveModel(Intent.class, requiredIntent);
+                    requiredIntents.add(requiredIntent);
+                    if (requiredIntent.isUnresolved()) {
+                        isUnresolved = true;
+                    }
+                }
+            }
+            policyIntent.getRequiredIntents().clear();
+            policyIntent.getRequiredIntents().addAll(requiredIntents);
+        }
+        policyIntent.setUnresolved(isUnresolved);
+        
+        return policyIntent;
+    }
+    
+    private Intent resolveQualifiableIntent(QualifiedIntent policyIntent, ModelResolver resolver) throws ContributionResolveException {
+        boolean isUnresolved = false;
+
+        if (policyIntent != null && policyIntent.isUnresolved()) {
+            //resolve the qualifiable intent
+            Intent qualifiableIntent = 
+                resolver.resolveModel(Intent.class, policyIntent.getQualifiableIntent());
+            policyIntent.setQualifiableIntent(qualifiableIntent);
+            isUnresolved = qualifiableIntent.isUnresolved();
+        }
+        policyIntent.setUnresolved(isUnresolved);
+        
+        return policyIntent;
+    }
+    
+    protected void resolveContrainedArtifacts(Intent policyIntent, ModelResolver resolver) {
+        //FIXME : need to figure out this resolution. 
+        policyIntent.setUnresolved(false);
+    }
+    
+    public void resolve(Intent policyIntent, ModelResolver resolver) throws ContributionResolveException {
+        if ( policyIntent instanceof ProfileIntent ) {
+            resolveRequiredIntents((ProfileIntent)policyIntent, resolver);
+        } 
+        
+        if ( policyIntent instanceof QualifiedIntent ) {
+            resolveQualifiableIntent((QualifiedIntent)policyIntent, resolver);
+        }
+        
+        resolveContrainedArtifacts(policyIntent, resolver);
+        
+        if ( !policyIntent.isUnresolved() ) {
+            resolver.addModel(policyIntent);
+        }
+    }
+    
+    public QName getArtifactType() {
+        return POLICY_INTENT_QNAME;
+    }
+    
+    public Class<Intent> getModelType() {
+        return Intent.class;
+    }
+    
+    protected void readConstrainedArtifacts(Intent policyIntent, XMLStreamReader reader) throws ContributionReadException {
+        String value = reader.getAttributeValue(null, CONSTRAINS);
+        if ( policyIntent instanceof QualifiedIntent && value != null) {
+            String errorMsg = 
+                "Error in PolicyIntent Definition - " + policyIntent.getName() + QUALIFIED_INTENT_CONSTRAINS_ERROR;
+            throw new ContributionReadException(errorMsg);
+        } else {
+            if (value != null) {
+                List<QName> constrainedArtifacts = policyIntent.getConstrains();
+                for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+                    QName qname = getQNameValue(reader, tokens.nextToken());
+                    constrainedArtifacts.add(qname);
+                }
+            }
+        }
+    }
+    
+    protected void readRequiredIntents(ProfileIntent policyIntent, XMLStreamReader reader) {
+        String value = reader.getAttributeValue(null, REQUIRES);
+        if (value != null) {
+            List<Intent> requiredIntents = policyIntent.getRequiredIntents();
+            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+                QName qname = getQNameValue(reader, tokens.nextToken());
+                Intent intent = policyFactory.createIntent();
+                intent.setName(qname);
+                requiredIntents.add(intent);
+            }
+        }
+    }
+    
+    protected QName getQNameValue(XMLStreamReader reader, String value) {
+        if (value != null) {
+            int index = value.indexOf(':');
+            String prefix = index == -1 ? "" : value.substring(0, index);
+            String localName = index == -1 ? value : value.substring(index + 1);
+            String ns = reader.getNamespaceContext().getNamespaceURI(prefix);
+            if (ns == null) {
+                ns = "";
+            }
+            return new QName(ns, localName, prefix);
+        } else {
+            return null;
+        }
+    }
+}

Added: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsDocumentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsDocumentProcessor.java?view=auto&rev=555688
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsDocumentProcessor.java (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsDocumentProcessor.java Thu Jul 12 09:29:23 2007
@@ -0,0 +1,99 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+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.policy.SCADefinitions;
+
+/**
+ * A SCA Definitions Document processor.
+ * 
+ */
+public class SCADefinitionsDocumentProcessor  implements URLArtifactProcessor<SCADefinitions> {
+    protected StAXArtifactProcessor<Object> extensionProcessor;
+
+    private static final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
+    static {
+        domFactory.setNamespaceAware(true);
+    }
+    private XMLInputFactory inputFactory;
+
+    /**
+     * Construct a new SCADefinitions processor
+     * @param assemblyFactory
+     * @param policyFactory
+     * @param staxProcessor
+     */
+    public SCADefinitionsDocumentProcessor(StAXArtifactProcessor staxProcessor, XMLInputFactory inputFactory) {
+        this.extensionProcessor = (StAXArtifactProcessor<Object>)staxProcessor;
+        this.inputFactory = inputFactory;
+    }
+
+    public SCADefinitions read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+        InputStream urlStream = null;
+        try {
+            urlStream = url.openStream();
+            XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream);
+            reader.nextTag();
+            SCADefinitions scaDefns = (SCADefinitions)extensionProcessor.read(reader);
+            return scaDefns;
+            
+        } catch (XMLStreamException e) {
+            throw new ContributionReadException(e);
+        } catch (IOException e) {
+            throw new ContributionReadException(e);
+        } finally {
+            try {
+                if (urlStream != null) {
+                    urlStream.close();
+                    urlStream = null;
+                }
+            } catch (IOException ioe) {
+                //ignore
+            }
+        }
+    }
+    
+    public void resolve(SCADefinitions composite, ModelResolver resolver) throws ContributionResolveException {
+        extensionProcessor.resolve(composite, resolver);
+    }
+
+    public String getArtifactType() {
+        return "definitions.composite";
+    }
+    
+    public Class<SCADefinitions> getModelType() {
+        return SCADefinitions.class;
+    }
+}

Added: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsProcessor.java?view=auto&rev=555688
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsProcessor.java (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SCADefinitionsProcessor.java Thu Jul 12 09:29:23 2007
@@ -0,0 +1,278 @@
+/*
+ * 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.net.URI;
+import java.net.URISyntaxException;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+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.BindingType;
+import org.apache.tuscany.sca.policy.ImplementationType;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.SCADefinitions;
+import org.apache.tuscany.sca.policy.impl.SCADefinitionsImpl;
+
+/**
+ * Processor for SCA Definitions
+ * 
+ */
+public class SCADefinitionsProcessor implements StAXArtifactProcessor<SCADefinitions>, PolicyConstants {
+    
+    protected PolicyFactory policyFactory;
+    protected StAXArtifactProcessor<Object> extensionProcessor;
+    protected PolicyIntentProcessor policyIntentResolver;
+    
+    /**
+     * Construct a new (sca) definitions processor
+     * @param assemblyFactory
+     * @param policyFactory
+     * @param extensionProcessor 
+     */
+    public SCADefinitionsProcessor(PolicyFactory policyFactory,
+                              StAXArtifactProcessor extensionProcessor) {
+        this.policyFactory = policyFactory;
+        this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor;
+        this.policyIntentResolver = new PolicyIntentProcessor(null);
+    }
+
+    /**
+     * Returns a qname from a string.  
+     * @param reader
+     * @param value
+     * @return
+     */
+    protected QName getQNameValue(XMLStreamReader reader, String value) {
+        if (value != null) {
+            int index = value.indexOf(':');
+            String prefix = index == -1 ? "" : value.substring(0, index);
+            String localName = index == -1 ? value : value.substring(index + 1);
+            String ns = reader.getNamespaceContext().getNamespaceURI(prefix);
+            if (ns == null) {
+                ns = "";
+            }
+            return new QName(ns, localName, prefix);
+        } else {
+            return null;
+        }
+    }
+    
+    /**
+     * Returns the qname value of an attribute.
+     * @param reader
+     * @param name
+     * @return
+     */
+    protected QName getQName(XMLStreamReader reader, String name) {
+        String qname = reader.getAttributeValue(null, name);
+        return getQNameValue(reader, qname);
+    }
+    
+    public SCADefinitions read(XMLStreamReader reader) throws ContributionReadException {
+        QName name = null;
+        SCADefinitions scaDefns = null;
+        try {
+            // Read the composite document
+            while (reader.hasNext()) {
+                int event = reader.getEventType();
+                switch (event) {
+                    case START_ELEMENT: {
+                        name = reader.getName();
+                        if ( SCA_DEFNS_QNAME.equals(name)) {
+                            scaDefns = new SCADefinitionsImpl();
+                            try {
+                                scaDefns.setTargetNamespace(new URI(reader.getAttributeValue(null, TARGET_NAMESPACE)));
+                            } catch ( URISyntaxException e ) {
+                                throw new ContributionReadException(e);
+                            }
+                        } else {
+                            Object extension = extensionProcessor.read(reader);
+                            if (extension != null) {
+                                if ( extension instanceof Intent ) {
+                                    scaDefns.getPolicyIntents().add((Intent)extension);
+                                } else if ( extension instanceof PolicySet ) {
+                                    scaDefns.getPolicySets().add((PolicySet)extension);
+                                } else if ( extension instanceof BindingType ) {
+                                    scaDefns.getBindingTypes().add((BindingType)extension);
+                                } else if ( extension instanceof ImplementationType ) {
+                                    scaDefns.getImplementationTypes().add((ImplementationType)extension);
+                                }
+                            }
+                            break;
+                        }
+                    }
+    
+                    case XMLStreamConstants.CHARACTERS:
+                        break;
+    
+                    case END_ELEMENT:
+                        break;
+                }
+                
+                //Read the next element
+                if (reader.hasNext()) {
+                    reader.next();
+                }
+            }
+            return scaDefns;
+            
+        } catch (XMLStreamException e) {
+            throw new ContributionReadException(e);
+        }
+    }
+    
+    /**
+     * Write attributes to the current element.
+     * @param writer
+     * @param attrs
+     * @throws XMLStreamException
+     */
+    protected void writeAttributes(XMLStreamWriter writer, XAttr... attrs) throws XMLStreamException {
+        for (XAttr attr : attrs) {
+            if (attr != null)
+                attr.write(writer);
+        }
+    }
+    
+    /**
+     * Start an element.
+     * @param uri
+     * @param name
+     * @param attrs
+     * @throws XMLStreamException
+     */
+    protected void writeStart(XMLStreamWriter writer, String uri, String name, XAttr... attrs) throws XMLStreamException {
+        writer.writeStartElement(uri, name);
+        writeAttributes(writer, attrs);
+    }
+
+    /**
+     * Start an element.
+     * @param writer
+     * @param name
+     * @param attrs
+     * @throws XMLStreamException
+     */
+    protected void writeStart(XMLStreamWriter writer, String name, XAttr... attrs) throws XMLStreamException {
+        writer.writeStartElement(SCA10_NS, name);
+        writeAttributes(writer, attrs);
+    }
+    
+    /**
+     * Start a document.
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void writeStartDocument(XMLStreamWriter writer, String name, XAttr... attrs) throws XMLStreamException {
+        writer.writeStartDocument();
+        writer.setDefaultNamespace(SCA10_NS);
+        writeStart(writer, name, attrs);
+        writer.writeDefaultNamespace(SCA10_NS);
+    }
+    
+    /**
+     * End a document.
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void writeEndDocument(XMLStreamWriter writer) throws XMLStreamException {
+        writer.writeEndDocument();
+    }
+    
+    public void write(SCADefinitions scaDefns, XMLStreamWriter writer) throws ContributionWriteException {
+
+        try {
+            writeStartDocument(writer, 
+                                   SCA_DEFINITIONS,
+                                   new XAttr(TARGET_NAMESPACE, scaDefns.getTargetNamespace().toString())
+                );
+    
+            for (Intent policyIntent : scaDefns.getPolicyIntents()) {
+                extensionProcessor.write(policyIntent, writer);
+            }
+            
+            for (PolicySet policySet : scaDefns.getPolicySets()) {
+                extensionProcessor.write(policySet, writer);
+            }
+            
+            for (BindingType bindingType : scaDefns.getBindingTypes()) {
+                extensionProcessor.write(bindingType, writer);
+            }
+            
+            for (ImplementationType implType : scaDefns.getImplementationTypes()) {
+                extensionProcessor.write(implType, writer);
+            }
+
+            writeEndDocument(writer);
+            
+        } catch (XMLStreamException e) {
+            throw new ContributionWriteException(e);
+        }
+    }
+    
+    public void resolve(SCADefinitions scaDefns, ModelResolver resolver) throws ContributionResolveException {
+        
+        for (int count = 0, size = scaDefns.getPolicyIntents().size(); count < size; count++) {
+            Intent policyIntent = scaDefns.getPolicyIntents().get(count);
+            policyIntentResolver.resolve(policyIntent, resolver);
+            //extensionProcessor.resolve(policyIntent, resolver);
+        }
+        
+        for (int count = 0, size = scaDefns.getPolicySets().size(); count < size; count++) {
+            PolicySet policySet = scaDefns.getPolicySets().get(count);
+            policySet = resolver.resolveModel(PolicySet.class, policySet);
+            scaDefns.getPolicySets().set(count, policySet);
+        }
+        
+        for (int count = 0, size = scaDefns.getBindingTypes().size(); count < size; count++) {
+            BindingType bindingType = scaDefns.getBindingTypes().get(count);
+            bindingType = resolver.resolveModel(BindingType.class, bindingType);
+            scaDefns.getBindingTypes().set(count, bindingType);
+        }
+        
+        for (int count = 0, size = scaDefns.getImplementationTypes().size(); count < size; count++) {
+            ImplementationType implType = scaDefns.getImplementationTypes().get(count);
+            implType = resolver.resolveModel(ImplementationType.class, implType);
+            scaDefns.getImplementationTypes().set(count, implType);
+        }
+    }
+
+    public QName getArtifactType() {
+        return SCA_DEFNS_QNAME;
+    }
+    
+    public Class<SCADefinitions> getModelType() {
+        return SCADefinitions.class;
+    }
+}

Added: incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/XAttr.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/XAttr.java?view=auto&rev=555688
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/XAttr.java (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/XAttr.java Thu Jul 12 09:29:23 2007
@@ -0,0 +1,121 @@
+/*
+ * 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 javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+
+/**
+ * Represents an XML attribute that needs to be written to a document.
+ *
+ */
+class XAttr {
+
+    String uri = PolicyConstants.SCA10_NS;
+    String name;
+    Object value;
+
+    public XAttr(String uri, String name, String value) {
+        this.uri = uri;
+        this.name = name;
+        this.value = value;
+    }
+
+    public XAttr(String name, String value) {
+        this.name = name;
+        this.value = value;
+    }
+
+    public XAttr(String uri, String name, boolean value) {
+        this.uri = uri;
+        this.name = name;
+        this.value = value;
+    }
+
+    public XAttr(String name, boolean value) {
+        this.name = name;
+        this.value = value;
+    }
+
+    public XAttr(String uri, String name, QName value) {
+        this.uri = uri;
+        this.name = name;
+        this.value = value;
+    }
+
+    public XAttr(String name, QName value) {
+        this.name = name;
+        this.value = value;
+    }
+
+    /**
+     * Writes a string from a qname and registers a prefix for its namespace.  
+     * @param reader
+     * @param value
+     * @return
+     */
+    protected String writeQNameValue(XMLStreamWriter writer, QName qname) throws XMLStreamException {
+        if (qname != null) {
+            String prefix = qname.getPrefix();
+            String uri = qname.getNamespaceURI();
+            prefix = writer.getPrefix(uri);
+            if (prefix != null) {
+
+                // Use the prefix already bound to the given uri
+                return prefix + ":" + qname.getLocalPart();
+            } else {
+                
+                // Find an available prefix and bind it to the given uri 
+                NamespaceContext nsc = writer.getNamespaceContext();
+                for (int i=1; ; i++) {
+                    prefix = "ns" + i;
+                    if (nsc.getNamespaceURI(prefix) == null) {
+                        break;
+                    }
+                }
+                writer.setPrefix(prefix, uri);
+                writer.writeNamespace(prefix, uri);
+                return prefix + ":" + qname.getLocalPart();
+            }
+        } else {
+            return null;
+        }
+    }
+
+    void write(XMLStreamWriter writer) throws XMLStreamException {
+        if (value != null) {
+            String str;
+            if (value instanceof QName) {
+                str = writeQNameValue(writer, (QName)value);
+            } else {
+                str = String.valueOf(value);
+            }
+            if (uri != null && !uri.equals(PolicyConstants.SCA10_NS)) {
+                writer.writeAttribute(uri, name, str);
+            } else {
+                writer.writeAttribute(name,str);
+            }
+        }
+    }
+
+}

Added: 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?view=auto&rev=555688
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java Thu Jul 12 09:29:23 2007
@@ -0,0 +1,100 @@
+/*
+ * 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 java.net.URI;
+import java.net.URL;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.SCADefinitions;
+
+/**
+ * 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 TestModelResolver resolver; 
+    private SCADefinitionsDocumentProcessor scaDefnDocProcessor = null;
+    private SCADefinitionsProcessor scaDefnProcessor = null;
+    
+
+    public void setUp() throws Exception {
+        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+        PolicyFactory policyFactory = new DefaultPolicyFactory();
+        
+        // Create Stax processors
+        DefaultStAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint();
+        ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance());
+        
+        scaDefnDocProcessor = new SCADefinitionsDocumentProcessor(staxProcessor, inputFactory);
+        scaDefnProcessor = new SCADefinitionsProcessor(policyFactory, staxProcessor);
+        staxProcessors.addArtifactProcessor(scaDefnProcessor);
+        staxProcessors.addArtifactProcessor(new PolicyIntentProcessor(policyFactory));
+        
+        resolver = new TestModelResolver(getClass().getClassLoader());
+    }
+
+    public void tearDown() throws Exception {
+        resolver = null;
+        scaDefnDocProcessor = null;
+        scaDefnProcessor = null;
+    }
+
+    public void testLoadSCADefinitions() throws Exception {
+        
+        URL url = getClass().getResource("definitions.xml");
+        URI uri = URI.create("definitions.xml");
+        SCADefinitions scaDefinitions = (SCADefinitions)scaDefnDocProcessor.read(null, uri, url);
+        assertNotNull(scaDefinitions);
+        
+        resolver.addModel(scaDefinitions);
+        scaDefnDocProcessor.resolve(scaDefinitions, resolver);
+        
+        /*assertEquals(composite.getConstrainingType(), constrainingType);
+        assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType);*/
+    }
+
+    /*public void testResolveComposite() throws Exception {
+        URL url = getClass().getResource("Calculator.composite");
+        URI uri = URI.create("Calculator.composite");
+        Composite nestedComposite = (Composite)documentProcessor.read(null, uri, url);
+        assertNotNull(nestedComposite);
+        resolver.addModel(nestedComposite);
+
+        url = getClass().getResource("TestAllCalculator.composite");
+        uri = URI.create("TestAllCalculator.composite");
+        Composite composite = (Composite)documentProcessor.read(null, uri, url);
+        
+        documentProcessor.resolve(composite, resolver);
+        
+        assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
+    }
+*/
+}

Added: incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestModelResolver.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestModelResolver.java?view=auto&rev=555688
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestModelResolver.java (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestModelResolver.java Thu Jul 12 09:29:23 2007
@@ -0,0 +1,63 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+
+/**
+ * A default implementation of an artifact resolver, based on a map.
+ *
+ * @version $Rev: 538445 $ $Date: 2007-05-16 11:50:37 +0530 (Wed, 16 May 2007) $
+ */
+public class TestModelResolver implements ModelResolver {
+    private static final long serialVersionUID = -7826976465762296634L;
+    
+    private Map<Object, Object> map = new HashMap<Object, Object>();
+    
+    public TestModelResolver(ClassLoader classLoader) {
+    }
+
+    public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+        Object resolved = map.get(unresolved);
+        if (resolved != null) {
+            
+            // Return the resolved object
+            return modelClass.cast(resolved);
+            
+        } else {
+            
+            // Return the unresolved object
+            return unresolved;
+        }
+    }
+    
+    public void addModel(Object resolved) {
+        map.put(resolved, resolved);
+    }
+    
+    public Object removeModel(Object resolved) {
+        return map.remove(resolved);
+    }
+    
+}

Added: incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/definitions.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/definitions.xml?view=auto&rev=555688
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/definitions.xml (added)
+++ incubator/tuscany/java/sca/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/definitions.xml Thu Jul 12 09:29:23 2007
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="ASCII"?>
+<definitions xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ 			targetNamespace="http://test"
+ 			xmlns:sca="http://www.osoa.org/xmlns/sca/1.0">
+
+<!-- simple intent -->
+ <intent name="confidentiality" 
+ 			 constrains="sca:binding">
+ 			 <description>
+ 			 Communitcation thro this binding must prevent
+ 			 unauthorized users from reading the messages.
+ 			 </description>
+ </intent>
+ 
+ <intent name="integrity" 
+ 			 constrains="sca:binding">
+ 			 <description>
+ 			 Communitcation thro this binding must prevent
+ 			 unauthorized modification of the messages.
+ 			 </description>
+ </intent>
+ 
+ <!-- profile intent -->
+ <intent name="messageProtection" 
+ 			 constrains="sca:binding"
+ 			 requires="confidentiality integrity">
+ 			 <description>
+ 			 	Protect messages from unauthorized reading or modification
+ 			 </description>
+ </intent>
+ 
+ <!-- qualified intents -->
+ <intent name="confidentiality.transport" />
+ <intent name="confidentiality.message" />
+</definitions>
\ No newline at end of file



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