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

7.4.        Composite

7.4.1.       解释

       如果说componentSCA的原子的话,composite则是分子。一些component组成composite,进而一些composite组成application

Composite包含componentspromoted services, promoted references, propterties wires

Composite可以是componentimplementation。就是说更高一层的composite可以包含实现是compositecomponent

Composite可以通过inclusion在其他Composite中使用。当一个组合构件被另一个组合构件包含时,上级Composite的其他元素可以使用被包含Composite全部内容。

Composite可以作为一个发布单元。当发布一个CompositeSCA domaincomposite会发布其所有的元素到SCA domain,一般我们会称作这个compositeapplication。我们会说deploy一个application,等同于deploy那个application对应的最上一层的Composite includecomposite,作为component实现的Composite,也可以被发布到domain

7.4.2.       Composite的属性和元素

打开Restaurant2.composite

<?xml version="1.0" encoding="UTF-8"?>

<sca:composite xmlns:frascati="http://frascati.ow2.org" xmlns:instance="http://www.w3.org/2004/08/wsdl-instance" xmlns:sawsdl="http://www.w3.org/ns/sawsdl" xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" xmlns:tuscany="http://tuscany.apache.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:reference name="menuService"/>

    <sca:reference name="billService"/>

    <sca:service name="RestaurantService">

      <sca:interface.wsdl interface="http://api.restaurant2/#wsdl.interface(RestaurantService)"/>

      <sca:binding.ws uri="http://localhost:8085/RestaurantService"/>

      <sawsdl:semantic.sawsdl/>

    </sca:service>

    <sawsdl:semantic.sawsdl/>

  </sca:component>

  <sca:component name="MenuServiceComponent">

    <sca:implementation.java class="restaurant2.lib.MenuServiceImpl"/>

    <sca:service name="MenuService">

      <sca:interface.java interface="restaurant2.api.MenuService"/>

    </sca:service>

  </sca:component>

  <sca:component name="BillServiceComponent">

    <sca:implementation.java class="restaurant2.lib.BillServiceImpl"/>

    <sca:service name="BillService">

      <sca:interface.java interface="restaurant2.api.BillService"/>

    </sca:service>

    <sca:reference name="vatService"/>

    <sca:reference name="tipService">

      <sca:interface.java callbackInterface="restaurant2.api.TipServiceCallback" interface="restaurant2.api.TipService"/>

      <sca:binding.ws uri="http://localhost:8086/TipServiceComponent"/>

      <sca:callback>

        <sca:binding.ws uri="http://localhost:8087/TipServiceComponentCB"/>

      </sca:callback>

    </sca:reference>

  </sca:component>

  <sca:component name="VatServiceComponent">

    <tuscany:implementation.script script="restaurant2/lib/VatServiceImpl.js"/>

    <sca:service name="VatService">

      <sca:interface.java interface="restaurant2.api.VatService"/>

    </sca:service>

  </sca:component>

  <sca:wire source="RestaurantServiceComponent/billService" target="BillServiceComponent/BillService"/>

  <sca:wire source="BillServiceComponent/vatService" target="VatServiceComponent/VatService"/>

  <sca:service name="RestaurantService" promote="RestaurantServiceComponent/RestaurantService"/>

  <sca:wire source="RestaurantServiceComponent/menuService" target="MenuServiceComponent/MenuService"/>

</sca:composite>

Composite包含元素和属性:

• name,必填项。在由targetNamespace属性标识的命名空间中。

• targetNamespace,声明命名空间

• localcompositecomponents是否必须运行于同一个进程。Local=”true”指示所有component运行于同一进程。默认是false

• autowirecomponentreference是否自动wire。默认为false

• constrainingType

• requiresintents

• policySets policy sets,这些后面介绍

CompositeserviceComposite对外提供的服务,可以被Composite外面的访问。Composite reference表示composite通过reference 调用其他CompositeserviceWire是描述Composite内的component之间的调用关系。

Composite servicecomponent service 提升(promote)来的,实际是有component来提供服务。Composite reference也是由component reference 提升来的。

多个component reference可以promote到一个composite reference 一个component service可以promote到多个composite service。当多个component reference 提升到一个composite reference,它们都共享相同的配置,包括相同的target service

 

7.4.3.   例子,Component实现类型是composite

Ø         在项目Restaurant2Tip下,新建SCA Composite Diagram,名字为Testaurant2TipInner

Ø         新建component TipServiceInnerComponent,在新component上添加java implementationserviceservice interfacebinding。所有的属性和名称和Restaurant2Tip里的component TipServiceComponent完全相同

7_4_1

7_4_1

然后编辑Restaurant2TipInner.composite文件,设置targetNamespace,这个要和Restaurant2Tip.composite里相同,并定义新的namespace tip

<?xml version="1.0" encoding="UTF-8"?>

<sca:composite xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" xmlns:tip="http://eclipse.org/Restaurant2Tip/src/Restaurant2Tip" name="Restaurant2TipInner" targetNamespace="http://eclipse.org/Restaurant2Tip/src/Restaurant2Tip">

  <sca:component name="TipServiceInnerComponent">

    <sca:implementation.java class="restaurant2.lib.TipServiceImpl"/>

    <sca:service name="TipService">

      <sca:interface.java callbackInterface="restaurant2.api.TipServiceCallback" interface="restaurant2.api.TipService"/>

      <sca:binding.ws uri="http://localhost:8086/TipServiceComponent"/>

    </sca:service>

  </sca:component>

</sca:composite>

Ø         打开Restaurant2Tip.composite_diagram,删除component上的service

 

7_4_2

7_4_2

Ø         删除componentJava implementation

 

7_4_3

7_4_3

 

7_4_4

7_4_4

 

Ø         component添加新的implementationSCA implementation

 

7_4_5

7_4_5

编辑implementation的属性,你会发现name不可编辑,但后面有个button

 

7_4_6

7_4_6

点击那个button

 

7_4_7

7_4_7

选择一个已存在的namespace

 

7_4_8

7_4_8

Local part中填入之前新建的那个composite的名字,Restaurant2TipInner,点ok

 

7_4_9

7_4_9

 

现在Restaurant2Tip.composite的内容为

<?xml version="1.0" encoding="UTF-8"?>

<sca:composite xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" xmlns:tip="http://eclipse.org/Restaurant2Tip/src/Restaurant2Tip" name="Restaurant2Tip" targetNamespace="http://eclipse.org/Restaurant2Tip/src/Restaurant2Tip">

  <sca:component name="TipServiceComponent">

    <sca:implementation.composite name="tip:Restaurant2TipInner"/>

  </sca:component>

</sca:composite>

运行TipServiceServerRestaurantServiceServer

使用soapUI调用ws getBill,正常得到结果

 

7_4_10

7_4_10

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值