tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r572848 - in /incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context: CallableReferenceImpl.java ComponentContextHelper.java ReferenceParameterProcessor.java ReferenceParameters.java RequestContextImpl.java
Date Wed, 05 Sep 2007 00:32:24 GMT
Author: rfeng
Date: Tue Sep  4 17:32:24 2007
New Revision: 572848

URL: http://svn.apache.org/viewvc?rev=572848&view=rev
Log:
Serialize the states for CallableReference as an extension element to the <reference>
and apply the patch for TUSCANY-1661

Added:
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameterProcessor.java
  (with props)
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameters.java
  (with props)
Modified:
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java
    incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java?rev=572848&r1=572847&r2=572848&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
(original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
Tue Sep  4 17:32:24 2007
@@ -23,7 +23,6 @@
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.net.URI;
-import java.util.StringTokenizer;
 import java.util.UUID;
 
 import org.apache.tuscany.sca.assembly.Binding;
@@ -95,7 +94,7 @@
                 this.binding = this.reference.getBindings().get(0);
             }
         }
-        
+
         // FIXME: Should we normalize the componentName/serviceName URI into an absolute
SCA URI in the SCA binding?
         // sca:component1/component11/component112/service1?
         String componentURI = component.getURI(); // The target will be relative to this
base URI
@@ -118,7 +117,7 @@
             return null;
         }
     }
-    
+
     protected void bind(RuntimeWire wire) {
         if (wire != null) {
             this.component = wire.getSource().getComponent();
@@ -127,9 +126,9 @@
             this.componentURI = component.getURI();
             this.compositeActivator = ((ComponentContextImpl)component.getComponentContext()).getCompositeActivator();
             init(wire);
-        }        
+        }
     }
-    
+
     protected void init(RuntimeWire wire) {
         EndpointReference target = wire.getTarget();
 
@@ -191,26 +190,6 @@
      */
     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
         this.scdl = in.readUTF();
-        // resolve();
-
-        String uri = in.readUTF();
-        int index = uri.indexOf('?');
-        if (index == -1) {
-            componentURI = uri;
-        } else {
-            componentURI = uri.substring(0, index);
-            String query = uri.substring(index);
-            StringTokenizer tokenizer = new StringTokenizer(query, "&");
-            while (tokenizer.hasMoreTokens()) {
-                String attr = tokenizer.nextToken();
-                String pair[] = attr.split("=");
-                if (pair[0].equals("sca.conversationID")) {
-                    this.conversationID = pair[1];
-                } else if (pair[0].equals("sca.callbackID")) {
-                    this.callbackID = pair[1];
-                }
-            }
-        }
     }
 
     /**
@@ -227,6 +206,18 @@
                 currentActivator.configureComponentContext(this.component);
                 this.reference = (RuntimeComponentReference)c.getReferences().get(0);
                 this.reference.setComponent(this.component);
+                ReferenceParameters parameters = null;
+                for (Object ext : reference.getExtensions()) {
+                    if (ext instanceof ReferenceParameters) {
+                        parameters = (ReferenceParameters)ext;
+                        break;
+                    }
+                }
+                if (parameters != null) {
+                    this.callbackID = parameters.getCallbackID();
+                    this.conversationID = parameters.getConversationID();
+                    this.componentURI = parameters.getComponentURI();
+                }
                 URI uri = URI.create("/" + componentURI);
                 for (Binding binding : reference.getBindings()) {
                     if (binding instanceof WireableBinding) {
@@ -289,24 +280,15 @@
      */
     public void writeExternal(ObjectOutput out) throws IOException {
         try {
+            ReferenceParameters parameters = new ReferenceParameters();
+            parameters.setCallbackID(callbackID);
+            parameters.setComponentURI(componentURI);
+            parameters.setConversationID(conversationID);
+            reference.getExtensions().add(parameters);
             String scdl =
                 ((CompositeActivatorImpl)compositeActivator).getComponentContextHelper().toXML(component,
reference);
+            reference.getExtensions().remove(parameters);
             out.writeUTF(scdl);
-            StringBuffer uri = new StringBuffer(componentURI);
-            boolean first = true;
-            if (conversationID != null) {
-                uri.append("?sca.conversationID=").append(conversationID);
-                first = false;
-            }
-            if (callbackID != null) {
-                if (!first) {
-                    uri.append("&");
-                } else {
-                    uri.append("?");
-                }
-                uri.append("sca.callbackID=").append(callbackID);
-            }
-            out.writeUTF(uri.toString());
         } catch (Exception e) {
             e.printStackTrace();
             throw new IOException(e.getMessage());
@@ -321,9 +303,13 @@
     private String createCallbackID() {
         return UUID.randomUUID().toString();
     }
-    
+
     public void attachCallbackID(Object callbackID) {
         this.callbackID = callbackID;
+    }
+
+    public void attachConversationID(Object conversationID) {
+        conversation.setConversationID(conversationID);
     }
 
 }

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java?rev=572848&r1=572847&r2=572848&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java
(original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java
Tue Sep  4 17:32:24 2007
@@ -78,6 +78,7 @@
         this.assemblyFactory = assemblyFactory;
         this.javaInterfaceFactory = javaInterfaceFactory;
         this.staxProcessors = processors;
+        staxProcessors.addArtifactProcessor(new ReferenceParameterProcessor());
     }
 
     /**

Added: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameterProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameterProcessor.java?rev=572848&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameterProcessor.java
(added)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameterProcessor.java
Tue Sep  4 17:32:24 2007
@@ -0,0 +1,92 @@
+/*
+ * 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.core.context;
+
+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.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;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceParameterProcessor implements StAXArtifactProcessor<ReferenceParameters>
{
+    private final static QName REFERENCE_PARAMETERS =
+        new QName("http://tuscany.apache.org/xmlns/sca/1.0", "referenceParameters", "tuscany");
+
+    /**
+     * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#getArtifactType()
+     */
+    public QName getArtifactType() {
+        return REFERENCE_PARAMETERS;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#read(javax.xml.stream.XMLStreamReader)
+     */
+    public ReferenceParameters read(XMLStreamReader reader) throws ContributionReadException,
XMLStreamException {
+        ReferenceParameters parameters = new ReferenceParameters();
+        parameters.setComponentURI(reader.getAttributeValue(null, "componentURI"));
+        parameters.setConversationID(reader.getAttributeValue(null, "conversationID"));
+        parameters.setCallbackID(reader.getAttributeValue(null, "callbackID"));
+        return parameters;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#write(java.lang.Object,
javax.xml.stream.XMLStreamWriter)
+     */
+    public void write(ReferenceParameters model, XMLStreamWriter writer) throws ContributionWriteException,
+        XMLStreamException {
+        writer.writeStartElement(REFERENCE_PARAMETERS.getPrefix(),
+                                 REFERENCE_PARAMETERS.getLocalPart(),
+                                 REFERENCE_PARAMETERS.getNamespaceURI());
+        writer.writeNamespace(REFERENCE_PARAMETERS.getPrefix(), REFERENCE_PARAMETERS.getNamespaceURI());
+        if (model.getComponentURI() != null) {
+            writer.writeAttribute("componentURI", model.getComponentURI());
+        }
+        if (model.getConversationID() != null) {
+            writer.writeAttribute("conversationID", model.getConversationID().toString());
+        }
+        if (model.getCallbackID() != null) {
+            writer.writeAttribute("callbackID", model.getCallbackID().toString());
+        }
+        writer.writeEndElement();
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#getModelType()
+     */
+    public Class<ReferenceParameters> getModelType() {
+        return ReferenceParameters.class;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#resolve(java.lang.Object,
org.apache.tuscany.sca.contribution.resolver.ModelResolver)
+     */
+    public void resolve(ReferenceParameters model, ModelResolver resolver) throws ContributionResolveException
{
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameterProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameterProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameters.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameters.java?rev=572848&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameters.java
(added)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameters.java
Tue Sep  4 17:32:24 2007
@@ -0,0 +1,65 @@
+/*
+ * 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.core.context;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceParameters {
+    private String componentURI;
+    private Object callbackID;
+    private Object conversationID;
+    /**
+     * @return the callbackID
+     */
+    public Object getCallbackID() {
+        return callbackID;
+    }
+    /**
+     * @param callbackID the callbackID to set
+     */
+    public void setCallbackID(Object callbackID) {
+        this.callbackID = callbackID;
+    }
+    /**
+     * @return the conversationID
+     */
+    public Object getConversationID() {
+        return conversationID;
+    }
+    /**
+     * @param conversationID the conversationID to set
+     */
+    public void setConversationID(Object conversationID) {
+        this.conversationID = conversationID;
+    }
+    /**
+     * @return the componentURI
+     */
+    public String getComponentURI() {
+        return componentURI;
+    }
+    /**
+     * @param componentURI the componentURI to set
+     */
+    public void setComponentURI(String componentURI) {
+        this.componentURI = componentURI;
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ReferenceParameters.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java?rev=572848&r1=572847&r2=572848&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java
(original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java
Tue Sep  4 17:32:24 2007
@@ -62,6 +62,9 @@
         
         CallableReference<B> callableReference = component.getComponentContext().getCallableReference(null,
component, service);
         ((CallableReferenceImpl<B>) callableReference).attachCallbackID(ThreadMessageContext.getMessageContext().getCorrelationID());
+        if (callableReference.getConversation() != null) {
+            ((CallableReferenceImpl<B>) callableReference).attachConversationID(ThreadMessageContext.getMessageContext().getConversationID());
+        }
         return callableReference;
     }
 
@@ -84,6 +87,9 @@
         CallbackWireObjectFactory factory = new CallbackWireObjectFactory(javaClass, proxyFactory,
wires);
         factory.resolveTarget();
         factory.attachCallbackID(ThreadMessageContext.getMessageContext().getCorrelationID());
+        if (factory.getConversation() != null) {
+            factory.attachConversationID(ThreadMessageContext.getMessageContext().getConversationID());
+        }
         return factory;
     }
 }



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