01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.injection.handler;
16:
17: import javax.servlet.ServletContext;
18:
19: import org.apache.commons.logging.Log;
20: import org.apache.commons.logging.LogFactory;
21: import org.strecks.context.ActionContext;
22: import org.strecks.spring.SpringUtils;
23: import org.strecks.util.Assert;
24:
25: /**
26: * InjectionHandler to find a named Spring bean. Uses
27: * <code>WebApplicationContextUtils.getWebApplicationContext(servletContext)</code> to obtain the
28: * Spring application context, then <code>context.getBean(beanName)</code> to locate the bean
29: * itself. Throws <code>ApplicationConfigurationException</code> if named bean is not present in application
30: * context
31: * @author Phil Zoio
32: */
33: public class SpringBeanInjectionHandler implements InjectionHandler {
34:
35: Log log = LogFactory.getLog(SpringBeanInjectionHandler.class);
36:
37: private String beanName;
38:
39: public SpringBeanInjectionHandler(String parameterName) {
40:
41: super ();
42:
43: Assert.notNull(parameterName);
44: this .beanName = parameterName;
45:
46: }
47:
48: public String getBeanName() {
49: return beanName;
50: }
51:
52: public Object getValue(ActionContext injectionContext) {
53: ServletContext servletContext = injectionContext.getContext();
54: return SpringUtils.getSpringBean(servletContext, beanName);
55: }
56:
57: }
|