You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by me...@apache.org on 2007/02/28 00:09:26 UTC

svn commit: r512475 - in /incubator/tuscany/java/sca/kernel: core/src/main/java/org/apache/tuscany/core/marshaller/ spi/src/main/java/org/apache/tuscany/spi/model/physical/

Author: meerajk
Date: Tue Feb 27 15:09:25 2007
New Revision: 512475

URL: http://svn.apache.org/viewvc?view=rev&rev=512475
Log:
first set of marshallers

Added:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/ChangeSetMarshaller.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/OperationDefinitionMarshaller.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/WireDefinitionMarshaller.java   (with props)
Modified:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/AbstractMarshallerExtension.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalChangeSet.java

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/AbstractMarshallerExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/AbstractMarshallerExtension.java?view=diff&rev=512475&r1=512474&r2=512475
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/AbstractMarshallerExtension.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/AbstractMarshallerExtension.java Tue Feb 27 15:09:25 2007
@@ -19,11 +19,8 @@
 package org.apache.tuscany.core.marshaller;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.tuscany.spi.annotation.Autowire;
-import org.apache.tuscany.spi.marshaller.MarshallException;
 import org.apache.tuscany.spi.marshaller.ModelMarshaller;
 import org.apache.tuscany.spi.marshaller.ModelMarshallerRegistry;
 import org.apache.tuscany.spi.model.ModelObject;
@@ -31,7 +28,7 @@
 public abstract class AbstractMarshallerExtension<MD extends ModelObject> implements ModelMarshaller<MD> {
 
     // Private Model marshaller registry
-    private ModelMarshallerRegistry registry;
+    protected ModelMarshallerRegistry registry;
     
     /**
      * Injects the model marshaller registry.

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/ChangeSetMarshaller.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/ChangeSetMarshaller.java?view=auto&rev=512475
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/ChangeSetMarshaller.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/ChangeSetMarshaller.java Tue Feb 27 15:09:25 2007
@@ -0,0 +1,85 @@
+/*
+ * 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.core.marshaller;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.END_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.spi.marshaller.MarshallException;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.physical.PhysicalChangeSet;
+
+/**
+ * Marshaller for physical changeset.
+ * 
+ * @version $Revision$ $Date$
+ *
+ */
+public class ChangeSetMarshaller extends AbstractMarshallerExtension<PhysicalChangeSet> {
+
+    // QName for the root element
+    private static final QName QNAME = new QName("http://tuscany.apache.org/xmlns/1.0-SNAPSHOT", "changeSet");
+    
+    /**
+     * Marshalls a physical change set to the xml writer.
+     */
+    public void marshall(PhysicalChangeSet modelObject, XMLStreamWriter writer) throws MarshallException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Unmarshalls a physical change set from the xml reader.
+     */
+    public PhysicalChangeSet unmarshall(XMLStreamReader reader) throws MarshallException {
+        
+        try {
+            PhysicalChangeSet changeSet = new PhysicalChangeSet();
+            while (true) {
+                switch (reader.next()) {
+                    case START_ELEMENT:
+                        // Marshall the wire definitions and component definitions
+                        ModelObject modelObject = registry.unmarshall(reader);
+                        changeSet.addModelObject(modelObject);
+                        break;
+                    case END_ELEMENT:
+                        return changeSet;
+                }
+            }
+        } catch(XMLStreamException ex) {
+            throw new MarshallException(ex);
+        }
+        
+    }
+
+    @Override
+    protected QName getModelObjectQName() {
+        return QNAME;
+    }
+
+    @Override
+    protected Class<PhysicalChangeSet> getModelObjectType() {
+        return PhysicalChangeSet.class;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/ChangeSetMarshaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/ChangeSetMarshaller.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/OperationDefinitionMarshaller.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/OperationDefinitionMarshaller.java?view=auto&rev=512475
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/OperationDefinitionMarshaller.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/OperationDefinitionMarshaller.java Tue Feb 27 15:09:25 2007
@@ -0,0 +1,70 @@
+/*
+ * 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.core.marshaller;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.spi.marshaller.MarshallException;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+
+/**
+ * Marshaller for physical wire definition.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class OperationDefinitionMarshaller extends AbstractMarshallerExtension<PhysicalOperationDefinition> {
+
+    // Source URI attribute
+    private static final String NAME = "name";
+
+    // QName for the root element
+    private static final QName QNAME = new QName("http://tuscany.apache.org/xmlns/1.0-SNAPSHOT", "operation");
+
+    /**
+     * Marshalls a physical change set to the xml writer.
+     */
+    public void marshall(PhysicalOperationDefinition modelObject, XMLStreamWriter writer) throws MarshallException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Unmarshalls a physical change set from the xml reader.
+     */
+    public PhysicalOperationDefinition unmarshall(XMLStreamReader reader) throws MarshallException {
+
+        PhysicalOperationDefinition operation = new PhysicalOperationDefinition();
+        operation.setName(reader.getAttributeValue(null, NAME));
+        operation.setCallback(Boolean.valueOf(reader.getAttributeValue(null, NAME)));
+        return operation;
+
+    }
+
+    @Override
+    protected QName getModelObjectQName() {
+        return QNAME;
+    }
+
+    @Override
+    protected Class<PhysicalOperationDefinition> getModelObjectType() {
+        return PhysicalOperationDefinition.class;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/OperationDefinitionMarshaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/OperationDefinitionMarshaller.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/WireDefinitionMarshaller.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/WireDefinitionMarshaller.java?view=auto&rev=512475
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/WireDefinitionMarshaller.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/WireDefinitionMarshaller.java Tue Feb 27 15:09:25 2007
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.core.marshaller;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.spi.marshaller.MarshallException;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+
+/**
+ * Marshaller for physical wire definition.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class WireDefinitionMarshaller extends AbstractMarshallerExtension<PhysicalWireDefinition> {
+
+    // Source URI attribute
+    private static final String SOURCE_URI = "sourceUri";
+
+    // Source URI attribute
+    private static final String TARGET_URI = "targetUri";
+
+    // QName for the root element
+    private static final QName QNAME = new QName("http://tuscany.apache.org/xmlns/1.0-SNAPSHOT", "wire");
+
+    /**
+     * Marshalls a physical change set to the xml writer.
+     */
+    public void marshall(PhysicalWireDefinition modelObject, XMLStreamWriter writer) throws MarshallException {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Unmarshalls a physical change set from the xml reader.
+     */
+    public PhysicalWireDefinition unmarshall(XMLStreamReader reader) throws MarshallException {
+
+        try {
+            PhysicalWireDefinition wireDefinition = new PhysicalWireDefinition();
+            wireDefinition.setSourceUri(new URI(reader.getAttributeValue(null, SOURCE_URI)));
+            wireDefinition.setTargetUri(new URI(reader.getAttributeValue(null, TARGET_URI)));
+            while (true) {
+                switch (reader.next()) {
+                    case START_ELEMENT:
+                        // Marshall the operation definitions
+                        PhysicalOperationDefinition operation =
+                            (PhysicalOperationDefinition)registry.unmarshall(reader);
+                        wireDefinition.addOperation(operation);
+                        break;
+                    case END_ELEMENT:
+                        return wireDefinition;
+
+                }
+            }
+        } catch (XMLStreamException ex) {
+            throw new MarshallException(ex);
+        } catch (URISyntaxException ex) {
+            throw new MarshallException(ex);
+        }
+
+    }
+
+    @Override
+    protected QName getModelObjectQName() {
+        return QNAME;
+    }
+
+    @Override
+    protected Class<PhysicalWireDefinition> getModelObjectType() {
+        return PhysicalWireDefinition.class;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/WireDefinitionMarshaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/WireDefinitionMarshaller.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalChangeSet.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalChangeSet.java?view=diff&rev=512475&r1=512474&r2=512475
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalChangeSet.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalChangeSet.java Tue Feb 27 15:09:25 2007
@@ -47,14 +47,6 @@
     }
 
     /**
-     * Adds a physical component definition to the physical change set.
-     * @param physicalComponentDefinition Physical component definition.
-     */
-    public void addPhysicalComponentDefinition(PhysicalComponentDefinition physicalComponentDefinition) {
-        physicalComponentDefinitions.add(physicalComponentDefinition);
-    }
-
-    /**
      * Get all the wire definitions.
      * @return Wire definitions in the changeset.
      */
@@ -63,11 +55,17 @@
     }
 
     /**
-     * Adds a wire definition to the physical change set.
-     * @param wireDefinition Wire definition.
+     * Adds a physical component definition to the physical change set.
+     * @param physicalComponentDefinition Physical component definition.
      */
-    public void addWireDefinition(PhysicalWireDefinition wireDefinition) {
-        wireDefinitions.add(wireDefinition);
+    public void addModelObject(ModelObject modelObject) {
+        if(modelObject instanceof PhysicalComponentDefinition) {
+            physicalComponentDefinitions.add((PhysicalComponentDefinition) modelObject);
+        } else if(modelObject instanceof PhysicalWireDefinition) {
+            wireDefinitions.add((PhysicalWireDefinition) modelObject);
+        } else {
+            throw new IllegalArgumentException("Unexpected model object " + modelObject.getClass());
+        }
     }
 
 }



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