01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tcspring;
05:
06: import org.springframework.context.ApplicationContext;
07: import org.springframework.context.support.ClassPathXmlApplicationContext;
08:
09: import com.tc.aspectwerkz.AspectContext;
10: import com.tc.aspectwerkz.aspect.AbstractAspectContainer;
11:
12: import java.util.Map;
13:
14: /**
15: * Spring custom aspect container, grabs the aspects from the bean factory.
16: *
17: * @author Jonas Bonér
18: */
19: public final class SpringAspectContainer extends
20: AbstractAspectContainer {
21:
22: public static final String BEAN_FACTORY_KEY = "bean-factory";
23:
24: private final ApplicationContext m_beanFactory;
25:
26: /**
27: * Create a new Spring aspect container.
28: *
29: * @param aspectClass
30: * @param aopSystemClassLoader the classloader of the defining system (not necessary the one of the aspect class)
31: * @param uuid
32: * @param qualifiedName
33: * @param parameters
34: */
35: public SpringAspectContainer(final Class aspectClass,
36: final ClassLoader aopSystemClassLoader, final String uuid,
37: final String qualifiedName, final Map parameters) {
38: super (aspectClass, aopSystemClassLoader, uuid, qualifiedName,
39: parameters);
40: String beanConfig = (String) parameters.get(BEAN_FACTORY_KEY);
41: if (beanConfig == null) {
42: throw new AssertionError();
43: }
44:
45: m_beanFactory = new ClassPathXmlApplicationContext(beanConfig);
46: }
47:
48: /**
49: * Creates a new aspect by getting it from the spring bean factory for the proxy.
50: *
51: * @param aspectContext
52: * @return an aspect instance
53: */
54: protected Object createAspect(final AspectContext aspectContext) {
55: return m_beanFactory.getBean(aspectContext.getName());
56: }
57: }
|