基于Jazz技术构建企业级Web2.0应用(3)
第三步,定义和实现ICustomerService
在公共bundle com.ibm.petstore.common中定义服务接口com.ibm.petstore.common.service. ICustomerService:
清单6. ICustomerService定义
public interface ICustomerService {
public void buyProduct(IProduct product,int accountNo,String password,String email) throws TeamRepositoryException;
}
在com.ibm.petstore.common的plugin.xml中添加ICustomerService的声明:
清单7. ICustomerService声明
<service
kind="RPC"
name="ICustomerService"
uri="com.ibm.petstore.common.service.ICustomerService"
version="1">
</service>
在服务bundle com.ibm.petstore.service中添加类com.ibm.petstore.service.CustomerService实现ICustomerService接口:
清单8. CustomerService
public class CustomerService extends AbstractService implements ICustomerService {
public void buyProduct(IProduct product, int accountNo, String password,
String email) throws TeamRepositoryException {
IProcessServerService processServerService =
getService(IProcessServerService.class);
ITeamArea teamArea = getTeamArea("PetStoreUserTeam");
if(teamArea==null)
throw new TeamRepositoryException(
"petstore user team doesn't exist");
IServerProcess serverProcess = processServerService
.getServerProcess(teamArea);
BuyPetOperation buyOperation = new BuyPetOperation(teamArea, accountNo,
password, product.getPrice(), email);
serverProcess.adviseAndExecute(buyOperation);
}
……
}
注意:在buyProduct方法中通过IServerProcess的adviceAndExecute方法调用了operation"buy"。
在com.ibm.petstore.service的plugin.xml中将ICustomerService及其实现类绑定:
清单9. ICustomerService与实现类的绑定
<serviceProvider
componentId="com.ibm.petstore"
implementationClass="com.ibm.petstore.service.CustomerService">
<provides>
<providedService
interface="com.ibm.petstore.common.service.ICustomerService">
</providedService>
</provides>
<prerequisites>
<requiredService
interface="com.ibm.team.repository.common.service.IQueryService">
</requiredService>
<requiredService
interface="com.ibm.team.repository.service.IRepositoryItemService">
</requiredService>
<requiredService
interface="com.ibm.team.process.service.IProcessServerService">
</requiredService>
</prerequisites>
</serviceProvider>
注意:这里对于IProcessServerService的依赖。