webx中的pull service

来源:互联网 发布:投影机写码软件 编辑:程序博客网 时间:2024/06/05 23:36

(1)概述

              1.pull service作用

                 实际上pull service就相当于提供工具类,可以将工具定义成java类而能够在vm模板中调用

              2.webx定义的pull service

    <services:pull>        <!-- Webx3 tools。 -->        <pull-factories:utils />        <pull-factories:rundata-tool />        <pull-factories:csrfToken />        <pull-factories:form-tool />        <pull-factories:control-tool />        <pull-factories:uris-tool />    </services:pull>


(2)自定义PullService

              1.定义工具类

 public class DomTool {       public void addScript(String scriptURI) {       }       public void addCss(String cssURI) {       } }

              2.实现ToolFactory接口

public class MyToolFactory implements ToolFactory {    private boolean singleton = true;    private DomTool tool;    public void setSingleton(boolean singleton) {        this.singleton = singleton;    }    public Object createTool() throws Exception {        if (this.singleton) {            if (tool == null) {                tool = new DomTool();            }            return tool;        } else {            return new DomTool();        }    }    public boolean isSingleton() {        return this.singleton;    }}

              3.暴露服务工具

    <services:pull>        <pull-factories:factory id="domTool"                                class="com.alibaba.sample.petstore.web.common.util.MyToolFactory" />    </services:pull>

              4.vm中使用

 $domTool.addScript("scripts/test.js");



0 0