Aspect Hello World Example : Spring Aspect : Spring : Java examples (example source code) Organized by topic

Java
C++
PHP


Java  »  Spring   » [  Spring Aspect  ]  Screenshots 
 



Aspect Hello World Example

/*
Pro Spring
By Rob Harrop
Jan Machacek
ISBN: 1-59059-461-4
Publisher: Apress
*/



///////////////////////////////////////////////////////////////////////////////////////

public interface IMessageWriter {

    public void writeMessage();
}


///////////////////////////////////////////////////////////////////////////////////////


public class MessageWriter implements IMessageWriter{

    public void writeMessage() {
        System.out.print("World");
    }

}
///////////////////////////////////////////////////////////////////////////////////////

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;


public class MessageDecorator implements MethodInterceptor {

    public Object invoke(MethodInvocation invocationthrows Throwable {
        System.out.print("Hello ");
        Object retVal = invocation.proceed();
        System.out.println("!");
        return retVal;
    }

}

///////////////////////////////////////////////////////////////////////////////////////
import org.springframework.aop.framework.ProxyFactory;

public class HelloWorldAOPExample {

    public static void main(String[] args) {
        MessageWriter target = new MessageWriter();
        
        // create the proxy
        ProxyFactory pf = new ProxyFactory();

        pf.addAdvice(new MessageDecorator());
        pf.setTarget(target);


        MessageWriter proxy = (MessageWriterpf.getProxy();
        
        // write the messages
        target.writeMessage();
        System.out.println("");
        proxy.writeMessage();
    }
}
           
       
Download: SpringHelloWorldExample.zip   ( 1,479  K )  
Related examples in the same category
1.  Profiling ExampleHas Download File
2.  Introduction Config ExampleHas Download File
3.  Security ExampleHas Download File
4.  Simple After Returning AdviceHas Download File
5.  Simple Before AdviceHas Download File
6.  Simple Throws AdviceHas Download File
7.  Composable Pointcut ExampleHas Download File
8.  Control Flow ExampleHas Download File
9.  Dynamic Pointcut Example Has Download File
10.  Hello World With PointcutHas Download File
11.  Spring Aspect Introduction ExampleHas Download File
12.  Static Pointcut ExampleHas Download File
13.  Name Pointcut ExampleHas Download File
14.  Name Pointcut Using AdvisorHas Download File
15.  Proxy Factory Bean ExampleHas Download File
16.  Proxy Perf TestHas Download File
17.  Regexp Pointcut ExampleHas Download File
18.  After Advice ExampleHas Download File
19.  AspectJ Example from Pro SpringHas Download File
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.