tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r526342 - in /incubator/tuscany/java/sca/modules: assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ contribution/src/main/java/org/apache/tuscany/services/spi/contribution/
Date Sat, 07 Apr 2007 01:29:29 GMT
Author: jsdelfino
Date: Fri Apr  6 18:29:28 2007
New Revision: 526342

URL: http://svn.apache.org/viewvc?view=rev&rev=526342
Log:
Skeleton implementation of writers for composite, componentType and constrainingType models.

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/ComponentTypeDocumentProcessor.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/main/java/org/apache/tuscany/assembly/xml/impl/CompositeDocumentProcessor.java
    incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/CompositeProcessor.java
    incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ConstrainingTypeDocumentProcessor.java
    incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ConstrainingTypeProcessor.java
    incubator/tuscany/java/sca/modules/contribution/src/main/java/org/apache/tuscany/services/spi/contribution/DefaultStAXArtifactProcessorRegistry.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=526342&r1=526341&r2=526342
==============================================================================
--- 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 18:29:28 2007
@@ -19,6 +19,7 @@
 
 package org.apache.tuscany.assembly.xml.impl;
 
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
@@ -69,9 +70,53 @@
         this.value = value;
     }
 
+    /**
+     * Writes a string from a qname and registers a prefix for its namespace.  
+     * @param reader
+     * @param value
+     * @return
+     */
+    protected String writeQNameValue(XMLStreamWriter writer, QName qname) throws XMLStreamException
{
+        if (qname != null) {
+            String prefix = qname.getPrefix();
+            String uri = qname.getNamespaceURI();
+            prefix = writer.getPrefix(uri);
+            if (prefix != null) {
+
+                // Use the prefix already bound to the given uri
+                return prefix + ":" + qname.getLocalPart();
+            } else {
+                
+                // Find an available prefix and bind it to the given uri 
+                NamespaceContext nsc = writer.getNamespaceContext();
+                for (int i=1; ; i++) {
+                    prefix = "ns" + i;
+                    if (nsc.getNamespaceURI(prefix) == null) {
+                        break;
+                    }
+                }
+                writer.setPrefix(prefix, uri);
+                writer.writeNamespace(prefix, uri);
+                return prefix + ":" + qname.getLocalPart();
+            }
+        } else {
+            return null;
+        }
+    }
+
     void write(XMLStreamWriter writer) throws XMLStreamException {
         if (value != null) {
-            writer.writeAttribute(uri, name, String.valueOf(value));
+            String str;
+            if (value instanceof QName) {
+                str = writeQNameValue(writer, (QName)value);
+            } else {
+                str = String.valueOf(value);
+            }
+            if (uri != null && !uri.equals(Constants.SCA10_NS)) {
+                writer.writeAttribute(uri, name, str);
+            } else {
+                writer.writeAttribute(name,str);
+            }
         }
     }
 

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=526342&r1=526341&r2=526342
==============================================================================
--- 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 18:29:28 2007
@@ -457,9 +457,11 @@
      * @param writer
      * @throws XMLStreamException
      */
-    protected void writeStartDocument(XMLStreamWriter writer) throws XMLStreamException {
+    protected void writeStartDocument(XMLStreamWriter writer, String name, Attr... attrs)
throws XMLStreamException {
         writer.writeStartDocument();
         writer.setDefaultNamespace(SCA10_NS);
+        writeStart(writer, name, attrs);
+        writer.writeDefaultNamespace(SCA10_NS);
     }
     
     /**

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ComponentTypeDocumentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ComponentTypeDocumentProcessor.java?view=diff&rev=526342&r1=526341&r2=526342
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ComponentTypeDocumentProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ComponentTypeDocumentProcessor.java
Fri Apr  6 18:29:28 2007
@@ -95,6 +95,8 @@
     }
     
     public void write(ComponentType model, URL outputSource) throws ContributionWriteException
{
+        // Can't write to a URL
+        throw new UnsupportedOperationException();
     }
     
     public void resolve(ComponentType componentType, ArtifactResolver resolver) throws ContributionResolveException
{

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=526342&r1=526341&r2=526342
==============================================================================
--- 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 18:29:28 2007
@@ -207,12 +207,8 @@
     public void write(ComponentType componentType, XMLStreamWriter writer) throws ContributionWriteException
{
         
         try {
-            writeStartDocument(writer);
-            writer.setPrefix("sca", SCA10_NS);
-            
-            writeStart(writer, COMPONENT_TYPE,
+            writeStartDocument(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()));
@@ -241,8 +237,6 @@
                 writeEnd(writer);
             }
     
-            writeEnd(writer);
-            
             writeEndDocument(writer);
             
         } catch (XMLStreamException e) {

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/CompositeDocumentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/CompositeDocumentProcessor.java?view=diff&rev=526342&r1=526341&r2=526342
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/CompositeDocumentProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/CompositeDocumentProcessor.java
Fri Apr  6 18:29:28 2007
@@ -94,9 +94,9 @@
         }
     }
     
-    public void write(Composite model, URL outputSource) throws ContributionWriteException
{
-        // TODO Auto-generated method stub
-        
+    public void write(Composite model, URL url) throws ContributionWriteException {
+        // Can't write to a URL
+        throw new UnsupportedOperationException();
     }
     
     public void resolve(Composite composite, ArtifactResolver resolver) throws ContributionResolveException
{

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/CompositeProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/CompositeProcessor.java?view=diff&rev=526342&r1=526341&r2=526342
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/CompositeProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/CompositeProcessor.java
Fri Apr  6 18:29:28 2007
@@ -42,6 +42,8 @@
 import org.apache.tuscany.assembly.Contract;
 import org.apache.tuscany.assembly.Implementation;
 import org.apache.tuscany.assembly.Property;
+import org.apache.tuscany.assembly.Reference;
+import org.apache.tuscany.assembly.Service;
 import org.apache.tuscany.assembly.Wire;
 import org.apache.tuscany.assembly.impl.DefaultAssemblyFactory;
 import org.apache.tuscany.assembly.util.CompositeUtil;
@@ -328,9 +330,84 @@
         }
     }
     
-    public void write(Composite model, XMLStreamWriter outputSource) throws ContributionWriteException
{
-        // TODO Auto-generated method stub
-        
+    public void write(Composite composite, XMLStreamWriter writer) throws ContributionWriteException
{
+
+        try {
+            writeStartDocument(writer, COMPOSITE, new Attr(CONSTRAINING_TYPE, getConstrainingTypeAttr(composite)));
+    
+            for (Service service : composite.getServices()) {
+                CompositeService compositeService = (CompositeService)service;
+                ComponentService promotedService = compositeService.getPromotedService();
+                String promote = promotedService != null ? promotedService.getName() : null;
+                writeStart(writer, SERVICE, new Attr(NAME, service.getName()), new Attr(PROMOTE,
promote));
+                if (service.getCallback() != null) {
+                    writeStart(writer, CALLBACK);
+                    writeEnd(writer);
+                }
+                writeEnd(writer);
+            }
+    
+            for (Component component : composite.getComponents()) {
+                writeStart(writer, COMPONENT, new Attr(NAME, component.getName()));
+    
+                for (ComponentService service : component.getServices()) {
+                    writeStart(writer, SERVICE, new Attr(NAME, service.getName()));
+                    writeEnd(writer);
+                    if (service.getCallback() != null) {
+                        writeStart(writer, CALLBACK);
+                        writeEnd(writer);
+                    }
+                }
+    
+                for (ComponentReference reference : component.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 (ComponentProperty property : component.getProperties()) {
+                    writeStart(writer, PROPERTY, new Attr(NAME, property.getName()));
+                    writeEnd(writer);
+                }
+    
+                writeEnd(writer);
+            }
+    
+            for (Reference reference : composite.getReferences()) {
+                // TODO handle multivalued promote attribute
+                CompositeReference compositeReference = (CompositeReference)reference;
+                String promote;
+                if (!compositeReference.getPromotedReferences().isEmpty())
+                    promote = compositeReference.getPromotedReferences().get(0).getName();
+                else
+                    promote = null;
+                writeStart(writer, REFERENCE,
+                           new Attr(NAME, reference.getName()),
+                           new Attr(PROMOTE, promote));
+                if (reference.getCallback() != null) {
+                    writeStart(writer, CALLBACK);
+                    writeEnd(writer);
+                }
+                writeEnd(writer);
+            }
+    
+            for (Property property : composite.getProperties()) {
+                writeStart(writer, PROPERTY, new Attr(NAME, property.getName()));
+                writeEnd(writer);
+            }
+    
+            writeEndDocument(writer);
+            
+        } catch (XMLStreamException e) {
+            throw new ContributionWriteException(e);
+        }
     }
     
     public void resolve(Composite composite, ArtifactResolver resolver) throws ContributionResolveException
{

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ConstrainingTypeDocumentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ConstrainingTypeDocumentProcessor.java?view=diff&rev=526342&r1=526341&r2=526342
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ConstrainingTypeDocumentProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ConstrainingTypeDocumentProcessor.java
Fri Apr  6 18:29:28 2007
@@ -96,8 +96,8 @@
     }
     
     public void write(ConstrainingType model, URL outputSource) throws ContributionWriteException
{
-        // TODO Auto-generated method stub
-        
+        // Can't write to a URL
+        throw new UnsupportedOperationException();
     }
     
     public void resolve(ConstrainingType constrainingType, ArtifactResolver resolver) throws
ContributionResolveException {

Modified: incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ConstrainingTypeProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ConstrainingTypeProcessor.java?view=diff&rev=526342&r1=526341&r2=526342
==============================================================================
--- incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ConstrainingTypeProcessor.java
(original)
+++ incubator/tuscany/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/assembly/xml/impl/ConstrainingTypeProcessor.java
Fri Apr  6 18:29:28 2007
@@ -172,9 +172,32 @@
         }
     }
     
-    public void write(ConstrainingType model, XMLStreamWriter outputSource) throws ContributionWriteException
{
-        // TODO Auto-generated method stub
+    public void write(ConstrainingType constrainingType, XMLStreamWriter writer) throws ContributionWriteException
{
         
+        try {
+            writeStartDocument(writer, CONSTRAINING_TYPE);
+    
+            for (AbstractService service : constrainingType.getServices()) {
+                writeStart(writer, SERVICE, new Attr(NAME, service.getName()));
+                writeEnd(writer);
+            }
+    
+            for (AbstractReference reference : constrainingType.getReferences()) {
+                writeStart(writer, REFERENCE,
+                      new Attr(NAME, reference.getName()));
+                writeEnd(writer);
+            }
+    
+            for (AbstractProperty property : constrainingType.getProperties()) {
+                writeStart(writer, PROPERTY, new Attr(NAME, property.getName()));
+                writeEnd(writer);
+            }
+    
+            writeEndDocument(writer);
+            
+        } catch (XMLStreamException e) {
+            throw new ContributionWriteException(e);
+        }
     }
     
     public void resolve(ConstrainingType constrainingType, ArtifactResolver resolver) throws
ContributionResolveException {

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=526342&r1=526341&r2=526342
==============================================================================
--- 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 18:29:28 2007
@@ -52,6 +52,7 @@
         super();
         this.inputFactory = inputFactory;
         this.outputFactory = outputFactory;
+        this.outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces",Boolean.TRUE);
     }
 
     public DefaultStAXArtifactProcessorRegistry() {



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