/*
 * 作成日： 2004/09/07
 */
package org.seasar.tapestry.pageinjection.impl;

import org.seasar.framework.util.StringUtil;
import org.seasar.tapestry.pageinjection.Injection;
import org.seasar.tapestry.util.InjectionUtil;

/**
 * 指定したクラスのサブクラスに対してインジェクションを行う。
 * @author maruo_syunsuke
 * @user-object
 */
public class ExtentionClassInjection implements Injection {

	private final Class baseClass;

	/**
	 *  
	 */
	public ExtentionClassInjection() {
		this.baseClass = null ;
	}
	public ExtentionClassInjection(String clazz)
		throws ClassNotFoundException {
		if (StringUtil.isEmpty(clazz) == false) {
			this.baseClass = Class.forName(clazz);
		} else {
			this.baseClass = null;
		}
	}

	public void invoke(Object target) {
		Class runClass = target.getClass();

		for(runClass = target.getClass();
			runClass != null && runClass.equals(this.baseClass) == false ;
			runClass = runClass.getSuperclass()
		) {
			InjectionUtil.invokeSetterInjection(runClass, target );
		}
	}
}