- 浏览: 497364 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
chimpp55:
java.lang.NoSuchMethodError: or ...
基于Junit2.0的StrutsTestCase应用 -
opmic:
<property name="srcDir& ...
使用Eclipse与Ant进行java程序开发 -
univasity:
非常好,谢谢分享。
使用Eclipse与Ant进行java程序开发 -
peanut_sei:
exception handlers 译成 例外处理 倒是第 ...
JavaScript高级应用:例外处理
3. 接口。它表示“命令链”,要在其中执行的命令,需要先添加到Chain中。Chain的父接口是Command,ChainBase实现了它。 Chain
public class Command1 implements Command { public boolean execute(Context arg0) throws Exception { System.out.println("Command1 is done!"); return false; } } |
public class Command2 implements Command { public boolean execute(Context arg0) throws Exception { System.out.println("Command2 is done!"); return false; } } |
public class Command3 implements Command { public boolean execute(Context arg0) throws Exception { System.out.println("Command3 is done!"); return true; } } |
public class CommandChain extends ChainBase { //增加命令的顺序也决定了执行命令的顺序 public CommandChain(){ addCommand( new Command1()); addCommand( new Command2()); addCommand( new Command3()); } public static void main(String[] args) throws Exception{ Command process = new CommandChain(); Context ctx= new ContextBase(); process.execute( ctx); } } |
<?xml version="1.0" encoding="gb2312"?> <catalog> <chain name="CommandChain"> <!-- 定义的顺序决定执行的顺序 --> <command id="command1" className= "chain.Command1"/> <command id="command2" className= "chain.Command2"/> <command id="command3" className= "chain.Command3"/> </chain> <command name="command4" className="chain.Command1"/> </catalog> |
public class CatalogLoader { static final String cfgFile= "/chain/chain-cfg.xml"; public static void main(String[] args) throws Exception{ CatalogLoader loader= new CatalogLoader(); ConfigParser parser= new ConfigParser(); parser.parse( loader.getClass().getResource( cfgFile)); Catalog catalog= CatalogFactoryBase.getInstance().getCatalog(); //加载Chain Command cmd= catalog.getCommand("CommandChain"); Context ctx= new ContextBase(); cmd.execute( ctx); //加载Command cmd= catalog.getCommand( "command4"); cmd.execute( ctx); } } |
注意:使用配置文件的话,需要使用Commons Digester。而Digester则依赖:Commons Collections、Commons Logging和Commons BeanUtils。
<context-param> <param-name>org.apache.commons.chain.CONFIG_CLASS_RESOURCE</param-name> <param-value>resources/catalog.xml</param-value> </context-param> <listener> <listener-class>org.apache.commons.chain.web.ChainListener</listener-class> </listener> |
.getServletContext().getAttribute("catalog");
public class Filter1 implements Filter { public boolean postprocess(Context arg0, Exception arg1) { System.out.println("Filter1 is after done!"); return false; } public boolean execute(Context arg0) throws Exception { System.out.println("Filter1 is done!"); return false; } } |
<?xml version="1.0" encoding="UTF-8"?> <catalog> <chain name="CommandChain"> <command id="command1" className= "chain.Command1"/> <command id="filter1" className= "chain.Filter1"/> <command className="org.apache.commons.chain.generic.LookupCommand" name="chain_command3" optional="true"/> <command id="command2" className= "chain.Command2"/> </chain> <chain name="chain_command3"> <command id="command3" className= "chain.Command3"/> </chain> </catalog> |
<?xml version="1.0" encoding="gb2312"?> <catalog> <!-- Command的别名,以后直接使用即可 --> <define name="command1" className="chain.Command1"/> <define name="command2" className="chain.Command2"/> <define name="command3" className="chain.Command3"/> <define name="filter1" className="chain.Filter1"/> <define name="lookupCommand" className="org.apache.commons.chain.generic.LookupCommand"/> <chain name="CommandChain"> <command1 id="1"/> <filter1 id="2"/> <lookupCommand name="chain_command3" optional="true"/> <command2 id="3"/> </chain> <chain name="chain_command3"> <command3 id="3"/> </chain> <command1 name="command4"/> </catalog> |
- 使用<define>定义别名,简化书写。
发表评论
-
Eclipse快捷键(引用转贴)
2004-09-23 11:47 831本文档从Eclipse软件上整理,是列出了标准的快捷键,未列出 ... -
java Excel API 简介(翻译)
2004-09-23 11:49 947java Excel API 简介(翻译) 版权声明:CSD ... -
spring-richclient开发swing应用程序
2005-09-03 18:00 1928Swing桌面应用程序的开发一直以来都是Java桌面开发者心中 ... -
spring-richclient开发swing应用程序 2
2005-09-03 18:07 12011 Main函数PetClinicStandalone里面基本 ... -
spring-richclient开发swing应用程序 3
2005-09-03 18:36 1751richclient-application-context. ... -
spring-richclient开发swing应用程序 4
2005-09-03 18:50 1254spring-rcp里面简单到极点(相对)的就算是菜单和导航条 ... -
关于Ajaxian JSF的设计原则
2005-09-09 16:05 670目前网上大大小小的Ajax Framework已经计算不清了, ... -
Velocity学习笔记1——Velocity是什么
2006-05-23 22:38 1061Velocity是一个基于Java的模版引擎。它允 ... -
Velocity学习笔记2——Velocity能够做什么
2006-05-24 11:06 969一个 ... -
JDBMonitor全攻略:10秒为任意数据库增加执行日志功能
2006-05-16 22:34 1224JDBMonitor是一个开源项目 ... -
使用JDBMonitor剖析Hibernate的实现机制
2006-05-17 18:20 1066使用JDBMonitor剖析Hibernate的实现机制现在j ... -
Log4j和JDBMonitor的比较
2006-05-17 18:21 803Log4j和JDBMonitor的比较Log4 ... -
开始使用Commons Chain (第一部分)
2007-05-25 01:12 1114作为程序开发人员,我 ... -
在JAVA中使用文档对象模型DOM经验小结
2007-07-13 23:20 802文档对象模型 (DOM) 是一个文档标准,对于完备的文档和复杂 ... -
什么时候该用synchronized
2007-07-13 23:48 1391由于同一进程的多个线 ... -
XMLC在eclipse中的使用
2007-07-13 23:50 933关于外部插件的使用可以用link的方式做,如果简单的只把插件丢 ... -
J2EE架构学习者的6个最佳实践
2007-07-14 00:06 773虽然许多文章曾经讨论 ... -
面向Java程序员的Ajax:构建动态Java程序
2007-07-14 00:11 752Ajax(即异步 JavaScript 和 ... -
用java打包成zip
2007-08-21 11:51 1389--- 大家可能对于Zip格式的文件已经司空见惯了,我们可以使 ... -
利用java处理XML文档
2007-08-22 23:43 818在java对XML进行处理时, ...
相关推荐
apache commons all 中文api合集
apache commons jar(commons所有的jar包... apache-sanselan-incubating-0.97-bin bcel-5.2 commons-beanutils-1.9.2-bin commons-chain-1.2-bin commons-cli-1.3.1-bin commons-codec-1.10-bin commons-collections4-4
commons-lang3.3.1.jar、Apache Commons包中的一个,包含了一些数据类型工具类,是java.lang.*的扩展。必须使用的jar包。为JRE5.0+的更好的版本所提供 Jar文件包含的类: META-INF/MANIFEST.MFMETA-INF/LICENSE....
apache Commons Lang 2.4 API apache Commons Lang 2.4 API
commons-lang3.3.1.jar、Apache Commons包中的一个,包含了一些数据类型工具类,是java.lang.*的扩展。必须使用的jar包。为JRE5.0+的更好的版本所提供 Jar文件包含的类: META-INF/MANIFEST.MFMETA-INF/LICENSE....
Apache-commons源码其中包括(commons-email-1.5-src、commons-fileupload-1.4-src、commons-io-2.8.0-src、commons-jelly-1.0.1-src、commons-lang3-3.11-src...)
天天都有人导入Apache的包,但是里面那么多工具类又有多少人使用过,这里面有一些使用介绍
Apache_Commons_Net_2_API.chm
介绍了Apache Jakarta Commons 项目下Java组件,如FileUpload, HttpClient, DBCP,BeanUtils,Logging,Lang, 以及 Collections,Codec等,是学习和使用Apache Jakarta Commons良好的参考使用手册。
主要介绍了Apache Commons Math3探索之多项式曲线拟合实现代码,小编觉得挺不错的,这里分享给大家,供需要的朋友参考。
Apache Commons Collections,commons-collections-3.2.1和commons-collections4-4.0,含jar包及源码和api文档。
Apache Commons API简介,主要介绍Apache Commons API所包含的包,后续更新补充各类的简介和使用方法
Commons-beanutils-API Commons-collections-API Commons-configuration-API Commons-lang-API Commons-logging-API Dom4j_API java api javascript Struts API J2EE API
apache-commons下全部官方源码和官方API文档,其中有: commons-beanutils-1.8.0 commons-codec commons-collections commons-dbcp commons-dbutils commons-fileupload commons-io commons-lang commons-lang3 ...
apache commons 工具包中提供的一个针对配置文件动态修改的工具类
Apache Commons IO 2.5 (要求 JDK 1.6),IOUtils,FileUtils,jar包下载
Apache Commons是一个非常有用的工具包,解决各种实际的通用问题。(附件中提供了该工具包的jar包,及源文件以供研究) BeanUtils Commons-BeanUtils 提供对 Java 反射和自省API的包装 Betwixt Betwixt提供将 ...
Apache Commons Logging 1.2
Apache Commons官网jar包,包含io,cli,codec,net,lang,email等等等等
apache commons apiapache commons apiapache commons apiapache commons apiapache commons apiapache commons apiapache commons apiapache commons api