tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r618585 - in /incubator/tuscany/java/sca/modules: contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ contribution/src/main/java/org/apache/tuscany/...
Date Tue, 05 Feb 2008 09:20:07 GMT
Author: jsdelfino
Date: Tue Feb  5 01:20:05 2008
New Revision: 618585

URL: http://svn.apache.org/viewvc?rev=618585&view=rev
Log:
Cleaned up contribution metadata processor. Initial implementation of a contribution workspace
processor.

Added:
    incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceDocumentProcessor.java
  (with props)
    incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceProcessor.java
  (with props)
    incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java
      - copied, changed from r618158, incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessorTestCase.java
    incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceProcessorTestCase.java
  (with props)
Removed:
    incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessorTestCase.java
Modified:
    incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
    incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java

Modified: incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java?rev=618585&r1=618584&r2=618585&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
Tue Feb  5 01:20:05 2008
@@ -40,7 +40,7 @@
 import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
 
 /**
- * Processor responsible for loading particular elements from contribution metadata file
+ * Processor for contribution metadata
  * 
  * @version $Rev$ $Date$
  */
@@ -48,8 +48,8 @@
     
     private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
     
-    private static final QName CONTRIBUTION = new QName(SCA10_NS, "contribution");
-    private static final QName DEPLOYABLE = new QName(SCA10_NS, "deployable");
+    private static final QName CONTRIBUTION_QNAME = new QName(SCA10_NS, "contribution");
+    private static final QName DEPLOYABLE_QNAME = new QName(SCA10_NS, "deployable");
     
     private final AssemblyFactory assemblyFactory;
     private final ContributionFactory contributionFactory;
@@ -57,7 +57,6 @@
     private final StAXArtifactProcessor<Object> extensionProcessor;
 
     public ContributionMetadataProcessor(AssemblyFactory assemblyFactory, ContributionFactory
contributionFactory, StAXArtifactProcessor<Object> extensionProcessor) {
-        super();
         this.assemblyFactory = assemblyFactory;
         this.contributionFactory = contributionFactory;
         this.extensionProcessor = extensionProcessor;
@@ -65,7 +64,7 @@
     
     
     public QName getArtifactType() {
-        return CONTRIBUTION;
+        return CONTRIBUTION_QNAME;
     }
 
     public Class<Contribution> getModelType() {
@@ -74,20 +73,20 @@
 
     public Contribution read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException
{
         Contribution contribution = null;
+        QName name = null;
         
-        QName element = null;
         while (reader.hasNext()) {
             int event = reader.getEventType();
             switch (event) {
                 case START_ELEMENT:
-                    element = reader.getName();
+                    name = reader.getName();
                     
-                    if (CONTRIBUTION.equals(element)) {
+                    if (CONTRIBUTION_QNAME.equals(name)) {
 
                         // Read <contribution>
                         contribution = this.contributionFactory.createContribution();
                         
-                    } else if (DEPLOYABLE.equals(element)) {
+                    } else if (DEPLOYABLE_QNAME.equals(name)) {
                         
                         
                         // Read <deployable>
@@ -118,7 +117,7 @@
                     break;
                     
                 case XMLStreamConstants.END_ELEMENT:
-                    if (CONTRIBUTION.equals(reader.getName())) {
+                    if (CONTRIBUTION_QNAME.equals(reader.getName())) {
                         return contribution;
                     }
                     break;        
@@ -136,21 +135,21 @@
     public void write(Contribution contribution, XMLStreamWriter writer) throws ContributionWriteException,
XMLStreamException {
         
         // Write <contribution>
-        writeStartDocument(writer, CONTRIBUTION.getNamespaceURI(), CONTRIBUTION.getLocalPart());
+        writeStartDocument(writer, CONTRIBUTION_QNAME.getNamespaceURI(), CONTRIBUTION_QNAME.getLocalPart());
 
-        // Write imports
+        // Write <import>
         for (Import imp: contribution.getImports()) {
             extensionProcessor.write(imp, writer);
         }
         
-        // Write exports
+        // Write <export>
         for (Export export: contribution.getExports()) {
             extensionProcessor.write(export, writer);
         }
     
-        // Write <deployable> elements
+        // Write <deployable>
         for (Composite deployable: contribution.getDeployables()) {
-            writeStart(writer, DEPLOYABLE.getNamespaceURI(), DEPLOYABLE.getLocalPart(),
+            writeStart(writer, DEPLOYABLE_QNAME.getNamespaceURI(), DEPLOYABLE_QNAME.getLocalPart(),
                        new XAttr("composite", deployable.getName()));
             writeEnd(writer);
         }

Added: incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceDocumentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceDocumentProcessor.java?rev=618585&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceDocumentProcessor.java
(added)
+++ incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceDocumentProcessor.java
Tue Feb  5 01:20:05 2008
@@ -0,0 +1,102 @@
+/*
+ * 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.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.contribution.Workspace;
+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;
+
+/**
+ * A contribution workspace document processor.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ContributionWorkspaceDocumentProcessor implements URLArtifactProcessor<Workspace>
{
+    private XMLInputFactory inputFactory;
+    private StAXArtifactProcessor<Object> staxProcessor;
+    
+    /**
+     * Constructs a new componentType processor.
+     * @param factory
+     * @param policyFactory
+     * @param registry
+     */
+    public ContributionWorkspaceDocumentProcessor(StAXArtifactProcessor<Object> staxProcessor,
XMLInputFactory inputFactory) {
+        this.staxProcessor = staxProcessor;
+        this.inputFactory = inputFactory;
+    }
+    
+    public Workspace read(URL contributionURL, URI uri, URL url) throws ContributionReadException
{
+        InputStream urlStream = null;
+        try {
+            
+            // Create a stream reader
+            urlStream = url.openStream();
+            XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream);
+            reader.nextTag();
+            
+            // Reader the componentType model 
+            Workspace workspace = (Workspace)staxProcessor.read(reader);
+            if (workspace != null) {
+                workspace.setURI(uri.toString());
+            }
+
+            return workspace;
+            
+        } 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(Workspace workspace, ModelResolver resolver) throws ContributionResolveException
{
+        staxProcessor.resolve(workspace, resolver);
+    }
+    
+    public String getArtifactType() {
+        return ".workspace";
+    }
+    
+    public Class<Workspace> getModelType() {
+        return Workspace.class;
+    }
+}

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

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

Added: incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceProcessor.java?rev=618585&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceProcessor.java
(added)
+++ incubator/tuscany/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceProcessor.java
Tue Feb  5 01:20:05 2008
@@ -0,0 +1,136 @@
+/*
+ * 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.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+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.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.Workspace;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+
+/**
+ * A contribution workspace processor.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ContributionWorkspaceProcessor extends BaseStAXArtifactProcessor implements
StAXArtifactProcessor<Workspace> {
+    
+    private ContributionFactory contributionFactory;
+    
+    private static final String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.0";
+    private static final QName WORKSPACE_QNAME = new QName(SCA10_TUSCANY_NS, "workspace");
+    private static final QName CONTRIBUTION_QNAME = new QName(SCA10_TUSCANY_NS, "contribution");
+    private static final String URI = "uri";
+    private static final String LOCATION = "location";
+    
+    /**
+     * Constructs a new contribution workspace processor.
+     * @param contributionFactory
+     * @param extensionProcessor
+     */
+    public ContributionWorkspaceProcessor(ContributionFactory contributionFactory, StAXArtifactProcessor<Object>
extensionProcessor) {
+        this.contributionFactory = contributionFactory;
+    }
+    
+    public Workspace read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException
{
+        
+        Workspace workspace = null;
+        Contribution contribution = null;
+        
+        // Read the workspace document
+        while (reader.hasNext()) {
+            int event = reader.getEventType();
+            switch (event) {
+                case START_ELEMENT:
+                    QName name = reader.getName();
+
+                    if (WORKSPACE_QNAME.equals(name)) {
+
+                        // Read a <workspace>
+                        workspace = contributionFactory.createWorkspace();
+
+                    } else if (CONTRIBUTION_QNAME.equals(name)) {
+
+                        // Read a <contribution>
+                        contribution = contributionFactory.createContribution();
+                        contribution.setURI(getString(reader, URI));
+                        contribution.setLocation(getString(reader, LOCATION));
+                        contribution.setUnresolved(true);
+                        workspace.getContributions().add(contribution);
+                    }
+                    break;
+
+                case END_ELEMENT:
+                    name = reader.getName();
+
+                    // Clear current state when reading reaching end element
+                    if (CONTRIBUTION_QNAME.equals(name)) {
+                        contribution = null;
+                    }
+                    break;
+            }
+            
+            // Read the next element
+            if (reader.hasNext()) {
+                reader.next();
+            }
+        }
+        return workspace;
+    }
+    
+    public void write(Workspace workspace, XMLStreamWriter writer) throws ContributionWriteException,
XMLStreamException {
+        
+        // Write <workspace> element
+        writeStartDocument(writer, WORKSPACE_QNAME);
+
+        // Write <contribution> elements
+        for (Contribution contribution: workspace.getContributions()) {
+            writeStart(writer, CONTRIBUTION_QNAME,
+                           new XAttr(URI, contribution.getURI()), new XAttr(LOCATION, contribution.getLocation()));
+            writeEnd(writer);
+        }
+
+        writeEndDocument(writer);
+    }
+    
+    public void resolve(Workspace workspace, ModelResolver resolver) throws ContributionResolveException
{
+        //TODO Resolve contribution models
+    }
+    
+    public QName getArtifactType() {
+        return WORKSPACE_QNAME;
+    }
+    
+    public Class<Workspace> getModelType() {
+        return Workspace.class;
+    }
+}

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

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

Copied: incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java
(from r618158, incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessorTestCase.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java?p2=incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java&p1=incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessorTestCase.java&r1=618158&r2=618585&rev=618585&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessorTestCase.java
(original)
+++ incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java
Tue Feb  5 01:20:05 2008
@@ -39,7 +39,7 @@
  * @version $Rev$ $Date$
  */
 
-public class ContributionMetadataDocumentProcessorTestCase extends TestCase {
+public class ContributionMetadataProcessorTestCase extends TestCase {
 
     private static final String VALID_XML =
         "<?xml version=\"1.0\" encoding=\"ASCII\"?>" 
@@ -61,30 +61,30 @@
         xmlFactory = XMLInputFactory.newInstance();
     }
 
-    public void testLoad() throws Exception {
+    public void testRead() throws Exception {
         XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(VALID_XML));
 
         AssemblyFactory assemblyFactory = new DefaultAssemblyFactory();
         ContributionFactory contributionFactory = new DefaultContributionFactory();
-        ContributionMetadataProcessor loader = 
+        ContributionMetadataProcessor processor = 
             new ContributionMetadataProcessor(assemblyFactory, contributionFactory, null);
         Contribution contribution = contributionFactory.createContribution();
         contribution.setModelResolver(new TestModelResolver(contribution, null));
-        contribution = loader.read(reader);
+        contribution = processor.read(reader);
         assertNotNull(contribution);
         assertEquals(2, contribution.getDeployables().size());
   }
 
-    public void testLoadInvalid() throws Exception {
+    public void testReadInvalid() throws Exception {
         XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(INVALID_XML));
         AssemblyFactory assemblyFactory = new DefaultAssemblyFactory();
         ContributionFactory contributionFactory = new DefaultContributionFactory();
-        ContributionMetadataProcessor loader = 
+        ContributionMetadataProcessor processor = 
             new ContributionMetadataProcessor(assemblyFactory, contributionFactory, null);
         Contribution contribution = contributionFactory.createContribution();
         contribution.setModelResolver(new TestModelResolver(contribution, null));
         try {
-            loader.read(reader);
+            processor.read(reader);
             fail("InvalidException should have been thrown");
         } catch (ContributionReadException e) {
             assertTrue(true);

Added: incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceProcessorTestCase.java?rev=618585&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceProcessorTestCase.java
(added)
+++ incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceProcessorTestCase.java
Tue Feb  5 01:20:05 2008
@@ -0,0 +1,89 @@
+/*
+ * 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.xml;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.DefaultContributionFactory;
+import org.apache.tuscany.sca.contribution.Workspace;
+
+/**
+ * Test the contribution metadata processor.
+ * 
+ * @version $Rev$ $Date$
+ */
+
+public class ContributionWorkspaceProcessorTestCase extends TestCase {
+
+    private static final String VALID_XML =
+        "<?xml version=\"1.0\" encoding=\"ASCII\"?>" 
+            + "<workspace xmlns=\"http://tuscany.apache.org/xmlns/sca/1.0\">"
+            + "<contribution uri=\"uri1\" location=\"location1\"/>"
+            + "<contribution uri=\"uri2\" location=\"location2\"/>"
+            + "</workspace>";
+
+    private static final String INVALID_XML =
+        "<?xml version=\"1.0\" encoding=\"ASCII\"?>" 
+            + "<workspace xmlns=\"http://tuscany.apache.org/xmlns/sca/1.0\">"
+            + "<contribution uri=\"uri1\" location=\"location1\"/>"
+            + "<contribution uri=\"uri2\" location=\"location2\"/>"
+            + "</contribution>"
+            + "</workspace>";
+
+    private XMLInputFactory xmlFactory;
+
+    @Override
+    protected void setUp() throws Exception {
+        xmlFactory = XMLInputFactory.newInstance();
+    }
+
+    public void testRead() throws Exception {
+        XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(VALID_XML));
+
+        ContributionFactory contributionFactory = new DefaultContributionFactory();
+        ContributionWorkspaceProcessor processor = 
+            new ContributionWorkspaceProcessor(contributionFactory, null);
+        Workspace workspace = processor.read(reader);
+        assertNotNull(workspace);
+        assertEquals(2, workspace.getContributions().size());
+        assertEquals("uri2", workspace.getContributions().get(1).getURI());
+        assertEquals("location2", workspace.getContributions().get(1).getLocation());
+  }
+
+    public void testReadInvalid() throws Exception {
+        XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(INVALID_XML));
+        ContributionFactory contributionFactory = new DefaultContributionFactory();
+        ContributionWorkspaceProcessor processor = 
+            new ContributionWorkspaceProcessor(contributionFactory, null);
+        try {
+            processor.read(reader);
+            fail("InvalidException should have been thrown");
+        } catch (XMLStreamException e) {
+            assertTrue(true);
+        }
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceProcessorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionWorkspaceProcessorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 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=618585&r1=618584&r2=618585&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java
Tue Feb  5 01:20:05 2008
@@ -225,7 +225,17 @@
         }
         writeAttributes(writer, attrs);
     }
-
+    
+    /**
+     * Start an element.
+     * @param qname
+     * @param attrs
+     * @throws XMLStreamException
+     */
+    protected void writeStart(XMLStreamWriter writer, QName qname, XAttr... attrs) throws
XMLStreamException {
+        writeStart(writer, qname.getNamespaceURI(), qname.getLocalPart(), attrs);
+    }
+    
     /**
      * End an element. 
      * @param writer
@@ -245,6 +255,17 @@
         writer.setDefaultNamespace(uri);
         writeStart(writer, uri, name, attrs);
         writer.writeDefaultNamespace(uri);
+    }
+
+    /**
+     * Start a document.
+     * @param writer
+     * @param qname
+     * @param attrs
+     * @throws XMLStreamException
+     */
+    protected void writeStartDocument(XMLStreamWriter writer, QName qname, XAttr... attrs)
throws XMLStreamException {
+        writeStartDocument(writer, qname.getNamespaceURI(), qname.getLocalPart(), attrs);
     }
 
     /**



---------------------------------------------------------------------
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