Classes used in the examples

4.3.9.RELEASE Spring Framework 211 public class TemplateParserContext implements ParserContext { public String getExpressionPrefix { return { ; } public String getExpressionSuffix { return } ; } public boolean isTemplate { return true; } }

10.6 Classes used in the examples

Inventor.java 4.3.9.RELEASE Spring Framework 212 package org.spring.samples.spel.inventor; import java.util.Date; import java.util.GregorianCalendar; public class Inventor { private String name; private String nationality; private String[] inventions; private Date birthdate; private PlaceOfBirth placeOfBirth; public InventorString name, String nationality { GregorianCalendar c= new GregorianCalendar; this .name = name; this .nationality = nationality; this .birthdate = c.getTime; } public InventorString name, Date birthdate, String nationality { this .name = name; this .nationality = nationality; this .birthdate = birthdate; } public Inventor { } public String getName { return name; } public void setNameString name { this .name = name; } public String getNationality { return nationality; } public void setNationalityString nationality { this .nationality = nationality; } public Date getBirthdate { return birthdate; } public void setBirthdateDate birthdate { this .birthdate = birthdate; } public PlaceOfBirth getPlaceOfBirth { return placeOfBirth; } public void setPlaceOfBirthPlaceOfBirth placeOfBirth { this .placeOfBirth = placeOfBirth; } public void setInventionsString[] inventions { this .inventions = inventions; } public String[] getInventions { return inventions; } } 4.3.9.RELEASE Spring Framework 213 PlaceOfBirth.java package org.spring.samples.spel.inventor; public class PlaceOfBirth { private String city; private String country; public PlaceOfBirthString city { this .city=city; } public PlaceOfBirthString city, String country { this city; this .country = country; } public String getCity { return city; } public void setCityString s { this .city = s; } public String getCountry { return country; } public void setCountryString country { this .country = country; } } Society.java 4.3.9.RELEASE Spring Framework 214 package org.spring.samples.spel.inventor; import java.util.; public class Society { private String name; public static String Advisors = advisors ; public static String President = president ; private ListInventor members = new ArrayListInventor; private Map officers = new HashMap; public List getMembers { return members; } public Map getOfficers { return officers; } public String getName { return name; } public void setNameString name { this .name = name; } public boolean isMemberString name { for Inventor inventor : members { if inventor.getName.equalsname { return true; } } return false; } } 4.3.9.RELEASE Spring Framework 215

11. Aspect Oriented Programming with Spring

11.1 Introduction

Aspect-Oriented Programming AOP complements Object-Oriented Programming OOP by providing another way of thinking about program structure. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect. Aspects enable the modularization of concerns such as transaction management that cut across multiple types and objects. Such concerns are often termed crosscutting concerns in AOP literature. One of the key components of Spring is the AOP framework. While the Spring IoC container does not depend on AOP, meaning you do not need to use AOP if you don’t want to, AOP complements Spring IoC to provide a very capable middleware solution. Spring 2.0 AOP Spring 2.0 introduces a simpler and more powerful way of writing custom aspects using either a schema-based approach or the AspectJ annotation style . Both of these styles offer fully typed advice and use of the AspectJ pointcut language, while still using Spring AOP for weaving. The Spring 2.0 schema- and AspectJ-based AOP support is discussed in this chapter. Spring 2.0 AOP remains fully backwards compatible with Spring 1.2 AOP, and the lower-level AOP support offered by the Spring 1.2 APIs is discussed in the following chapter . AOP is used in the Spring Framework to… • … provide declarative enterprise services, especially as a replacement for EJB declarative services. The most important such service is declarative transaction management . • … allow users to implement custom aspects, complementing their use of OOP with AOP. Note If you are interested only in generic declarative services or other pre-packaged declarative middleware services such as pooling, you do not need to work directly with Spring AOP, and can skip most of this chapter. AOP concepts Let us begin by defining some central AOP concepts and terminology. These terms are not Spring- specific… unfortunately, AOP terminology is not particularly intuitive; however, it would be even more confusing if Spring used its own terminology. • Aspect: a modularization of a concern that cuts across multiple classes. Transaction management is a good example of a crosscutting concern in enterprise Java applications. In Spring AOP, aspects are implemented using regular classes the schema-based approach or regular classes annotated with the Aspect annotation the AspectJ style . • Join point: a point during the execution of a program, such as the execution of a method or the handling of an exception. In Spring AOP, a join point always represents a method execution.