ã€?/font> (t¨©ng)<wire />å…ƒç´ åQŒè¿™äº›å…ƒç´ çš„å«ä¹‰åœ¨ä¹‹å‰çš„éšç¬”ä¸?
å·²ç»è¯´è¿‡ã€‚Component包å«Module的业务逻辑åQŒW(xu¨¦)ireæè¿°Component之间的Service的连接,Entry
Point定义Moduleæä¾›çš„ã€å¯ä¾›å¤–部访问的public serviceåQŒExternal
Service表示Module对外部Serviceçš„ä¾èµ–ã€?br />Component
Component
是Implementation的酾|®å®žä¾‹ï¼Œå®ƒå³æä¾›
Service也消费Service。多个Componentå¯ä»¥ä½¿ç”¨òq‰™…¾|®åŒä¸€ä¸ªImplementationåQŒåªè¦æ¯ä¸ªComponent都采用ä¸å?
的酾|®ã€‚Implementation通过component
typeæ¥å®šä¹‰å¯ç”±Componenté…置的aspect。SCA支æŒå¤šç§ä¸åŒçš„实现技术,如Javaã€BEPLã€C++。SCA定义äº?ji¨£n)一¿U坿‰©å±•机制æ?
引入新类型的Implementation。目å‰çš„è§„èŒƒä¸æŒ‡å®šå¿…™å»è¢«SCA
runtime支æŒçš„实现技术,供应商å¯ä»¥é€‰æ‹©ä»–ä»¬è®¤äØ“(f¨´)é‡è¦çš„æŠ€æœ¯äºˆä»¥æ”¯æŒã€‚我们æ¥çœ‹ä¸€ä¸‹Componentçš„schemaåQ?br /><component (t¨©ng)name="xs:NCName">*
 (t¨©ng) (t¨©ng) (t¨©ng) <implementation.implementation-type (t¨©ng)/>
 (t¨©ng) (t¨©ng) (t¨©ng) <properties>?
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) <v:property-name>property-value</v:property-name>+
 (t¨©ng) (t¨©ng) (t¨©ng) </properties>
 (t¨©ng) (t¨©ng) (t¨©ng) <references>?
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) <v:reference-name>wire-target-URI</v:reference-name>+
 (t¨©ng) (t¨©ng) (t¨©ng) </references>
</component>
<component />çš„name属性表½Cø™¿™ä¸ªcomponentçš„åå—,它必™åÕdœ¨å½“å‰module䏿˜¯å”¯ä¸€çš„。å¦å¤–,当å‰moduleä¸çš„entry pointå’Œexternal servicä¸å¯ä»¥å’Œcomponenté‡åã€?br /><component />å¿?
™åÀLœ‰ä¸€ä¸ªimplementationåå…ƒç´ ï¼Œå®ƒæŒ‡å‘component的具体实现。implementationå…ƒç´ çš„åå—由两部分组æˆï¼š(x¨¬)
"implementation"+代表implementation-typeçš„é™å®šè¯åQŒä¾‹å¦‚:(x¨¬)implementation.java表示是由
Javaæ¥å®žçŽŽÍ¼Œimplementation.bepl表示是由BPELæ¥å®žçްã€?br /><implementation.java (t¨©ng)class="services.myvalue.MyValueServiceImpl"/>
<implementation.bpel (t¨©ng)process="â€?/>
Component Type
Component
Type表示一个Implementationçš„å¯é…置的东东,它由Implementationæä¾›çš„Serviceã€å¯è®„¡½®çš„å…³è”到其他
Serviceçš„Referenceå’Œå¯è®„¡½®çš„属性组æˆã€‚属性和Referencež®†åœ¨ä½¿ç”¨˜q™ä¸ªImplementationçš„Componentä¸å…·ä½?
é…ç½®ã€?br />¼‹®å®šä¸€ä¸ªComponent Type需è¦ä¸¤ä¸ªæ¥éª¤ï¼š(x¨¬)
- 从Implementation自èín获得信æ¯åQˆä¾‹å¦‚:(x¨¬)从code annotation获得信æ¯åQ?/font>
- 从SCA component typeæ–‡äšg获得信æ¯åQˆXMLé…置文äšgåQ?/font>
˜q™æ˜¯æ—¶ä¸‹‹¹è¡Œçš„åšæ³•,既å¯ä»¥ä»Žcode annotation˜q›è¡Œé…ç½®åQŒä¹Ÿå¯ä»¥ä»ŽXML˜q›è¡Œé…ç½®åQŒå¦‚æžœä¸¤è€…åŒæ—¶ä‹É用,code annotation的优先çñ”高,但是两者的é…ç½®è¦ç»Ÿä¸€ã€?br />SCA component typeæ–‡äšg的扩展åä¸?.componentType"åQŒå…¶ä¸é€šè¿‡componentTypeå…ƒç´ æ¥è¿›è¡Œé…¾|®ï¼Œæˆ‘们æ¥çœ‹çœ‹å®ƒçš„schemaåQ?br /><?xml (t¨©ng)version="1.0" (t¨©ng)encoding="ASCII"?>
<componentType (t¨©ng)xmlns="http://www.osoa.org/xmlns/sca/0.9" (t¨©ng)>
 (t¨©ng) (t¨©ng) (t¨©ng) <service (t¨©ng)name="xs:NCName">*
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) <interface.interface-type/>
 (t¨©ng) (t¨©ng) (t¨©ng) </service>
 (t¨©ng) (t¨©ng) (t¨©ng) <reference (t¨©ng)name="xs:NCName" (t¨©ng)multiplicity="0..1 (t¨©ng)or (t¨©ng)1..1 (t¨©ng)or (t¨©ng)0..n (t¨©ng)or (t¨©ng)1..n"?>*
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) <interface.interface-type/>
 (t¨©ng) (t¨©ng) (t¨©ng) </reference>
 (t¨©ng) (t¨©ng) (t¨©ng) <property (t¨©ng)name="xs:NCName" (t¨©ng)type="xs:QName" (t¨©ng)many="xs:boolean"? default="xs:string"? (t¨©ng)required="xs:boolean"?/>*
</componentType>
<service />表示˜q™ä¸ªComponent Typeæä¾›çš„ServiceåQŒå¯ä»¥é€šè¿‡<interface.interface-type />讄¡½®å…¶äØ“(f¨´)remotableã€?/font><reference />表示˜q™ä¸ªComponent Typeä¾èµ–的其他ServiceåQŒä¹Ÿå¯ä»¥é€šè¿‡<interface.interface-type />讄¡½®å…¶äØ“(f¨´)remotableåQŒmultiplicity属性表½Cºå¯ä»¥å…³è”到˜q™ä¸ªReferenceçš„Wire的数é‡ã€?/font><property />表示˜q™ä¸ªComponent Typeå¯é…¾|®çš„属性ã€?br />让我们æ¥çœ‹ä¸€ä¸ªä¾‹å,Javaæ–‡äšgMyValueServiceImpl是这个例åä¸çš„ImplementationåQŒå…¶SCA component type如下åQ?br /><?xml (t¨©ng)version="1.0" (t¨©ng)encoding="ASCII"?>
<componentType (t¨©ng)xmlns="http://www.osoa.org/xmlns/sca/0.9">
 (t¨©ng) (t¨©ng) (t¨©ng) <service (t¨©ng)name="MyValueService">
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) <interface.java (t¨©ng)interface="services.myvalue.MyValueService"/>
 (t¨©ng) (t¨©ng) (t¨©ng) </service>
 (t¨©ng) (t¨©ng) (t¨©ng) <reference (t¨©ng)name="customerService">
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) <interface.java (t¨©ng)interface="services.customer.CustomerService"/>
 (t¨©ng) (t¨©ng) (t¨©ng) </reference>
 (t¨©ng) (t¨©ng) (t¨©ng) <reference (t¨©ng)name="stockQuoteService">
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) <interface.java (t¨©ng)interface="services.stockquote.StockQuoteService"/>
 (t¨©ng) (t¨©ng) (t¨©ng) </reference>
 (t¨©ng) (t¨©ng) (t¨©ng) <property (t¨©ng)name="currency" (t¨©ng)type="xsd:string" (t¨©ng)default="USD"/>
</componentType>
相应的Java代ç 如下åQ?br />
// (t¨©ng)MyValueService (t¨©ng)interface.
package (t¨©ng)services.myvalue;
public (t¨©ng)interface (t¨©ng)MyValueService (t¨©ng){
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng)public (t¨©ng)void (t¨©ng)calculate();
}
// (t¨©ng)MyValueServiceImpl (t¨©ng)class
package (t¨©ng)services.myvalue;
import (t¨©ng)services.customer.CustomerService;
import (t¨©ng)services.stockquote.StockQuoteService;
public (t¨©ng)class (t¨©ng)MyValueServiceImpl (t¨©ng)implements (t¨©ng)MyValueService (t¨©ng){
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng)// (t¨©ng)Code (t¨©ng)annotation. (t¨©ng)å’ŒXML的功能相åŒï¼Œä¸¤è€…å–一个ä‹É用就够了(ji¨£n)ã€?/span>
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng)@Property
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng)private (t¨©ng)String (t¨©ng)currency (t¨©ng)= (t¨©ng)"USD";
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng)@Reference
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng)private (t¨©ng)CustomerService (t¨©ng)customerService;
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng)@Reference
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng)private (t¨©ng)StockQuoteService (t¨©ng)stockQuoteService;
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng)public (t¨©ng)void (t¨©ng)calculate() (t¨©ng){
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng)// (t¨©ng)do (t¨©ng)your (t¨©ng)real (t¨©ng)business (t¨©ng)logic (t¨©ng)here.
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng)}
}
Implementation
Implementation
是业务逻辑的具体实玎ͼŒ˜q™äº›ä¸šåŠ¡é€»è¾‘ä¼?x¨¬)æä¾›æˆ–消费Service。SCA支æŒå¤šç§å®žçŽ°æŠ€æœ¯ï¼Œå¦‚Javaã€BPEL或C++。我们已¾l知é“,
Serviceã€Referenceå’ŒProperty是Implementationä¸å…³äºŽé…¾|®çš„东东åQŒä»–们组æˆComponent
Type。在˜q行æ—Óž¼ŒImplementation
Instance是Implementation的实例化åQŒå®ƒæä¾›çš„业务逻辑和Implementationä¸çš„相åŒåQŒä½†Propertyå’?
Reference则å–决于Componentä¸çš„é…置。下图æ˜qîCº†(ji¨£n)Component
Typeã€Componentã€Implementationå’ŒImplementation Instance之间的关¾p»ï¼š(x¨¬)


Interface
Interface
负责定义一个或多个business function。这些business
function通过Serviceæä¾›¾l™å¤–部,外部通过Reference使用它们。Serviceç”Þp‡ªå·±å®žçŽ°çš„Interface定义。SCA支æŒå¦?
ä¸?¿UInterfaceåQ?br />- Java interfaces
- WSDL 1.1 portTypes
- WSDL 2.0 interfaces
我们一个一个æ¥çœ‹ï¼š(x¨¬)
<interface.java (t¨©ng)interface="NCName" (t¨©ng)…Â?/span>/>
å…¶ä¸interfaceå±žæ€§äØ“(f¨´)Java interface的全å(包括packageåQ‰ã€‚例如:(x¨¬)
<interface.java (t¨©ng)interface="services.stockquote.StockQuoteService" />
<interface.wsdl (t¨©ng)interface="xs:anyURI" (t¨©ng)…Â?/span>/>
å…¶ä¸interfaceå±žæ€§äØ“(f¨´)portType/interfaceçš„URIåQŒå…¶æ ¼å¼ä¸?lt;WSDL-namespace-URI>#wsdl.interface(<portType or Interface-name>)。例如:(x¨¬)
<interface.wsdl (t¨©ng)interface="http://www.stockquote.org/StockQuoteService#wsdl.interface(StockQuote)"/>
如果使用Java interfaceåQŒServiceæ–ÒŽ(gu¨©)³•çš„ä¼ å…¥å‚æ•°å’Œ˜q”回值å¯ä»¥ä‹É用Java class或Primitive type。最好ä‹É用SDO生æˆçš„Java classåQŒå› 为它们和XML之间åšäº†(ji¨£n)æ•´åˆã€‚(SDO也是IBM推出的一个SOA¾pÕdˆ—çš„æ ‡å‡†ã€‚ï¼‰(j¨ª)
如果使用WSDLåQŒServiceæ–ÒŽ(gu¨©)³•çš„ä¼ å…¥å‚æ•°å’Œ˜q”回值则使用XML schemaæè¿°ã€‚XML schema¿Uæ˜q°çš„傿•°ä»¥SDO DataObjectçš„åÅžå¼æš´éœ²ç»™å¼€å‘者ã€?br />
一
个Component
Implementationçš„Serviceæ˜¯å¦æ˜¯remotable的是由Serviceçš„Interface定义的。如果ä‹É用JavaåQŒäØ“(f¨´)
Interfaceæ·ÕdŠ @Remotable
annotationå¯ä»¥æŠŠService声明为remotable。WSDL定义的interface永远是remotableçš„ã€?br />
典型的remoteable interface是粗力度的,用于æ¾è€¦åˆçš„交互。Remotable Service Interfaceä¸å…许函数é‡è½½ã€‚æ— è®ºæ˜¯åœ?Module之外˜q˜æ˜¯åœ¨Module内的其他Componentä¸ä‹Éç”?/font>remotable ServiceåQŒæ•°æ®äº¤æ¢éƒ½é‡‡ç”¨by-valueè¯ä¹‰ã€?br />Remotable
Servicedçš„Implementationå¯èƒ½ä¼?x¨¬)在Service调用˜q‡ç¨‹ä¸æˆ–è°ƒç”¨ä¹‹åŽæ”¹å˜ä¼ 入傿•°åQŒä¹Ÿå¯èƒ½åœ¨è°ƒç”¨ä¹‹åŽä¿®æ”¹è¿”回倹{€‚如æž?
remotable Service被locally或remotely调用åQŒSCA
containerä¼?x¨¬)ä¿è¯ä¼ 入傿•°å?qi¨¢ng)˜q”回值的改å˜å¯¹Service的调用者是ä¸å¯è§çš„åQˆè¿™ž®±æ˜¯by-valueè¯ä¹‰åQ‰ã€‚䏋颿˜¯ä¸€ä¸ªremotable
java interface的例å:(x¨¬)
package (t¨©ng)services.hello;
@Remotable
// (t¨©ng)@AllowsPassByReference
public (t¨©ng)interface (t¨©ng)HelloService (t¨©ng){
 (t¨©ng) (t¨©ng) (t¨©ng) (t¨©ng)public (t¨©ng)String (t¨©ng)sayHello(String (t¨©ng)message);
}
ç”±External
Serviceæä¾›çš„Service永远是remotable的。å¯ä»¥ä‹É用@AllowsPassByReference
annotationå…许一个remotable
Service在被åŒä¸€Moduleä¸çš„å…¶ä»–Component调用时ä‹É用by-referenceè¯ä¹‰åQŒè¿™æ ·å¯ä»¥æé«˜æ€§èƒ½ã€?br />
ç”±local Interfaceæä¾›çš„Serviceåªèƒ½åœ¨åŒä¸€Moduleä¸ä‹É用,它们ä¸èƒ½é€šè¿‡Entry
Pointå‘布到外部。如果ä¸å£°æ˜Ž@RemotableåQŒJava interface默认为local。典型的local
Interface是细¾_’度的,用于紧耦åˆçš„交互。它å…许æ–ÒŽ(gu¨©)³•é‡è²åQŒåƈ采用by-referenceè¯ä¹‰ã€?br />
]]>