Example usage for org.springframework.aop.framework ProxyFactory getProxy

List of usage examples for org.springframework.aop.framework ProxyFactory getProxy

Introduction

In this page you can find the example usage for org.springframework.aop.framework ProxyFactory getProxy.

Prototype

public Object getProxy() 

Source Link

Document

Create a new proxy according to the settings in this factory.

Usage

From source file:staticpc.StaticPointcutExample.java

public static void main(String[] args) {
    BeanOne one = new BeanOne();
    BeanTwo two = new BeanTwo();
    BeanOne proxyOne;/*from   ww  w .  j ava2  s.com*/
    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:aop.SimpleBeforeAdvice.java

public static void main(String[] args) {
    MessageWriter target = new MessageWriter();
    ProxyFactory pf = new ProxyFactory();
    pf.addAdvice(new SimpleBeforeAdvice());
    pf.setTarget(target);//w w w.  ja va 2  s .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   w w w .  j a  v  a  2  s . com*/

    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  ww.jav a 2 s  .  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);// ww w. ja v a  2 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:introducitons.IntroducitonExample.java

public static void main(String[] args) {
    TargetBean target = new TargetBean();
    target.setName("Loup Garou");
    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(target);/*from   ww w .ja v  a2s.c o  m*/

    Advisor advisor = new IsModifiedAdvisor();
    pf.addAdvisor(advisor);
    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: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);//from  w  ww  .j av a  2s . co m

    UserService userServiceProxy = (UserService) proxyFactory.getProxy();
    userServiceProxy.addUser();

}

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);/*w  w w  . ja  v  a 2s  . c o m*/
    factory.addAdvice(advice);
    return (SecureBean) factory.getProxy();
}

From source file:profiling.ProfillingExample.java

private static WorkerBean getWorkerBean() {
    WorkerBean target = new WorkerBean();
    ProxyFactory factory = new ProxyFactory();
    factory.setTarget(target);// ww  w.j  a va 2s  .  c om
    factory.addAdvice(new ProfilingInterceptor());
    return (WorkerBean) factory.getProxy();
}

From source file:org.openmrs.module.jmx.util.MBeanProxifier.java

/**
 * Gets a proxied MBean//from  w  ww .  ja va 2s  . 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();
}