您的位置:首页 > 其它

SCA概念与应用实践(7.SCA装配模型--7.1 compoent)

2010-06-24 01:33 686 查看
7. SCA装配模型

7.1. Component
这个对应规范SCA Assembly Model V1.00(http://www.osoa.org/display/Main/Service+Component+Architecture+Specifications) 的1.3节
7.1.1. Component
Compoent是SCA中基本的元素。每一个composite都是有一个或多个component构成。Application对应的是最上层的composite。对于简单的application,component就是一个java类,相互间的调用通过暴露出来的java interface。就像上面的例子。复杂一点,各个component可能运行在不同的机器上,那么就需要其他交流机制(例如jms,或rmi)来进行相互调用。
选中一个component,查看它的properties。



图7_1_1
Component包含的属性
Name,这个是必须的。
Autowire,表示component的reference是否自动连接到service上
Requires,0…n个policy intents,这个和policy set 后面介绍
PolicySet,0…n个policy Set
Constraining Type,强制类型名字,我们可以预先定义一些强制类型,强制类型中包含一些service,reference,和intent。那么使用这个强制类型的component,就要实现所有强制类型中的service,reference等。

打开Restaurant2.composite,就可以看到component的定义,他是composite的子元素。
<?xml version="1.0" encoding="UTF-8"?>
<sca:composite xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" name="Restaurant2" targetNamespace="http://eclipse.org/Restaurant2/src/Restaurant2">
<sca:component name="RestaurantServiceComponent">
<sca:implementation.java class="restaurant2.lib.RestaurantServiceImpl"/>
<sca:service name="RestaurantService">
<sca:interface.java interface="restaurant2.api.RestaurantService"/>
</sca:service>
<sca:reference name="menuService"/>
<sca:reference name="billService"/>
</sca:component>

</sca:composite>
Component RestaurantServiceComponent只有一个属性name,包含service和reference子元素。还有一个子元素就是 implementation,8节说这个implementation。

7.1.2. Service
可以从diagram上查看service的properties



图7_1_2
Name:是必须的
PolicySets,
Reqiures,一系列policy intents。作用在service上的intents包括(1)requires里定义的,(2)implementation里给service定义的

打开Restaurant2.composite查看service的定义:
<sca:service name="BillService">
<sca:interface.java interface="restaurant2.api.BillService"/>
</sca:service>

Service里包含0..n个interface,interface里描述这个service所提供的操作。在这个interface里定义的方法,一定要在comonent的implementation里实现。
比如BillServiceComponent定义了一个service BillService,BillService里定义了interface restaurant2.api.BillService, 在这个interface里,定义了一个方法
public interface BillService {
double getBill(double menuPrice);
}
那么在BillServiceComponent的实现类restaurant2.lib.BillServiceImpl里,就要实现这个方法。外部调用这个service的getBill的时候,实际调用的BillServiceImpl里的实现。9节会详细说interface。
7.1.3. Reference
可以从diagram上查看reference的properties,下面这个是RestaurantServiceComponent上的refernece(menuService)的属性



图7_1_3
Name: 必填
Autowire:说明该reference是否自动连线。在autowire节说明。
Policy Sets:policy set后面介绍
Requires: intents
Multiplicity:定义该reference能连接到service的wire的数目,
1..1 –只能有一个wire
0..1 –能有0个或1个wire
1..n –能有1个或多个wire
0..n -能有0个或多个wire
Target:一个或多个目标service的URI的列表,依赖于multiplicty的设置。每个值都指向component的service。用此值说明该reference连接到哪些service。
wiredByImpl:默认”false”。 定义是否动态地wire。如果设置为“true”,这个reference的目标service由实现代码在运行时设置。如果设置为”true”,该reference不需要显示的wire。

Reference可以有0个或1个interface。 也可以有0个或多个binding。Reference节详细说明。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: