SCA Java implementation.script (TUSCANY) edited by ant
Page:
http://cwiki.apache.org/confluence/display/TUSCANY/SCA+Java+implementation.script
Changes:
http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=55156&originalVersion=9&revisedVersion=10
Content:
---------------------------------------------------------------------
{section:border=false}
{column:width=15%}
{include: SCA Java Subproject Menu}
{include: Java SCA Menu New}
{column}
{column:width=85%}
h3. <implementation.script>
Tuscany supports SCA components implemented 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:
{code}
<implementation.script [ script="" | language="" ] >
[inline src]
</implementation.script>
{code}
The source code for the script may be 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.
h4. Some examples:
A Ruby program defined in a file 'myScript.rb' in a folder named 'test':
{code}
<implementation.script script="test/myScript.rb"/>
{code}
A JavaScript program defined inline:
{code}
<implementation.script language="js">
function sayHello(name) {
return "Hello " + name;
}
</implementation.script>
{code}
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:
{code}
<implementation.script language="js"><![CDATA[
function sayHello(inXML) {
return <sayHelloResponse>Hello { inXML..name }</sayHelloResponse>;
}
]]></implementation.script>
{code}
The previous example demonstrated using JavaScript's
[E4X|http://www.ecma-international.org/publications/standards/Ecma-357.htm]
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:
{code}
<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>
{code}
{note:title=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.
{note}
{note:title=0.90}
In release 0.90 and before, inline scripts are not supported and scripts
require an associated .componentType side file
{note}
{column}
{section}
---------------------------------------------------------------------
CONFLUENCE INFORMATION
This message is automatically generated by Confluence
Unsubscribe or edit your notifications preferences
http://cwiki.apache.org/confluence/users/viewnotifications.action
If you think it was sent incorrectly contact one of the administrators
http://cwiki.apache.org/confluence/administrators.action
If you want more information on Confluence, or have a bug to report see
http://www.atlassian.com/software/confluence
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]