Author: jsdelfino
Date: Mon Oct 29 01:15:47 2007
New Revision: 589538

URL: http://svn.apache.org/viewvc?rev=589538&view=rev
Log:
Fixed how the URI or the widget implementation script and the URIs or JSON and 
Atom references are determined. This will have to be revisited when the 
distributed domain supports configuration of other bindings than the SCA 
binding.

Added:
    
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetComponentServlet.java
      - copied, changed from r589490, 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetReferenceServlet.java
Removed:
    
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetReferenceServlet.java
Modified:
    
incubator/tuscany/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java
    
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java
    
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java
    
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetProxyHelper.java
    
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java

Modified: 
incubator/tuscany/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java?rev=589538&r1=589537&r2=589538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java
 Mon Oct 29 01:15:47 2007
@@ -22,6 +22,10 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
 import org.apache.tuscany.sca.binding.feed.AtomBinding;
 import org.apache.tuscany.sca.policy.Intent;
 import org.apache.tuscany.sca.policy.IntentAttachPointType;
@@ -31,7 +35,7 @@
 /**
  * Implementation of the Atom Feed binding model.
  */
-class AtomBindingImpl implements AtomBinding, PolicySetAttachPoint {
+class AtomBindingImpl implements AtomBinding, OptimizableBinding, 
PolicySetAttachPoint {
 
     private String name;
     private String uri;
@@ -80,4 +84,40 @@
     public void setType(IntentAttachPointType intentAttachPointType) {
         this.intentAttachPointType = intentAttachPointType;
     }
+
+    //FIXME Temporary to get access to the target binding information
+    // To be removed when the distributed domain supports wiring of other
+    // bindings than the SCA binding
+    private Binding targetBinding; 
+    private Component targetComponent; 
+    private ComponentService targetComponentService; 
+    
+    public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+    
+    public Binding getTargetBinding() {
+        return targetBinding;
+    }
+    
+    public void setTargetBinding(Binding binding) {
+        this.targetBinding = binding;
+    }
+    
+    public Component getTargetComponent() {
+        return targetComponent;
+    }
+    
+    public void setTargetComponent(Component component) {
+        this.targetComponent = component;
+    }
+    
+    public ComponentService getTargetComponentService() {
+        return targetComponentService;
+    }
+    
+    public void setTargetComponentService(ComponentService service) {
+        this.targetComponentService = service; 
+    }
+
 }

Modified: 
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java?rev=589538&r1=589537&r2=589538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java
 Mon Oct 29 01:15:47 2007
@@ -20,13 +20,16 @@
 package org.apache.tuscany.sca.binding.jsonrpc;
 
 import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
 
 /**
  * A model for the JSONRPC binding.
  * 
  * @version $Rev$ $Date$
  */
-public class JSONRPCBinding implements Binding {
+public class JSONRPCBinding implements OptimizableBinding {
     private String name;
     private String uri;
 
@@ -53,6 +56,41 @@
 
     public void setUnresolved(boolean unresolved) {
         // The binding is always resolved
+    }
+
+    //FIXME Temporary to get access to the target binding information
+    // To be removed when the distributed domain supports wiring of other
+    // bindings than the SCA binding
+    private Binding targetBinding; 
+    private Component targetComponent; 
+    private ComponentService targetComponentService; 
+    
+    public Object clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+    
+    public Binding getTargetBinding() {
+        return targetBinding;
+    }
+    
+    public void setTargetBinding(Binding binding) {
+        this.targetBinding = binding;
+    }
+    
+    public Component getTargetComponent() {
+        return targetComponent;
+    }
+    
+    public void setTargetComponent(Component component) {
+        this.targetComponent = component;
+    }
+    
+    public ComponentService getTargetComponentService() {
+        return targetComponentService;
+    }
+    
+    public void setTargetComponentService(ComponentService service) {
+        this.targetComponentService = service; 
     }
 
 }

Copied: 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetComponentServlet.java
 (from r589490, 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetReferenceServlet.java)
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetComponentServlet.java?p2=incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetComponentServlet.java&p1=incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetReferenceServlet.java&r1=589490&r2=589538&rev=589538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetReferenceServlet.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetComponentServlet.java
 Mon Oct 29 01:15:47 2007
@@ -30,6 +30,7 @@
 
 import org.apache.tuscany.sca.assembly.Binding;
 import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 
 /**
@@ -37,12 +38,15 @@
  * 
  * @version $Rev$ $Date$
  */
-public class WidgetReferenceServlet extends HttpServlet {
+public class WidgetComponentServlet extends HttpServlet {
+    private static final long serialVersionUID = -2996033426789721509L;
     
-    protected transient RuntimeComponent component;
+    private transient RuntimeComponent component;
+    private transient URI servletURI;
 
-    public WidgetReferenceServlet(RuntimeComponent component) {
+    public WidgetComponentServlet(RuntimeComponent component, String 
servletURI) {
         this.component = component;
+        this.servletURI = URI.create(servletURI);
     }
 
     @Override
@@ -59,7 +63,7 @@
 
     /**
      */
-    protected void writeSCAWidgetCode(ServletOutputStream out, String path) 
throws IOException {
+    private void writeSCAWidgetCode(ServletOutputStream out, String path) 
throws IOException {
         out.println();
         out.println("/* Apache Tuscany SCA Widget header */");
         out.println();
@@ -68,7 +72,6 @@
         path = path.substring(1);
 
         for(ComponentReference reference : component.getReferences()) {
-            String referenceName = reference.getName();
             for(Binding binding : reference.getBindings()) {
                 String bindingProxyName = 
WidgetProxyHelper.getJavaScriptProxyFile(binding.getClass().getName());
                 if(bindingProxyName != null) {
@@ -89,7 +92,7 @@
      * Retrieve the binding proxy based on the bind name
      * and embedded the javascript into this js
      */
-    protected void writeJavaScriptBindingProxy(ServletOutputStream os, String 
bindingProxyName) throws IOException {
+    private void writeJavaScriptBindingProxy(ServletOutputStream os, String 
bindingProxyName) throws IOException {
         
         URL url = getClass().getClassLoader().getResource(bindingProxyName); 
//Thread.currentThread().getContextClassLoader().getResource(bindingProxyName);
         InputStream is = url.openStream();
@@ -101,24 +104,38 @@
         os.println();
     }
     
-    protected void writeJavaScriptReferenceFunction (ServletOutputStream os) 
throws IOException {
+    private void writeJavaScriptReferenceFunction (ServletOutputStream os) 
throws IOException {
         
         os.println("var referenceMap = new Object();");
         for(ComponentReference reference : component.getReferences()) {
             String referenceName = reference.getName();
             Binding binding = reference.getBindings().get(0);
-            if( binding != null) {
+            if (binding != null) {
+                
                 String proxyClient = 
WidgetProxyHelper.getJavaScriptProxyClient(binding.getClass().getName());
                 if(proxyClient != null) {
-                    URI uri = URI.create(binding.getURI());
-                    String path = uri.getPath();
-                    if (!path.startsWith("/")) {
-                        path = "/" + path;
+                    
+                    //FIXME Eventually the binding URI should be initialized 
from the SCA domain
+                    // for now point to the target binding model directly, 
assuming that it's available
+                    // in the same node
+                    String targetURI = null;
+                    if (binding instanceof OptimizableBinding) {
+                        Binding targetBinding = 
((OptimizableBinding)binding).getTargetBinding();
+                        if (targetBinding != null) {
+                            targetURI = 
URI.create(targetBinding.getURI()).getPath();
+                        }
+                    }
+                    if (targetURI == null) {
+                        targetURI = URI.create(binding.getURI()).getPath();
+                        if (!targetURI.startsWith("/")) {
+                            targetURI = "/" + targetURI;
+                        }
                     }
+                    
                     if(proxyClient.equals("JSONRpcClient")) {
-                        os.println("referenceMap." + referenceName + " = new " 
+ proxyClient + "(\"" + path + "\").Service;");
+                        os.println("referenceMap." + referenceName + " = new " 
+ proxyClient + "(\"" + targetURI + "\").Service;");
                     } else {
-                        os.println("referenceMap." + referenceName + " = new " 
+ proxyClient + "(\"" + path + "\");");
+                        os.println("referenceMap." + referenceName + " = new " 
+ proxyClient + "(\"" + targetURI + "\");");
                     }
                 }                
             }
@@ -128,19 +145,5 @@
         os.println("    return referenceMap[name];");
         os.println("}");
     }
-
-    /*
-    public void addService(String serviceName) {
-        serviceNames.add(serviceName);
-    }
-
-    public void removeService(String serviceName) {
-        serviceNames.remove(serviceName);
-    }
-
-    public List<String> getServiceNames() {
-        return serviceNames;
-    }
-    */
 
 }

Modified: 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java?rev=589538&r1=589537&r2=589538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java
 Mon Oct 29 01:15:47 2007
@@ -38,7 +38,7 @@
  * The model representing a widget implementation in an SCA assembly model.
  */
 public class WidgetImplementation implements Implementation {
-    AssemblyFactory assemblyFactory;
+    private AssemblyFactory assemblyFactory;
     
     private Service widgetService;
     private List<Reference> references = null;

Modified: 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetProxyHelper.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetProxyHelper.java?rev=589538&r1=589537&r2=589538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetProxyHelper.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetProxyHelper.java
 Mon Oct 29 01:15:47 2007
@@ -22,9 +22,9 @@
 import java.util.HashMap;
 import java.util.Map;
 
-public class WidgetProxyHelper {
-    protected static Map<String, String> proxyFileRegistry = new 
HashMap<String, String>();
-    protected static Map<String, String> proxyClient = new HashMap<String, 
String>();
+class WidgetProxyHelper {
+    private static Map<String, String> proxyFileRegistry = new HashMap<String, 
String>();
+    private static Map<String, String> proxyClient = new HashMap<String, 
String>();
 
     static {
         
proxyFileRegistry.put("org.apache.tuscany.sca.binding.feed.impl.AtomBindingImpl",
 "binding-atom.js");
@@ -34,15 +34,11 @@
         
proxyClient.put("org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding", 
"JSONRpcClient");
     }
     
-    protected WidgetProxyHelper() {
-        
-    }
-    
-    public static String getJavaScriptProxyFile(String bindingClass) {
+    static String getJavaScriptProxyFile(String bindingClass) {
         return proxyFileRegistry.get(bindingClass);
     }
     
-    public static String getJavaScriptProxyClient(String bindingClass) {
+    static String getJavaScriptProxyClient(String bindingClass) {
         return proxyClient.get(bindingClass);
     }
 }

Modified: 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java?rev=589538&r1=589537&r2=589538&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java
 Mon Oct 29 01:15:47 2007
@@ -18,14 +18,18 @@
  */
 package org.apache.tuscany.sca.implementation.widget.provider;
 
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.ComponentService;
 import org.apache.tuscany.sca.host.http.ServletHost;
 import org.apache.tuscany.sca.implementation.widget.WidgetImplementation;
-import org.apache.tuscany.sca.implementation.widget.WidgetReferenceServlet;
+import org.apache.tuscany.sca.implementation.widget.WidgetComponentServlet;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.provider.ImplementationProvider;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.osoa.sca.ServiceRuntimeException;
+
 
 /**
  * The model representing a resource implementation in an SCA assembly model.
@@ -33,8 +37,8 @@
 class WidgetImplementationProvider implements ImplementationProvider {
     private RuntimeComponent component;
     private WidgetImplementation implementation;
-
     private ServletHost servletHost;
+    private String servletMapping;
 
     /**
      * Constructs a new resource implementation provider.
@@ -57,13 +61,31 @@
 
     public void start() {
 
-        WidgetReferenceServlet widgetServlet = new 
WidgetReferenceServlet(component);
+        // Determine the widget URI
+        String widgetURI = null;
+        for (ComponentService componentService: component.getServices()) {
+            if (componentService.getName().equals("Widget")) {
+                if (componentService.getBindings().size() != 0) {
+                    widgetURI = componentService.getBindings().get(0).getURI();
+                }
+                break;
+            }
+        }
+        if (widgetURI == null) {
+            throw new ServiceRuntimeException("Could not find Widget service");
+        }
         
-        String uri = component.getURI() + "/" + component.getURI() + ".js";
-        servletHost.addServletMapping(uri, widgetServlet);        
+        // Register the widget's ComponentServlet under the same URI as the 
widget
+        String widgetArtifact = implementation.getLocation();
+        widgetArtifact = widgetArtifact.substring(0, 
widgetArtifact.lastIndexOf('.'));
+        widgetArtifact = 
widgetArtifact.substring(widgetArtifact.lastIndexOf('/') + 1);
+        servletMapping = widgetURI + "/" + widgetArtifact + ".js";
+        WidgetComponentServlet widgetComponentServlet = new 
WidgetComponentServlet(component, servletMapping);
+        servletHost.addServletMapping(servletMapping, widgetComponentServlet); 
       
     }
 
     public void stop() {
+        servletHost.removeServletMapping(servletMapping);
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to