<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    耐心無(wú)止境 成功一瞬間

    BlogJava 聯(lián)系 聚合 管理
      31 Posts :: 5 Stories :: 25 Comments :: 0 Trackbacks
    在學(xué)習(xí)tuscany到過(guò)程遇到一個(gè)疑問(wèn)(java組件實(shí)現(xiàn)是如何解析java類(lèi)文件中的服務(wù)的?如果沒(méi)有配置服務(wù),默認(rèn)服務(wù)應(yīng)該是什么?),開(kāi)始的時(shí)候一直無(wú)法想清楚,通過(guò)閱讀源碼終于了解了部分解析過(guò)程

    以tuscany中的Calculator為例說(shuō)明服務(wù)的定義:

    1.  如果按照例子本身的代碼和配置,我們應(yīng)該如何獲取服務(wù)呢?


    CalculatorService實(shí)現(xiàn)代碼
    package calculator;

    import org.osoa.sca.annotations.Reference;


    /**
     * An implementation of the Calculator service.
     
    */
    public class CalculatorServiceImpl implements CalculatorService {

        
    private AddService addService;
        
    private SubtractService subtractService;
        
    private MultiplyService multiplyService;
    。。。。。。。。。。。。。

    配置:

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

      a. 例子中獲取服務(wù)的方法:

    CalculatorService calculatorService = 
                scaDomain.getService(CalculatorService.
    class"CalculatorServiceComponent");

    通過(guò)上述代碼我們就可以獲取相應(yīng)的服務(wù)了,我們不僅要問(wèn),為什么能夠獲取相應(yīng)的服務(wù)呢?

    根據(jù)java組件實(shí)現(xiàn)規(guī)范說(shuō)明,如果組件只包含一個(gè)服務(wù),那么我們?cè)讷@取服務(wù)的時(shí)候可以省略服務(wù)的名字。


    我的問(wèn)題是:省略的服務(wù)名字是什么?


    b. 完整獲取服務(wù)的方法:

    CalculatorService calculatorService1 =scaDomain.getService(CalculatorService.class"CalculatorServiceComponent/CalculatorServiceImpl");

    大家通過(guò)比較就可以知道,其實(shí)省略的服務(wù)名字是 CalculatorServiceImpl

    為什么是這個(gè)名字,大家可以參考源碼中的

    if (services.isEmpty()) {
           
    // class is the interface
           addService(type, clazz);
        }


    2. 自己定義一個(gè)服務(wù)

    自己在實(shí)現(xiàn)中添加服務(wù)聲明

    1 @Service(CalculatorService.class)
    2 public class CalculatorServiceImpl implements CalculatorService {
    3 
    4     private AddService addService;
    5     private SubtractService subtractService;
    6     private MultiplyService multiplyService;
    7     private DivideService divideService;
    。。。。。。


    我們可以通過(guò)如下方式獲取服務(wù):

    a. 例子中的方式

    CalculatorService calculatorService = 
                scaDomain.getService(CalculatorService.
    class"CalculatorServiceComponent");

    b. 完整方式

    CalculatorService calculatorService1 =scaDomain.getService(CalculatorService.class"CalculatorServiceComponent/CalculatorService");

    我們通過(guò)如下方式就*不能*獲取服務(wù)了

    CalculatorService calculatorService1 =scaDomain.getService(CalculatorService.class"CalculatorServiceComponent/CalculatorServiceImpl");


    原因很簡(jiǎn)單,實(shí)現(xiàn)不會(huì)再添加默認(rèn)服務(wù)(CalculatorServiceImpl)了











    源碼摘錄如下:

     1 org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor
     2 
     3 
     4 public <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
     5         List<org.apache.tuscany.sca.assembly.Service> services = type.getServices();
     6         if (services.isEmpty()) {
     7             // heuristically determine the service
     8             /**
     9              * The following is quoted from Java Specification 1.2.1.3. Introspecting services offered by a Java implementation
    10              * In the cases described below, the services offered by a Java implementation class may be determined
    11              * through introspection, eliding the need to specify them using @Service. The following algorithm is used 
    12              * to determine how services are introspected from an implementation class:
    13              * 
    14              * If the interfaces of the SCA services are not specified with the @Service annotation on the 
    15              * implementation class, it is assumed that all implemented interfaces that have been annotated 
    16              * as @Remotable are the service interfaces provided by the component. If none of the implemented 
    17              * interfaces is remotable, then by default the implementation offers a single service whose type 
    18              * is the implementation class.
    19              */
    20             Set<Class> interfaces = getAllInterfaces(clazz);
    21             for (Class<?> i : interfaces) {
    22                 if (i.isAnnotationPresent(Remotable.class|| i.isAnnotationPresent(WebService.class)) {
    23                     addService(type, i);
    24                 }
    25             }
    26             if (services.isEmpty()) {
    27                 // class is the interface
    28                 addService(type, clazz);
    29             }
    30         }
    31         Set<Method> methods = getAllUniquePublicProtectedMethods(clazz, false);
    32         if (!type.getReferenceMembers().isEmpty() || !type.getPropertyMembers().isEmpty()) {
    33             // references and properties have been explicitly defined
    34             //            if (type.getServices().isEmpty()) {
    35             //                calculateServiceInterface(clazz, type, methods);
    36             //                if (type.getServices().isEmpty()) {
    37             //                    throw new ServiceTypeNotFoundException(clazz.getName());
    38             //                }
    39             //            }
    40             evaluateConstructor(type, clazz);
    41             return;
    42         }
    43         calcPropRefs(methods, services, type, clazz);
    44         evaluateConstructor(type, clazz);
    45     }
    46 


















    posted on 2008-12-20 18:01 Joshua Yan 閱讀(1365) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): tuscany

    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲精品午夜无码电影网| 18禁止看的免费污网站| 在线免费一区二区| 亚洲爆乳无码专区| eeuss影院ss奇兵免费com| 国产福利在线免费| 亚洲综合视频在线观看| 国产免费人成视频尤勿视频| 国产大片51精品免费观看| 亚洲伊人久久大香线焦| 亚洲免费黄色网址| 666精品国产精品亚洲| 日韩精品无码一区二区三区免费 | 亚洲免费在线视频播放| 亚洲网站免费观看| 亚洲精品在线不卡| 18国产精品白浆在线观看免费| 亚洲美女视频网址| 四虎在线视频免费观看视频| 亚洲国产成人久久精品app| 免费精品国偷自产在线在线| 亚洲国产视频久久| 免费一级毛片在级播放| 国产精品免费久久久久影院| 亚洲天堂免费在线视频| 91成人免费福利网站在线| 亚洲国产综合精品中文第一区| 18未年禁止免费观看| 亚洲熟妇AV一区二区三区浪潮| www国产亚洲精品久久久日本| jizz日本免费| 日韩精品一区二区亚洲AV观看 | 中文字幕不卡亚洲| 91精品视频在线免费观看| 亚洲色一区二区三区四区| 亚洲综合激情另类专区| 亚洲免费闲人蜜桃| 免费精品国产自产拍在线观看| 亚洲AV无码成人精品区蜜桃| 免费看国产精品3a黄的视频| 黄色三级三级三级免费看|