diff options
Diffstat (limited to 'branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca')
5 files changed, 46 insertions, 51 deletions
diff --git a/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetComponentScriptGenerator.java b/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetComponentScriptGenerator.java index 1b42359a81..0e56d25c51 100644 --- a/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetComponentScriptGenerator.java +++ b/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetComponentScriptGenerator.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; -import java.net.URI; import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; @@ -33,6 +32,8 @@ import java.util.Map; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.ComponentProperty; import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.core.web.JavascriptProxyFactory; +import org.apache.tuscany.sca.core.web.JavascriptProxyFactoryExtensionPoint; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -43,22 +44,20 @@ import org.w3c.dom.Element; * @version $Rev: 665897 $ $Date: 2008-06-09 14:31:03 -0700 (Mon, 09 Jun 2008) $ */ public class WidgetComponentScriptGenerator { - - private static final long serialVersionUID = 1L; - public static InputStream generateWidgetCode(RuntimeComponent component) throws IOException, URISyntaxException { + public static InputStream generateWidgetCode(RuntimeComponent component, JavascriptProxyFactoryExtensionPoint javascriptProxyFactories) throws IOException, URISyntaxException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(bos); - generateWidgetCode(component, pw); + generateWidgetCode(component, javascriptProxyFactories, pw); return new ByteArrayInputStream(bos.toByteArray()); } - public static void generateWidgetCode(RuntimeComponent component, OutputStream os) throws IOException, URISyntaxException { + public static void generateWidgetCode(RuntimeComponent component, JavascriptProxyFactoryExtensionPoint javascriptProxyFactories, OutputStream os) throws IOException, URISyntaxException { PrintWriter pw = new PrintWriter(os); - generateWidgetCode(component, pw); + generateWidgetCode(component, javascriptProxyFactories, pw); } @@ -66,7 +65,7 @@ public class WidgetComponentScriptGenerator { * This helper class concatenates the necessary JavaScript client code into a * single JavaScript per component */ - public static void generateWidgetCode(RuntimeComponent component, PrintWriter pw) throws IOException, URISyntaxException { + public static void generateWidgetCode(RuntimeComponent component, JavascriptProxyFactoryExtensionPoint javascriptProxyFactories, PrintWriter pw) throws IOException, URISyntaxException { pw.println(); pw.println("/* Apache Tuscany SCA Widget header */"); pw.println(); @@ -108,7 +107,7 @@ public class WidgetComponentScriptGenerator { pw.println(); //process references - generateJavaScriptReferenceFunction(component, pw); + generateJavaScriptReferenceFunction(component, javascriptProxyFactories,pw); pw.println(); @@ -198,43 +197,19 @@ public class WidgetComponentScriptGenerator { * @param pw * @throws IOException */ - private static void generateJavaScriptReferenceFunction (RuntimeComponent component, PrintWriter pw) throws IOException, URISyntaxException { + private static void generateJavaScriptReferenceFunction (RuntimeComponent component, JavascriptProxyFactoryExtensionPoint javascriptProxyFactories, PrintWriter pw) throws IOException, URISyntaxException { pw.println("tuscany.sca.referenceMap = new Object();"); for(ComponentReference reference : component.getReferences()) { - String referenceName = reference.getName(); Binding binding = reference.getBindings().get(0); + if (binding != null) { + + String referenceName = reference.getName(); + JavascriptProxyFactory jsProxyFactory = javascriptProxyFactories.getProxyFactory(binding.getClass()); + + pw.println("tuscany.sca.referenceMap." + referenceName + " = new " + jsProxyFactory.scriptReference(reference) + ";"); - String proxyClient = WidgetProxyHelper.getJavaScriptProxyClient(binding.getClass().getName()); - if(proxyClient != null) { - - // Generate the JavaScript proxy configuration code - // Proxies are configured with the target URI path, as at this point we shouldn't - // be generating proxies that communicate with other hosts (if a proxy needs to - // communicate with another host it should be generated on and served by - // that particular host) - - /* - URI targetURI = URI.create(binding.getURI()); - String targetPath; - if(targetURI.getScheme() == null) { - targetPath = targetURI.getPath(); - } else { - targetPath = targetURI.toString(); - } - */ - - URI targetURI = URI.create(binding.getURI()); - String targetPath = targetURI.getPath(); - - if(proxyClient.equals("JSONRpcClient")) { - //FIXME Proxies should follow the same pattern, saving us from having to test for JSONRpc here - pw.println("tuscany.sca.referenceMap." + referenceName + " = new " + proxyClient + "(\"" + targetPath + "\").Service;"); - } else { - pw.println("tuscany.sca.referenceMap." + referenceName + " = new " + proxyClient + "(\"" + targetPath + "\");"); - } - } } } diff --git a/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetComponentScriptServlet.java b/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetComponentScriptServlet.java index a8129aa151..819159d553 100644 --- a/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetComponentScriptServlet.java +++ b/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetComponentScriptServlet.java @@ -29,6 +29,8 @@ import javax.servlet.http.HttpServletResponse; import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.core.web.JavascriptProxyFactoryExtensionPoint; + /** * Servlet to handle requests for the widget component .js script. @@ -38,6 +40,7 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent; public class WidgetComponentScriptServlet extends HttpServlet { private static final long serialVersionUID = 2454705532282398190L; + private transient JavascriptProxyFactoryExtensionPoint javascriptProxyFactories; private transient RuntimeComponent component; @@ -45,15 +48,16 @@ public class WidgetComponentScriptServlet extends HttpServlet { * Constructor receiving the runtimeComponent reference that is going to be used to generate the widget client js * @param component */ - public WidgetComponentScriptServlet(RuntimeComponent component) { - this.component = component; + public WidgetComponentScriptServlet(RuntimeComponent component, JavascriptProxyFactoryExtensionPoint javascriptProxyFactories) { + this.component = component; + this.javascriptProxyFactories = javascriptProxyFactories; } @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { try { ServletOutputStream os = response.getOutputStream(); - WidgetComponentScriptGenerator.generateWidgetCode(component, os); + WidgetComponentScriptGenerator.generateWidgetCode(component, javascriptProxyFactories, os); }catch(URISyntaxException e) { throw new IOException("Invalid uri creating JavaScript resource"); } diff --git a/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java b/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java index 3b8e92be5e..9d5fa7ae5b 100644 --- a/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java +++ b/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java @@ -25,6 +25,7 @@ import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; +import org.apache.tuscany.sca.core.web.JavascriptProxyFactoryExtensionPoint; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.runtime.RuntimeComponent; @@ -37,12 +38,14 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent; */ class WidgetImplementationInvoker implements Invoker { private RuntimeComponent component; + private JavascriptProxyFactoryExtensionPoint javascriptProxyFactories; private String widgetName; private String widgetFolderURL; private String widgetLocationURL; - WidgetImplementationInvoker(RuntimeComponent component, String widgetName, String widgetFolderURL, String widgetLocationURL) { + WidgetImplementationInvoker(RuntimeComponent component, JavascriptProxyFactoryExtensionPoint javascriptProxyFactories, String widgetName, String widgetFolderURL, String widgetLocationURL) { this.component = component; + this.javascriptProxyFactories = javascriptProxyFactories; this.widgetName = widgetName + ".js"; this.widgetFolderURL = widgetFolderURL; this.widgetLocationURL = widgetLocationURL; @@ -64,7 +67,7 @@ class WidgetImplementationInvoker implements Invoker { } else if (id.equals(widgetName)) { // Generate JavaScript header for use in the Widget - InputStream is = WidgetComponentScriptGenerator.generateWidgetCode(component); + InputStream is = WidgetComponentScriptGenerator.generateWidgetCode(component, javascriptProxyFactories); msg.setBody(is); } else { diff --git a/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java b/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java index 26f8c78677..8f1511f483 100644 --- a/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java +++ b/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java @@ -23,6 +23,7 @@ import java.net.URI; import javax.servlet.Servlet; import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.core.web.JavascriptProxyFactoryExtensionPoint; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.implementation.widget.WidgetImplementation; import org.apache.tuscany.sca.interfacedef.Operation; @@ -41,6 +42,7 @@ class WidgetImplementationProvider implements ImplementationProvider { private RuntimeComponent component; + private JavascriptProxyFactoryExtensionPoint javascriptProxyFactories; private ServletHost servletHost; private String widgetLocationURL; @@ -52,9 +54,13 @@ class WidgetImplementationProvider implements ImplementationProvider { /** * Constructs a new resource implementation provider. */ - WidgetImplementationProvider(RuntimeComponent component, WidgetImplementation implementation, ServletHost servletHost) { + WidgetImplementationProvider(RuntimeComponent component, + WidgetImplementation implementation, + JavascriptProxyFactoryExtensionPoint javascriptProxyFactories, + ServletHost servletHost) { this.component = component; + this.javascriptProxyFactories = javascriptProxyFactories; this.servletHost = servletHost; widgetLocationURL = implementation.getLocationURL().toString(); @@ -65,7 +71,7 @@ class WidgetImplementationProvider implements ImplementationProvider { } public Invoker createInvoker(RuntimeComponentService service, Operation operation) { - WidgetImplementationInvoker invoker = new WidgetImplementationInvoker(component, widgetName, widgetFolderURL, widgetLocationURL); + WidgetImplementationInvoker invoker = new WidgetImplementationInvoker(component, javascriptProxyFactories, widgetName, widgetFolderURL, widgetLocationURL); return invoker; } @@ -74,8 +80,6 @@ class WidgetImplementationProvider implements ImplementationProvider { } public void start() { - System.out.println(">>> Starting component : " + this.component.getName()); - String contextRoot = getContextRoot(); // get the ScaDomainScriptServlet, if it doesn't yet exist create one @@ -84,7 +88,7 @@ class WidgetImplementationProvider implements ImplementationProvider { Servlet servlet = servletHost.getServletMapping(scriptURI); if (servlet == null /*|| servlet instanceof HTTPGetListenerServlet*/) { WidgetComponentScriptServlet widgetScriptServlet; - widgetScriptServlet = new WidgetComponentScriptServlet(this.component); + widgetScriptServlet = new WidgetComponentScriptServlet(this.component, javascriptProxyFactories); servletHost.addServletMapping(scriptURI, widgetScriptServlet); } else { System.out.println(">>>Servlet::" + servlet.getClass().toString()); @@ -101,6 +105,10 @@ class WidgetImplementationProvider implements ImplementationProvider { } + /** + * Get the contextRoot considering the HTTP Binding URI when in a embedded environment + * @return + */ private String getContextRoot() { String contextRoot = null; diff --git a/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProviderFactory.java b/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProviderFactory.java index f702cc7eb5..3cc1a64a68 100644 --- a/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProviderFactory.java +++ b/branches/sca-java-1.x/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProviderFactory.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.implementation.widget.provider; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.web.JavascriptProxyFactoryExtensionPoint; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; import org.apache.tuscany.sca.implementation.widget.WidgetImplementation; @@ -33,6 +34,8 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent; */ public class WidgetImplementationProviderFactory implements ImplementationProviderFactory<WidgetImplementation> { private ServletHost servletHost; + private JavascriptProxyFactoryExtensionPoint javascriptProxyFactories; + /** * Constructs a resource implementation. @@ -40,10 +43,12 @@ public class WidgetImplementationProviderFactory implements ImplementationProvid public WidgetImplementationProviderFactory(ExtensionPointRegistry extensionPoints) { ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); this.servletHost = servletHosts.getServletHosts().get(0); + + this.javascriptProxyFactories = extensionPoints.getExtensionPoint(JavascriptProxyFactoryExtensionPoint.class); } public ImplementationProvider createImplementationProvider(RuntimeComponent component, WidgetImplementation implementation) { - return new WidgetImplementationProvider(component, implementation, servletHost); + return new WidgetImplementationProvider(component, implementation, javascriptProxyFactories, servletHost); } public Class<WidgetImplementation> getModelType() { |