List of usage examples for org.springframework.aop.framework ProxyFactory addAdvice
@Override public void addAdvice(Advice advice) throws AopConfigException
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);//from w w w.jav a2s . c o m MessageWriter proxyTarget = (MessageWriter) pf.getProxy(); proxyTarget.writeMessage(); 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);/*from www. j a v a2s.c o m*/ MessageWriter proxy = (MessageWriter) pf.getProxy(); target.writeMessage(); System.out.println(""); proxy.writeMessage(); }
From source file:throwsaop.SimpleThrowsAdvice.java
public static void main(String[] args) { ErrorBean bean = new ErrorBean(); ProxyFactory f = new ProxyFactory(); f.setTarget(bean);//from w w w.ja v a 2s. co m f.addAdvice(new SimpleThrowsAdvice()); ErrorBean proxy = (ErrorBean) f.getProxy(); try { proxy.errorProneMethod(); } catch (Exception e) { } try { proxy.otherErrorProneMethod(); } catch (Exception e) { } }
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);//from w w w. j av a2 s . c o m MessageWriter proxyObj = (MessageWriter) pf.getProxy(); pf2.setTarget(proxyObj); 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);/* w w w . ja v a2 s . co m*/ 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);//from www.j a v a 2 s . co m factory.addAdvice(advice); return (SecureBean) factory.getProxy(); }
From source file:com.github.jasonruckman.sidney.generator.BeanBuilder.java
public static <R> BeanBuilder<R> stub(final Class<R> type) { InstanceFactory<R> fact = new DefaultInstanceFactory<>(type); R stub = fact.newInstance();//from www . j a v a2 s . co m ProxyFactory factory = new ProxyFactory(stub); final Stack<Method> m = new Stack<>(); factory.addAdvice(new MethodInterceptor() { @Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { PropertyDescriptor descriptor = BeanUtils.findPropertyForMethod(methodInvocation.getMethod()); if (descriptor == null) { throw new IllegalStateException(String.format("Method %s is not a getter or setter", methodInvocation.getMethod().getName())); } m.push(methodInvocation.getMethod()); return defaultReturnObjects.get(methodInvocation.getMethod().getReturnType()); } }); return new BeanBuilder<>((R) factory.getProxy(), fact, m); }
From source file:org.LexGrid.LexBIG.caCore.utils.LexEVSCaCoreUtils.java
public static Object createProxy(Object objectToProxy, ApplicationService advice, ProxyHelper proxyHelper) { ProxyFactory pf = new ProxyFactory(objectToProxy); pf.setProxyTargetClass(true);//from www . jav a 2s .co m pf.addAdvice(new LexEVSBeanProxy(advice, proxyHelper)); pf.setExposeProxy(true); return pf.getProxy(); }
From source file:org.jdal.aop.SerializableProxyUtils.java
/** * Create a new Serializable proxy for the given target. * @param target target to proxy/*ww w.j a va2 s . c o m*/ * @param reference serializable reference * @return a new serializable proxy */ private static Object createSerializableProxy(Object target, SerializableReference reference) { ProxyFactory pf = new ProxyFactory(target); pf.setExposeProxy(true); pf.setProxyTargetClass(reference.isProxyTargetClass()); pf.addInterface(SerializableObject.class); pf.addAdvice(new SerializableIntroductionInterceptor(reference)); return pf.getProxy(reference.getBeanFactory().getBeanClassLoader()); }
From source file:oz.hadoop.yarn.api.YarnAssembly.java
/** * //w w w . java 2 s . c o m */ @SuppressWarnings("unchecked") private static WithVcPrMemCount<Void> createV(String command, Class<? extends ApplicationContainerProcessor> applicationContainer, ByteBuffer arguments, String javaShellPath) { ProxyFactory pf = new ProxyFactory(); pf.setInterfaces(WithVcPrMemCount.class); AssemblyAdvice assemblyAdvice = new AssemblyAdvice(command, applicationContainer, arguments, javaShellPath); pf.addAdvice(assemblyAdvice); WithVcPrMemCount<Void> builder = (WithVcPrMemCount<Void>) pf.getProxy(); return builder; }