diff options
Diffstat (limited to 'site/trunk/site-publish/sca-java-implementationspring.html')
-rw-r--r-- | site/trunk/site-publish/sca-java-implementationspring.html | 473 |
1 files changed, 473 insertions, 0 deletions
diff --git a/site/trunk/site-publish/sca-java-implementationspring.html b/site/trunk/site-publish/sca-java-implementationspring.html new file mode 100644 index 0000000000..76bb8cdfb1 --- /dev/null +++ b/site/trunk/site-publish/sca-java-implementationspring.html @@ -0,0 +1,473 @@ + +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE- 2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + + +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<HTML> + <HEAD> + <!-- generateKeywords macro --> + <META name="description" content="Apache Tuscany"> + <META name="keywords" content="apache, apache tuscany, tuscany, service, services, fabric, soa, service oriented architecture, sca, service component architecture, das, sdo, csa, ruby, opensource"> + <!-- generateKeywords macro end --> + + <LINK type="text/css" rel="stylesheet" href="http://tuscany.apache.org/stylesheets/default.css"> + <LINK rel="SHORTCUT ICON" href="https://cwiki.apache.org/confluence/display/TUSCANY/$images/favicon.ico"> + <TITLE>Apache Tuscany : SCA Java implementation.spring</TITLE> + <META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD> + + <BODY onload="init()"> + <!-- topNav macro --> + <TABLE valign="top" border="0" cellspacing="0" cellpadding="0" width="100%" background="http://tuscany.apache.org/images/TuscanyLogoNEW_Text_120px_bg.jpg"> + <TR> + <TD valing="top" align="left"> + <A href="https://cwiki.apache.org/confluence/pages/viewpage.action?spaceKey=TUSCANY&title=$siteroot"><IMG src="http://tuscany.apache.org/images/TuscanyLogoNEW_Text_120px_bg.jpg" height="91" width="25" border="0"></A> + </TD> + <TD> + <A href="http://tuscany.apache.org/"><IMG src="http://tuscany.apache.org/images/TuscanyLogo.jpg" border="0"></A> + </TD> + + <TD width="100%"> + + </TD> + + <!-- Adds the edit page link to the top banner--> + <TD valign="bottom"> + <DIV style="padding: 2px 10px; margin: 0px;"> + <A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=66253"> + <IMG src="http://tuscany.apache.org/images/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A> + </DIV> + </TD> + + </TR> + </TABLE> + <!-- topNav macro end --> + + <!-- breadCrumbs macro --> + <TABLE border="0" cellpadding="2" cellspacing="0" width="100%"> + <TR class="topBar"> + <TD align="left" valign="middle" class="topBarDiv" nowrap="true" width="100%"> + <A href="home.html" title="Apache Tuscany">Apache Tuscany</A> > <A href="home.html" title="Home">Home</A> > <A href="sca-overview.html" title="SCA Overview">SCA Overview</A> > <A href="sca-java.html" title="SCA Java">SCA Java</A> > <A href="java-sca-documentation-menu.html" title="Java SCA Documentation Menu">Java SCA Documentation Menu</A> > <A href="sca-java-user-guide.html" title="SCA Java User Guide">SCA Java User Guide</A> > <A href="" title="SCA Java implementation.spring">SCA Java implementation.spring</A> + </TD> + + <TD align="right" valign="middle" class="topBarDiv" align="left" nowrap="true"> + <A href="http://mail-archives.apache.org/mod_mbox/tuscany-user">User List</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-dev">Dev List</A> | <A href="http://issues.apache.org/jira/browse/Tuscany">Issue Tracker</A> + </TD> + </TR> + </TABLE> + <!-- breadCrumbs macro end --> + + + <TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF"> + <TR> + <TD align="left" valign="top"> + + <!-- pageContent macro --> + <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="background-color: #ECF4D1;border-color: #C3CDA1;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;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> +<A href="http://www.apache.org/licenses/LICENSE-2.0.html" class="external-link" rel="nofollow">License </A><BR> +<A href="sca-java-get-involved.html" title="SCA Java Get Involved">Get Involved</A><BR> +<A href="sca-java-found-a-bug.html" title="SCA Java Found A Bug">Found a Bug?</A></P> +</DIV></DIV> + +<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>SCA Java</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;"> +<P><A href="sca-java.html" title="SCA Java">SCA Java Home</A><BR> +<A href="tuscany-dashboard.html" title="Tuscany Dashboard">SCA Dashboard</A><BR> +<A href="java-sca-tools.html" title="Java SCA Tools">Tools </A><BR> +<A href="tuscany-sca-java-faq.html" title="Tuscany SCA Java - FAQ">FAQ</A></P> +</DIV></DIV> + +<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>SCA Java 1.x</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;"> +<P><A href="sca-java-releases.html" title="SCA Java Releases">Downloads</A><BR> +<A href="java-sca-documentation-menu.html" title="Java SCA Documentation Menu">Documentation</A><BR> +<A href="https://svn.apache.org/repos/asf/tuscany/sca-java-1.x/trunk/" class="external-link" rel="nofollow">1.x Source Code</A><BR> +<A href="http://tinyurl.com/8rlxd3" class="external-link" rel="nofollow">Roadmap</A></P> +</DIV></DIV> + +<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>SCA Java 2.x</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;"> +<P><A href="sca-java-2x-releases.html" title="SCA Java 2.x Releases">Downloads</A><BR> +<A href="http://tuscany.apache.org/documentation-2x/" class="external-link" rel="nofollow">Documentation</A><BR> +<A href="https://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/" class="external-link" rel="nofollow">2.x Source Code</A><BR> +<A href="http://tinyurl.com/8rlxd3" class="external-link" rel="nofollow">Roadmap</A></P> +</DIV></DIV> + + +<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>Documentation</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;"> +<P><A href="sca-java-user-guide.html" title="SCA Java User Guide">User Guide</A><BR> +<A href="sca-java-architecture-guide.html" title="SCA Java Architecture Guide">Architecture Guide</A><BR> +<A href="sca-java-development-guide.html" title="SCA Java Development Guide">Developer Guide</A><BR> +<A href="sca-java-extension-development-guide.html" title="SCA Java Extension Development Guide">Extension Developer Guide</A></P> +</DIV></DIV> + +<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;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> +<A href="https://svn.apache.org/repos/asf/incubator/tuscany/java/sca" class="external-link" rel="nofollow">Source Code</A></P> +</DIV></DIV> +</TD> +<TD class="confluenceTd" valign="top" width="85%"> + +<H2><A name="SCAJavaimplementation.spring-%3Cimplementation.spring%3E"></A><implementation.spring></H2> + +<P>The Tuscany Java SCA runtime supports components implemented with Spring Framework by using the <implementation.spring> SCDL extension. </P> + +<P>The <A href="http://www.osoa.org/download/attachments/35/SCA_SpringComponentImplementationSpecification-V100.pdf?version=1" class="external-link" rel="nofollow">Spring specification</A> defines how Spring and SCA work with one another. The Spring Component implementation is one of the SCA extensions which is being formalized in the OASIS Open Composite Services Architecture with a published <A href="http://www.oasis-opencsa.org/sca-spring" class="external-link" rel="nofollow">specifications </A> document.</P> + +<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> In <A href="http://static.springframework.org/spring/docs/2.5.5/reference" class="external-link" rel="nofollow">Spring Framework</A> an ApplicationContext is the main interface to the Spring IoC container. It is used to look up objects. It can be viewed as the Java object representation of the application-Context.xml file that contains the bean definitions.</P> + +<P>The integration with Spring will be at the SCA Composite level, where a Spring application context provides a complete composite, exposing services and using references via SCA. This means that a Spring application context defines the internal structure of a SCA composite implementation.</P> + +<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> Tuscany uses Spring Framework 2.5.5 (requires Java 1.4+)</P> + +<H3><A name="SCAJavaimplementation.spring-HowSpringApplicationContextisusedasSCACompositeImplementation%3F"></A>How Spring Application Context is used as SCA Composite Implementation?</H3> + +<UL> + <LI>A Spring Application Context is used as an implementation within an SCA composite component.</LI> + <LI>A component that uses Spring for an implementation can wire SCA services and references without introducing SCA metadata into the Spring configuration.<BR> +The Spring context knows very little about the SCA environment. </LI> + <LI>SCA runtime enforces SCA policies and Spring Application Context is unaware of it.</LI> + <LI>It should be possible to generate an SCA Composite from any Spring context and use that composite within an SCA assembly.<BR> +<EM>This feature is under review by the OASIS Specs Team, yet to be implemented in Tuscany</EM></LI> +</UL> + + +<H3><A name="SCAJavaimplementation.spring-HowtoUseSpringComponentImplementation%3F"></A>How to Use Spring Component Implementation?</H3> + +<P>The Spring component implementation SCDL has the following format:</P> + +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> + <implementation.spring location=<SPAN class="code-quote">"targetURI"</SPAN> /> +</PRE> +</DIV></DIV> + +<P>Where the location attribute of that element specifies the target uri of an archive file or directory or the fully qualified path that contains the Spring application context files. </P> + +<P>An example of all the three ways of specifying the target uri in the location attribute is shown below</P> + +<P>a) Specifying Fully Qualified Path:</P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> + <implementation.spring location=<SPAN class="code-quote">"./spring/application-context.xml"</SPAN> /> +</PRE> +</DIV></DIV> + +<P>b) Specifying a Directory:</P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> + <implementation.spring location=<SPAN class="code-quote">"./spring"</SPAN> /> +</PRE> +</DIV></DIV> + +<P>Here the target uri specifies the resource as a directory named "spring", where all the spring related files are available.</P> + +<P>c) Specifying an Archive file:</P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> + <implementation.spring location=<SPAN class="code-quote">"./spring.jar"</SPAN> /> +</PRE> +</DIV></DIV> + +<P>Here the target uri specifies the resource as an archive file name "spring.jar", where all the spring related files are available.</P> + +<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> In case of b) and c), If the resource identified by the location attribute is an archive file then the file META-INF/MANIFEST.MF is read from the archive. If the location URI identifies a directory, then META-INF/MANIFEST.MF must exist underneath that directory.</P> + +<P>If the manifest file contains a header "Spring-Context" of the format: <INS>Spring-Context ::= path ( ';' path )*</INS></P> + +<P>Where path is a relative path with respect to the location URI, then the set of paths specified in the header identify the context configuration files. If there is no MANIFEST.MF file or no Spring-Context header within that file, then the default behavior is to build an application context using application-context.xml file in the META-INF/spring directory.</P> + +<H3><A name="SCAJavaimplementation.spring-HowSpringApplicationContextisAwareofBeansusedinSCAcomposition%3F"></A>How Spring Application Context is Aware of Beans used in SCA composition?</H3> + +<P>Your existing Spring Application context should define the <A href="http://www.springframework.org/schema/sca" class="external-link" rel="nofollow">http://www.springframework.org/schema/sca</A> namespace in order to make the Spring aware of the SCA related beans. This is shown below.</P> + +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<beans xmlns=<SPAN class="code-quote">"http:<SPAN class="code-comment">//www.springframework.org/schema/beans"</SPAN> +</SPAN> xmlns:xsi=<SPAN class="code-quote">"http:<SPAN class="code-comment">//www.w3.org/2001/XMLSchema-instance"</SPAN> +</SPAN> xmlns:sca=<SPAN class="code-quote">"http:<SPAN class="code-comment">//www.springframework.org/schema/sca"</SPAN> +</SPAN> xsi:schemaLocation=" + http:<SPAN class="code-comment">//www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd +</SPAN> http:<SPAN class="code-comment">//www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd"> +</SPAN> + <sca:service name=<SPAN class="code-quote">"StockQuoteService"</SPAN> + type=<SPAN class="code-quote">"bigbank.stockquote.StockQuoteService"</SPAN> target=<SPAN class="code-quote">"StockQuoteServiceBean"</SPAN>/> + + <bean id=<SPAN class="code-quote">"StockQuoteServiceBean"</SPAN> class=<SPAN class="code-quote">"bigbank.stockquote.StockQuoteImpl"</SPAN>> + </bean> +</beans> +</PRE> +</DIV></DIV> + + +<H3><A name="SCAJavaimplementation.spring-HandlingmultipleSpringApplicationContexts"></A>Handling multiple Spring Application Contexts </H3> + +<P>Tuscany supports the following configurations to handle multiple Spring Application Context XML files.</P> + +<H4><A name="SCAJavaimplementation.spring-Using%3Cimport%3EElement%3A"></A>Using <import> Element:</H4> +<P>Each import element points to an application context xml file.</P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<beans> + <<SPAN class="code-keyword">import</SPAN> resource=<SPAN class="code-quote">"services.xml"</SPAN>/> + <<SPAN class="code-keyword">import</SPAN> resource=<SPAN class="code-quote">"resources/messageSource.xml"</SPAN>/> + + <<SPAN class="code-keyword">import</SPAN> resource=<SPAN class="code-quote">"/resources/themeSource.xml"</SPAN>/> + + <bean id=<SPAN class="code-quote">"bean1"</SPAN> class=<SPAN class="code-quote">"..."</SPAN>/> + <bean id=<SPAN class="code-quote">"bean2"</SPAN> class=<SPAN class="code-quote">"..."</SPAN>/> +</beans> +</PRE> +</DIV></DIV> + +<H4><A name="SCAJavaimplementation.spring-UsingClassPathXmlApplicationContextBeanDefinition%3A"></A>Using ClassPathXmlApplicationContext Bean Definition:</H4> +<P>Each list value points to an application context xml file.</P> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<bean id=<SPAN class="code-quote">"beanRefFactory"</SPAN> class=<SPAN class="code-quote">"org.springframework.context.support.ClassPathXmlApplicationContext"</SPAN>> + <constructor-arg> + <list> + <value>services.xml</value> + <value>resources/messageSource.xml</value> + </list> + </constructor-arg> +</bean> +</PRE> +</DIV></DIV> + +<H3><A name="SCAJavaimplementation.spring-SomeExamples%3A"></A>Some Examples:</H3> + +<H4><A name="SCAJavaimplementation.spring-SpringBigBankSample"></A>Spring BigBank Sample</H4> +<P>The spring-bigbank sample demonstrates most of the functionality that is specified in the <A href="http://www.oasis-opencsa.org/sca-spring" class="external-link" rel="nofollow">specifications </A>.</P> + +<P>See the <A href="http://svn.apache.org/repos/asf/tuscany/java/sca/samples/simple-bigbank-spring/" class="external-link" rel="nofollow">simple-bigbank-spring </A> sample for a complete example.</P> + +<H4><A name="SCAJavaimplementation.spring-DirectuseofSCAreferenceswithinaSpringconfiguration"></A>Direct use of SCA references within a Spring configuration</H4> +<P>See the <A href="http://svn.apache.org/repos/asf/tuscany/java/sca/samples/spring-bigbank-calculator/" class="external-link" rel="nofollow">spring-bigbank-calculator </A> sample for a complete example of using direct SCA references within Spring configuration.</P> + +<P>The properties like addService, subtractService, multiplyService and divideService defined in the Spring configuration as shown below</P> + +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<beans> + + <sca:service name=<SPAN class="code-quote">"CalculatorService"</SPAN> + type=<SPAN class="code-quote">"bigbank.calculator.CalculatorService"</SPAN> target=<SPAN class="code-quote">"CalculatorServiceBean"</SPAN>/> + + <bean id=<SPAN class="code-quote">"CalculatorServiceBean"</SPAN> class=<SPAN class="code-quote">"bigbank.calculator.CalculatorServiceImpl"</SPAN>> + <!-- Here are some implicit references - a property with a ref not satisifed within the + * Spring application context. + --> + <property name=<SPAN class="code-quote">"addService"</SPAN> ref=<SPAN class="code-quote">"addService"</SPAN>/> + <property name=<SPAN class="code-quote">"subtractService"</SPAN> ref=<SPAN class="code-quote">"subtractService"</SPAN>/> + <property name=<SPAN class="code-quote">"multiplyService"</SPAN> ref=<SPAN class="code-quote">"multiplyService"</SPAN>/> + <property name=<SPAN class="code-quote">"divideService"</SPAN> ref=<SPAN class="code-quote">"divideService"</SPAN>/> + </bean> + +</beans> +</PRE> +</DIV></DIV> + +<P>are the direct representation of the SCA references defined in the composite file.</P> + +<H4><A name="SCAJavaimplementation.spring-ExplicitdeclarationofSCArelatedbeansinsideaSpringApplicationContext"></A>Explicit declaration of SCA related beans inside a Spring Application Context</H4> +<P>It is also possible to explicitly declare SCA-related beans inside a Spring configuration to proxy SCA references. The primary reason you may do this is to enable the Spring container to decorate the bean (using Spring AOP for example).</P> + +<P>The properties checkingAccountService, calculatorService and stockQuoteService defined in the Spring configuration as shown below</P> + +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<beans> + <bean id=<SPAN class="code-quote">"AccountServiceBean"</SPAN> class=<SPAN class="code-quote">"bigbank.account.AccountServiceImpl"</SPAN>> + <property name=<SPAN class="code-quote">"calculatorService"</SPAN> ref=<SPAN class="code-quote">"calculatorService"</SPAN>/> + <property name=<SPAN class="code-quote">"stockQuoteService"</SPAN> ref=<SPAN class="code-quote">"stockQuoteService"</SPAN>/> + <property name=<SPAN class="code-quote">"checkingAccountService"</SPAN> ref=<SPAN class="code-quote">"checkingAccountService"</SPAN>/> + + <!-- Here are some implicit references & properties - a property with a ref not satisifed + * within the Spring application context. + --> + <property name=<SPAN class="code-quote">"savingsAccountService"</SPAN> ref=<SPAN class="code-quote">"savingsAccountService"</SPAN>/> + <property name=<SPAN class="code-quote">"stockAccountService"</SPAN> ref=<SPAN class="code-quote">"stockAccountService"</SPAN>/> + <property name=<SPAN class="code-quote">"currency"</SPAN> value=<SPAN class="code-quote">"EURO"</SPAN>/> + </bean> + + <sca:reference name=<SPAN class="code-quote">"checkingAccountService"</SPAN> type=<SPAN class="code-quote">"bigbank.account.checking.CheckingAccountService"</SPAN>/> + + <sca:reference name=<SPAN class="code-quote">"calculatorService"</SPAN> type=<SPAN class="code-quote">"bigbank.calculator.CalculatorService"</SPAN>/> + + <sca:reference name=<SPAN class="code-quote">"stockQuoteService"</SPAN> type=<SPAN class="code-quote">"bigbank.stockquote.StockQuoteService"</SPAN>/> +</beans> +</PRE> +</DIV></DIV> + +<P>can be declared explicit as SCA beans in Spring Application Context using the <sca:reference> element.</P> + +<P>See the <A href="http://svn.apache.org/repos/asf/tuscany/java/sca/samples/simple-bigbank-spring/" class="external-link" rel="nofollow">simple-bigbank-spring </A> sample for a complete example of using explicit declaration of SCA related beans.</P> + +<H4><A name="SCAJavaimplementation.spring-UsingSCABindingsforSpringImplementation"></A>Using SCA Bindings for Spring Implementation</H4> + +<P>We know that a component that uses Spring for an implementation can wire SCA services and references without introducing SCA metadata into the Spring configuration. The Spring context knows very little about the SCA environment. Hence the SpringComponent implementation remains the same as shown from some of the examples above but different bindings are chosen at the SCA Composite level as shown below.</P> + +<P><IMG class="emoticon" src="https://cwiki.apache.org/confluence/images/icons/emoticons/lightbulb_on.gif" height="16" width="16" align="absmiddle" alt="" border="0"> All kind of bindings supported by SCA can be used for Spring Implementation as the bindings are independent of Spring context. Few examples can be seen below.</P> + +<H5><A name="SCAJavaimplementation.spring-WorkingwithSCAWebServicesBinding"></A>Working with SCA WebServices Binding</H5> + +<P>Declaring Service</P> + +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<composite name=<SPAN class="code-quote">"StockQuote"</SPAN>> + + <service name=<SPAN class="code-quote">"StockQuoteService"</SPAN> promote=<SPAN class="code-quote">"StockQuoteServiceComponent"</SPAN>> + <<SPAN class="code-keyword">interface</SPAN>.java <SPAN class="code-keyword">interface</SPAN>=<SPAN class="code-quote">"bigbank.stockquote.StockQuoteService"</SPAN>/> + <binding.ws uri=<SPAN class="code-quote">"http:<SPAN class="code-comment">//localhost:8081/services/StockQuoteWebService"</SPAN>/> +</SPAN> </service> + + <component name=<SPAN class="code-quote">"StockQuoteServiceComponent"</SPAN>> + <implementation.spring location=<SPAN class="code-quote">"META-INF/spring/StockQuoteService-context.xml"</SPAN>/> + </component> + +</composite> +</PRE> +</DIV></DIV> + +<P>Declaring Reference in a component which consumes the Service declared above</P> + +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<component name=<SPAN class="code-quote">"AccountServiceComponent"</SPAN>> + <implementation.spring location=<SPAN class="code-quote">"spring-context/Account-spring-context.xml"</SPAN>/> + + <reference name=<SPAN class="code-quote">"stockQuoteService"</SPAN>> + <binding.ws uri=<SPAN class="code-quote">"http:<SPAN class="code-comment">//localhost:8081/services/StockQuoteWebService"</SPAN>/> +</SPAN> </reference> +</component> +</PRE> +</DIV></DIV> + +<P>See the <A href="http://svn.apache.org/repos/asf/tuscany/java/sca/samples/spring-bigbank-stockquote/" class="external-link" rel="nofollow">spring-bigbank-stockquote </A> sample for a complete example of using SCA Web Service binding.</P> + +<H5><A name="SCAJavaimplementation.spring-WorkingwithSCARMIBinding"></A>Working with SCA RMI Binding</H5> + +<P>See the <A href="http://svn.apache.org/repos/asf/tuscany/java/sca/samples/spring-bigbank-calculator/" class="external-link" rel="nofollow">spring-bigbank-calculator </A> sample for a complete example of using SCA RMI binding.</P> + +<H3><A name="SCAJavaimplementation.spring-AccesstheSpringApplicationContextfromeverywhereinyourApplication"></A>Access the Spring-ApplicationContext from everywhere in your Application</H3> +<P>Tuscany creates an custom Application context with an implementation logic for all SCA related beans like <sca:service>, <sca:reference> and <sca:properties> available in the Spring Application Context.</P> + +<P>To access the application context in your application we recommend to use the suggested approach in this article.<BR> +<A href="http://blog.jdevelop.eu/2008/07/06/access-the-spring-applicationcontext-from-everywhere-in-your-application/" class="external-link" rel="nofollow">http://blog.jdevelop.eu/2008/07/06/access-the-spring-applicationcontext-from-everywhere-in-your-application/</A></P> + +<H3><A name="SCAJavaimplementation.spring-NonSupportedFeaturesinTuscany"></A>Non-Supported Features in Tuscany</H3> +<P>Currently Tuscany does not support implicit SCA references and properties for scenario 1 & 2 in spring context as shown below.</P> + +<H5><A name="SCAJavaimplementation.spring-Scenario1%3AUsingimplicitSCAReferences%26PropertiesforConstructors"></A>Scenario 1: Using implicit SCA References & Properties for Constructors</H5> +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<constructor-arg><ref bean=<SPAN class="code-quote">"mySCAService1"</SPAN>/></constructor-arg> +<constructor-arg><ref bean=<SPAN class="code-quote">"mySCAService2"</SPAN>/></constructor-arg> +</PRE> +</DIV></DIV> + +<P>In the above scenario, particularly in cases where the spring bean has defined only one constructor, implicit references / properties can be supported when the contructor-arg element specifies the type of the SCA reference/property that its trying to consume by specifying a type attribute in the contructor-arg OR when the appropriate index attribute is specified in the constructor-arg element.</P> + +<P>In cases where the spring bean has defined multiple contructors, its mandatory that all the SCA references / properties used by the constructors should be defined explicitly. And when the constructor-arg uses SCA reference/property within collections, those should be defined explicitly.</P> + +<H5><A name="SCAJavaimplementation.spring-Scenario2%3AUsingimplicitSCAReferences%26PropertiesinList%2CMapandSetofbeanproperties."></A>Scenario 2: Using implicit SCA References & Properties in List, Map and Set of bean properties.</H5> +<P>Using implicit SCA references and properties within collection as shown in the below code sample will not be supported by Tuscany. Instead we recommed to use explicit SCA references/properties in such cases.</P> + +<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent"> +<PRE class="code-java"> +<bean id=<SPAN class="code-quote">"moreComplexObject"</SPAN> class=<SPAN class="code-quote">"example.ComplexObject"</SPAN>> + <!-- results in a setSomeList(java.util.List) call --> + <property name=<SPAN class="code-quote">"someList"</SPAN>> + <list> + <value>a list element followed by a reference</value> + <ref bean=<SPAN class="code-quote">"mySCAService1"</SPAN> /> + </list> + </property> + <!-- results in a setSomeMap(java.util.Map) call --> + <property name=<SPAN class="code-quote">"someMap"</SPAN>> + <map> + <entry> + <key> + <value>an entry</value> + </key> + <value>just some string</value> + </entry> + <entry> + <key> + <value>a ref</value> + </key> + <ref bean=<SPAN class="code-quote">"mySCAService2"</SPAN> /> + </entry> + </map> + </property> + <!-- results in a setSomeSet(java.util.Set) call --> + <property name=<SPAN class="code-quote">"someSet"</SPAN>> + <set> + <value>just some string</value> + <ref bean=<SPAN class="code-quote">"mySCAService3"</SPAN> /> + </set> + </property> +</bean> +</PRE> +</DIV></DIV> + +<H5><A name="SCAJavaimplementation.spring-Scenario3%3AExposingSCAServicefromSpringBeanthatimplementsmultipleinterfaces."></A>Scenario 3: Exposing SCA Service from Spring Bean that implements multiple interfaces.</H5> + +<P>Raised as Specification Issue: <A href="http://www.osoa.org/jira/browse/JAVA-59" class="external-link" rel="nofollow">http://www.osoa.org/jira/browse/JAVA-59</A></P> + +<H3><A name="SCAJavaimplementation.spring-SpringSCANamespaceschema"></A>Spring SCA Namespace schema</H3> + +<P>The spring-sca.xsd can be found at the following location: <A href="http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd" class="external-link" rel="nofollow">http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd</A></P> + +<H3><A name="SCAJavaimplementation.spring-References"></A>References</H3> + +<P>Spring Framework - <A href="http://static.springframework.org/spring/docs/2.5.5/reference/index.html" class="external-link" rel="nofollow">http://static.springframework.org/spring/docs/2.5.5/reference/index.html</A></P> +</TD></TR></TBODY></TABLE> + </DIV> + </DIV> + </DIV> + <!-- pageContent macro end --> + + </TD> + </TR> + </TABLE> + + <!-- footer macro --> + <SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript"> + </SCRIPT> + <SCRIPT type="text/javascript"> + _uacct = "UA-1174707-5"; + urchinTracker(); + </SCRIPT> + + <A href="http://www.statcounter.com/" target="_blank"><IMG src="http://c26.statcounter.com/counter.php?sc_project=2619156&java=0&security=94bd7e7d&invisible=0" alt="website stats" border="0"></A> + + <DIV class="footer"> + Copyright � 2003-2012, The Apache Software Foundation </BR> + Apache Tuscany and the Apache Tuscany project logo are trademarks of The Apache Software Foundation. + </DIV> + <!-- footer macro end --> + + </BODY> +</HTML> |