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;
}
下面是解析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);
}
parse类中的方法
public Object parseElement(Element element, Parse parse, String category) {
Object object = null;
String tagName = element.getLocalName();
Binding binding = getBinding(element, category);
if (binding != null) {
object = binding.parse(element, parse, this);
}
else if (log.isDebugEnabled()) {
log.debug("no element parser for tag " + tagName
+ (category != null ? " in category " + category : " in the default category"));
}
return object;
}
分享到:
相关推荐
设计模式之责任链模式源码 设计模式之责任链模式源码 设计模式之责任链模式源码
spring责任链模式详解,包含项目中应用
一、责任链模式 现有 “战士”、“班长”、“排长”、“连长”,“营长”五种角色,当有人要请假时要进行以下处理 1.只能是下级象上级请假(如“排长”只能向“连长请假”) 2.班长可以批准1天内的假期,排长批5天,...
职责链模式 设计模式 Chain of Responsibility 若有问题望指出。
责任链模式代码
开始击鼓时,花束就开始依次传递,鼓声一落,如果花束在某人手中,则该人就得饮酒,这是很典型的行为责任链模式。 State模式主要解决的是在开发中时常遇到的根据不同的状态需要进行不同的处理操作的问题,而这样的...
责任链模式(Chain of Responsibility)的目标是使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系。将这些对象连成一条链,并沿着这条链传递请求,直到有一个对象处理它为止。 在处理用户的...
责任链模式demo
C# 职责链模式 代码 模型代码,学习。
责任链模式的小例子
【设计模式】之责任链模式责任链模式概念责任链,顾名思义,就是用来处理相关事务责任的一条执行链,执行链上有多个节点,每个节点都有机会(条件匹配)处理请求事务,如果
设计模式的责任链模式的例子,希望对大家有用~~~~~~~~
责任链模式小demo
责任链模式 C++ 实现
设计模式之责任链模式Java版本实现和UML类图设计
ios平台中通过最简单的代码讲解责任链模式,可在博客http://blog.sina.com.cn/s/blog_161d504630102wxis.html中查看简单解释
JAVA 设计模式: 工厂模式 代理模式 迭代模式 责任链模式 源码
设计模式之责任链模式,使用形象化例子来解释说明。
设计模式C++学习之责任链模式(Chain of Responsibility)