CommonTemplate配置方案确定

根据前几天的思考:[url]http://javatar.iteye.com/blog/139420[/url]
CommonTemplate([url]http://www.commontemplate.org[/url])的配置方案确定,
采用全setter方式配置,以保持可以用任意IoC容器进行配置,
但为了不依赖于任何IoC容器使用组件,
在util包中实现了一个简单的BeanFactory,作为默认IoC容器实现:
org.commontemplate.util.PropertiesBeanFactory
(实现的是上面思考帖子的第二种方案)

采用properties作为配置,所以需遵循java.util.Properties的所有规则,如:# ! = :等符号需转义等

1.以()结尾表示创建实例,
实例可以注入属性:使用实例的key作为前缀,点号后跟其属性
如:

templateCache=org.commontemplate.standard.cache.FIFOCache()
templateCache.maxSize=1000

前提是FIFOCache中有一个setMaxSize(int)注入函数

2.以[]结尾表示List<Object>,并以其value作为前缀搜索List的项
如:

templateNameFilter=templateNameFilters[]
templateNameFilters[100]=org.commontemplate.standard.filter.TemplateNameRelativer()
templateNameFilters[200]=org.commontemplate.standard.filter.TemplateNameCleaner()
templateNameFilters[200].maxLength=10

下标号用来唯一识别及排序,必需为数字,大小任意。
通常下标号都留一点间距,如上面的100,200,
这样当子级配置继承当前配置时,可以让其配置的templateNameFilter项插在已有的列表项中间。
如子配置中有:
templateNameFilters[101]=com.xxx.YYYFilter()
就会排序到上面配置的中间。

3.以{}结尾表示Map<String, Object>,并以其value作为前缀搜索Map的项
如:

directiveHandlers=directive{}
directive{if}=org.commontemplate.standard.directive.condition.IfDirectiveHandler()
directive{for}=org.commontemplate.standard.directive.iteration.ForeachDirectiveHandler()
directive{for}.statusName=for

下标{}中名称若有符号,均作为字符串。

4.基本类型处理与Java相似
null, true, false为关键字,表示特殊值。
以数字开头的为Number,识别后缀L,F,D,S
以单引号括起的为Character
以双引号括起的为String,如:"xxxx"

5.其它情况均作为String处理,
但若要输出特殊标识的String,必需用双引号,如:"true"

6.采用@extends作为配置继承专用属性,可以多继承,用逗号分隔各父级配置文件,
如:
@extends=org/commontemplate/standard/commontemplate-standard.properties

整个配置的设计思想是,尽可能把所有设置项行级展开,以便于子级配置可以轻松的覆盖父级的所有配置细节,
如:用户可以写一个commontemplate-my.properties:
@extends=org/commontemplate/standard/commontemplate-standard.properties
directive{for}.statusName=for

现在只能用List<Object>和Map<String, Object>作为容器类进行配置,以后会改进加入其它容器。
如果完善后可以考虑抽取出来单独作为一个发行包。

如果各位有好的建议,不妨讨论下。

另,可参见CommonTemplate的标准配置:
org/commontemplate/standard/commontemplate-standard.properties
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值