Method Lookup : AOP « Spring « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » Spring » AOPScreenshots 
Method Lookup

       
File: context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

  <bean id="dataService" class="DataServiceImpl">
    <lookup-method name="getDataDao" bean="dataDao"/>
  </bean>

  <bean id="dataDao" singleton="false"
        class="StatefulDataDataDaoImpl">
  </bean>

</beans>


File: Main.java

import java.util.Date;
import java.util.GregorianCalendar;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

class Main {
  public static void main(String args[]) throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext(
        "context.xml");
    DataService ws = (DataServicectx.getBean("dataService");

    Double high = ws.getHistoricalHigh(new GregorianCalendar(200401).getTime());
    System.out.println("High was: " + high);

    ws = new DataServiceImpl() {
      protected DataDao getDataDao() {
        return null;
      }
    };
  }
}

abstract class DataServiceImpl implements DataService {

  protected abstract DataDao getDataDao();

  public Double getHistoricalHigh(Date date) {
    DataData wd = getDataDao().find(date);
    if (wd != null)
      return new Double(wd.getHigh());
    return null;
  }
}

interface DataService {
  Double getHistoricalHigh(Date date);
}

class DataData {

  Date date;

  double low;

  double high;
  public Date getDate() {
    return date;
  }

  public void setDate(Date date) {
    this.date = date;
  }

  public double getLow() {
    return low;
  }

  public void setLow(double low) {
    this.low = low;
  }

  public double getHigh() {
    return high;
  }

  public void setHigh(double high) {
    this.high = high;
  }
}

interface DataDao {

  DataData find(Date date);

  DataData save(Date date);

  DataData update(Date date);
}

class StatefulDataDataDaoImpl implements DataDao {

  public DataData find(Date date) {

    DataData wd = new DataData();
    wd.setDate((Datedate.clone());
    wd.setLow(5);
    wd.setHigh(15);
    return wd;
  }

  public DataData save(Date date) {
    throw new UnsupportedOperationException("This class uses static data only");
  }

  public DataData update(Date date) {
    throw new UnsupportedOperationException("This class uses static data only");
  }
}




           
       
Spring-MethodLoopup.zip( 2,895 k)
Related examples in the same category
1.Spring Tracing Aspect
2.Method Before Advice
3.Matcher For Getter And Setter
4.Spring AOP Examples
5.Jdk Regexp Method Pointcut
6.Customizable TraceInterceptor
7.Concurrency Throttle Interceptor
8.ComposablePointcut Union
9.ComposablePointcut Intersection
10.AspectJ Expression Pointcut
11.AspectJ AutoProxy
12.Aspect Filter
13.Aspect Annotation Pointcut AroundAfter
14.Aspect Annotation
15.AOP Annotation
16.Annotation Scope
17.Annotation Component
18.Annotated Autowiring
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.