A simple yet complete and working example would help me tremendously
Try this:
Code:
package introductions;
public class Car {}
Code:
package introductions;
public interface PaintColor {
public String getColor();
public void setColor(String color);
}
Code:
package introductions;
import org.springframework.aop.support.DelegatingIntroductionInterceptor;
public class PaintColorMixin extends DelegatingIntroductionInterceptor
implements PaintColor {
private String color = "Not Set";
public String getColor() {return color;}
public void setColor(String color) {this.color = color;}
}
Code:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="carTarget" class="introductions.Car" singleton="false"></bean>
<bean id="paintColorMixin" class="introductions.PaintColorMixin" singleton="false"></bean>
<bean id="paintColorAdvisor" class="org.springframework.aop.support.DefaultIntroductionAdvisor" singleton="false">
<constructor-arg>
<ref bean="paintColorMixin"/>
</constructor-arg>
</bean>
<bean id="car" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyTargetClass"> <value>true</value> </property>
<property name="interceptorNames">
<list>
<value>paintColorAdvisor</value>
</list>
</property>
<property name="target"> <ref bean="carTarget"/> </property>
</bean>
</beans>
Code:
package introductions;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class IntroductionDriver {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"/introductions/introductions.xml");
Car car = (Car) ctx.getBean("car");
PaintColor carColor = (PaintColor) car;
// test interfaces
System.out.println("Is Car?: " + (car instanceof Car));
System.out.println("Is PaintColor?: " + (car instanceof PaintColor));
// test is modified implementation
System.out.println("Get color: " + carColor.getColor());
carColor.setColor("Blue");
System.out.println("Get color: " + carColor.getColor());
carColor.setColor("Red");
System.out.println("Get color: " + carColor.getColor());
}
}