public Object invoke(Invocation invocation) throws Throwable { // create a key identifying the overall cflow match status int key = 0; for (int i = 0; i < cflows.length; i++) { key = key + cflows[i].evaluate(invocation) << i; } Interceptor[] chain; // if we have seen the same match status before, just reuse the chain if (this.chains.containsKey(key)) { chain = this.chains.get(key); } else { Collection<Interceptor> chainCollection = new ArrayList<Interceptor>(); for (int i = 0; i < this.sortedInterceptors.length; i++) { if (this.sortedCFlows[i] == null || this.sortedCFlows[i].matches()) { chainCollection.add(this.sortedInterceptors[i]); } } chain = chainCollection.toArray(new Interceptor[chainCollection.size()]); // store the chain in the cache for reuse on subsequent invocations this.chains.put(key, chain); } return invocation.getWrapper(chain).invokeNext(); }
public Object invoke(Invocation invocation) throws Throwable { if (new CFlowMatcher().matches(expr, invocation)) { Invocation wrapper = invocation.getWrapper(chain); return wrapper.invokeNext(); } // no match for cflow so just go down chain return invocation.invokeNext(); } }