1. Tapestry提供的页面加强
a) 说明:Tapestry的Page Enhancement的配置是在tapestry.enhance.xml内部。
b) 配置文件:
<contribution configuration-id="EnhancementWorkers">
<!-- These can actually run in any order, as long as abstract-property runs later. -->
<command id="inject-messages" object="service:InjectMessagesWorker" before="abstract-property"/>
<command id="inject-specification" object="service:InjectSpecificationWorker"
before="abstract-property"/>
<command id="specified-property" object="service:SpecifiedPropertyWorker" before="abstract-property"/>
<command id="parameter" object="service:ParameterPropertyWorker" before="abstract-property"/>
<command id="dispatch-inject" object="service:DispatchToInjectWorker" before="abstract-property"/>
<command id="inject-component" object="service:InjectComponentWorker" before="abstract-property"/>
<command id="inject-bean" object="service:InjectBeanWorker" before="abstract-property"/>
<command id="inject-asset" object="service:InjectAssetWorker" before="abstract-property"/>
<!-- After all the previous workers have had their chance, we "fill in" any unclaimed properties
as transient page properties. -->
<command id="abstract-property" object="service:AbstractPropertyWorker"/>
<!-- These need to come last, since the previous commands (including abstract-property)
may have added interfaces to the class. -->
<command id="page-detach-listener" object="service:InjectPageDetachListenerWorker"
after="abstract-property"/>
<command id="page-attach-listener" object="service:InjectPageAttachListenerWorker"
after="abstract-property"/>
<command id="page-validate-listener" object="service:InjectPageValidateListenerWorker"
after="abstract-property"/>
<command id="page-begin-render-listener" object="service:InjectPageBeginRenderListenerWorker"
after="abstract-property"/>
<command id="page-end-render-listener" object="service:InjectPageEndRenderListenerWorker"
after="abstract-property"/>
</contribution>
这里的定义包含了三部分。第一部分,主要是定义了用于处理注入的Worker。被注入的属性可能是文本,对象,
或者其他用户自定义的内容。他们当中的一部分可能会需要在类当中添加一些新的属性。如果这些属性只是一些普通的
get/set方法,那么他们只需在类声明中增加一个抽象属性的定义,而具体的方法注入,则可以交给后续的
AbstractPropertyWorker来完成。
第二部分,就是AbstractPropertyWorker属性定义,也就是类似于插入一些<property>的声明。
最后一部分就是为页面类增加事件处理部分。这些事件处理很大一部分是用于初始化,或者回滚某些属性值的。
2. Tapestry Annotation提供的页面加强
a) 说明:通过Hivemind的contribute功能,Tapestry Annotation,扩展了Tapestry的页面加强功能。
b) 配置文件:
<contribution configuration-id="tapestry.enhance.EnhancementWorkers" if="class
java.lang.annotation.Annotation">
<command id="annotation-worker" object="service:AnnotationEnhancementWorker" before="*" />
<command id="component-housekeeping-worker" object="service:ComponentHousekeepingWorker"
after="annotation-worker" />
<command id="component-propertyproxy-worker" object="service:ComponentPropertyProxyWorker"
before="tapestry.enhance.specified-property" />
<command id="inject-asset-annotation" object="service:InjectAssetAnnotationWorker"
after="tapestry.enhance.inject-asset" />
</contribution>
这里把annotatioin-worker,加入到了Tapestry Page Enhance的链当中。
<service-point id="AnnotationEnhancementWorker" interface="org.apache.tapestry.enhance.EnhancementWorker">
<invoke-factory>
<construct class="AnnotationEnhancementWorker">
<set-configuration property="methodWorkers" configuration-id="MethodWorkers" />
<set-configuration property="classWorkers" configuration-id="ClassWorkers" />
<set-configuration property="secondaryAnnotationWorkers"
configuration-id="SecondaryAnnotationWorkers" />
</construct>
</invoke-factory>
</service-point>
AnnotationEnhancementWorker是Tapestry Annotation Enhancement的入口,她支持在类上或者方法上通过
Annotation进行的加强。