From 200a40b332420f94992eb39a6d0ea1cf1490ffc4 Mon Sep 17 00:00:00 2001 From: coreyg Date: Fri, 21 Nov 2014 09:30:19 +0000 Subject: Adding tuscany's website to their svn repo for svnpubsub git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1640879 13f79535-47bb-0310-9956-ffa450edef68 --- .../java-sca-implementationscript.html | 170 +++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 site/trunk/site-publish/java-sca-implementationscript.html (limited to 'site/trunk/site-publish/java-sca-implementationscript.html') diff --git a/site/trunk/site-publish/java-sca-implementationscript.html b/site/trunk/site-publish/java-sca-implementationscript.html new file mode 100644 index 0000000000..e8b5125f81 --- /dev/null +++ b/site/trunk/site-publish/java-sca-implementationscript.html @@ -0,0 +1,170 @@ + + + + + + + Java SCA implementation.script : Apache Tuscany + + + + + + + + + + + + + + +
+ + + + +   + +
+ + +
+
+ + + + + + + +
+  Apache Tuscany > Home > Java SCA Subproject > Java SCA Documentation Menu > Java SCA implementation.script + + User List | Dev List | Issue Tracker   +
+ + + + + +
+
+ +
+
+ + +
+
General
+
+ +

<implementation.script>

+ +

The Tuscany Java SCA runtime supports implementing SCA components in a wide variety of dynamic or scripting languages by using the <implementation.script> SCDL extension.

+ +

Any language that supports the "Scripting for Java" APIs defined by JSR-223 is supported, this includes Groovy, JavaScript, JRuby, Jython, and many others.

+ +

To use these languages the SCA assembly SCDL is extended with an "implementation.script" element which has the following options:

+ + +
+
<implementation.script [ script="" | language="" ] >
+     [inline src]
+</implementation.script>
+
+ +

The source code for the script maybe defined in a seperate file pointed to by the 'script=' attribute, or the source code maybe embedded within the SCDL inline inside the <implementation.script> element.

+ +

The 'language=' attribute defines the language of the program. The language attribute is optional when the source code is in a separate file in which case the file extension of the file is used to determine the language.

+ +

Some examples:

+ + +

A Ruby program defined in a file 'myScript.rb' in a folder named 'test':

+ +
+
<implementation.script script="test/myScript.rb"/>
+
+ + +

A JavaScript program defined inline:

+ +
+
<implementation.script language="js">
+      function sayHello(name) {
+         return "Hello " + name;
+      }
+</implementation.script>
+
+ + +

When using inline scripts which contain special characters such as XML markup you may need to enclose the source within a CDATA region, for example:

+ +
+
<implementation.script language="js"><![CDATA[
+      function sayHello(inXML) {
+         return <sayHelloResponse>Hello { inXML..name }</sayHelloResponse>;
+      }
+]]></implementation.script>
+
+ +

The previous example demonstrated using JavaScript's E4X language extension for manipulating XML. Many dynamic languages have enhanced XML capabilities like this which can make working with XML much easier than in a more traditional language such as Java. For example, along with JavaScript's E4X, Ruby has ReXML and Groovy has its markup builders.

+ +

Tuscany tries to simplify this for the script program developer and will try to automatically ensure arguments are in the native XML format of the language when the component is wired to a WSDL interface.

+ +

As an example of this the following shows a composite that can replace the Tuscany helloworld-ws-service sample and requires no other files other than the asscociated WSDL document packaged with the contribution:

+ +
+
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+	targetNamespace="http://helloworld"
+	xmlns:hw="http://helloworld"
+        name="helloworldws">
+
+    <service name="HelloWorldService" promote="HelloWorldServiceComponent">
+       <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" />
+       <binding.ws uri=""/>
+    </service>
+
+    <component name="HelloWorldServiceComponent">
+        <implementation.script language="js"><![CDATA[
+
+           function getGreetings(xmlIn) {
+              return <ns1:getGreetings xmlns:ns1="http://helloworld">
+                        <ns1:name>Hello { xmlIn..name }</ns1:name>
+                     </ns1:getGreetings>
+           }
+
+        ]]></implementation.script>
+    </component>
+
+</composite>
+
+ +
Best practice?
+

Using inline scripts can make creating simple components very easier however there are issues around whether or not this is good practice.
+Depending on the circumstance consideration should be given as to if it would be better to define the script in a seperate file.

+ +
0.90
+

In release 0.90 and before, inline scripts are not supported and scripts require an associated .componentType side file

+ +
+
+
+
+
+ + + + + \ No newline at end of file -- cgit v1.2.3