KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > interceptor > request > RequestInterceptorContext


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.request;
19
20 import org.apache.beehive.netui.pageflow.interceptor.InterceptorContext;
21 import org.apache.beehive.netui.pageflow.internal.InternalConstants;
22 import org.apache.beehive.netui.util.config.ConfigUtil;
23 import org.apache.beehive.netui.util.config.bean.RequestInterceptors;
24
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.ServletContext JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30
31 /**
32  * Context passed to methods on {@link RequestInterceptor}.
33  */

34 public class RequestInterceptorContext
35         extends InterceptorContext
36 {
37     private static final String JavaDoc INTERCEPTORS_LIST_ATTR = InternalConstants.ATTR_PREFIX + "requestInterceptors";
38     
39     private transient ServletContext JavaDoc _servletContext;
40     private transient HttpServletRequest JavaDoc _request;
41     private transient HttpServletResponse JavaDoc _response;
42     
43     public RequestInterceptorContext( HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response,
44                                       ServletContext JavaDoc servletContext )
45     {
46         _request = request;
47         _response = response;
48         _servletContext = servletContext;
49     }
50     
51     public void cancelRequest( RequestInterceptor interceptor )
52     {
53         setResultOverride( null, interceptor );
54     }
55     
56     public boolean requestWasCancelled()
57     {
58         return hasResultOverride() && getResultOverride() == null;
59     }
60     
61     public HttpServletRequest JavaDoc getRequest()
62     {
63         return _request;
64     }
65     
66     public HttpServletResponse JavaDoc getResponse()
67     {
68         return _response;
69     }
70     
71     public ServletContext JavaDoc getServletContext()
72     {
73         return _servletContext;
74     }
75     
76     public static void init( ServletContext JavaDoc servletContext )
77     {
78         RequestInterceptors requestInterceptors = ConfigUtil.getConfig().getRequestInterceptors();
79         
80         if ( requestInterceptors != null )
81         {
82             RequestInterceptors.Global globalRequestInterceptors = requestInterceptors.getGlobal();
83             
84             if ( globalRequestInterceptors != null )
85             {
86                 org.apache.beehive.netui.util.config.bean.Interceptor[] interceptors =
87                         globalRequestInterceptors.getRequestInterceptorArray();
88                 ArrayList JavaDoc/*< Interceptor >*/ interceptorsList = new ArrayList JavaDoc/*< Interceptor >*/();
89                 addInterceptors( interceptors, interceptorsList, RequestInterceptor.class );
90                 servletContext.setAttribute( INTERCEPTORS_LIST_ATTR, interceptorsList );
91             }
92         }
93     }
94     
95     public List JavaDoc/*< Interceptor >*/ getRequestInterceptors()
96     {
97         return ( List JavaDoc/*< Interceptor >*/ ) getServletContext().getAttribute( INTERCEPTORS_LIST_ATTR );
98     }
99     
100     public static void addInterceptor( ServletContext JavaDoc servletContext, RequestInterceptor interceptor )
101     {
102         List JavaDoc/*< Interceptor >*/ interceptorsList =
103                 ( List JavaDoc/*< Interceptor >*/ ) servletContext.getAttribute( INTERCEPTORS_LIST_ATTR );
104         if ( interceptorsList == null ) interceptorsList = new ArrayList JavaDoc/*< Interceptor >*/();
105         interceptorsList.add( interceptor );
106         servletContext.setAttribute( INTERCEPTORS_LIST_ATTR, interceptorsList );
107     }
108 }
109
Popular Tags