[王洪伟]Tuscany SCA以独立应用方式运行的简单例子

开发者在线 Builder.com.cn 更新时间:2007-09-29作者:王洪伟 来源:CSDN

本文关键词: 王洪伟 SCA 独立应用 运行

这个例子是基于tuscany-sca-1.0--incubator-M2环境的。

可以从http://incubator.apache.org/tuscany/sca_downloads.html 下载相关的运行环境和例子的代码。

在SCA规范中,component被定义为执行代码的基本单元。每个component对外提供一个功能。在本例子中共有五个component,其中有四个分别实现了加法、减法、乘法和除法的功能。

Compostie作为发布的单元,在每一个配置文件中都是以composite作为XML文档的根元素。

Composite包含0...n个Component,Service,Reference,Wire,Property,还可以包含0...n个其他的Composite。根据Composite的这个特点,可以组合成很多中情况。在以后的例子中会涉及,到时候在详细列举。

在tuscany-sca-1.0--incubator-M2环境下,应用的装配文件被命名为default.scdl。内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"  name="CalculatorComposite">

    
<service name="CalculatorService">
        
<interface.java interface="calculator.CalculatorService"/>
        
<reference>CalculatorServiceComponent</reference>
    
</service>

    
<component name="CalculatorServiceComponent">
        
<implementation.java class="calculator.CalculatorServiceImpl"/>
        
<reference name="addService">AddServiceComponent</reference>
        
<reference name="subtractService">SubtractServiceComponent</reference>
        
<reference name="multiplyService">MultiplyServiceComponent</reference>
        
<reference name="divideService">DivideServiceComponent</reference>
    
</component>

    
<component name="AddServiceComponent">
        
<implementation.java class="calculator.AddServiceImpl"/>
    
</component>

    
<component name="SubtractServiceComponent">
        
<implementation.java class="calculator.SubtractServiceImpl"/>
    
</component>

    
<component name="MultiplyServiceComponent">
        
<implementation.java class="calculator.MultiplyServiceImpl"/>
    
</component>

    
<component name="DivideServiceComponent">
        
<implementation.java class="calculator.DivideServiceImpl"/>
    
</component>

</composite>

在系统环境的装配文件system.scdl被装配完毕之后,应用的装配文件default.scdl也被装配完毕,这些步骤是在SCA环境启动过程中完成的。

Composite中Servcie的名称是CalculatorService。CalculatorService对外提供Java接口和一个指向CalculatorServiceComponent的引用。

在Java 接口中声明了外部可以调用的方法,CalculatorService.java文件内容如下:

package calculator;


/**
 * The Calculator service interface.
 
*/
public interface CalculatorService {

    
double add(double n1, double n2);

    
double subtract(double n1, double n2);

    
double multiply(double n1, double n2);

    
double divide(double n1, double n2);

}

用户评论

  • 用户名
  • 评论内容