AutoRegister.diconサンプル

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.3//EN"
	"http://www.seasar.org/dtd/components23.dtd">

<components>

	<!-- INCLUDE -->
	<include path="aop.dicon"/>
	<include path="j2ee.dicon"/>
	<include path="dao.dicon"/>

	<!-- COMPONENT -->
	<component class="org.seasar.framework.container.autoregister.FileSystemComponentAutoRegister">
		<initMethod name="addClassPattern">
			<arg>"examples.jsf"</arg>
			<arg>".*Dao,.*DaoImpl,.*LogicImpl"</arg>
		</initMethod>
		<initMethod>#out.println("=== AutoRegister: singleton")</initMethod>
	</component>
	<component class="org.seasar.framework.container.autoregister.FileSystemComponentAutoRegister">
		<property name="instanceDef">@org.seasar.framework.container.deployer.InstanceDefFactory@REQUEST</property>
		<initMethod name="addClassPattern">
			<arg>"examples.jsf"</arg>
			<arg>".*Dto,.*ActionImpl"</arg>
		</initMethod>
		<initMethod name="addIgnoreClassPattern">
			<arg>"examples.jsf"</arg>
			<arg>".*ConditionDto"</arg>
		</initMethod>
		<initMethod>#out.println("=== AutoRegister: request")</initMethod>
	</component>
	<component class="org.seasar.framework.container.autoregister.FileSystemComponentAutoRegister">
		<property name="instanceDef">@org.seasar.framework.container.deployer.InstanceDefFactory@REQUEST</property>
		<property name="autoNaming">
			<component class="org.seasar.framework.container.autoregister.DefaultAutoNaming">
				<initMethod name="addReplaceRule">
					<arg>"\\b[A-Za-z_0-9]\\w*\\Dto\\b"</arg>
					<arg>"db$0"</arg>
				</initMethod>
			</component>
		</property>
		<initMethod name="addClassPattern">
			<arg>"examples.jsf"</arg>
			<arg>".*Dto"</arg>
		</initMethod>
		<initMethod name="addIgnoreClassPattern">
			<arg>"examples.jsf"</arg>
			<arg>".*ConditionDto"</arg>
		</initMethod>
		<initMethod>#out.println("=== AutoRegister: request(like a 'dbFooDto')")</initMethod>
	</component>
	<component class="org.seasar.framework.container.autoregister.FileSystemComponentAutoRegister">
		<property name="instanceDef">@org.seasar.framework.container.deployer.InstanceDefFactory@SESSION</property>
		<initMethod name="addClassPattern">
			<arg>"examples.jsf"</arg>
			<arg>".*ConditionDto"</arg>
		</initMethod>
		<initMethod>#out.println("=== AutoRegister: session")</initMethod>
	</component>

	<!-- CHAIN -->
	<component name="daoInterceptorChain" class="org.seasar.framework.aop.interceptors.InterceptorChain">
		<initMethod name="add"><arg>aop.traceInterceptor</arg></initMethod>
		<initMethod name="add"><arg>dao.interceptor</arg></initMethod>
	</component>
	<component name="logicInterceptorChain" class="org.seasar.framework.aop.interceptors.InterceptorChain">
		<initMethod name="add"><arg>aop.traceInterceptor</arg></initMethod>
		<initMethod name="add"><arg>aop.traceThrowsInterceptor</arg></initMethod>
		<initMethod name="add"><arg>j2ee.requiredTx</arg></initMethod>
	</component>
	<component name="actionThrowsInterceptor" class="examples.jsf.interceptor.ActionThrowsInterceptor"/>
	<component name="actionInterceptorChain" class="org.seasar.framework.aop.interceptors.InterceptorChain">
		<initMethod name="add"><arg>aop.traceInterceptor</arg></initMethod>
		<initMethod name="add"><arg>actionThrowsInterceptor</arg></initMethod>
	</component>

	<!-- AOP -->
	<component class="org.seasar.framework.container.autoregister.AspectAutoRegister">
		<property name="interceptor">daoInterceptorChain</property>
		<initMethod name="addClassPattern">
			<arg>"examples.jsf"</arg>
			<arg>".*Dao"</arg>
		</initMethod>
		<initMethod>#out.println("=== AOP: daoInterceptorChain")</initMethod>
	</component>
	<component class="org.seasar.framework.container.autoregister.AspectAutoRegister">
		<property name="interceptor">logicInterceptorChain</property>
		<initMethod name="addClassPattern">
			<arg>"examples.jsf"</arg>
			<arg>".*LogicImpl"</arg>
		</initMethod>
		<initMethod>#out.println("=== AOP: logicInterceptorChain")</initMethod>
	</component>
	<component class="org.seasar.framework.container.autoregister.AspectAutoRegister">
		<property name="interceptor">actionInterceptorChain</property>
		<initMethod name="addClassPattern">
			<arg>"examples.jsf"</arg>
			<arg>".*ActionImpl"</arg>
		</initMethod>
		<initMethod>#out.println("=== AOP: actionInterceptorChain")</initMethod>
	</component>

</components>

DefaultAutoNamingのaddReplaceRuleでコンポーネント正規表現命名してみた。こんな感じで同じクラスを異なる名称で登録する事が出来た。利用する場合はセッターインジェクションで取得したりするといい。今後はフィールドインジェクションでいいそうだ。楽だ。