From 8b6715b0a49263ab101682148daf09594cfd187e Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 12 Aug 2008 13:50:49 +0000 Subject: Add the script initilization code git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@685149 13f79535-47bb-0310-9956-ffa450edef68 --- .../implementation/web/ComponentContextServlet.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'java') diff --git a/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ComponentContextServlet.java b/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ComponentContextServlet.java index d6d015992d..052b87f714 100644 --- a/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ComponentContextServlet.java +++ b/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ComponentContextServlet.java @@ -85,6 +85,27 @@ public class ComponentContextServlet extends HttpServlet { */ protected void doScriptInit(HttpServletRequest req, HttpServletResponse response) throws IOException, UnsupportedEncodingException { + PrintWriter out = response.getWriter(); + + out.println("if (SCA == undefined) var SCA = new Object();"); + out.println("if (SCA.componentContext == undefined) {"); + out.println(" SCA.componentContext = new Object();"); + out.println(" SCA.componentContext.serviceNames = [];"); + out.println(" SCA.componentContext.serviceProxys = [];"); + out.println(" SCA.componentContext.getService = function(serviceName){"); + out.println(" var i = SCA.componentContext.serviceNames.indexOf(serviceName);"); + out.println(" return SCA.componentContext.serviceProxys[i];"); + out.println(" };"); + out.println(" if (componentContext == undefined) var componentContext = SCA.componentContext;"); + + // TODO remove this dummy service once the rest is implemented + out.println(" var proxy = new Object();"); + out.println(" proxy.sayHello = function(s, f) {f('proxyHello ' + s);};"); + out.println(" SCA.componentContext.serviceProxys.push(proxy);"); + out.println(" SCA.componentContext.serviceNames.push('service');"); + + out.println("}"); + for (ContextScriptProcessor csp : WebSingleton.INSTANCE.getContextScriptProcessors()) { csp.scriptInit(req, response); } -- cgit v1.2.3