summaryrefslogtreecommitdiffstats
path: root/site/trunk/site-publish/java-sca-implementationscript.html
blob: e8b5125f818d99dbf5b4dbb7f3d76de37ba683a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
    <HEAD>
        <LINK type="text/css" rel="stylesheet" href="http://people.apache.org/~svkrish/tuscanySite/style/default.css">
        <LINK rel="SHORTCUT ICON" href="http://cwiki.apache.org/confluence/display/TUSCANY/$images/favicon.ico">   
        <TITLE>Java SCA implementation.script : Apache Tuscany</TITLE>
    <META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD>
    
    <BODY onload="init()">
        
            <TABLE valign="top" border="0" cellspacing="0" cellpadding="0" width="100%" background="http://people.apache.org/~svkrish/tuscanySite/images/TuscanyLogoNEW_Text_120px_bg.jpg">
        <TR>
            <TD valing="top" align="left">
			    <A href="http://cwiki.apache.org/confluence/pages/viewpage.action?spaceKey=TUSCANY&title=$siteroot"><IMG src="http://people.apache.org/~svkrish/tuscanySite/images/TuscanyLogoNEW_Text_120px_bg.jpg" height="91" width="25" border="0"></A>
			</TD>
			<TD>
                <A href="http://cwiki.apache.org/confluence/pages/viewpage.action?spaceKey=TUSCANY&title=$siteroot"><IMG src="http://people.apache.org/~svkrish/tuscanySite/images/TuscanyLogo.jpg" border="0"></A>
            </TD>
            
            <TD width="100%">
                &nbsp;
            </TD>
            <!-- Adds the edit page link to the top banner-->
            <TD valign="bottom">
                <DIV style="padding: 2px 10px; margin: 0px;">
                    <A href="http://cwiki.apache.org/confluence/pages/editpage.action?pageId=55156">
                    <IMG src="http://people.apache.org/~svkrish/tuscanySite/images/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A>
                </DIV>
            </TD>

        </TR>
    </TABLE>

            <TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
        <TR class="topBar">
            <TD align="left" valign="middle" class="topBarDiv" nowrap="true" width="100%">
                &nbsp;<A href="home.html" title="Apache Tuscany">Apache Tuscany</A>&nbsp;&gt;&nbsp;<A href="home.html" title="Home">Home</A>&nbsp;&gt;&nbsp;<A href="java-sca-subproject.html" title="Java SCA Subproject">Java SCA Subproject</A>&nbsp;&gt;&nbsp;<A href="java-sca-documentation-menu.html" title="Java SCA Documentation Menu">Java SCA Documentation Menu</A>&nbsp;&gt;&nbsp;<A href="" title="Java SCA implementation.script">Java SCA implementation.script</A>
            </TD>
            
            <TD align="left" valign="middle" class="topBarDiv" nowrap="true">
            <A href="http://mail-archives.apache.org/mod_mbox/ws-tuscany-user">User List</A> | <A href="http://mail-archives.apache.org/mod_mbox/ws-tuscany-dev">Dev List</A> | <A href="http://issues.apache.org/jira/browse/Tuscany">Issue Tracker</A>&nbsp;&nbsp;
            </TD>
        </TR>
    </TABLE>

        <TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF">
            <TR>
                <TD align="left" valign="top">
                        <DIV id="PageContent">
                
        <DIV class="pagecontent">
            <DIV class="wiki-content">
                <TABLE class="sectionMacro" border="0" cellpadding="5" cellspacing="0" width="100%"><TBODY><TR>
<TD class="confluenceTd" valign="top" width="15%">
<DIV class="panel" style="border-style: solid; border-color: #C3CDA1; "><DIV class="panelHeader" style="border-bottom-style: solid; border-bottom-color: #C3CDA1; background-color: #C3CDA1; "><B>General</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1; ">
<P><A href="home.html" title="Home">Home</A><BR>
<SPAN class="nobr"><A href="http://www.apache.org/licenses/LICENSE-2.0.html" title="Visit page outside Confluence" rel="nofollow">License <SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN><BR>
<A href="tuscany-downloads.html" title="Tuscany Downloads">Downloads</A></P>
</DIV></DIV>
<DIV class="panel" style="border-style: solid; border-color: #b4b4b5; "><DIV class="panelHeader" style="border-bottom-style: solid; border-bottom-color: #b4b4b5; background-color: #C3CDA1; "><B>Resources</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1; ">
<P><A href="tuscany-sca-java-faq.html" title="Tuscany SCA Java - FAQ">FAQ</A><BR>
<SPAN class="nobr"><A href="http://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANY&title=Java%20SCA%20Documentation&linkCreation=true&fromPageId=55228" title="Create Page: Java SCA Documentation" class="createlink">Documentation <SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/plus.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN><BR>
<SPAN class="nobr"><A href="https://svn.apache.org/repos/asf/incubator/tuscany/java/sca" title="Visit page outside Confluence" rel="nofollow">Source Code<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN></P>
</DIV></DIV></TD>
<TD class="confluenceTd" valign="top" width="85%">

<H3><A name="JavaSCAimplementation.script-%3Cimplementation.script%3E"></A>&lt;implementation.script&gt;</H3>

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

<P>Any language that supports the &quot;Scripting for Java&quot; APIs defined by JSR-223 is supported, this includes Groovy, JavaScript, JRuby, Jython, and many others.</P>

<P>To use these languages the SCA assembly SCDL is extended with an &quot;implementation.script&quot; element which has the following options:</P>


<DIV class="code"><DIV class="codeContent">
<PRE class="code-java">&lt;implementation.script [ script=<SPAN class="code-quote">&quot;&quot; | language=&quot;</SPAN>&quot; ] &gt;
     [inline src]
&lt;/implementation.script&gt;</PRE>
</DIV></DIV>

<P>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 &lt;implementation.script&gt; element.</P>

<P>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.</P>

<H4><A name="JavaSCAimplementation.script-Someexamples%3A"></A>Some examples:</H4>


<P>A Ruby program defined in a file 'myScript.rb' in a folder named 'test':</P>

<DIV class="code"><DIV class="codeContent">
<PRE class="code-java">&lt;implementation.script script=<SPAN class="code-quote">&quot;test/myScript.rb&quot;</SPAN>/&gt;</PRE>
</DIV></DIV>


<P>A JavaScript program defined inline:</P>

<DIV class="code"><DIV class="codeContent">
<PRE class="code-java">&lt;implementation.script language=<SPAN class="code-quote">&quot;js&quot;</SPAN>&gt;
      function sayHello(name) {
         <SPAN class="code-keyword">return</SPAN> <SPAN class="code-quote">&quot;Hello &quot;</SPAN> + name;
      }
&lt;/implementation.script&gt;</PRE>
</DIV></DIV>


<P>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:</P>

<DIV class="code"><DIV class="codeContent">
<PRE class="code-java">&lt;implementation.script language=<SPAN class="code-quote">&quot;js&quot;</SPAN>&gt;&lt;![CDATA[
      function sayHello(inXML) {
         <SPAN class="code-keyword">return</SPAN> &lt;sayHelloResponse&gt;Hello { inXML..name }&lt;/sayHelloResponse&gt;;
      }
]]&gt;&lt;/implementation.script&gt;</PRE>
</DIV></DIV>

<P>The previous example demonstrated using JavaScript's <SPAN class="nobr"><A href="http://www.ecma-international.org/publications/standards/Ecma-357.htm" title="Visit page outside Confluence" rel="nofollow">E4X<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN> 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. </P>

<P>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.  </P>

<P>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:</P>

<DIV class="code"><DIV class="codeContent">
<PRE class="code-java">&lt;composite xmlns=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//www.osoa.org/xmlns/sca/1.0&quot;</SPAN>
</SPAN>	targetNamespace=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//helloworld&quot;</SPAN>
</SPAN>	xmlns:hw=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//helloworld&quot;</SPAN>
</SPAN>        name=<SPAN class="code-quote">&quot;helloworldws&quot;</SPAN>&gt;

    &lt;service name=<SPAN class="code-quote">&quot;HelloWorldService&quot;</SPAN> promote=<SPAN class="code-quote">&quot;HelloWorldServiceComponent&quot;</SPAN>&gt;
       &lt;<SPAN class="code-keyword">interface</SPAN>.wsdl <SPAN class="code-keyword">interface</SPAN>=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//helloworld#wsdl.<SPAN class="code-keyword">interface</SPAN>(HelloWorld)&quot;</SPAN> /&gt;
</SPAN>       &lt;binding.ws uri=&quot;&quot;/&gt;
    &lt;/service&gt;

    &lt;component name=<SPAN class="code-quote">&quot;HelloWorldServiceComponent&quot;</SPAN>&gt;
        &lt;implementation.script language=<SPAN class="code-quote">&quot;js&quot;</SPAN>&gt;&lt;![CDATA[

           function getGreetings(xmlIn) {
              <SPAN class="code-keyword">return</SPAN> &lt;ns1:getGreetings xmlns:ns1=<SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//helloworld&quot;</SPAN>&gt;
</SPAN>                        &lt;ns1:name&gt;Hello { xmlIn..name }&lt;/ns1:name&gt;
                     &lt;/ns1:getGreetings&gt;
           }

        ]]&gt;&lt;/implementation.script&gt;
    &lt;/component&gt;

&lt;/composite&gt;</PRE>
</DIV></DIV>

<TABLE cellpadding="5" width="85%" cellspacing="8px" class="noteMacro" border="0" align="center"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="http://cwiki.apache.org/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD><B class="strong">Best practice?</B><BR>
<P>Using inline scripts can make creating simple components very easier however there are issues around whether or not this is good practice. <BR>
Depending on the circumstance consideration should be given as to if it would be better to define the script in a seperate file.</P></TD></TR></TABLE>

<TABLE cellpadding="5" width="85%" cellspacing="8px" class="noteMacro" border="0" align="center"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="http://cwiki.apache.org/confluence/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD><B class="strong">0.90</B><BR>
<P>In release 0.90 and before, inline scripts are not supported and scripts require an associated .componentType side file</P></TD></TR></TABLE>

</TD></TR></TBODY></TABLE>
            </DIV>
        </DIV>
    </DIV>
                </TD>
            </TR>
        </TABLE>

            <DIV class="footer">
        Copyright &copy; 2003-2007, The Apache Software Foundation&nbsp;&nbsp;
    </DIV>

    </BODY>
</HTML>