Created
April 20, 2015 02:03
-
-
Save an-sangkil/82fe1d33dd0ee1fbadff to your computer and use it in GitHub Desktop.
Proxy Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package proxy; | |
import java.lang.reflect.InvocationHandler; | |
import java.lang.reflect.Method; | |
public class DebugHandler implements InvocationHandler { | |
public DebugHandler() { | |
} | |
private Object target; | |
public Object getTarget() { | |
return target; | |
} | |
public void setTarget(Object target) { | |
this.target = target; | |
} | |
@Override | |
public Object invoke(Object proxy, Method method, Object[] args) | |
throws Throwable { | |
System.out.println("----------------------------"); | |
System.out.println("Method 호출 = " + method); | |
return method.invoke(target, args); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package proxy; | |
public class EmpManager implements IEmpManager{ | |
public void getMessage () { | |
System.out.println("message Call"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package proxy; | |
public interface IEmpManager { | |
public void getMessage (); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package proxy; | |
import java.lang.reflect.Proxy; | |
public class ProxyTest { | |
public static void main(String args[]) throws Exception { | |
IEmpManager empManager = new EmpManager(); | |
DebugHandler debugHandler = new DebugHandler(); | |
debugHandler.setTarget(empManager); | |
IEmpManager proxyManager = (IEmpManager)Proxy.newProxyInstance(IEmpManager.class.getClassLoader(), new Class[] {IEmpManager.class}, debugHandler); | |
proxyManager.getMessage(); | |
System.out.println("end"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment