01: /*
02: * Copyright (c) 2005 Opensymphony. All Rights Reserved.
03: */
04: package com.opensymphony.webwork.spring;
05:
06: import com.opensymphony.webwork.spring.lifecycle.ApplicationContextSessionListener;
07: import com.opensymphony.xwork.ActionContext;
08: import com.opensymphony.xwork.spring.SpringProxyableObjectFactory;
09: import org.apache.commons.logging.Log;
10: import org.apache.commons.logging.LogFactory;
11: import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
12: import org.springframework.context.ApplicationContext;
13:
14: import java.util.Map;
15:
16: /**
17: * SessionContextSpringProxyableObjectFactory
18: *
19: * @author Jason Carreira <jcarreira@eplus.com>
20: */
21: public class SessionContextSpringProxyableObjectFactory extends
22: SpringProxyableObjectFactory {
23: private static final Log log = LogFactory
24: .getLog(SessionContextSpringProxyableObjectFactory.class);
25:
26: protected ApplicationContext getApplicationContext(Map context) {
27: if (log.isDebugEnabled()) {
28: log.debug("Getting the session-scoped app context");
29: }
30: if (context == null) {
31: return appContext;
32: }
33: Map session = (Map) context.get(ActionContext.SESSION);
34: if (session == null) {
35: log.warn("There is no session map in the ActionContext.");
36: return appContext;
37: }
38: ApplicationContext sessionContext = (ApplicationContext) session
39: .get(ApplicationContextSessionListener.APP_CONTEXT_SESSION_KEY);
40: if (sessionContext == null) {
41: throw new IllegalStateException(
42: "There is no application context in the user's session.");
43: }
44: return sessionContext;
45: }
46:
47: public Object buildBean(String beanName, Map extraContext)
48: throws Exception {
49: Object bean = super .buildBean(beanName, extraContext);
50: AutowireCapableBeanFactory autoWiringBeanFactory = findAutoWiringBeanFactory(getApplicationContext(extraContext));
51: return autoWireBean(bean, autoWiringBeanFactory);
52: }
53:
54: }
|