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

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

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

    耐心無止境 成功一瞬間

    BlogJava 聯系 聚合 管理
      31 Posts :: 5 Stories :: 25 Comments :: 0 Trackbacks
    在學習tuscany到過程遇到一個疑問(java組件實現是如何解析java類文件中的服務的?如果沒有配置服務,默認服務應該是什么?),開始的時候一直無法想清楚,通過閱讀源碼終于了解了部分解析過程

    以tuscany中的Calculator為例說明服務的定義:

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


    CalculatorService實現代碼
    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. 例子中獲取服務的方法:

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

    通過上述代碼我們就可以獲取相應的服務了,我們不僅要問,為什么能夠獲取相應的服務呢?

    根據java組件實現規范說明,如果組件只包含一個服務,那么我們在獲取服務的時候可以省略服務的名字。


    我的問題是:省略的服務名字是什么?


    b. 完整獲取服務的方法:

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

    大家通過比較就可以知道,其實省略的服務名字是 CalculatorServiceImpl

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

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


    2. 自己定義一個服務

    自己在實現中添加服務聲明

    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;
    。。。。。。


    我們可以通過如下方式獲取服務:

    a. 例子中的方式

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

    b. 完整方式

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

    我們通過如下方式就*不能*獲取服務了

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


    原因很簡單,實現不會再添加默認服務(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 閱讀(1370) 評論(0)  編輯  收藏 所屬分類: tuscany

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 德国女人一级毛片免费| 97国产免费全部免费观看| 免费观看国产精品| 天天综合亚洲色在线精品| 成人免费视频软件网站| 亚洲中文字幕乱码一区| av大片在线无码免费| 亚洲成AV人片久久| 欧美男同gv免费网站观看| 亚洲日韩国产AV无码无码精品 | 国产一二三四区乱码免费| 久久久久无码专区亚洲av| 中文精品人人永久免费| 久久精品国产亚洲| 亚洲视频在线免费看| 一区二区亚洲精品精华液| 免费涩涩在线视频网| 污网站在线观看免费| 亚洲精品乱码久久久久久久久久久久 | 亚洲综合久久夜AV | 国产一级在线免费观看| 亚洲AV无码专区国产乱码4SE | 免费国产成人午夜电影| 人妻仑乱A级毛片免费看| 亚洲精品美女久久久久99| 24小时日本韩国高清免费| 亚洲精品第一国产综合野| 国产乱子伦精品免费女| 成人无码视频97免费| 亚洲网红精品大秀在线观看| 免费99精品国产自在现线| 亚洲乱色伦图片区小说| 久久久久亚洲AV成人网人人软件| 久久国产乱子伦精品免费看| 久久精品亚洲AV久久久无码| 亚洲v国产v天堂a无码久久| 免费观看男人吊女人视频| 亚洲中文字幕乱码AV波多JI| 国产亚洲精品AA片在线观看不加载| 三年片在线观看免费观看大全动漫 | 四虎国产精品免费视|