diff options
Diffstat (limited to '')
3 files changed, 13 insertions, 46 deletions
diff --git a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptGenerator.java b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptGenerator.java index ffd300cb01..56cf30715a 100644 --- a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptGenerator.java +++ b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptGenerator.java @@ -5,20 +5,18 @@ import org.apache.tuscany.sca.interfacedef.Operation; public class JavascriptGenerator { + public static final String JS_NAMESPACE = "SCA"; + private static final String COMPONENT_CONTEXT = "this.CometComponentContext"; + private static final String TUSCANY_COMET = "SCA.TuscanyComet"; + public static StringBuffer javascript = new StringBuffer(); - private static final String COMPONENT_CONTEXT_NAMESPACE = "cometComponentContext"; - private static final String TUSCANY_COMET_NAMESPACE = "tuscanyComet"; public static void generateServiceProxy(ComponentService service) { - javascript.append(COMPONENT_CONTEXT_NAMESPACE + "." + service.getName() + " = new Object();\n"); + javascript.append(COMPONENT_CONTEXT + "." + service.getName() + " = new Object();\n"); } public static void generateMethodProxy(ComponentService service, Operation operation) { - javascript.append(COMPONENT_CONTEXT_NAMESPACE + "." - + service.getName() - + "." - + operation.getName() - + " = function("); + javascript.append(COMPONENT_CONTEXT + "." + service.getName() + "." + operation.getName() + " = function("); for (int i = 0; i < operation.getInputType().getLogical().size(); i++) { javascript.append("p" + i + ", "); } @@ -27,7 +25,7 @@ public class JavascriptGenerator { for (int i = 0; i < operation.getInputType().getLogical().size(); i++) { javascript.append(" params.push(p" + i + ");\n"); } - javascript.append(" " + TUSCANY_COMET_NAMESPACE + javascript.append(" " + TUSCANY_COMET + ".callAsync('" + service.getName() + "/" @@ -37,36 +35,3 @@ public class JavascriptGenerator { } } - -// cometComponentContext.c1 = new Object(); -// cometComponentContext.c1.TemperatureService = new Object(); -// cometComponentContext.c1.TemperatureService.getTemperatureCelsius = -// function(p0, callbackMethod) { -// tuscanyComet.callAsync('c1/TemperatureService/getTemperatureCelsius', x, -// callbackMethod); -// } -// cometComponentContext.c1.TemperatureService.getTemperatureFahrenheit = -// function(callbackMethod) { -// tuscanyComet.callAsync('c1/TemperatureService/getTemperatureFahrenheit', x, -// callbackMethod); -// } -// -// if (cometComponentContext.c1 == null) { -// cometComponentContext.c1 = new Object(); -// } -// cometComponentContext.c1.HumidityService = new Object(); -// cometComponentContext.c1.HumidityService.getHumidity = function(p0, -// callbackMethod) { -// var params = []; -// params.push(p0); -// tuscanyComet.callAsync('c1/HumidityService/getHumidity', $.toJSON(params), -// callbackMethod); -// } -// -// cometComponentContext.c2 = new Object(); -// cometComponentContext.c2.PrecipitationService = new Object(); -// cometComponentContext.c2.PrecipitationService.getPrecipitation = -// function(callbackMethod) { -// tuscanyComet.callAsync('c2/PrecipitationService/getPrecipitation', x, -// callbackMethod); -// } diff --git a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptResource.java b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptResource.java index 6df45e4ca8..650cb218d2 100644 --- a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptResource.java +++ b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/javascript/JavascriptResource.java @@ -26,7 +26,8 @@ public class JavascriptResource { @GET public InputStream getJavascript(@PathParam("file") PathSegment fileName) { - InputStream stream = null; + InputStream stream = + new ByteArrayInputStream(("var " + JavascriptGenerator.JS_NAMESPACE + " = new function() {\n").getBytes()); for (String dependency : DEPENDENCIES) { if (stream == null) { stream = getClass().getResourceAsStream(dependency); @@ -34,7 +35,7 @@ public class JavascriptResource { stream = new SequenceInputStream(stream, getClass().getResourceAsStream(dependency)); } } - String generatedJs = ((StringBuffer)sc.getAttribute(ServletFactory.JS_KEY)).toString(); + String generatedJs = ((StringBuffer)sc.getAttribute(ServletFactory.JS_KEY)).toString() + "\n}"; return new SequenceInputStream(stream, new ByteArrayInputStream(generatedJs.getBytes())); } } diff --git a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/resources/cometComponentContext.js b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/resources/cometComponentContext.js index 7352a2215c..d9b2c1ea7c 100644 --- a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/resources/cometComponentContext.js +++ b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/resources/cometComponentContext.js @@ -1,4 +1,5 @@ -var tuscanyComet = { + +this.TuscanyComet = { appUrl: 'tuscany-comet', connectedEndpoint : null, connect : function(transport) { @@ -23,4 +24,4 @@ var tuscanyComet = { } }; -var cometComponentContext = new Object(); +this.CometComponentContext = new Object(); |