S2を使ったプラグインのロード方法
http://code.google.com/p/t-2/wiki/WorkMemo_Plugin_Spec によると、プラグインのロード方法は3つあるようだ。
プラグインのロードはContainerAdapter経由でコンテナから取得します。
具体的な方法が分からないのでソースを見てみると、org.t2framework.t2.plugin.impl.PluginProcessorImpl#getPluginsでContainerAdapterからプラグインをgetComponentsしてロードしている模様。
PluginProcessorImpl.java
@Override public List<Plugin> getPlugins() { return containerAdapter.getComponents(Plugin.class); }
早速、簡単なプラグインを作成
package org.t2framework.plugins; import org.t2framework.commons.meta.MethodDesc; import org.t2framework.t2.action.ActionContext; import org.t2framework.t2.plugin.AbstractPlugin; import org.t2framework.t2.spi.Navigation; public class SimplePlugin extends AbstractPlugin { @Override public Navigation beforeActionInvoke(ActionContext actionContext, MethodDesc targetMethod, Object page, Object[] args) { System.out.println("++++++++++ SimplePlugin#beforeActionInvoke ++++++++++"); return super.beforeActionInvoke(actionContext, targetMethod, page, args); } }
オーバーライドできるメソッドは以下の通り。(org.t2framework.t2.plugin.Pluginより)
* - initialize : Initialize phase as Filter.init().
* - beginRequestProcessing : Begin request processing as the first point of Filter.doFilter().
* - createRequest : Create request.
* - createResponse : Create response.
* - componentCreated : Create the Page instance.
* - beforeActionInvoke : Just before invoking the Page's action method.
* - afterActionInvoke : Just after invoking the Page's action method.
* - beforeNavigation : Just before executing Navigation like forward or redirect.
* - afterNavigation : Just after executing Navigation.
* - endRequestProcessing : End request processing as the end point of Filter.doFilter().
* - destroy : Destroy phase as Filter.destroy().
ContainerAdapterは「Seasar2Adapter」を使用しているので、app.diconにプラグインのコンポーネントの登録を書く。
app.dicon
・・・ <component class="org.t2framework.plugins.SimplePlugin" /> <component class="org.t2framework.plugins.SimplePlugin2" /> ・・・
上記のように複数プラグインを登録することも可能。
[追記]
あれ、ServiceLoader使っていないや。。。