diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules')
6 files changed, 65 insertions, 4 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-atom-js-dojo/src/main/java/org/apache/tuscany/sca/binding/atom/js/dojo/AtomBindingJavascriptProxyFactoryImpl.java b/sca-java-2.x/trunk/modules/binding-atom-js-dojo/src/main/java/org/apache/tuscany/sca/binding/atom/js/dojo/AtomBindingJavascriptProxyFactoryImpl.java index b67500152e..abc3c0c342 100644 --- a/sca-java-2.x/trunk/modules/binding-atom-js-dojo/src/main/java/org/apache/tuscany/sca/binding/atom/js/dojo/AtomBindingJavascriptProxyFactoryImpl.java +++ b/sca-java-2.x/trunk/modules/binding-atom-js-dojo/src/main/java/org/apache/tuscany/sca/binding/atom/js/dojo/AtomBindingJavascriptProxyFactoryImpl.java @@ -52,6 +52,10 @@ public class AtomBindingJavascriptProxyFactoryImpl implements JavascriptProxyFac return null; } + public String createJavascriptHeader(ComponentReference componentReference) throws IOException { + return "dojo.require('tuscany.AtomService');"; + } + public String createJavascriptReference(ComponentReference componentReference) throws IOException { EndpointReference epr = componentReference.getEndpointReferences().get(0); Endpoint targetEndpoint = epr.getTargetEndpoint(); diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-js-dojo/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/dojo/JSONRPCBindingJavascriptProxyFactoryImpl.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-js-dojo/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/dojo/JSONRPCBindingJavascriptProxyFactoryImpl.java index fc4d7a2318..0388c8bd77 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-js-dojo/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/dojo/JSONRPCBindingJavascriptProxyFactoryImpl.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-js-dojo/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/dojo/JSONRPCBindingJavascriptProxyFactoryImpl.java @@ -52,6 +52,10 @@ public class JSONRPCBindingJavascriptProxyFactoryImpl implements JavascriptProxy return null; } + public String createJavascriptHeader(ComponentReference componentReference) throws IOException { + return "dojo.require('dojo.rpc.JsonService');"; + } + public String createJavascriptReference(ComponentReference componentReference) throws IOException { EndpointReference epr = componentReference.getEndpointReferences().get(0); Endpoint targetEndpoint = epr.getTargetEndpoint(); diff --git a/sca-java-2.x/trunk/modules/implementation-widget-runtime-dojo/pom.xml b/sca-java-2.x/trunk/modules/implementation-widget-runtime-dojo/pom.xml index 74ba4af61f..ffee3ad510 100644 --- a/sca-java-2.x/trunk/modules/implementation-widget-runtime-dojo/pom.xml +++ b/sca-java-2.x/trunk/modules/implementation-widget-runtime-dojo/pom.xml @@ -35,6 +35,12 @@ <artifactId>tuscany-implementation-widget-runtime</artifactId> <version>2.0-SNAPSHOT</version> </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-web-javascript-dojo</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> <dependency> <groupId>junit</groupId> diff --git a/sca-java-2.x/trunk/modules/implementation-widget-runtime-dojo/src/main/java/org/apache/tuscany/sca/implementation/widget/dojo/DojoJavaScriptComponentGeneratorImpl.java b/sca-java-2.x/trunk/modules/implementation-widget-runtime-dojo/src/main/java/org/apache/tuscany/sca/implementation/widget/dojo/DojoJavaScriptComponentGeneratorImpl.java index 4aede2806f..64c75b4a7b 100644 --- a/sca-java-2.x/trunk/modules/implementation-widget-runtime-dojo/src/main/java/org/apache/tuscany/sca/implementation/widget/dojo/DojoJavaScriptComponentGeneratorImpl.java +++ b/sca-java-2.x/trunk/modules/implementation-widget-runtime-dojo/src/main/java/org/apache/tuscany/sca/implementation/widget/dojo/DojoJavaScriptComponentGeneratorImpl.java @@ -61,7 +61,7 @@ public class DojoJavaScriptComponentGeneratorImpl implements ComponentJavaScript pw.println(); pw.println("/* Apache Tuscany SCA Widget header */"); pw.println(); - + Map<String, Boolean> bindingClientProcessed = new HashMap<String, Boolean>(); for(ComponentReference reference : component.getReferences()) { @@ -90,14 +90,14 @@ public class DojoJavaScriptComponentGeneratorImpl implements ComponentJavaScript } } } - - //pw.println("dojo.require(\"/dojo.rpc.JsonService\");"); - //pw.println("dojo.require(\"/tuscany.AtomService\");"); pw.println(); pw.println("/* Tuscany Reference/Property injection code */"); pw.println(); + generateJavaScriptHeader(component, javascriptProxyFactories,pw); + + pw.println(); //define tuscany.sca namespace generateJavaScriptNamespace(pw); @@ -137,6 +137,42 @@ public class DojoJavaScriptComponentGeneratorImpl implements ComponentJavaScript pw.println(); pw.println(); } + + /** + * + * @param pw + * @throws IOException + */ + private static void generateJavaScriptHeader(RuntimeComponent component, JavascriptProxyFactoryExtensionPoint javascriptProxyFactories, PrintWriter pw) throws IOException { + Map<String, Boolean> bindingHeaderProcessed = new HashMap<String, Boolean>(); + + for(ComponentReference reference : component.getReferences()) { + for(EndpointReference epr : reference.getEndpointReferences()) { + Endpoint targetEndpoint = epr.getTargetEndpoint(); + if (targetEndpoint.isUnresolved()) { + //force resolution and targetEndpoint binding calculations + //by calling the getInvocationChain + ((RuntimeEndpointReference) epr).getInvocationChains(); + targetEndpoint = epr.getTargetEndpoint(); + } + + Binding binding = targetEndpoint.getBinding(); + if (binding != null) { + JavascriptProxyFactory jsProxyFactory = javascriptProxyFactories.getProxyFactory(binding.getClass()); + + String bindingKey = binding.getClass().getName(); + Boolean processedFlag = bindingHeaderProcessed.get(bindingKey); + + //check if binding client code was already processed and inject to the generated script + if( processedFlag == null || processedFlag.booleanValue() == false) { + pw.println(jsProxyFactory.createJavascriptHeader(reference)); + bindingHeaderProcessed.put(bindingKey, Boolean.TRUE); + } + } + } + } + } + /** * Generate the tuscany.sca namespace if not yet available diff --git a/sca-java-2.x/trunk/modules/web-javascript-dojo/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/web-javascript-dojo/META-INF/MANIFEST.MF index 5feed60e41..8e78a97910 100644 --- a/sca-java-2.x/trunk/modules/web-javascript-dojo/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/web-javascript-dojo/META-INF/MANIFEST.MF @@ -18,4 +18,6 @@ Import-Package: javax.servlet, org.apache.tuscany.sca.runtime;version="2.0.0"
Bundle-SymbolicName: org.apache.tuscany.sca.core.web.javascript.dojo
Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
+
diff --git a/sca-java-2.x/trunk/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/JavascriptProxyFactory.java b/sca-java-2.x/trunk/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/JavascriptProxyFactory.java index 10455ef764..825d3281e4 100644 --- a/sca-java-2.x/trunk/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/JavascriptProxyFactory.java +++ b/sca-java-2.x/trunk/modules/web-javascript/src/main/java/org/apache/tuscany/sca/web/javascript/JavascriptProxyFactory.java @@ -58,6 +58,15 @@ public interface JavascriptProxyFactory { */ InputStream getJavascriptProxyFileAsStream() throws IOException; + /** + * Create any necessary JavaScript imports/headers necessary for the extension to work + * This is useful in case of Dojo that need to generate the requires statements to load the dependencies + * + * @param componentReference + * @return + * @throws IOException + */ + String createJavascriptHeader(ComponentReference componentReference) throws IOException; /** * Create a JavaScript Proxy for a given reference |