AspectFlowみたいな。

今日の禿会で、ちょっと出た話。

  • 複数のアスペクトを1つの塊として捉えて、対象となるオブジェクトに適用したい感じ。
  • その塊は、定義上それなりに自由にコンポジット出来ると良い感じ。

と、言う訳で、AopProxyとかMethodInvocationImpl辺りを眺めてみる…。
何か大変な事になっとる…。特に、AopProxy…。知らないコードがイパーイ。


あんまり大変なコードを書き出すと、1:Nマッピングの方が疎かになりそうなので、
S2に手を入れずに、作る方法を考えてみる。3分で出来たのがこんな感じ。

public class InterceptorFlowInterceptor implements MethodInterceptor, Serializable {
	
	private List interceptors_ = new ArrayList();
	
	public Object invoke(MethodInvocation invocation) throws Throwable {
		MethodInvocationProxy proxy = new MethodInvocationProxy(invocation);
		return proxy.proceed();
	}
	
	public void addInterceptor(MethodInterceptor interceptor) {
		interceptors_.add(interceptor);
	}
	
	public void addInterceptors(InterceptorFlowInterceptor interceptors) {
		interceptors_.addAll(interceptors.interceptors_);
	}
	
	private class MethodInvocationProxy implements MethodInvocation {
		private MethodInvocation invocation_;
		private int interceptorsIndex_ = 0;
		
		private MethodInvocationProxy(MethodInvocation invocation) {
			invocation_ = invocation;
		}
		public Object[] getArguments() {
			return this.invocation_.getArguments();
		}
		public Method getMethod() {
			return this.invocation_.getMethod();
		}
		public AccessibleObject getStaticPart() {
			return this.invocation_.getStaticPart();
		}
		public Object getThis() {
			return this.invocation_.getThis();
		}
		public Object proceed() throws Throwable {
			while (interceptorsIndex_ < interceptors_.size()) {
				return ((MethodInterceptor) 
					interceptors_.get(interceptorsIndex_++)).invoke(this);
			}
			return this.invocation_.proceed();
		}
	}


作ってみた後に、そう言えばAbstractInterceptorってあったような…と、コード見る。
あぅあ…、id:koichikさんの言ってたgetComponentDefってこれくぁ……。
簡単に作ったやつじゃ、上手く動かないデスヨ…。残念…。考え直しますです。