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配置文件解析
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
JBPM4 jbpm4 DeployCmd NullPointerException異常
harbey
2018-11-21 07:08:06
JBPM4連接HSQLDB數據庫
harbey
2018-11-21 07:08:06
opencms7.5
harbey
2018-11-07 07:23:40
天乙社區8.5.0Beta2
harbey
2018-11-04 07:59:42