软件频道>程序开发>JavaVBVCDelphiC/C++Web开发微软专栏移动数据库程序人生软件工程|开发客
您现在的位置: 天极网 > 开发频道 > SCA中Java接口实现Service
全文

SCA中Java接口实现Service

2007-11-15 10:35作者:王洪伟出处:论坛整理责任编辑:方舟
  1、基于Java 的service 接口和实现组件的Java类

  接口

package services.hello;
public interface HelloService {
 String hello(String message);
}

  实现

package services.hello;
import org.osoa.sca.annotations.*;
@Service(HelloService.class)
public class HelloServiceImpl implements HelloService {
 public String hello(String message) {
  ...
 }
}

  对应的Componet Type

<?xml version="1.0" encoding="ASCII"?>
<componentType xmlns=http://www.osoa.org/xmlns/sca/1.0>
<service name="HelloService">
<interface.java interface="services.hello.HelloService"/>
</service>
</componentType>

  2、自己定义的service接口并实现的Java 实现类

package services.hello;
import org.osoa.sca.annotations.*;
@Service(HelloServiceImpl.class)
public class HelloServiceImpl implements AnotherInterface {
 public String hello(String message) {
  ...
 }
 …
}

  根据@service注解的默认规则:如果一个service只有一个接口,实现了接口就是实现了service。

  所以上面的实现还可以改写,如下:

package services.hello;
public class HelloServiceImpl implements AnotherInterface {
 public String hello(String message) {
  ...
 }
 …
}

  对应的Component Type

<?xml version="1.0" encoding="ASCII"?>
<componentType xmlns=http://www.osoa.org/xmlns/sca/1.0>
<service name="HelloService">
<interface.java interface="services.hello.HelloServiceImpl"/>
</service>
</componentType>

  3、一个Java实现类实现两个service

package services.hello;
import org.osoa.sca.annotations.*;
@Service(interfaces={HelloService.class, AnotherInterface.class})
public class HelloServiceImpl implements HelloService, AnotherInterface {
 public String hello(String message) {
  ...
 }
 …
}

  对应的Component Type

<?xml version="1.0" encoding="ASCII"?>
<componentType xmlns=http://www.osoa.org/xmlns/sca/1.0>
<service name="HelloService">
<interface.java interface="services.hello.HelloService"/>
</service>
<service name="AnotherService">
<interface.java interface="services.hello.AnotherService"/>
</service>
</componentType>

  4、Java实现类通过接口子类关系实现两个service

service 1

package services.hello;
public interface HelloService {
 String hello(String message);
}
service 2

package services.hello;
public interface HelloService2 extends HelloService {}

  实现

package services.hello;
import org.osoa.sca.annotations.*;
@Service(interfaces={HelloService.class,HelloService2.class})
public class HelloServiceImpl implements HelloService {
 public String hello(String message) {
  ...
 }
}

  对应Component Type

<?xml version="1.0" encoding="ASCII"?>
<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0">
<service name="HelloService">
<interface.java interface="services.hello.HelloService"/>
</service>
<service name="HelloService2">
<interface.java interface="services.hello.HelloService2"/>
</service>
</componentType>
相关搜索:
关注此文读者还看过
文章排行
本周
本月
最近更新
关于我们|About us|网站律师|天极服务|电子杂志|RSS订阅|加入我们|网站地图
TMG
Copyright (C) 1999-2009 Chinabyte.com, All Rights Reserved 版权所有 天极网络
商务联系、网站内容、合作建议:010-82657868
版权声明 在线提交意见反馈 渝ICP证B2-20030003号
经营性网站备案信息 网警备案 中国网站排名
天极传媒:天极网|比特网|IT专家网|IT商网|52PK游戏网|IT分众