List of usage examples for org.springframework.aop.framework ProxyFactory setTarget
public void setTarget(Object target)
From source file:introducitons.IntroducitonExample.java
public static void main(String[] args) { TargetBean target = new TargetBean(); target.setName("Loup Garou"); ProxyFactory pf = new ProxyFactory(); pf.setTarget(target); Advisor advisor = new IsModifiedAdvisor(); pf.addAdvisor(advisor);// www . j ava 2 s. c om pf.setOptimize(true); TargetBean proxy = (TargetBean) pf.getProxy(); IsModified proxyInterface = (IsModified) proxy; System.out.println("Proxy is target bean ? : " + (proxy instanceof TargetBean)); System.out.println("Proxy is child of Ismodified? : " + (proxy instanceof IsModified)); System.out.println("Has been modified interface? : " + proxyInterface.isModified()); proxy.setName("Loup Garou"); System.out.println("Has been modified? Loup Garou != Loup Garou : " + proxyInterface.isModified()); proxy.setName("Za Warudo"); System.out.println("Has been modified? : " + proxyInterface.isModified()); }
From source file:staticpc.StaticPointcutExample.java
public static void main(String[] args) { BeanOne one = new BeanOne(); BeanTwo two = new BeanTwo(); BeanOne proxyOne;//from w w w .java2s . c o m BeanTwo proxyTwo; Pointcut pc = new SimpleStaticPointCut(); Advice advice = new SimpleAdvice(); Advisor advisor = new DefaultPointcutAdvisor(pc, advice); ProxyFactory pf = new ProxyFactory(); pf.setTarget(one); pf.addAdvisor(advisor); proxyOne = (BeanOne) pf.getProxy(); pf = new ProxyFactory(); pf.setTarget(two); pf.addAdvisor(advisor); proxyTwo = (BeanTwo) pf.getProxy(); proxyOne.foo(); proxyOne.bar(); proxyTwo.foo(); proxyTwo.bar(); }
From source file:throwsaop.SimpleThrowsAdvice.java
public static void main(String[] args) { ErrorBean bean = new ErrorBean(); ProxyFactory f = new ProxyFactory(); f.setTarget(bean); f.addAdvice(new SimpleThrowsAdvice()); ErrorBean proxy = (ErrorBean) f.getProxy(); try {/*from w w w .j a v a 2 s . c om*/ proxy.errorProneMethod(); } catch (Exception e) { } try { proxy.otherErrorProneMethod(); } catch (Exception e) { } }
From source file:com.aop.ProxyFactoryTest.java
public static void main(String[] args) { UserService userService = new UserServiceImpl(); ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTarget(userService); proxyFactory.setInterfaces(new Class[] { UserService.class }); NameMatchMethodPointcutAdvisor advisor = new NameMatchMethodPointcutAdvisor(); advisor.setMappedName("addUser"); advisor.setAdvice(new CheckInterceptor()); proxyFactory.addAdvisor(advisor);/*ww w . ja va2 s . c o m*/ UserService userServiceProxy = (UserService) proxyFactory.getProxy(); userServiceProxy.addUser(); }
From source file:aop.SimpleBeforeAdvice.java
public static void main(String[] args) { MessageWriter target = new MessageWriter(); ProxyFactory pf = new ProxyFactory(); pf.addAdvice(new SimpleBeforeAdvice()); pf.setTarget(target); MessageWriter proxyTarget = (MessageWriter) pf.getProxy(); proxyTarget.writeMessage();/*from ww w . ja v a 2s . co m*/ System.out.println(""); proxyTarget.writeAnotherMessage(); System.out.println(""); }
From source file:orz.neptune.prospring3.ch6.HelloWorldAOPExample.java
public static void main(String[] args) { MessageWriter target = new MessageWriter(); ProxyFactory pf = new ProxyFactory(); pf.addAdvice(new MessageDecorator()); pf.setTarget(target); MessageWriter proxy = (MessageWriter) pf.getProxy(); target.writeMessage();/*from w w w.java2 s . c o m*/ System.out.println(""); proxy.writeMessage(); }
From source file:aop.HelloWorldAOPExample.java
public static void main(String[] args) { MessageWriter target = new MessageWriter(); ProxyFactory pf = new ProxyFactory(); ProxyFactory pf2 = new ProxyFactory(); pf.addAdvice(new MessageDecorator()); pf.setTarget(target); MessageWriter proxyObj = (MessageWriter) pf.getProxy(); pf2.setTarget(proxyObj);//from www . j a va 2 s .co m pf2.addAdvice(new MessageDecorator()); MessageWriter proxyObj2 = (MessageWriter) pf2.getProxy(); System.out.println("::::::::::::"); target.writeMessage(); System.out.println("\n:::::::::::::"); proxyObj2.writeMessage(); proxyObj2.writeAnotherMessage(); // Advisor a = new Advisor }
From source file:profiling.ProfillingExample.java
private static WorkerBean getWorkerBean() { WorkerBean target = new WorkerBean(); ProxyFactory factory = new ProxyFactory(); factory.setTarget(target); factory.addAdvice(new ProfilingInterceptor()); return (WorkerBean) factory.getProxy(); }
From source file:security.SecurityExample.java
private static SecureBean getSecureBean() { SecureBean target = new SecureBean(); SecurityAdvice advice = new SecurityAdvice(); ProxyFactory factory = new ProxyFactory(); factory.setTarget(target); factory.addAdvice(advice);/* w w w . ja va2 s .c om*/ return (SecureBean) factory.getProxy(); }
From source file:org.openmrs.module.jmx.util.MBeanProxifier.java
/** * Gets a proxied MBean//from ww w .j av a2s.c o m * @param mbean the MBean * @return the proxied MBean */ public static Object getProxy(Object mbean) { Class<?> clazz = getMBeanInterface(mbean); if (clazz == null) throw new IllegalArgumentException("Object does not implement an MXBean interface"); ProxyFactory factory = new ProxyFactory(clazz, interceptor); factory.setTarget(mbean); return factory.getProxy(); }