KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > interceptor > action > ActionInterceptor


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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  * $Header:$
17  */

18 package org.apache.beehive.netui.pageflow.interceptor.action;
19
20 import org.apache.beehive.netui.pageflow.interceptor.AbstractInterceptor;
21 import org.apache.beehive.netui.pageflow.interceptor.InterceptorChain;
22 import org.apache.beehive.netui.pageflow.interceptor.InterceptorContext;
23 import org.apache.beehive.netui.pageflow.interceptor.InterceptorException;
24
25
26 /**
27  * Base class for Page Flow action interceptors. These are configured in /WEB-INF/beehive-netui-config.xml like this:
28  * <pre>
29  * &lt;netui-config xmlns="http://beehive.apache.org/netui/2004/server/config"&gt;
30  * ...
31  *
32  * &lt;pageflow-action-interceptors&gt;
33  * &lt;global&gt;
34  * &lt;before-action&gt;
35  * &lt;action-interceptor&gt;
36  * &lt;interceptor-class&gt;test.BeforeActionInterceptor1&lt;/interceptor-class&gt;
37  * &lt;/action-interceptor&gt;
38  * &lt;action-interceptor&gt;
39  * &lt;interceptor-class&gt;test.BeforeActionInterceptor2&lt;/interceptor-class&gt;
40  * &lt;/action-interceptor&gt;
41  * ...
42  * &lt;/before-action&gt;
43  * &lt;after-action&gt;
44  * &lt;action-interceptor&gt;
45  * &lt;interceptor-class&gt;test.AfterActionInterceptor1&lt;/interceptor-class&gt;
46  * &lt;/action-interceptor&gt;
47  * &lt;action-interceptor&gt;
48  * &lt;interceptor-class&gt;test.AfterActionInterceptor2&lt;/interceptor-class&gt;
49  * &lt;/action-interceptor&gt;
50  * &lt;/after-action&gt;
51  * &lt;/global&gt;
52  * &lt;/pageflow-action-interceptors&gt;
53  *
54  * ...
55  * &lt;/netui-config&gt;
56  *
57  * </pre>
58  *
59  * Note that a registered ActionInterceptor is created and cached as a single instance per ServletContext.
60  * It should not hold any per-request or per-session state.
61  */

62 public abstract class ActionInterceptor
63         extends AbstractInterceptor
64 {
65     /**
66      * Callback invoked before the action is processed. During this method, {@link #setOverrideForward} may be called
67      * to:
68      * <ul>
69      * <li>change the destination URI and thus prevent the action from running, or,</li>
70      * <li>set the destination URI to <code>null</code> (no forwarding) and thus prevent the action from running, or,</li>
71      * <li>
72      * "inject" an entire nested page flow to run before the action is invoked. If the override forward URI
73      * is a nested page flow, then it will run until it raises one of its return actions. At that point,
74      * {@link #afterNestedIntercept} is called on <i>this interceptor</i>, which can again choose to override
75      * the forward or allow the original action to run.
76      * </li>
77      * </ul>
78      *
79      * {@link InterceptorChain#continueChain} is called to invoke the rest of the
80      * interceptor chain, anywhere within this method (e.g., at the end, or within a try/finally).
81      *
82      * @param context the current ActionInterceptorContext.
83      * @param chain the interceptor chain. Calling <code>continueChain</code> on this runs the rest of the interceptors.
84      */

85     public abstract void preAction( ActionInterceptorContext context, InterceptorChain chain )
86             throws InterceptorException;
87     
88     /**
89      * Callback invoked before the action is processed. {@link #preAction} may be used instead.
90      */

91     public void preInvoke( InterceptorContext context, InterceptorChain chain ) throws InterceptorException
92     {
93         preAction( ( ActionInterceptorContext ) context, chain );
94     }
95     
96     /**
97      * Callback invoked after the action is processed. During this method, {@link #setOverrideForward} may be called
98      * to:
99      * <ul>
100      * <li>change the destination URI and thus override the one returned from the action, or,</li>
101      * <li>set the destination URI to <code>null</code> (no forwarding).</li>
102      * </ul>
103      *
104      * {@link InterceptorChain#continueChain} is called to invoke the rest of the
105      * interceptor chain, anywhere within this method (e.g., at the end, or within a try/finally).
106      *
107      * @param context the current ActionInterceptorContext.
108      * @param chain the interceptor chain. Calling <code>continueChain</code> on this runs the rest of the interceptors.
109      */

110     public abstract void postAction( ActionInterceptorContext context, InterceptorChain chain )
111         throws InterceptorException;
112     
113     /**
114      * Callback invoked after the action is processed. {@link #postAction} may be used instead.
115      */

116     public void postInvoke( InterceptorContext context, InterceptorChain chain ) throws InterceptorException
117     {
118         postAction( ( ActionInterceptorContext ) context, chain );
119     }
120
121     /**
122      * Callback invoked after a nested page flow has been "injected" by {@link #preAction}, and before the original
123      * action has run. During this method, {@link #setOverrideForward} may be called to:
124      *
125      * <ul>
126      * <li>change the destination URI that was returned by the action, or,</li>
127      * <li>set the destination URI to <code>null</code> (no forwarding).</li>
128      * </ul>
129      *
130      * {@link InterceptorChain#continueChain} is called to invoke the rest of the
131      * interceptor chain, anywhere within this method (e.g., at the end, or within a try/finally).
132      *
133      * @param context an extension of {@link ActionInterceptorContext} which contains the return action from the
134      * injected nested page flow.
135      * @throws InterceptorException
136      */

137     public abstract void afterNestedIntercept( AfterNestedInterceptContext context )
138             throws InterceptorException;
139
140     /**
141      * Override the Forward, either before or after the target action is run. See {@link #preAction} and
142      * {@link #postAction} for information on how this is used.
143      *
144      * @param forward an InterceptorForward that will override the target action's forward; or <code>null</code> to
145      * cancel navigation.
146      * @param context the current ActionInterceptorContext.
147      */

148     protected void setOverrideForward( InterceptorForward forward, ActionInterceptorContext context )
149     {
150         context.setOverrideForward( forward, this );
151     }
152
153     /**
154      * Optional method that "wraps" the target action invocation. This is mainly useful for surrounding an action
155      * (and the rest of the interceptor chain) with try/catch/finally. This default implementation simply <i>returns</i>
156      * <code>continueChain</code> on the passed-in InterceptorChain, which allows the rest of the interceptors
157      * <i>and</i> the action to run.
158      *
159      * @param context the current ActionInterceptorContext.
160      * @param chain the interceptor chain. This chain is different from the ones passed to {@link #preAction} and
161      * {@link #postAction} in that the action invocation itself is included in it.
162      * @return the ActionForward returned by the action.
163      */

164     public Object JavaDoc wrapAction( ActionInterceptorContext context, InterceptorChain chain )
165         throws InterceptorException
166     {
167         return chain.continueChain();
168     }
169 }
170
Popular Tags