`

JBPM4配置文件解析

阅读更多
xml -> Binding -> Descriptor -> WireDefinition -> WireContext

xml     :JBPM配置文件,主配置文件jbpm.cfg.xml;
binding :解析JBPM配置文件中的标签,解析后生成Descritor对象;每个bind对象和xml中的标签一一对应;可以参看WireParser类中对bind的解析和初始化,bindings定义文件jbpm.wire.bindings.xml;
descritor:JBPM配置文件的描述对象,暂且没有实例化,但是有创建和初始化的方法;
wireDefinition:description对象的集合,用Map对象实现;
wireContext:解析上下文,包含wireDefine对象,封装了descrition的创建方法,相当于descritor的代理;


1、jbpm.tx.hibernate.cfg.xml中有如下定义:
    <command-service name="txRequiredCommandService">
      <skip-interceptor />
      <retry-interceptor />
      <environment-interceptor />
      <standard-transaction-interceptor />
    </command-service>

    <command-service name="newTxRequiredCommandService">
      <retry-interceptor />
      <environment-interceptor policy="requiresNew" />
      <standard-transaction-interceptor />
    </command-service>

2、Binding对象用于解析xml:

public class CommandServiceBinding extends WireDescriptorBinding {

  public CommandServiceBinding() {
    super("command-service");
  }
 
  protected CommandServiceBinding(String tagName) {
    super(tagName);
  }

  public Object parse(Element element, Parse parse, Parser parser) {
    CommandServiceDescriptor commandServiceDescriptor = new CommandServiceDescriptor();

    CommandService commandService = getCommandService(element, parse, parser);
    commandServiceDescriptor.setCommandService(commandService);
   
    List<Element> interceptorElements = XmlUtil.elements(element);
    for (Element interceptorElement : interceptorElements) {
      Descriptor interceptorDescriptor = (Descriptor) parser.parseElement(interceptorElement, parse, WireParser.CATEGORY_INTERCEPTOR);
      commandServiceDescriptor.addInterceptorDescriptor(interceptorDescriptor);
    }

    return commandServiceDescriptor;
  }

  protected CommandService getCommandService(Element element, Parse parse, Parser parser) {
    Boolean async = XmlUtil.attributeBoolean(element, "async", parse);
    if (Boolean.TRUE.equals(async)) {
      AsyncCommandService asyncCommandService = new AsyncCommandService();

      Boolean propagateUserId = XmlUtil.attributeBoolean(element, "propagate-auth", parse);
      if (propagateUserId!=null) {
        asyncCommandService.setPropagateUserId(propagateUserId);
      }
      return asyncCommandService;
    }
   
    return new DefaultCommandService();
  }
}

3、Descriptor的代码:
public class CommandServiceDescriptor extends AbstractDescriptor {

  private static final long serialVersionUID = 1L;
 
  CommandService commandService;
  List<Descriptor> interceptorDescriptors;

  public Object construct(WireContext wireContext) {
    CommandService interceptedCommandService = commandService;
    if (interceptorDescriptors!=null) {
      for (int i=interceptorDescriptors.size()-1 ; i>=0; i--) {
        Descriptor descriptor = interceptorDescriptors.get(i);
        Interceptor interceptor = (Interceptor) descriptor.construct(wireContext);
        interceptor.setNext(interceptedCommandService);
        interceptedCommandService = interceptor;
      }
    }
    return interceptedCommandService;
  }
 
  public Class< ? > getType(WireDefinition wireDefinition) {
    return (name==null ? CommandService.class : null);
  }
 
  public void addInterceptorDescriptor(Descriptor descriptor) {
    if (interceptorDescriptors==null) {
      interceptorDescriptors = new ArrayList<Descriptor>();
    }
    interceptorDescriptors.add(descriptor);
  }
 
  public void setCommandService(CommandService commandService) {
    this.commandService = commandService;
  }
}
分享到:
评论

相关推荐

    JBPM4工作流应用开始指南.rar

    264 13.6.2 jBPM4流程历史数据表 265 13.6.3 jBPM4身份认证数据表 266 13.6.4 jBPM4引擎属性数据表 267 13.7 例程:扩展jBPM4的API满足客户化的需求 268 13.8 小结 270 第14章 随需而配jBPM4 272 14.1 配置文件设计...

    jbpm源代码阅读视频—第三次阅读part2

    1.2配置文件解析过程 1.3对象创建过程与binding解析过程 同时由于本人能力有限,时间有限. 这些东西仅仅为抛砖引玉,我是转而已。可能会有一些不到位的地方。 如有不同意见可以在此大家一起批评与探讨.谢谢 ...

    jbpm4.4源代码阅读视频

    1.2配置文件解析过程 1.3对象创建过程与binding解析过程 同时由于本人能力有限,时间有限. 这些东西仅仅为抛砖引玉,我是转而已。可能会有一些不到位的地方。 如有不同意见可以在此大家一起批评与探讨.谢谢 ...

    jbpm4.4源代码阅读视频——第二次阅读

    1.2配置文件解析过程 1.3对象创建过程与binding解析过程 同时由于本人能力有限,时间有限. 这些东西仅仅为抛砖引玉,我是转而已。可能会有一些不到位的地方。 如有不同意见可以在此大家一起批评与探讨.谢谢 ...

    jbpm4.4源代码阅读视频——第二次part2

    1.2配置文件解析过程 1.3对象创建过程与binding解析过程 同时由于本人能力有限,时间有限. 这些东西仅仅为抛砖引玉,我是转而已。可能会有一些不到位的地方。 如有不同意见可以在此大家一起批评与探讨.谢谢 ...

    jbpm4.4源代码阅读视频-第三次阅读part1

    1.2配置文件解析过程 1.3对象创建过程与binding解析过程 同时由于本人能力有限,时间有限. 这些东西仅仅为抛砖引玉,我是转而已。可能会有一些不到位的地方。 如有不同意见可以在此大家一起批评与探讨.谢谢 ...

    iuhyiuhkjh908u0980

    ant配置文件实例详解 build.xml 代码 xml version="1.0" encoding="UTF-8"?&gt; &lt;!-- name:对应工程的名字;default:需要的缺省任务(运行"ant"不指明任务时执行的任务) --&gt; by duzn 2007-04-02 回复 (0) Antenna与j2me...

    Spring攻略(第二版 中文高清版).part2

    1.2 配置Spring IoC容器中的Bean 4 1.2.1 问题 4 1.2.2 解决方案 4 1.2.3 工作原理 4 1.3 调用构造程序创建Bean 14 1.3.1 问题 14 1.3.2 解决方案 14 1.3.3 工作原理 14 1.4 解决构造程序歧义 17 ...

    Spring攻略(第二版 中文高清版).part1

    1.2 配置Spring IoC容器中的Bean 4 1.2.1 问题 4 1.2.2 解决方案 4 1.2.3 工作原理 4 1.3 调用构造程序创建Bean 14 1.3.1 问题 14 1.3.2 解决方案 14 1.3.3 工作原理 14 1.4 解决构造程序歧义 17 ...

Global site tag (gtag.js) - Google Analytics