1 /** 2 * Copyright 2005-2014 The Kuali Foundation 3 * 4 * Licensed under the Educational Community License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.opensource.org/licenses/ecl2.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.kuali.rice.krad.util; 17 18 import org.kuali.rice.krad.util.GlobalVariables; 19 20 import java.lang.reflect.InvocationHandler; 21 import java.lang.reflect.Method; 22 import java.util.concurrent.Callable; 23 24 /** 25 * A proxy invocationhandler that implements around advice which pushes a new GlobalVariables frame before 26 * invocation and pops it after invocation. 27 * @see GlobalVariables#doInNewGlobalVariables 28 */ 29 public class GlobalVariablesContextInvocationHandler implements InvocationHandler { 30 private Object proxied; 31 public GlobalVariablesContextInvocationHandler(Object proxied) { 32 this.proxied = proxied; 33 } 34 35 @Override 36 public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { 37 return GlobalVariables.doInNewGlobalVariables(new Callable() { 38 @Override 39 public Object call() throws Exception { 40 return method.invoke(proxied, args); 41 } 42 }); 43 } 44 }