BPEL的基本思想
http://tech.ddvip.com 2008年01月06日 社区交流
本文详细介绍BPEL的基本思想
下面的SubstractService .java相当SubstractService.wsdl。
Public class SubstractService{
Public double substract(double substractParameter1, double substractParameter2) {
Double substractResposne = substractParameter1 - substractParameter2;
Return substractResposne;
}
}
下面用Java模拟BPEL的创建过程。
首先需要创建BPEL的接口,下面用CaculatorBPELInterface.java来说明,它将有3个参数,其中paramter1和paramter2是需要运算的两个数,第3个参数processType表示运算的类型。
Public Interface CaculatorBPELInterface{
Public double caculatorProcess(double parameter1, double parameter2, String processType) ;
}
下面将创建一个Java实现类,说明如何对应于BPEL的创建过程(许多语句(如一些变量定义和赋值定义)对Java来说是不必要的;为了模拟BPEL的创建过程,让Java开发人员更好地把握BPEL的创建过程,相应地加入了这些程序语句)。
Public class CaculatorBPELImple implements CaculatorBPELInterface {
Public double caculatorProcess (double parameter1, double parameter2, String processType) {
//步骤1:定义所要调用的外部类(相当于定义BPEL里面partnerLink)
AddService addServer = new AddService();
SubstractService substractSevice = new SubstractService();
/*步骤2:定义输入和输出变量(相当于定义BPEL里面变量variable)
定义的变量如下:
● BPEL接口的输入和输出变量
● 所要调用的外部类的接口方法的输入和输出变量 */
//定义BPEL接口的输入变量
Double caculatorProcessParameter1Request;
Double caculatorProcessParameter2Request;
Double caculatorProcessTypeRequest;
//定义BPEL接口的输出变量
Double caculatorProcessResponse;
//定义加法服务的输入变量
Double addParameter1Request;
Double addParameter2Request;
//定义加法服务的输出变量
Double addResponse;
//定义减法服务的输入变量
Double substractParameter1Request;
Double substractParameter2Request;
//定义减法服务的输出变量
Double substractParameter1Response;
//***将请求参数赋值给BPEL接口的输入变量 (相当于BPEL的receive)
caculatorProcessParameter1Request = parameter1;
caculatorProcessParameter2Request= parameter2;
Double caculatorProcessTypeRequest= processType;
//步骤3:定义条件,并调用外部接口
If (caculatorProcessTypeRequest.equals.(“add”’)
// (相当于BPEL的switch/condition/case)
{
//**下面将调用加法服务
//将接口请求变量传给加法服务的请求变量 (相当于BPEL的assign/copy)
addParameter1Request = caculatorProcessParameter1Request;
addParameter2Request = caculatorProcessParameter2Request;
//调用addService的接口 (相当于BPEL的Invoke)
addResponse = addServer.add(addParameter1Request, addParameter2Request);
//将addResponse赋值给BPEL接口的输出变量 (相当于BPEL的assign/copy)
caculatorProcessResponse = addResponse;
} else //(相当于BPEL的 condition/otherwise)
{
//将接口请求变量传给减法服务的请求变量 (相当于BPEL的assign/copy)
substractParameter1Request = caculatorProcessParameter1Request;
substractParameter2Request = caculatorProcessParameter2Request;
//调用substractService的接口 (相当于BPEL的invoke)
substractResponse =
substractServer.substract(substractParameter1Request, substractParameter2Request);
//将substractResponse赋值给BPEL接口的输出变量(相当于BPEL的assign/copy)
caculatorProcessResponse = substractResponse;
}
Return caculatorProcessResponse; //相当于BPEL的reply
}
}
用实例概述BPEL的创建过程
责编:豆豆技术应用