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;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值