tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r526321 - in /incubator/tuscany/java/sca/modules: assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/ contribution/src/main/java/org/apache/tuscany/services/spi/contri...
Date Fri, 06 Apr 2007 23:42:36 GMT
Author: jsdelfino
Date: Fri Apr  6 16:42:35 2007
New Revision: 526321

URL: http://svn.apache.org/viewvc?view=rev&rev=526321
Log:
Simplified usage of generics in ArtifactProcessor SPI

Added:
    incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/ReadDocumentTestCase.java
  (with props)
    incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/WriteAllTestCase.java
  (with props)
Removed:
    incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/ReadAndResolveDocumentTestCase.java
Modified:
    incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/Attr.java
    incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/BaseArtifactProcessor.java
    incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ComponentTypeProcessor.java
    incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/ReadAllTestCase.java
    incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/ArtifactProcessor.java
    incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/ArtifactProcessorRegistry.java
    incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DOMArtifactProcessor.java
    incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultArtifactProcessorRegistry.java
    incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultStAXArtifactProcessorRegistry.java
    incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultURLArtifactProcessorRegistry.java
    incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/StAXArtifactProcessor.java
    incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/StAXArtifactProcessorRegistry.java
    incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/URLArtifactProcessor.java

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/Attr.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/Attr.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/Attr.java
(original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/Attr.java
Fri Apr  6 16:42:35 2007
@@ -23,6 +23,8 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.tuscany.assembly.xml.Constants;
+
 /**
  * Represents an XML attribute that needs to be written to a document.
  *
@@ -30,7 +32,7 @@
  */
 public class Attr {
 
-    String uri;
+    String uri = Constants.SCA10_NS;
     String name;
     Object value;
 

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/BaseArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/BaseArtifactProcessor.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/BaseArtifactProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/BaseArtifactProcessor.java
Fri Apr  6 16:42:35 2007
@@ -41,6 +41,7 @@
 import org.apache.tuscany.assembly.AbstractReference;
 import org.apache.tuscany.assembly.AssemblyFactory;
 import org.apache.tuscany.assembly.Binding;
+import org.apache.tuscany.assembly.ComponentType;
 import org.apache.tuscany.assembly.ConstrainingType;
 import org.apache.tuscany.assembly.Contract;
 import org.apache.tuscany.assembly.Multiplicity;
@@ -390,7 +391,7 @@
      * @throws XMLStreamException
      * @throws ContributionReadException
      */
-    public static Document readPropertyValue(XMLStreamReader reader, QName type)
+    protected Document readPropertyValue(XMLStreamReader reader, QName type)
         throws XMLStreamException, ContributionReadException {
         Document doc = DOMUtil.newDocument();
 
@@ -425,7 +426,7 @@
      * @param attrs
      * @throws XMLStreamException
      */
-    protected void start(XMLStreamWriter writer, String uri, String name, Attr... attrs)
throws XMLStreamException {
+    protected void writeStart(XMLStreamWriter writer, String uri, String name, Attr... attrs)
throws XMLStreamException {
         writer.writeStartElement(uri, name);
         writeAttributes(writer, attrs);
     }
@@ -437,7 +438,7 @@
      * @param attrs
      * @throws XMLStreamException
      */
-    protected void start(XMLStreamWriter writer, String name, Attr... attrs) throws XMLStreamException
{
+    protected void writeStart(XMLStreamWriter writer, String name, Attr... attrs) throws
XMLStreamException {
         writer.writeStartElement(SCA10_NS, name);
         writeAttributes(writer, attrs);
     }
@@ -447,11 +448,30 @@
      * @param writer
      * @throws XMLStreamException
      */
-    protected void end(XMLStreamWriter writer) throws XMLStreamException {
+    protected void writeEnd(XMLStreamWriter writer) throws XMLStreamException {
         writer.writeEndElement();
     }
 
     /**
+     * Start a document.
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void writeStartDocument(XMLStreamWriter writer) throws XMLStreamException {
+        writer.writeStartDocument();
+        writer.setDefaultNamespace(SCA10_NS);
+    }
+    
+    /**
+     * 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
@@ -480,4 +500,18 @@
     protected void writeProperty(XMLStreamWriter writer, Property prop) throws XMLStreamException
{
         writeAbstractProperty(writer, prop);
     }
+
+    /**
+     * Returns a constrainingType attribute.
+     * @param componentType
+     * @return
+     */
+    protected QName getConstrainingTypeAttr(ComponentType componentType) {
+        ConstrainingType constrainingType = componentType.getConstrainingType();
+        if (constrainingType != null)
+            return constrainingType.getName();
+        else
+            return null;
+    }
+
 }

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ComponentTypeProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ComponentTypeProcessor.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ComponentTypeProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ComponentTypeProcessor.java
Fri Apr  6 16:42:35 2007
@@ -204,14 +204,55 @@
         return componentType;
     }
 
-    public void write(ComponentType model, XMLStreamWriter outputSource) throws ContributionWriteException
{
-        // TODO Auto-generated method stub
+    public void write(ComponentType componentType, XMLStreamWriter writer) throws ContributionWriteException
{
         
+        try {
+            writeStartDocument(writer);
+            writer.setPrefix("sca", SCA10_NS);
+            
+            writeStart(writer, COMPONENT_TYPE,
+                       new Attr(Constants.CONSTRAINING_TYPE, getConstrainingTypeAttr(componentType)));
+            writer.writeDefaultNamespace(SCA10_NS);
+    
+            for (Service service : componentType.getServices()) {
+                writeStart(writer, SERVICE, new Attr(NAME, service.getName()));
+                if (service.getCallback() != null) {
+                    writeStart(writer, CALLBACK);
+                    writeEnd(writer);
+                }
+                writeEnd(writer);
+            }
+    
+            for (Reference reference : componentType.getReferences()) {
+                // TODO handle multivalued target attribute
+                String target = reference.getTargets().isEmpty() ? null : reference.getTargets().get(0).getName();
+                writeStart(writer, REFERENCE,
+                      new Attr(NAME, reference.getName()),
+                      new Attr(TARGET, target));
+                if (reference.getCallback() != null) {
+                    writeStart(writer, CALLBACK);
+                    writeEnd(writer);
+                }
+                writeEnd(writer);
+            }
+    
+            for (Property property : componentType.getProperties()) {
+                writeStart(writer, PROPERTY, new Attr(NAME, property.getName()));
+                writeEnd(writer);
+            }
+    
+            writeEnd(writer);
+            
+            writeEndDocument(writer);
+            
+        } catch (XMLStreamException e) {
+            throw new ContributionWriteException(e);
+        }
     }
     
     public void resolve(ComponentType componentType, ArtifactResolver resolver) throws ContributionResolveException
{
 
-        // Resolve componen type services and references
+        // Resolve component type services and references
         resolveContract(componentType.getServices(), resolver);
         resolveContract(componentType.getReferences(), resolver);
     }

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/ReadAllTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/ReadAllTestCase.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/ReadAllTestCase.java
(original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/ReadAllTestCase.java
Fri Apr  6 16:42:35 2007
@@ -19,7 +19,7 @@
 
 package org.apache.tuscany.assembly.xml;
 
-import java.net.URL;
+import java.io.InputStream;
 
 import javax.xml.namespace.QName;
 
@@ -34,11 +34,11 @@
 import org.apache.tuscany.assembly.CompositeService;
 import org.apache.tuscany.assembly.Multiplicity;
 import org.apache.tuscany.assembly.Property;
-import org.apache.tuscany.assembly.util.CompositeUtil;
 import org.apache.tuscany.assembly.util.PrintUtil;
 import org.apache.tuscany.assembly.xml.impl.ComponentTypeProcessor;
 import org.apache.tuscany.assembly.xml.impl.CompositeProcessor;
 import org.apache.tuscany.assembly.xml.impl.ConstrainingTypeProcessor;
+import org.apache.tuscany.services.spi.contribution.DefaultArtifactResolver;
 import org.apache.tuscany.services.spi.contribution.DefaultStAXArtifactProcessorRegistry;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -63,8 +63,8 @@
     }
 
     public void testReadComposite() throws Exception {
-        URL url = getClass().getClassLoader().getResource("TestAllCalculator.composite");
-        Composite composite = registry.read(url, Composite.class);
+        InputStream is = getClass().getClassLoader().getResourceAsStream("TestAllCalculator.composite");
+        Composite composite = registry.read(is, Composite.class);
         assertNotNull(composite);
         assertEquals(composite.getName(), new QName("http://calc", "TestAllCalculator"));
         assertEquals(composite.getConstrainingType().getName(), new QName("http://calc",
"CalculatorComponent"));
@@ -148,10 +148,11 @@
     }
 
     public void testReadCompositeAndWireIt() throws Exception {
-        URL url = getClass().getClassLoader().getResource("TestAllCalculator.composite");
-        Composite composite = registry.read(url, Composite.class);
+        InputStream is = getClass().getClassLoader().getResourceAsStream("TestAllCalculator.composite");
+        Composite composite = registry.read(is, Composite.class);
         assertNotNull(composite);
-        new CompositeUtil(composite).configure(null);
+        registry.resolve(composite, new DefaultArtifactResolver());
+        registry.wire(composite);
 
         Component calcComponent = composite.getComponents().get(0);
         CompositeService calcCompositeService = (CompositeService)composite.getServices().get(0);

Added: incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/ReadDocumentTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/ReadDocumentTestCase.java?view=auto&rev=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/ReadDocumentTestCase.java
(added)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/ReadDocumentTestCase.java
Fri Apr  6 16:42:35 2007
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.assembly.xml;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.assembly.Composite;
+import org.apache.tuscany.assembly.ConstrainingType;
+import org.apache.tuscany.assembly.xml.impl.ComponentTypeDocumentProcessor;
+import org.apache.tuscany.assembly.xml.impl.ComponentTypeProcessor;
+import org.apache.tuscany.assembly.xml.impl.CompositeDocumentProcessor;
+import org.apache.tuscany.assembly.xml.impl.CompositeProcessor;
+import org.apache.tuscany.assembly.xml.impl.ConstrainingTypeDocumentProcessor;
+import org.apache.tuscany.assembly.xml.impl.ConstrainingTypeProcessor;
+import org.apache.tuscany.services.spi.contribution.DefaultArtifactResolver;
+import org.apache.tuscany.services.spi.contribution.DefaultStAXArtifactProcessorRegistry;
+import org.apache.tuscany.services.spi.contribution.DefaultURLArtifactProcessorRegistry;
+
+/**
+ * Test the resolving SCA XML assemblies.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ReadDocumentTestCase extends TestCase {
+
+    private DefaultURLArtifactProcessorRegistry registry;
+
+    public void setUp() throws Exception {
+        registry = new DefaultURLArtifactProcessorRegistry();
+        
+        // Create Stax processors
+        DefaultStAXArtifactProcessorRegistry staxRegistry = new DefaultStAXArtifactProcessorRegistry();
+        staxRegistry.addArtifactProcessor(new CompositeProcessor(staxRegistry));
+        staxRegistry.addArtifactProcessor(new ComponentTypeProcessor(staxRegistry));
+        staxRegistry.addArtifactProcessor(new ConstrainingTypeProcessor(staxRegistry));
+        
+        // Create document processors
+        registry.addArtifactProcessor(new CompositeDocumentProcessor(staxRegistry));
+        registry.addArtifactProcessor(new ComponentTypeDocumentProcessor(staxRegistry));
+        registry.addArtifactProcessor(new ConstrainingTypeDocumentProcessor(staxRegistry));
+    }
+
+    public void tearDown() throws Exception {
+        registry = null;
+    }
+
+    public void testResolveConstrainingType() throws Exception {
+        DefaultArtifactResolver resolver = new DefaultArtifactResolver();
+        
+        URL url = getClass().getClassLoader().getResource("CalculatorComponent.constrainingType");
+        ConstrainingType constrainingType = (ConstrainingType)registry.read(url);
+        assertNotNull(constrainingType);
+        resolver.put(constrainingType, constrainingType);
+
+        url = getClass().getClassLoader().getResource("TestAllCalculator.composite");
+        Composite composite = (Composite)registry.read(url);
+        assertNotNull(composite);
+        
+        registry.resolve(composite, resolver);
+        
+        assertEquals(composite.getConstrainingType(), constrainingType);
+        assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType);
+    }
+
+    public void testResolveComposite() throws Exception {
+        DefaultArtifactResolver resolver = new DefaultArtifactResolver();
+        
+        URL url = getClass().getClassLoader().getResource("Calculator.composite");
+        Composite nestedComposite = (Composite)registry.read(url);
+        assertNotNull(nestedComposite);
+        resolver.put(nestedComposite, nestedComposite);
+
+        url = getClass().getClassLoader().getResource("TestAllCalculator.composite");
+        Composite composite = (Composite)registry.read(url);
+        
+        registry.resolve(composite, resolver);
+        
+        assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
+    }
+
+}

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

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

Added: incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/WriteAllTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/WriteAllTestCase.java?view=auto&rev=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/WriteAllTestCase.java
(added)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/assembly/xml/WriteAllTestCase.java
Fri Apr  6 16:42:35 2007
@@ -0,0 +1,84 @@
+/*
+ * 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.assembly.xml;
+
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.assembly.ComponentType;
+import org.apache.tuscany.assembly.Composite;
+import org.apache.tuscany.assembly.ConstrainingType;
+import org.apache.tuscany.assembly.xml.impl.ComponentTypeProcessor;
+import org.apache.tuscany.assembly.xml.impl.CompositeProcessor;
+import org.apache.tuscany.assembly.xml.impl.ConstrainingTypeProcessor;
+import org.apache.tuscany.services.spi.contribution.DefaultArtifactResolver;
+import org.apache.tuscany.services.spi.contribution.DefaultStAXArtifactProcessorRegistry;
+
+/**
+ * Test the usability of the assembly model API when loading SCDL
+ * 
+ * @version $Rev$ $Date$
+ */
+public class WriteAllTestCase extends TestCase {
+    private DefaultStAXArtifactProcessorRegistry registry;
+
+    public void setUp() throws Exception {
+        registry = new DefaultStAXArtifactProcessorRegistry();
+        registry.addArtifactProcessor(new CompositeProcessor(registry));
+        registry.addArtifactProcessor(new ComponentTypeProcessor(registry));
+        registry.addArtifactProcessor(new ConstrainingTypeProcessor(registry));
+    }
+
+    public void tearDown() throws Exception {
+        registry = null;
+    }
+
+    public void testReadWriteComposite() throws Exception {
+        InputStream is = getClass().getClassLoader().getResourceAsStream("TestAllCalculator.composite");
+        Composite composite = registry.read(is, Composite.class);
+        registry.write(composite, System.out);
+    }
+
+    public void testReadWireWriteComposite() throws Exception {
+        InputStream is = getClass().getClassLoader().getResourceAsStream("TestAllCalculator.composite");
+        Composite composite = registry.read(is, Composite.class);
+        registry.resolve(composite, new DefaultArtifactResolver());
+        registry.wire(composite);
+        registry.write(composite, System.out);
+    }
+    
+    public void testReadWriteComponentType() throws Exception {
+        InputStream is = getClass().getClassLoader().getResourceAsStream("CalculatorImpl.componentType");
+        ComponentType componentType = registry.read(is, ComponentType.class);
+        registry.resolve(componentType, new DefaultArtifactResolver());
+        registry.wire(componentType);
+        registry.write(componentType, System.out);
+    }
+
+    public void testReadWriteConstrainingType() throws Exception {
+        InputStream is = getClass().getClassLoader().getResourceAsStream("CalculatorComponent.constrainingType");
+        ConstrainingType constrainingType = registry.read(is, ConstrainingType.class);
+        registry.resolve(constrainingType, new DefaultArtifactResolver());
+        registry.wire(constrainingType);
+        registry.write(constrainingType, System.out);
+    }
+
+}

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

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

Modified: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/ArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/ArtifactProcessor.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/ArtifactProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/ArtifactProcessor.java
Fri Apr  6 16:42:35 2007
@@ -25,23 +25,7 @@
  * 
  * @version $Rev: 522653 $ $Date: 2007-03-26 15:30:21 -0700 (Mon, 26 Mar 2007) $
  */
-public interface ArtifactProcessor <I, O, M, T> {
-    
-    /**
-     * Reads a model from an input source. Examples of input sources are: a URI, a
-     * DOM node, an XML reader.
-     * @param source
-     * @return a model representation of the input.
-     */
-    M read(I inputSource) throws ContributionReadException;
-    
-    /**
-     * Writes a model to an ouput source. Examples of output sources are: a URI, a
-     * DOM node, an XML writer.
-     * @param source
-     * @return a model representation of the source.
-     */
-    void write(M model, O outputSource) throws ContributionWriteException;
+public interface ArtifactProcessor <M> {
     
     /**
      * Resolve references from this model to other models. For example references
@@ -60,12 +44,6 @@
      */
     void wire(M model) throws ContributionWireException;
     
-    /**
-     * Returns the type of artifact handled by this artifact processor. 
-     * @return the type of artifact handled by this artifact processor
-     */
-    T getArtifactType();
-
     /**
      * Returns the type of model handled by this artifact processor.
      * @return the type of model handled by this artifact processor

Modified: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/ArtifactProcessorRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/ArtifactProcessorRegistry.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/ArtifactProcessorRegistry.java
(original)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/ArtifactProcessorRegistry.java
Fri Apr  6 16:42:35 2007
@@ -31,6 +31,6 @@
      * Add an artifact processor.
      * @param artifactProcessor the artifact processor to add
      */
-    void addArtifactProcessor(Object artifactProcessor);
+    void addArtifactProcessor(P artifactProcessor);
 
 }

Modified: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DOMArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DOMArtifactProcessor.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DOMArtifactProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DOMArtifactProcessor.java
Fri Apr  6 16:42:35 2007
@@ -28,5 +28,28 @@
  * 
  * @version $Rev: 522653 $ $Date: 2007-03-26 15:30:21 -0700 (Mon, 26 Mar 2007) $
  */
-public interface DOMArtifactProcessor<M> extends ArtifactProcessor<Node, Node, M,
QName> {
+public interface DOMArtifactProcessor<M> extends ArtifactProcessor<M> {
+
+    /**
+     * Reads a model from an input source. Examples of input sources are: a URI, a
+     * DOM node, an XML reader.
+     * @param source
+     * @return a model representation of the input.
+     */
+    M read(Node inputSource) throws ContributionReadException;
+    
+    /**
+     * Writes a model to an ouput source. Examples of output sources are: a URI, a
+     * DOM node, an XML writer.
+     * @param source
+     * @return a model representation of the source.
+     */
+    void write(M model, Node outputSource) throws ContributionWriteException;
+    
+    /**
+     * Returns the type of artifact handled by this artifact processor. 
+     * @return the type of artifact handled by this artifact processor
+     */
+    QName getArtifactType();
+
 }

Modified: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultArtifactProcessorRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultArtifactProcessorRegistry.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultArtifactProcessorRegistry.java
(original)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultArtifactProcessorRegistry.java
Fri Apr  6 16:42:35 2007
@@ -26,9 +26,9 @@
  * 
  * @version $Rev$ $Date$
  */
-abstract class DefaultArtifactProcessorRegistry<P extends ArtifactProcessor> implements
ArtifactProcessorRegistry<P> {
-    private final Map<Object, P> processorsByArtifactType = new HashMap<Object,
P>();
-    private final Map<Class<?>, P> processorsByModelType = new HashMap<Class<?>,
P>();
+abstract class DefaultArtifactProcessorRegistry {
+    protected final Map<Object, ArtifactProcessor> processorsByArtifactType = new HashMap<Object,
ArtifactProcessor>();
+    protected final Map<Class<?>, ArtifactProcessor> processorsByModelType =
new HashMap<Class<?>, ArtifactProcessor>();
 
     /**
      * Constructs a new loader registry.
@@ -41,7 +41,7 @@
      * @param artifactType an artifact type
      * @return the processor associated with the given artifact type
      */
-    protected P getProcessor(Object artifactType) {
+    protected ArtifactProcessor getProcessor(Object artifactType) {
         return processorsByArtifactType.get(artifactType);
     }
 
@@ -50,20 +50,14 @@
      * @param modelType a model type
      * @return the processor associated with the given model type
      */
-    protected P getProcessor(Class<?> modelType) {
-        Class<?>[] classes = modelType.getClasses();
+    protected ArtifactProcessor getProcessor(Class<?> modelType) {
+        Class<?>[] classes = modelType.getInterfaces();
         for (Class<?> c: classes) {
-            P processor = processorsByModelType.get(c);
+            ArtifactProcessor processor = processorsByModelType.get(c);
             if (processor != null)
                 return processor;
         }
         return null;
     }
 
-    public void addArtifactProcessor(Object artifactProcessor) {
-        P processor = (P)artifactProcessor;
-        processorsByArtifactType.put((Object)processor.getArtifactType(), processor);
-        processorsByModelType.put(processor.getModelType(), processor);
-    }
-    
 }

Modified: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultStAXArtifactProcessorRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultStAXArtifactProcessorRegistry.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultStAXArtifactProcessorRegistry.java
(original)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultStAXArtifactProcessorRegistry.java
Fri Apr  6 16:42:35 2007
@@ -20,11 +20,12 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
+import java.io.OutputStream;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.Location;
 import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
@@ -35,24 +36,26 @@
  * @version $Rev$ $Date$
  */
 public class DefaultStAXArtifactProcessorRegistry
-    extends DefaultArtifactProcessorRegistry<StAXArtifactProcessor<Object>>
+    extends DefaultArtifactProcessorRegistry
     implements StAXArtifactProcessorRegistry, StAXArtifactProcessor<Object> {
 
-    private XMLInputFactory factory;
+    private XMLInputFactory inputFactory;
+    private XMLOutputFactory outputFactory;
 
     /**
      * Constructs a new loader registry.
      * @param assemblyFactory
      * @param policyFactory
-     * @param factory
+     * @param inputFactory
      */
-    public DefaultStAXArtifactProcessorRegistry(XMLInputFactory factory) {
+    public DefaultStAXArtifactProcessorRegistry(XMLInputFactory inputFactory, XMLOutputFactory
outputFactory) {
         super();
-        this.factory = factory;
+        this.inputFactory = inputFactory;
+        this.outputFactory = outputFactory;
     }
 
     public DefaultStAXArtifactProcessorRegistry() {
-        this(XMLInputFactory.newInstance());
+        this(XMLInputFactory.newInstance(), XMLOutputFactory.newInstance());
     }
 
     public Object read(XMLStreamReader source) throws ContributionReadException {
@@ -92,14 +95,19 @@
             processor.wire(model);
         }
     }
-    
-    public <MO> MO read(URL url, Class<MO> type) throws ContributionReadException
{
+
+    /**
+     * Read a model from an input stream.
+     * @param is
+     * @param type
+     * @return
+     * @throws ContributionReadException
+     */
+    public <MO> MO read(InputStream is, Class<MO> type) throws ContributionReadException
{
         try {
             XMLStreamReader reader;
-            InputStream is;
-            is = url.openStream();
             try {
-                reader = factory.createXMLStreamReader(is);
+                reader = inputFactory.createXMLStreamReader(is);
                 try {
                     reader.nextTag();
                     QName name = reader.getName();
@@ -108,7 +116,6 @@
                         return type.cast(mo);
                     } else {
                         UnrecognizedElementException e = new UnrecognizedElementException(name);
-                        e.setResourceURI(url.toString());
                         throw e;
                     }
                 } catch (ContributionReadException e) {
@@ -130,15 +137,34 @@
                     // ignore
                 }
             }
-        } catch (IOException e) {
+        } catch (XMLStreamException e) {
             ContributionReadException ce = new ContributionReadException(e);
-            ce.setResourceURI(url.toString());
             throw ce;
+        }
+    }
+
+    /**
+     * Write a model to an ouput stream.
+     * @param model
+     * @param os
+     * @throws ContributionWriteException
+     */
+    public void write(Object model, OutputStream os) throws ContributionWriteException {
+        try {
+            XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
+            write(model, writer);
+            writer.flush();
+            writer.close();
         } catch (XMLStreamException e) {
-            throw new InvalidConfigurationException("Invalid or missing resource: " + url.toString(),
e);
+            throw new ContributionWriteException(e);
         }
     }
 
+    public void addArtifactProcessor(StAXArtifactProcessor artifactProcessor) {
+        processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor);
+        processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor);
+    }
+    
     public QName getArtifactType() {
         return null;
     }

Modified: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultURLArtifactProcessorRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultURLArtifactProcessorRegistry.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultURLArtifactProcessorRegistry.java
(original)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultURLArtifactProcessorRegistry.java
Fri Apr  6 16:42:35 2007
@@ -26,7 +26,7 @@
  * @version $Rev$ $Date$
  */
 public class DefaultURLArtifactProcessorRegistry
-    extends DefaultArtifactProcessorRegistry<URLArtifactProcessor<Object>>
+    extends DefaultArtifactProcessorRegistry
     implements URLArtifactProcessorRegistry, URLArtifactProcessor<Object> {
 
     /**
@@ -88,6 +88,11 @@
             e.setResourceURI(url.toString());
             throw e;
         }
+    }
+    
+    public void addArtifactProcessor(URLArtifactProcessor artifactProcessor) {
+        processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor);
+        processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor);
     }
     
     public String getArtifactType() {

Modified: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/StAXArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/StAXArtifactProcessor.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/StAXArtifactProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/StAXArtifactProcessor.java
Fri Apr  6 16:42:35 2007
@@ -28,5 +28,28 @@
  * 
  * @version $Rev: 522653 $ $Date: 2007-03-26 15:30:21 -0700 (Mon, 26 Mar 2007) $
  */
-public interface StAXArtifactProcessor<M> extends ArtifactProcessor <XMLStreamReader,
XMLStreamWriter, M, QName> {
+public interface StAXArtifactProcessor<M> extends ArtifactProcessor<M> {
+
+    /**
+     * Reads a model from an input source. Examples of input sources are: a URI, a
+     * DOM node, an XML reader.
+     * @param source
+     * @return a model representation of the input.
+     */
+    M read(XMLStreamReader inputSource) throws ContributionReadException;
+    
+    /**
+     * Writes a model to an ouput source. Examples of output sources are: a URI, a
+     * DOM node, an XML writer.
+     * @param source
+     * @return a model representation of the source.
+     */
+    void write(M model, XMLStreamWriter outputSource) throws ContributionWriteException;
+    
+    /**
+     * Returns the type of artifact handled by this artifact processor. 
+     * @return the type of artifact handled by this artifact processor
+     */
+    QName getArtifactType();
+
 }

Modified: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/StAXArtifactProcessorRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/StAXArtifactProcessorRegistry.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/StAXArtifactProcessorRegistry.java
(original)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/StAXArtifactProcessorRegistry.java
Fri Apr  6 16:42:35 2007
@@ -25,7 +25,6 @@
  * 
  * @version $Rev$ $Date$
  */
-public interface StAXArtifactProcessorRegistry extends
-    ArtifactProcessorRegistry<StAXArtifactProcessor<Object>> {
+public interface StAXArtifactProcessorRegistry extends ArtifactProcessorRegistry<StAXArtifactProcessor>
{
     
 }

Modified: incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/URLArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/URLArtifactProcessor.java?view=diff&rev=526321&r1=526320&r2=526321
==============================================================================
--- incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/URLArtifactProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/URLArtifactProcessor.java
Fri Apr  6 16:42:35 2007
@@ -26,5 +26,28 @@
  * 
  * @version $Rev: 522653 $ $Date: 2007-03-26 15:30:21 -0700 (Mon, 26 Mar 2007) $
  */
-public interface URLArtifactProcessor<M> extends ArtifactProcessor<URL, URL, M,
String> {
+public interface URLArtifactProcessor<M> extends ArtifactProcessor<M> {
+
+    /**
+     * Reads a model from an input source. Examples of input sources are: a URI, a
+     * DOM node, an XML reader.
+     * @param source
+     * @return a model representation of the input.
+     */
+    M read(URL inputSource) throws ContributionReadException;
+    
+    /**
+     * Writes a model to an ouput source. Examples of output sources are: a URI, a
+     * DOM node, an XML writer.
+     * @param source
+     * @return a model representation of the source.
+     */
+    void write(M model, URL outputSource) throws ContributionWriteException;
+    
+    /**
+     * Returns the type of artifact handled by this artifact processor. 
+     * @return the type of artifact handled by this artifact processor
+     */
+    String getArtifactType();
+
 }



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