KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > struts > ActionServletAwareProcessor


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.struts;
18
19 import org.apache.struts.action.Action;
20 import org.apache.struts.action.ActionServlet;
21
22 import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
23
24 /**
25  * BeanPostProcessor implementation that passes the ActionServlet to beans
26  * that extend the Struts Action class. Invokes <code>Action.setServlet</code>
27  * with <code>null</dode> on bean destruction, providing the same lifecycle
28  * handling as Struts' ActionServlet.
29  *
30  * <p>ContextLoaderPlugIn automatically registers this processor
31  * with the underlying bean factory of its WebApplicationContext.
32  * Applications do not need to use this class directly.
33  *
34  * @author Juergen Hoeller
35  * @since 1.0.1
36  * @see ContextLoaderPlugIn
37  * @see org.apache.struts.action.Action#setServlet
38  */

39 public class ActionServletAwareProcessor implements DestructionAwareBeanPostProcessor {
40
41     private final ActionServlet actionServlet;
42
43
44     /**
45      * Create a new ActionServletAwareProcessor for the given servlet.
46      */

47     public ActionServletAwareProcessor(ActionServlet actionServlet) {
48         this.actionServlet = actionServlet;
49     }
50
51
52     public Object JavaDoc postProcessBeforeInitialization(Object JavaDoc bean, String JavaDoc beanName) {
53         if (bean instanceof Action) {
54             ((Action) bean).setServlet(this.actionServlet);
55         }
56         return bean;
57     }
58
59     public Object JavaDoc postProcessAfterInitialization(Object JavaDoc bean, String JavaDoc beanName) {
60         return bean;
61     }
62
63     public void postProcessBeforeDestruction(Object JavaDoc bean, String JavaDoc beanName) {
64         if (bean instanceof Action) {
65             ((Action) bean).setServlet(null);
66         }
67     }
68
69 }
70
Popular Tags