tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r572267 [3/6] - in /incubator/tuscany/java/sca: itest/ modules/ modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ modules/binding-jms/src/main/jav...
Date Mon, 03 Sep 2007 09:46:47 GMT
Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java Mon Sep  3 02:46:41 2007
@@ -46,7 +46,6 @@
 import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
 import org.apache.tuscany.sca.policy.IntentAttachPoint;
 import org.apache.tuscany.sca.policy.PolicyFactory;
-import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
 import org.apache.tuscany.sca.policy.SCADefinitions;
 import org.apache.tuscany.sca.policy.xml.PolicySetProcessor;
 import org.apache.tuscany.sca.policy.xml.ProfileIntentProcessor;
@@ -68,6 +67,7 @@
     CompositeBuilder compositeBuilder;
     Composite composite = null;
 
+    @Override
     public void setUp() throws Exception {
         AssemblyFactory factory = new DefaultAssemblyFactory();
         PolicyFactory policyFactory = new DefaultPolicyFactory();
@@ -122,6 +122,7 @@
         compositeBuilder.build(composite);
     }
 
+    @Override
     public void tearDown() throws Exception {
         documentProcessor = null;
         resolver = null;

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MockPolicyProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MockPolicyProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MockPolicyProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MockPolicyProcessor.java Mon Sep  3 02:46:41 2007
@@ -46,16 +46,13 @@
 
     public void write(Policy arg0, XMLStreamWriter arg1) throws ContributionWriteException,
                                                         XMLStreamException {
-
     }
 
     public Class<Policy> getModelType() {
-        // TODO Auto-generated method stub
         return Policy.class;
     }
 
     public void resolve(Policy arg0, ModelResolver arg1) throws ContributionResolveException {
-
     }
 
     

Modified: incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java Mon Sep  3 02:46:41 2007
@@ -31,6 +31,7 @@
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor;
 import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
 import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
 import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
@@ -106,11 +107,13 @@
 
 public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding>{
     
-    private PolicyFactory policyFactory;    
+    private PolicyFactory policyFactory;
+    private PolicyAttachPointProcessor policyProcessor;
 
 
     public JMSBindingProcessor(ModelFactoryExtensionPoint modelFactories) {
         this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
+        this.policyProcessor = new PolicyAttachPointProcessor(policyFactory);
     }
 
     public QName getArtifactType() {
@@ -121,171 +124,107 @@
         return JMSBinding.class;
     }
 
-    public JMSBinding read(XMLStreamReader reader) 
-      throws ContributionReadException {
-        try {
-            JMSBinding jmsBinding = new JMSBinding();
-            
-            // Read policies
-            if ( jmsBinding instanceof PolicySetAttachPoint ) {
-                readPolicies((PolicySetAttachPoint)jmsBinding, reader);
-            }
+    public JMSBinding read(XMLStreamReader reader)  throws ContributionReadException, XMLStreamException {
+        JMSBinding jmsBinding = new JMSBinding();
+        
+        // Read policies
+        policyProcessor.readPolicies(jmsBinding, reader);
 
-            // Read binding name
-            String name = reader.getAttributeValue(null, "name");
-            if (name != null) {
-                jmsBinding.setName(name);
-            }
-            
-            // Read binding URI
-            String uri = reader.getAttributeValue(null, "uri");
-            if (uri != null) {
-                jmsBinding.setURI(uri);
-                System.err.println("JMS Binding doesn't process uri yet");
-            }
+        // Read binding name
+        String name = reader.getAttributeValue(null, "name");
+        if (name != null) {
+            jmsBinding.setName(name);
+        }
+        
+        // Read binding URI
+        String uri = reader.getAttributeValue(null, "uri");
+        if (uri != null) {
+            jmsBinding.setURI(uri);
+            System.err.println("JMS Binding doesn't process uri yet");
+        }
 
-            // Read correlation scheme
-            String correlationScheme = reader.getAttributeValue(null, "correlationScheme");
-            if (correlationScheme != null && correlationScheme.length() > 0) {
-                if (JMSBindingConstants.VALID_CORRELATION_SCHEMES.contains(correlationScheme.toLowerCase())) {
-                    jmsBinding.setCorrelationScheme(correlationScheme);
-                } else {
-                    throw new JMSBindingException("invalid correlationScheme: " + correlationScheme);
-                }
-                System.err.println("JMS Binding doesn't process correlationScheme yet");
+        // Read correlation scheme
+        String correlationScheme = reader.getAttributeValue(null, "correlationScheme");
+        if (correlationScheme != null && correlationScheme.length() > 0) {
+            if (JMSBindingConstants.VALID_CORRELATION_SCHEMES.contains(correlationScheme.toLowerCase())) {
+                jmsBinding.setCorrelationScheme(correlationScheme);
+            } else {
+                throw new JMSBindingException("invalid correlationScheme: " + correlationScheme);
             }
+            System.err.println("JMS Binding doesn't process correlationScheme yet");
+        }
 
-            // Read initial context factory
-            String initialContextFactory = reader.getAttributeValue(null, "initialContextFactory");
-            if (initialContextFactory != null && initialContextFactory.length() > 0) {
-                jmsBinding.setInitialContextFactoryName(initialContextFactory);
-            }
+        // Read initial context factory
+        String initialContextFactory = reader.getAttributeValue(null, "initialContextFactory");
+        if (initialContextFactory != null && initialContextFactory.length() > 0) {
+            jmsBinding.setInitialContextFactoryName(initialContextFactory);
+        }
 
-            // Read jndi URL
-            String jndiURL = reader.getAttributeValue(null, "jndiURL");
-            if (jndiURL != null && jndiURL.length() > 0) {
-                jmsBinding.setJndiURL(jndiURL);
-            }
-            
-            // Read requestConnection
-            // TODO
-            // Read reponseConnection
-            // TODO
-            // Read operationProperties
-            // TODO
-            
-            // Read subelements of binding.jms
-            boolean endFound = false;
-            while (!endFound) {
-                switch (reader.next()) {
-                    case START_ELEMENT:
-                        String elementName = reader.getName().getLocalPart();
-                        if ("destination".equals(elementName)) {
-                            parseDestination(reader, jmsBinding);
-                        } else if ("connectionFactory".equals(elementName)) {
-                            parseConnectionFactory(reader, jmsBinding);
-                        } else if ("activationSpec".equals(elementName)) {
-                            parseActivationSpec(reader, jmsBinding);
-                        } else if ("response".equals(elementName)) {
-                            parseResponse(reader, jmsBinding);
-                        } else if ("resourceAdapter".equals(elementName)) {
-                            parseResourceAdapter(reader, jmsBinding);                            
-                        } else if ("headers".equals(elementName)) {
-                            parseHeaders(reader, jmsBinding);
-                        } else if ("operationProperties".equals(elementName)) {
-                            parseOperationProperties(reader, jmsBinding);
-                        } 
-                        reader.next();
-                        break;
-                    case END_ELEMENT:
-                        QName x = reader.getName();
-                        if (x.equals(JMSBindingConstants.BINDING_JMS_QNAME)) {
-                            endFound = true;
-                        } else {
-                            throw new RuntimeException("Incomplete binding.jms definition found unexpected element " + x.toString());
-                        }
-                }
+        // Read jndi URL
+        String jndiURL = reader.getAttributeValue(null, "jndiURL");
+        if (jndiURL != null && jndiURL.length() > 0) {
+            jmsBinding.setJndiURL(jndiURL);
+        }
+        
+        // Read requestConnection
+        // TODO
+        // Read reponseConnection
+        // TODO
+        // Read operationProperties
+        // TODO
+        
+        // Read subelements of binding.jms
+        boolean endFound = false;
+        while (!endFound) {
+            switch (reader.next()) {
+                case START_ELEMENT:
+                    String elementName = reader.getName().getLocalPart();
+                    if ("destination".equals(elementName)) {
+                        parseDestination(reader, jmsBinding);
+                    } else if ("connectionFactory".equals(elementName)) {
+                        parseConnectionFactory(reader, jmsBinding);
+                    } else if ("activationSpec".equals(elementName)) {
+                        parseActivationSpec(reader, jmsBinding);
+                    } else if ("response".equals(elementName)) {
+                        parseResponse(reader, jmsBinding);
+                    } else if ("resourceAdapter".equals(elementName)) {
+                        parseResourceAdapter(reader, jmsBinding);                            
+                    } else if ("headers".equals(elementName)) {
+                        parseHeaders(reader, jmsBinding);
+                    } else if ("operationProperties".equals(elementName)) {
+                        parseOperationProperties(reader, jmsBinding);
+                    } 
+                    reader.next();
+                    break;
+                case END_ELEMENT:
+                    QName x = reader.getName();
+                    if (x.equals(JMSBindingConstants.BINDING_JMS_QNAME)) {
+                        endFound = true;
+                    } else {
+                        throw new RuntimeException("Incomplete binding.jms definition found unexpected element " + x.toString());
+                    }
             }
-            
-            jmsBinding.validate();           
-            
-            return jmsBinding;
-        } catch (XMLStreamException e) {
-            throw new ContributionReadException(e);
         }
+        
+        jmsBinding.validate();           
+        
+        return jmsBinding;
     }
     
     public void resolve(JMSBinding model, ModelResolver resolver) throws ContributionResolveException {
     }    
 
-    public void write(JMSBinding rmiBinding, XMLStreamWriter writer) throws ContributionWriteException {
-        try {
-            // Write a <binding.ws>
-            writer.writeStartElement(Constants.SCA10_NS, JMSBindingConstants.BINDING_JMS);
-
-            // TODO 
-            
-            writer.writeEndElement();
+    public void write(JMSBinding rmiBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+        // Write a <binding.jms>
+        writer.writeStartElement(Constants.SCA10_NS, JMSBindingConstants.BINDING_JMS);
 
-        } catch (XMLStreamException e) {
-            throw new ContributionWriteException(e);
-        }
+        // FIXME Implement
+        
+        writer.writeEndElement();
     }
 
 
-    /**
-     * Reads policy intents and policy sets.
-     * @param attachPoint where the intents and policy sets will be stored
-     * @param reader the XML stream reader
-     */
-    private void readPolicies(PolicySetAttachPoint attachPoint, XMLStreamReader reader) {
-        String value = reader.getAttributeValue(null, Constants.REQUIRES);
-        if (value != null) {
-            List<Intent> requiredIntents = attachPoint.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);
-            }
-            System.err.println("JMS Binding doesn't process requires yet");            
-        }
-
-        value = reader.getAttributeValue(null, Constants.POLICY_SETS);
-        if (value != null) {
-            List<PolicySet> policySets = attachPoint.getPolicySets();
-            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
-                QName qname = getQNameValue(reader, tokens.nextToken());
-                PolicySet policySet = policyFactory.createPolicySet();
-                policySet.setName(qname);
-                policySets.add(policySet);
-            }
-            System.err.println("JMS Binding doesn't process policySets yet");
-        }
-    }
-    
-    /**
-     * Returns a qname from a string.  
-     * @param reader the XML stream reader
-     * @param value the string version of the QName
-     * @return
-     */
-    private 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;
-        }
-    } 
-    
-    protected void parseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
+    private void parseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
         String name = reader.getAttributeValue(null, "name");
         if (name != null && name.length() > 0) {
             jmsBinding.setDestinationName(name);
@@ -309,7 +248,7 @@
         }
     } 
     
-    protected void parseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) {
+    private void parseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) {
         String name = reader.getAttributeValue(null, "name");
         if (name != null && name.length() > 0) {
             jmsBinding.setConnectionFactoryName(name);
@@ -318,7 +257,7 @@
         }
     }    
 
-    protected void parseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) {
+    private void parseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) {
         String name = reader.getAttributeValue(null, "name");
         if (name != null && name.length() > 0) {
             jmsBinding.setActivationSpecName(name);
@@ -328,7 +267,7 @@
         }
     }
 
-    protected void parseResponseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
+    private void parseResponseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
         String name = reader.getAttributeValue(null, "name");
         if (name != null && name.length() > 0) {
             jmsBinding.setResponseDestinationName(name);
@@ -352,7 +291,7 @@
         }
     } 
     
-    protected void parseResponseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) {
+    private void parseResponseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) {
         String name = reader.getAttributeValue(null, "name");
         if (name != null && name.length() > 0) {
             jmsBinding.setResponseConnectionFactoryName(name);
@@ -362,7 +301,7 @@
         }
     }    
 
-    protected void parseResponseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) {
+    private void parseResponseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) {
         String name = reader.getAttributeValue(null, "name");
         if (name != null && name.length() > 0) {
             jmsBinding.setResponseActivationSpecName(name);
@@ -372,7 +311,7 @@
         }
     }
     
-    protected void parseResponse(XMLStreamReader reader, JMSBinding jmsBinding)
+    private void parseResponse(XMLStreamReader reader, JMSBinding jmsBinding)
       throws XMLStreamException {
         // Read subelements of response
         while (true) {
@@ -399,15 +338,15 @@
         }
     }
 
-    protected void parseResourceAdapter(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
+    private void parseResourceAdapter(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
         System.err.println("JMS Binding doesn't process resourceAdapter yet");
     }
     
-    protected void parseHeaders(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
+    private void parseHeaders(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
         System.err.println("JMS Binding doesn't process headers yet");
     }    
 
-    protected void parseOperationProperties(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
+    private void parseOperationProperties(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
         System.err.println("JMS Binding doesn't process operationProperties yet");
     }
 

Modified: incubator/tuscany/java/sca/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProcessor.java Mon Sep  3 02:46:41 2007
@@ -88,6 +88,8 @@
 
     public void write(NotificationBinding notificationBinding, XMLStreamWriter writer)
             throws ContributionWriteException, XMLStreamException {
+        
+        //FIXME Implement this method
     }
 
     public void resolve(NotificationBinding notificationBinding, ModelResolver resolver) throws ContributionResolveException {

Modified: incubator/tuscany/java/sca/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java Mon Sep  3 02:46:41 2007
@@ -21,9 +21,6 @@
 
 import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
 
-import java.util.List;
-import java.util.StringTokenizer;
-
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -33,18 +30,14 @@
 import org.apache.tuscany.sca.assembly.SCABinding;
 import org.apache.tuscany.sca.assembly.SCABindingFactory;
 import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor;
 import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
 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.interfacedef.Operation;
-import org.apache.tuscany.sca.policy.Intent;
-import org.apache.tuscany.sca.policy.IntentAttachPoint;
 import org.apache.tuscany.sca.policy.PolicyFactory;
-import org.apache.tuscany.sca.policy.PolicySet;
-import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
 
 /**
  * A processor to read the XML that describes the SCA binding.
@@ -52,25 +45,26 @@
 
 public class SCABindingProcessor implements StAXArtifactProcessor<SCABinding>, Constants{
     
-    protected AssemblyFactory assemblyFactory;
-    protected PolicyFactory policyFactory;       
+    private PolicyFactory policyFactory;       
     private SCABindingFactory scaBindingFactory;
+    private PolicyAttachPointProcessor policyProcessor;
 
     protected static final String BINDING_SCA = "binding.sca";
     protected static final QName BINDING_SCA_QNAME = new QName(Constants.SCA10_NS, BINDING_SCA);
 
     public SCABindingProcessor(ModelFactoryExtensionPoint modelFactories) {
-        this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
         this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
         this.scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class);
+        policyProcessor = new PolicyAttachPointProcessor(policyFactory);
     }
     
+    //FIXME Remove this constructor
     public SCABindingProcessor(AssemblyFactory assemblyFactory,
                                PolicyFactory policyFactory,
                                SCABindingFactory scaBindingFactory) {
-    	this.assemblyFactory = assemblyFactory;
     	this.policyFactory = policyFactory;
         this.scaBindingFactory = scaBindingFactory;
+        policyProcessor = new PolicyAttachPointProcessor(policyFactory);
     }
 
     public QName getArtifactType() {
@@ -81,141 +75,51 @@
         return SCABinding.class;
     }
 
-    public SCABinding read(XMLStreamReader reader) throws ContributionReadException {
-        try {
-            SCABinding scaBinding = scaBindingFactory.createSCABinding();
-            
-            // Read policies
-            if ( scaBinding instanceof IntentAttachPoint && scaBinding instanceof PolicySetAttachPoint ) {
-                readPolicies((PolicySetAttachPoint)scaBinding, reader);
-            }
-            
-            // Read binding name
-            String name = reader.getAttributeValue(null, NAME);
-            if (name != null) {
-                scaBinding.setName(name);
-            }
+    public SCABinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+        SCABinding scaBinding = scaBindingFactory.createSCABinding();
+        
+        // Read policies
+        policyProcessor.readPolicies(scaBinding, reader);
+        
+        // Read binding name
+        String name = reader.getAttributeValue(null, NAME);
+        if (name != null) {
+            scaBinding.setName(name);
+        }
 
-            // Read binding URI
-            String uri = reader.getAttributeValue(null, URI);
-            if (uri != null) {
-                scaBinding.setURI(uri);
-            }
+        // Read binding URI
+        String uri = reader.getAttributeValue(null, URI);
+        if (uri != null) {
+            scaBinding.setURI(uri);
+        }
 
-            // Skip to end element
-            while (reader.hasNext()) {
-                if (reader.next() == END_ELEMENT && BINDING_SCA_QNAME.equals(reader.getName())) {
-                    break;
-                }
+        // Skip to end element
+        while (reader.hasNext()) {
+            if (reader.next() == END_ELEMENT && BINDING_SCA_QNAME.equals(reader.getName())) {
+                break;
             }
-            return scaBinding;
-
-        } catch (XMLStreamException e) {
-            throw new ContributionReadException(e);
         }
+        return scaBinding;
     }
     
     public void resolve(SCABinding model, ModelResolver resolver) throws ContributionResolveException {
     }    
 
-    public void write(SCABinding scaBinding, XMLStreamWriter writer) throws ContributionWriteException {
-        try {
-            // Write a <binding.sca>
-            writer.writeStartElement(Constants.SCA10_NS, BINDING_SCA);
-
-            // Write binding URI
-            if (scaBinding.getURI() != null) {
-                writer.writeAttribute(URI, scaBinding.getURI());
-            }
-            
-            writer.writeEndElement();
-
-        } catch (XMLStreamException e) {
-            throw new ContributionWriteException(e);
+    public void write(SCABinding scaBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+        // Write <binding.sca>
+        writer.writeStartElement(Constants.SCA10_NS, BINDING_SCA);
+
+        // Write binding name
+        if (scaBinding.getName() != null) {
+            writer.writeAttribute(NAME, scaBinding.getName());
         }
-    }
-    
-    /**
-     * The following are copied from BaseArtefactProcessor as that class is
-     * abstract
-     */
-     
-    /**
-     * Reads policy intents and policy sets.
-     * @param attachPoint
-     * @param reader
-     */
-    protected void readPolicies(PolicySetAttachPoint attachPoint, XMLStreamReader reader) {
-        readPolicies(attachPoint, null, reader);
-    }
-
-    /**
-     * Reads policy intents and policy sets associated with an operation.
-     * @param attachPoint
-     * @param operation
-     * @param reader
-     */
-    protected void readPolicies(PolicySetAttachPoint attachPoint, Operation operation, XMLStreamReader reader) {
-        readIntents(attachPoint, operation, reader);
-
-        String value = reader.getAttributeValue(null, Constants.POLICY_SETS);
-        if (value != null) {
-            List<PolicySet> policySets = attachPoint.getPolicySets();
-            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
-                QName qname = getQNameValue(reader, tokens.nextToken());
-                PolicySet policySet = policyFactory.createPolicySet();
-                policySet.setName(qname);
-                if (operation != null) {
-                    //policySet.getOperations().add(operation);
-                }
-                policySets.add(policySet);
-            }
-        }
-    }  
-    
-    /**
-     * Read policy intents associated with an operation.
-     * @param attachPoint
-     * @param operation
-     * @param reader
-     */
-    protected void readIntents(IntentAttachPoint attachPoint, Operation operation, XMLStreamReader reader) {
-        String value = reader.getAttributeValue(null, Constants.REQUIRES);
-        if (value != null) {
-            List<Intent> requiredIntents = attachPoint.getRequiredIntents();
-            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
-                QName qname = getQNameValue(reader, tokens.nextToken());
-                Intent intent = policyFactory.createIntent();
-                intent.setName(qname);
-                if (operation != null) {
-                    //intent.getOperations().add(operation);
-                }
-                requiredIntents.add(intent);
-            }
+        
+        // Write binding URI
+        if (scaBinding.getURI() != null) {
+            writer.writeAttribute(URI, scaBinding.getURI());
         }
+        
+        writer.writeEndElement();
     }
     
-    /**
-     * 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;
-        }
-    }    
-    
-    
-
 }

Modified: incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java Mon Sep  3 02:46:41 2007
@@ -21,9 +21,7 @@
 
 import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
 
-import java.util.List;
 import java.util.Map;
-import java.util.StringTokenizer;
 
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
@@ -35,6 +33,7 @@
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor;
 import org.apache.tuscany.sca.binding.ws.DefaultWebServiceBindingFactory;
 import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
 import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory;
@@ -49,10 +48,7 @@
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
 import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
-import org.apache.tuscany.sca.policy.Intent;
 import org.apache.tuscany.sca.policy.PolicyFactory;
-import org.apache.tuscany.sca.policy.PolicySet;
-import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
 
 public class WebServiceBindingProcessor implements
     StAXArtifactProcessor<WebServiceBinding>, WebServiceConstants {
@@ -60,165 +56,163 @@
     private WSDLFactory wsdlFactory;
     private WebServiceBindingFactory wsFactory;
     private PolicyFactory policyFactory;
+    private PolicyAttachPointProcessor policyProcessor;
 
     public WebServiceBindingProcessor(ModelFactoryExtensionPoint modelFactories) {
         this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
         this.wsFactory = new DefaultWebServiceBindingFactory();
         this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class);
+        policyProcessor = new PolicyAttachPointProcessor(policyFactory);
     }
 
-    public WebServiceBinding read(XMLStreamReader reader) throws ContributionReadException {
-        try {
+    public WebServiceBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
 
-            // Read a <binding.ws>
-            WebServiceBinding wsBinding = wsFactory.createWebServiceBinding();
-            wsBinding.setUnresolved(true);
-
-            // Read policies
-            if ( wsBinding instanceof PolicySetAttachPoint ) {
-                readPolicies((PolicySetAttachPoint)wsBinding, reader);
-            }
-            
-            // Read the binding name
-            String name = reader.getAttributeValue(null, NAME);
-            if (name != null) {
-                wsBinding.setName(name);
-            }
+        // Read a <binding.ws>
+        WebServiceBinding wsBinding = wsFactory.createWebServiceBinding();
+        wsBinding.setUnresolved(true);
+
+        // Read policies
+        policyProcessor.readPolicies(wsBinding, reader);
+        
+        // Read the binding name
+        String name = reader.getAttributeValue(null, NAME);
+        if (name != null) {
+            wsBinding.setName(name);
+        }
 
-            // Read URI
-            String uri = reader.getAttributeValue(null, URI);
-            if (uri != null) {
-                wsBinding.setURI(uri);
-            }
+        // Read URI
+        String uri = reader.getAttributeValue(null, URI);
+        if (uri != null) {
+            wsBinding.setURI(uri);
+        }
 
-            // Read a qname in the form:
-            // namespace#wsdl.???(name)
-            String wsdlElement = reader.getAttributeValue(null, WSDL_ELEMENT);
-            if (wsdlElement != null) {
-                int index = wsdlElement.indexOf('#');
-                if (index == -1) {
+        // Read a qname in the form:
+        // namespace#wsdl.???(name)
+        String wsdlElement = reader.getAttributeValue(null, WSDL_ELEMENT);
+        if (wsdlElement != null) {
+            int index = wsdlElement.indexOf('#');
+            if (index == -1) {
+                throw new ContributionReadException(
+                                                    "Invalid WebService binding wsdlElement attribute: " + wsdlElement);
+            }
+            String namespace = wsdlElement.substring(0, index);
+            wsBinding.setNamespace(namespace);
+            String localName = wsdlElement.substring(index + 1);
+            if (localName.startsWith("wsdl.service")) {
+
+                // Read a wsdl.service
+                localName = localName.substring("wsdl.service(".length(), localName.length() - 1);
+                wsBinding.setServiceName(new QName(namespace, localName));
+
+            } else if (localName.startsWith("wsdl.port")) {
+
+                // Read a wsdl.port
+                localName = localName.substring("wsdl.port(".length(), localName.length() - 1);
+                int s = localName.indexOf('/');
+                if (s == -1) {
                     throw new ContributionReadException(
                                                         "Invalid WebService binding wsdlElement attribute: " + wsdlElement);
                 }
-                String namespace = wsdlElement.substring(0, index);
-                wsBinding.setNamespace(namespace);
-                String localName = wsdlElement.substring(index + 1);
-                if (localName.startsWith("wsdl.service")) {
-
-                    // Read a wsdl.service
-                    localName = localName.substring("wsdl.service(".length(), localName.length() - 1);
-                    wsBinding.setServiceName(new QName(namespace, localName));
-
-                } else if (localName.startsWith("wsdl.port")) {
-
-                    // Read a wsdl.port
-                    localName = localName.substring("wsdl.port(".length(), localName.length() - 1);
-                    int s = localName.indexOf('/');
-                    if (s == -1) {
-                        throw new ContributionReadException(
-                                                            "Invalid WebService binding wsdlElement attribute: " + wsdlElement);
-                    }
-                    wsBinding.setServiceName(new QName(namespace, localName.substring(0, s)));
-                    wsBinding.setPortName(localName.substring(s + 1));
-
-                } else if (localName.startsWith("wsdl.endpoint")) {
-
-                    // Read a wsdl.endpoint
-                    localName = localName.substring("wsdl.endpoint(".length(), localName.length() - 1);
-                    int s = localName.indexOf('/');
-                    if (s == -1) {
-                        throw new ContributionReadException(
-                                                            "Invalid WebService binding wsdlElement attribute: " + wsdlElement);
-                    }
-                    wsBinding.setServiceName(new QName(namespace, localName.substring(0, s)));
-                    wsBinding.setEndpointName(localName.substring(s + 1));
-
-                } else if (localName.startsWith("wsdl.binding")) {
-
-                    // Read a wsdl.service
-                    localName = localName.substring("wsdl.binding(".length(), localName.length() - 1);
-                    wsBinding.setBindingName(new QName(namespace, localName));
+                wsBinding.setServiceName(new QName(namespace, localName.substring(0, s)));
+                wsBinding.setPortName(localName.substring(s + 1));
+
+            } else if (localName.startsWith("wsdl.endpoint")) {
 
-                } else {
+                // Read a wsdl.endpoint
+                localName = localName.substring("wsdl.endpoint(".length(), localName.length() - 1);
+                int s = localName.indexOf('/');
+                if (s == -1) {
                     throw new ContributionReadException(
                                                         "Invalid WebService binding wsdlElement attribute: " + wsdlElement);
                 }
-            }
+                wsBinding.setServiceName(new QName(namespace, localName.substring(0, s)));
+                wsBinding.setEndpointName(localName.substring(s + 1));
 
-            // Read wsdlLocation
-            wsBinding.setLocation(reader.getAttributeValue(WSDLI_NS, WSDL_LOCATION));
+            } else if (localName.startsWith("wsdl.binding")) {
 
-            // Skip to end element
-            while (reader.hasNext()) {
-                if (reader.next() == END_ELEMENT && BINDING_WS_QNAME.equals(reader.getName())) {
-                    break;
-                }
+                // Read a wsdl.service
+                localName = localName.substring("wsdl.binding(".length(), localName.length() - 1);
+                wsBinding.setBindingName(new QName(namespace, localName));
+
+            } else {
+                throw new ContributionReadException(
+                                                    "Invalid WebService binding wsdlElement attribute: " + wsdlElement);
             }
-            return wsBinding;
+        }
 
-        } catch (XMLStreamException e) {
-            throw new ContributionReadException(e);
+        // Read wsdlLocation
+        wsBinding.setLocation(reader.getAttributeValue(WSDLI_NS, WSDL_LOCATION));
+
+        // Skip to end element
+        while (reader.hasNext()) {
+            if (reader.next() == END_ELEMENT && BINDING_WS_QNAME.equals(reader.getName())) {
+                break;
+            }
         }
+        return wsBinding;
     }
 
-    public void write(WebServiceBinding wsBinding, XMLStreamWriter writer) throws ContributionWriteException {
-        try {
-            // Write a <binding.ws>
-            writer.writeStartElement(Constants.SCA10_NS, BINDING_WS);
-
-            // Write binding URI
-            if (wsBinding.getURI() != null) {
-                writer.writeAttribute(Constants.URI, wsBinding.getURI());
-            }
+    public void write(WebServiceBinding wsBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
 
-            // Write wsdlElement attribute
-            if (wsBinding.getPortName() != null) {
+        // Write a <binding.ws>
+        policyProcessor.writePolicyPrefixes(wsBinding, writer);
+        writer.writeStartElement(Constants.SCA10_NS, BINDING_WS);
+        policyProcessor.writePolicyAttributes(wsBinding, writer);
+        
+        // Write binding name
+        if (wsBinding.getName() != null) {
+            writer.writeAttribute(NAME, wsBinding.getName());
+        }
 
-                // Write namespace#wsdl.port(service/port)
-                String wsdlElement = wsBinding.getServiceName().getNamespaceURI() + "#wsdl.port("
-                                     + wsBinding.getServiceName().getLocalPart()
-                                     + "/"
-                                     + wsBinding.getPortName()
-                                     + ")";
-                writer.writeAttribute(WSDL_ELEMENT, wsdlElement);
-
-            } else if (wsBinding.getEndpointName() != null) {
-
-                // Write namespace#wsdl.endpoint(service/endpoint)
-                String wsdlElement = wsBinding.getServiceName().getNamespaceURI() + "#wsdl.endpoint("
-                                     + wsBinding.getServiceName().getLocalPart()
-                                     + "/"
-                                     + wsBinding.getEndpointName()
-                                     + ")";
-                writer.writeAttribute(WSDL_ELEMENT, wsdlElement);
-
-            } else if (wsBinding.getBindingName() != null) {
-
-                // Write namespace#wsdl.binding(binding)
-                String wsdlElement = wsBinding.getBindingName().getNamespaceURI() + "#wsdl.binding("
-                                     + wsBinding.getBindingName().getLocalPart()
-                                     + ")";
-                writer.writeAttribute(WSDL_ELEMENT, wsdlElement);
-
-            } else if (wsBinding.getServiceName() != null) {
-
-                // Write namespace#wsdl.service(service)
-                String wsdlElement = wsBinding.getServiceName().getNamespaceURI() + "#wsdl.service("
-                                     + wsBinding.getServiceName().getLocalPart()
-                                     + ")";
-                writer.writeAttribute(WSDL_ELEMENT, wsdlElement);
-            }
+        // Write binding URI
+        if (wsBinding.getURI() != null) {
+            writer.writeAttribute(URI, wsBinding.getURI());
+        }
 
-            // Write location
-            if (wsBinding.getLocation() != null) {
-                writer.writeAttribute(WSDLI_NS, WSDL_LOCATION, wsBinding.getLocation());
-            }
+        // Write wsdlElement attribute
+        if (wsBinding.getPortName() != null) {
 
-            writer.writeEndElement();
+            // Write namespace#wsdl.port(service/port)
+            String wsdlElement = wsBinding.getServiceName().getNamespaceURI() + "#wsdl.port("
+                                 + wsBinding.getServiceName().getLocalPart()
+                                 + "/"
+                                 + wsBinding.getPortName()
+                                 + ")";
+            writer.writeAttribute(WSDL_ELEMENT, wsdlElement);
+
+        } else if (wsBinding.getEndpointName() != null) {
+
+            // Write namespace#wsdl.endpoint(service/endpoint)
+            String wsdlElement = wsBinding.getServiceName().getNamespaceURI() + "#wsdl.endpoint("
+                                 + wsBinding.getServiceName().getLocalPart()
+                                 + "/"
+                                 + wsBinding.getEndpointName()
+                                 + ")";
+            writer.writeAttribute(WSDL_ELEMENT, wsdlElement);
+
+        } else if (wsBinding.getBindingName() != null) {
+
+            // Write namespace#wsdl.binding(binding)
+            String wsdlElement = wsBinding.getBindingName().getNamespaceURI() + "#wsdl.binding("
+                                 + wsBinding.getBindingName().getLocalPart()
+                                 + ")";
+            writer.writeAttribute(WSDL_ELEMENT, wsdlElement);
+
+        } else if (wsBinding.getServiceName() != null) {
+
+            // Write namespace#wsdl.service(service)
+            String wsdlElement = wsBinding.getServiceName().getNamespaceURI() + "#wsdl.service("
+                                 + wsBinding.getServiceName().getLocalPart()
+                                 + ")";
+            writer.writeAttribute(WSDL_ELEMENT, wsdlElement);
+        }
 
-        } catch (XMLStreamException e) {
-            throw new ContributionWriteException(e);
+        // Write location
+        if (wsBinding.getLocation() != null) {
+            writer.writeAttribute(WSDLI_NS, WSDL_LOCATION, wsBinding.getLocation());
         }
+
+        writer.writeEndElement();
     }
 
     public void resolve(WebServiceBinding model, ModelResolver resolver) throws ContributionResolveException {
@@ -284,56 +278,6 @@
 
     public Class<WebServiceBinding> getModelType() {
         return WebServiceBinding.class;
-    }
-
-    /**
-     * Reads policy intents and policy sets.
-     * @param attachPoint
-     * @param reader
-     */
-    private void readPolicies(PolicySetAttachPoint attachPoint, XMLStreamReader reader) {
-        String value = reader.getAttributeValue(null, Constants.REQUIRES);
-        if (value != null) {
-            List<Intent> requiredIntents = attachPoint.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);
-            }
-        }
-
-        value = reader.getAttributeValue(null, Constants.POLICY_SETS);
-        if (value != null) {
-            List<PolicySet> policySets = attachPoint.getPolicySets();
-            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
-                QName qname = getQNameValue(reader, tokens.nextToken());
-                PolicySet policySet = policyFactory.createPolicySet();
-                policySet.setName(qname);
-                policySets.add(policySet);
-            }
-        }
-    }
-    
-    /**
-     * Returns a qname from a string.  
-     * @param reader
-     * @param value
-     * @return
-     */
-    private 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;
-        }
     }
 
 }

Modified: incubator/tuscany/java/sca/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataProcessor.java Mon Sep  3 02:46:41 2007
@@ -32,6 +32,7 @@
 import org.apache.tuscany.sca.contribution.ContributionFactory;
 import org.apache.tuscany.sca.contribution.Export;
 import org.apache.tuscany.sca.contribution.Import;
+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;
@@ -43,7 +44,8 @@
  * 
  * @version $Rev$ $Date$
  */
-public class ContributionMetadataProcessor implements StAXArtifactProcessor<Contribution> {
+public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<Contribution> {
+    
     private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
     private static final String TARGET_NAMESPACE = "targetNamespace";
     
@@ -53,9 +55,9 @@
     private final AssemblyFactory assemblyFactory;
     private final ContributionFactory contributionFactory;
     
-    private final StAXArtifactProcessor extensionProcessor;
+    private final StAXArtifactProcessor<Object> extensionProcessor;
 
-    public ContributionMetadataProcessor(AssemblyFactory assemblyFactory, ContributionFactory contributionFactory, StAXArtifactProcessor extensionProcessor) {
+    public ContributionMetadataProcessor(AssemblyFactory assemblyFactory, ContributionFactory contributionFactory, StAXArtifactProcessor<Object> extensionProcessor) {
         super();
         this.assemblyFactory = assemblyFactory;
         this.contributionFactory = contributionFactory;
@@ -72,11 +74,9 @@
     }
 
     public Contribution read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
-        Contribution contribution = this.contributionFactory.createContribution();
-        String targetNameSpaceURI = null;
-        QName element = null;
-
+        Contribution contribution = null;
         
+        QName element = null;
         while (reader.hasNext()) {
             int event = reader.getEventType();
             switch (event) {
@@ -84,46 +84,40 @@
                     element = reader.getName();
                     
                     if (CONTRIBUTION.equals(element)) {
-                        targetNameSpaceURI = reader.getAttributeValue(null, TARGET_NAMESPACE);    
+
+                        // Read <contribution>
+                        contribution = this.contributionFactory.createContribution();
+                        
                     } else if (DEPLOYABLE.equals(element)) {
-                        String name = reader.getAttributeValue(null, "composite");
-                        if (name == null) {
+                        
+                        
+                        // Read <deployable>
+                        QName compositeName = getQName(reader, "composite");
+                        if (compositeName == null) {
                             throw new ContributionReadException("Attribute 'composite' is missing");
                         }
-                        QName compositeName = null;
 
-                        int index = name.indexOf(':');
-                        if (index != -1) {
-                            String prefix = name.substring(0, index);
-                            String localPart = name.substring(index + 1);
-                            String ns = reader.getNamespaceContext().getNamespaceURI(prefix);
-                            if (ns == null) {
-                                throw new ContributionReadException("Invalid prefix: " + prefix);
-                            }
-                            compositeName = new QName(targetNameSpaceURI, localPart, prefix);
-                        } else {
-                            String prefix = "";
-                            String localPart = name;
-                            compositeName = new QName(targetNameSpaceURI, localPart, prefix);
+                        if (contribution != null) {
+                            Composite composite = assemblyFactory.createComposite();
+                            composite.setName(compositeName);
+                            composite.setUnresolved(true);
+                            contribution.getDeployables().add(composite);
+                            
                         }
-
-                        Composite composite = assemblyFactory.createComposite();
-                        composite.setName(compositeName);
-                        composite.setUnresolved(true);
-                        
-                        contribution.getDeployables().add(composite);
                     } else{
-                        //process extension
+
+                        // Read an extension element
                         Object extension = extensionProcessor.read(reader);
-                        if (extension != null) {
+                        if (extension != null && contribution != null) {
                             if (extension instanceof Import) {
                                 contribution.getImports().add((Import)extension);
-                            }else if (extension instanceof Export) {
+                            } else if (extension instanceof Export) {
                                 contribution.getExports().add((Export)extension);
                             }
                         }
                     }
                     break;
+                    
                 case XMLStreamConstants.END_ELEMENT:
                     if (CONTRIBUTION.equals(reader.getName())) {
                         return contribution;
@@ -140,13 +134,31 @@
         return contribution;
     }
 
-    public void write(Contribution model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
-        // TODO Auto-generated method stub
+    public void write(Contribution contribution, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+        
+        // Write <contribution>
+        writeStartDocument(writer, CONTRIBUTION.getNamespaceURI(), CONTRIBUTION.getLocalPart());
+
+        // Write imports
+        for (Import imp: contribution.getImports()) {
+            extensionProcessor.write(imp, writer);
+        }
         
+        // Write exports
+        for (Export export: contribution.getExports()) {
+            extensionProcessor.write(export, writer);
+        }
+    
+        // Write <deployable> elements
+        for (Composite deployable: contribution.getDeployables()) {
+            writeStart(writer, DEPLOYABLE.getNamespaceURI(), DEPLOYABLE.getLocalPart(),
+                       new XAttr("composite", deployable.getName()));
+            writeEnd(writer);
+        }
+        
+        writeEndDocument(writer);
     }
 
     public void resolve(Contribution model, ModelResolver resolver) throws ContributionResolveException {
-        // TODO Auto-generated method stub
-        
     }
 }

Modified: incubator/tuscany/java/sca/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java (original)
+++ incubator/tuscany/java/sca/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java Mon Sep  3 02:46:41 2007
@@ -228,16 +228,32 @@
         URL[] clUrls = {sourceURL};
         URLClassLoader cl = new URLClassLoader(clUrls, null);
         
-        
         ContributionMetadataDocumentProcessor metadataDocumentProcessor = 
-            new ContributionMetadataDocumentProcessor(cl, this.staxProcessor, this.assemblyFactory, this.contributionFactory, this.xmlFactory);
+            new ContributionMetadataDocumentProcessor(cl, staxProcessor, assemblyFactory, contributionFactory, xmlFactory);
         contributionMetadata = contributionFactory.createContribution();
         try {
             metadataDocumentProcessor.read(contributionMetadata);
         } catch (XMLStreamException e) {
             throw new InvalidContributionMetadataException("Invalid contribution metadata for contribution.");
-
         }
+        
+        // For debugging purposes, write it back to XML
+//        if (contributionMetadata != null) {
+//            try {
+//                ByteArrayOutputStream bos = new ByteArrayOutputStream();
+//                XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+//                outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+//                staxProcessor.write(contributionMetadata, outputFactory.createXMLStreamWriter(bos));
+//                Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray()));
+//                OutputFormat format = new OutputFormat();
+//                format.setIndenting(true);
+//                format.setIndent(2);
+//                XMLSerializer serializer = new XMLSerializer(System.out, format);
+//                serializer.serialize(document);
+//            } catch (Exception e) {
+//                e.printStackTrace();
+//            }
+//        }
         
         return contributionMetadata;
     }

Modified: incubator/tuscany/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java Mon Sep  3 02:46:41 2007
@@ -69,7 +69,6 @@
     public JavaExport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
         JavaExport javaExport = this.factory.createJavaExport();
         QName element = null;
-
         
         while (reader.hasNext()) {
             int event = reader.getEventType();
@@ -77,6 +76,7 @@
                 case START_ELEMENT:
                     element = reader.getName();
                     
+                    // Read <export.java>
                     if (EXPORT_JAVA.equals(element)) {
                         String packageName = reader.getAttributeValue(null, PACKAGE);
                         if (packageName == null) {
@@ -102,8 +102,16 @@
         return javaExport;
     }
 
-    public void write(JavaExport model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
+    public void write(JavaExport javaExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+        
+        // Write <export.java>
+        writer.writeStartElement(EXPORT_JAVA.getNamespaceURI(), EXPORT_JAVA.getLocalPart());
+        
+        if (javaExport.getPackage() != null) {
+            writer.writeAttribute(PACKAGE, javaExport.getPackage());
+        }
         
+        writer.writeEndElement();
     }
 
     public void resolve(JavaExport model, ModelResolver resolver) throws ContributionResolveException {

Modified: incubator/tuscany/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java Mon Sep  3 02:46:41 2007
@@ -76,7 +76,8 @@
             switch (event) {
                 case START_ELEMENT:
                     element = reader.getName();
-                    
+
+                    // Read <import.java>
                     if (IMPORT_JAVA.equals(element)) {
                         String packageName = reader.getAttributeValue(null, PACKAGE);
                         if (packageName == null) {
@@ -95,7 +96,7 @@
                     break;        
             }
             
-            //Read the next element
+            // Read the next element
             if (reader.hasNext()) {
                 reader.next();
             }
@@ -104,8 +105,19 @@
         return javaImport;
     }
 
-    public void write(JavaImport model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
+    public void write(JavaImport javaImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+        
+        // Write <import.java>
+        writer.writeStartElement(IMPORT_JAVA.getNamespaceURI(), IMPORT_JAVA.getLocalPart());
+        
+        if (javaImport.getPackage() != null) {
+            writer.writeAttribute(PACKAGE, javaImport.getPackage());
+        }
+        if (javaImport.getLocation() != null) {
+            writer.writeAttribute(LOCATION, javaImport.getLocation());
+        }
         
+        writer.writeEndElement();
     }
 
 

Modified: incubator/tuscany/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java Mon Sep  3 02:46:41 2007
@@ -42,16 +42,14 @@
  * @version $Rev$ $Date$
  */
 public class NamespaceExportProcessor implements StAXArtifactProcessor<NamespaceExport> {
+
     private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
-    
     private static final QName EXPORT = new QName(SCA10_NS, "export");
-    
     private static final String NAMESPACE = "namespace";
     
     private final NamespaceImportExportFactory factory;
     
     public NamespaceExportProcessor(ModelFactoryExtensionPoint modelFactories) {
-        super();
         this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class);
     }
 
@@ -69,7 +67,6 @@
     public NamespaceExport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
         NamespaceExport namespaceExport = this.factory.createNamespaceExport();
         QName element = null;
-
         
         while (reader.hasNext()) {
             int event = reader.getEventType();
@@ -77,6 +74,7 @@
                 case START_ELEMENT:
                     element = reader.getName();
                     
+                    // Read <export>
                     if (EXPORT.equals(element)) {
                         String ns = reader.getAttributeValue(null, NAMESPACE);
                         if (ns == null) {
@@ -93,7 +91,7 @@
                     break;        
             }
             
-            //Read the next element
+            // Read the next element
             if (reader.hasNext()) {
                 reader.next();
             }
@@ -102,8 +100,16 @@
         return namespaceExport;
     }
 
-    public void write(NamespaceExport model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
+    public void write(NamespaceExport namespaceExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+        
+        // Write <export>
+        writer.writeStartElement(EXPORT.getNamespaceURI(), EXPORT.getLocalPart());
+        
+        if (namespaceExport.getNamespace() != null) {
+            writer.writeAttribute(NAMESPACE, namespaceExport.getNamespace());
+        }
         
+        writer.writeEndElement();
     }
 
     public void resolve(NamespaceExport model, ModelResolver resolver) throws ContributionResolveException {

Modified: incubator/tuscany/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java Mon Sep  3 02:46:41 2007
@@ -52,7 +52,6 @@
     private final NamespaceImportExportFactory factory;
     
     public NamespaceImportProcessor(ModelFactoryExtensionPoint modelFactories) {
-        super();
         this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class);
     }
     
@@ -69,24 +68,26 @@
      */
     public NamespaceImport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
         NamespaceImport namespaceImport = this.factory.createNamespaceImport();
-        QName element = null;
+        QName element;
         
         while (reader.hasNext()) {
             int event = reader.getEventType();
             switch (event) {
                 case START_ELEMENT:
                     element = reader.getName();
-                    
+
+                    // Read <import>
                     if (IMPORT.equals(element)) {
                         String ns = reader.getAttributeValue(null, NAMESPACE);
                         if (ns == null) {
                             throw new ContributionReadException("Attribute 'namespace' is missing");
                         }
+                        namespaceImport.setNamespace(ns);
+
                         String location = reader.getAttributeValue(null, LOCATION);
                         if (location != null) {
                             namespaceImport.setLocation(location);
                         }
-                        namespaceImport.setNamespace(ns);
                     }
                     break;
                 case XMLStreamConstants.END_ELEMENT:
@@ -96,7 +97,7 @@
                     break;        
             }
             
-            //Read the next element
+            // Read the next element
             if (reader.hasNext()) {
                 reader.next();
             }
@@ -105,12 +106,22 @@
         return namespaceImport;
     }
 
-    public void write(NamespaceImport model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
+    public void write(NamespaceImport namespaceImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+        
+        // Write <import>
+        writer.writeStartElement(IMPORT.getNamespaceURI(), IMPORT.getLocalPart());
         
+        if (namespaceImport.getNamespace() != null) {
+            writer.writeAttribute(NAMESPACE, namespaceImport.getNamespace());
+        }
+        if (namespaceImport.getLocation() != null) {
+            writer.writeAttribute(LOCATION, namespaceImport.getLocation());
+        }
+        
+        writer.writeEndElement();
     }
 
 
     public void resolve(NamespaceImport model, ModelResolver resolver) throws ContributionResolveException {
-        
     }
 }

Added: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java?rev=572267&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java (added)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java Mon Sep  3 02:46:41 2007
@@ -0,0 +1,470 @@
+/*
+ * 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.contribution.processor;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+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;
+
+
+/**
+ * A base class with utility methods for the other artifact processors in this module. 
+ * 
+ * @version $Rev$ $Date$
+ */
+public abstract class BaseStAXArtifactProcessor {
+
+    /**
+     * 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 boolean value of an attribute.
+     * @param reader
+     * @param name
+     * @return
+     */
+    protected boolean getBoolean(XMLStreamReader reader, String name) {
+        String value = reader.getAttributeValue(null, name);
+        if (value == null) {
+            return false;
+        }
+        return Boolean.valueOf(value);
+    }
+
+    /**
+     * 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);
+    }
+
+    /**
+     * Returns the value of an attribute as a list of qnames.
+     * @param reader
+     * @param name
+     * @return
+     */
+    protected List<QName> getQNames(XMLStreamReader reader, String name) {
+        String value = reader.getAttributeValue(null, name);
+        if (value != null) {
+            List<QName> qnames = new ArrayList<QName>();
+            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+                qnames.add(getQName(reader, tokens.nextToken()));
+            }
+            return qnames;
+        } else {
+            return Collections.emptyList();
+        }
+    }
+
+    /**
+     * Returns the string value of an attribute.
+     * @param reader
+     * @param name
+     * @return
+     */
+    protected String getString(XMLStreamReader reader, String name) {
+        return reader.getAttributeValue(null, name);
+    }
+
+    /**
+     * Test if an attribute is explicitly set
+     * @param reader
+     * @param name
+     * @return
+     */
+    protected boolean isSet(XMLStreamReader reader, String name) {
+        return reader.getAttributeValue(null, name) != null;
+    }
+
+    /**
+     * Returns the value of xsi:type attribute
+     * @param reader The XML stream reader
+     * @return The QName of the type, if the attribute is not present, null is
+     *         returned.
+     */
+    protected QName getXSIType(XMLStreamReader reader) {
+        String qname = reader.getAttributeValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
+        return getQNameValue(reader, qname);
+    }
+
+    /**
+     * Parse the next child element.
+     * @param reader
+     * @return
+     * @throws XMLStreamException
+     */
+    protected boolean nextChildElement(XMLStreamReader reader) throws XMLStreamException {
+        while (reader.hasNext()) {
+            int event = reader.next();
+            if (event == END_ELEMENT) {
+                return false;
+            }
+            if (event == START_ELEMENT) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Advance the stream to the next END_ELEMENT event skipping any nested
+     * content.
+     * @param reader the reader to advance
+     * @throws XMLStreamException if there was a problem reading the stream
+     */
+    protected void skipToEndElement(XMLStreamReader reader) throws XMLStreamException {
+        int depth = 0;
+        while (reader.hasNext()) {
+            int event = reader.next();
+            if (event == XMLStreamConstants.START_ELEMENT) {
+                depth++;
+            } else if (event == XMLStreamConstants.END_ELEMENT) {
+                if (depth == 0) {
+                    return;
+                }
+                depth--;
+            }
+        }
+    }
+    
+    private void writeElementPrefix(XMLStreamWriter writer, String uri) throws XMLStreamException {
+        if (uri == null) {
+            return;
+        }
+        String prefix = writer.getPrefix(uri);
+        if (prefix != null) {
+            return;
+        } 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);
+        }
+        
+    }
+
+    /**
+     * Start an element.
+     * @param uri
+     * @param name
+     * @param attrs
+     * @throws XMLStreamException
+     */
+    protected void writeStart(XMLStreamWriter writer, String uri, String name, XAttr... attrs) throws XMLStreamException {
+        writeElementPrefix(writer, uri);
+        writeAttributePrefixes(writer, attrs);
+        writer.writeStartElement(uri, name);
+        writeAttributes(writer, attrs);
+    }
+
+    /**
+     * End an element. 
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void writeEnd(XMLStreamWriter writer) throws XMLStreamException {
+        writer.writeEndElement();
+    }
+
+    /**
+     * Start a document.
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void writeStartDocument(XMLStreamWriter writer, String uri, String name, XAttr... attrs) throws XMLStreamException {
+        writer.writeStartDocument();
+        writer.setDefaultNamespace(uri);
+        writeStart(writer, uri, name, attrs);
+        writer.writeDefaultNamespace(uri);
+    }
+
+    /**
+     * End a document.
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void writeEndDocument(XMLStreamWriter writer) throws XMLStreamException {
+        writer.writeEndDocument();
+    }
+
+    /**
+     * 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);
+        }
+    }
+
+    /**
+     * Write attribute prefixes to the current element.
+     * @param writer
+     * @param attrs
+     * @throws XMLStreamException
+     */
+    protected void writeAttributePrefixes(XMLStreamWriter writer, XAttr... attrs) throws XMLStreamException {
+        for (XAttr attr : attrs) {
+            if (attr != null)
+                attr.writePrefix(writer);
+        }
+    }
+
+    /**
+     * Represents an XML attribute that needs to be written to a document.
+     */
+    public static class XAttr {
+        
+        private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+
+        private String uri = SCA10_NS;
+        private String name;
+        private 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(null, name, value);
+        }
+
+        public XAttr(String uri, String name, List values) {
+            this.uri = uri;
+            this.name = name;
+            this.value = values;
+        }
+
+        public XAttr(String name, List values) {
+            this(null, name, values);
+        }
+
+        public XAttr(String uri, String name, Boolean value) {
+            this.uri = uri;
+            this.name = name;
+            this.value = value;
+        }
+
+        public XAttr(String name, Boolean value) {
+            this(null, name, 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(null, name, value);
+        }
+
+        /**
+         * Writes a string from a qname and registers a prefix for its namespace.  
+         * @param reader
+         * @param value
+         * @return
+         */
+        private 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 && prefix.length() > 0) {
+
+                    // 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;
+            }
+        }
+
+        /**
+         * Registers a prefix for the namespace of a QName.  
+         * @param reader
+         * @param value
+         * @return
+         */
+        private void writeQNamePrefix(XMLStreamWriter writer, QName qname) throws XMLStreamException {
+            if (qname != null) {
+                String prefix = qname.getPrefix();
+                String uri = qname.getNamespaceURI();
+                prefix = writer.getPrefix(uri);
+                if (prefix != null) {
+                    return;
+                } 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);
+                }
+            }
+        }
+
+        public void write(XMLStreamWriter writer) throws XMLStreamException {
+            String str;
+            if (value instanceof QName) {
+                
+                // Write a QName
+                str = writeQNameValue(writer, (QName)value);
+                
+            } else if (value instanceof List) {
+                
+                // Write a list of values
+                List values = (List)value;
+                if (values.isEmpty()) {
+                    return;
+                }
+                StringBuffer buffer = new StringBuffer();
+                for (Object v: values) {
+                    if (v == null) {
+                        // Skip null values
+                        continue;
+                    }
+                    
+                    if (v instanceof XAttr) {
+                        // Write an XAttr value
+                        ((XAttr)v).write(writer);
+                        continue;
+                    }
+
+                    if (buffer.length() != 0) {
+                        buffer.append(' ');
+                    }
+                    if (v instanceof QName) {
+                        // Write a qname value
+                        buffer.append(writeQNameValue(writer, (QName)v));
+                    } else {
+                        // Write value as a string 
+                        buffer.append(String.valueOf(v));
+                    }
+                }
+                str = buffer.toString();
+                
+            } else {
+                
+                // Write a string
+                if (value == null) {
+                    return;
+                }
+                str = String.valueOf(value);
+            }
+            if (str.length() == 0) {
+                return;
+            }
+
+            // Write the attribute
+            if (uri != null && !uri.equals(SCA10_NS)) {
+                writer.writeAttribute(uri, name, str);
+            } else {
+                writer.writeAttribute(name,str);
+            }
+        }
+
+        public void writePrefix(XMLStreamWriter writer) throws XMLStreamException {
+            if (value instanceof QName) {
+                
+                // Write prefix for a single QName value
+                writeQNamePrefix(writer, (QName)value);
+                
+            } else if (value instanceof List) {
+                
+                // Write prefixes for a list of values
+                for (Object v: (List)value) {
+                    if (v instanceof QName) {
+                        // Write prefix for a QName value
+                        writeQNamePrefix(writer, (QName)v);
+                        
+                    } else if (v instanceof XAttr) {
+                        // Write prefix for an XAttr value
+                        ((XAttr)v).writePrefix(writer);
+                    }
+                }
+            }
+        }
+    }
+    
+}

Propchange: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java?rev=572267&r1=572266&r2=572267&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java Mon Sep  3 02:46:41 2007
@@ -61,7 +61,7 @@
         this.outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE);
     }
 
-    public Object read(XMLStreamReader source) throws ContributionReadException {
+    public Object read(XMLStreamReader source) throws ContributionReadException, XMLStreamException {
         
         // Delegate to the processor associated with the element qname
         QName name = source.getName();
@@ -69,25 +69,17 @@
         if (processor == null) {
             return null;
         }
-        try {
-            return processor.read(source);
-        } catch (XMLStreamException e) {
-            throw new ContributionReadException(e);
-        }
+        return processor.read(source);
     }
     
     @SuppressWarnings("unchecked")
-    public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException {
+    public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
         
         // Delegate to the processor associated with the model type
         if (model != null) {
             StAXArtifactProcessor processor = processors.getProcessor(model.getClass());
             if (processor != null) {
-                try {
-                    processor.write(model, outputSource);
-                } catch (XMLStreamException e) {
-                    throw new ContributionWriteException(e);
-                }
+                processor.write(model, outputSource);
             }
         }
     }



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


Mime
View raw message