KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > util > FakeRequestDispatcher


1 /*
2  * Copyright 2005 Joe Walker
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.directwebremoting.util;
18
19 import javax.servlet.RequestDispatcher JavaDoc;
20 import javax.servlet.ServletRequest JavaDoc;
21 import javax.servlet.ServletResponse JavaDoc;
22
23 /**
24  * Mock implementation of the RequestDispatcher interface.
25  * @author Rod Johnson
26  * @author Juergen Hoeller
27  * @author Joe Walker [joe at getahead dot ltd dot uk]
28  */

29 public class FakeRequestDispatcher implements RequestDispatcher JavaDoc
30 {
31     /**
32      * Create a new FakeRequestDispatcher for the given URL.
33      * @param url the URL to dispatch to.
34      */

35     public FakeRequestDispatcher(String JavaDoc url)
36     {
37         this.url = url;
38     }
39
40     /* (non-Javadoc)
41      * @see javax.servlet.RequestDispatcher#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
42      */

43     public void forward(ServletRequest JavaDoc request, ServletResponse JavaDoc response)
44     {
45         if (response.isCommitted())
46         {
47             throw new IllegalStateException JavaDoc("Cannot perform forward - response is already committed");
48         }
49
50         if (!(response instanceof FakeHttpServletResponse))
51         {
52             throw new IllegalArgumentException JavaDoc("FakeRequestDispatcher requires FakeHttpServletResponse");
53         }
54
55         ((FakeHttpServletResponse) response).setForwardedUrl(this.url);
56
57         if (log.isDebugEnabled())
58         {
59             log.debug("FakeRequestDispatcher: forwarding to URL [" + this.url + "]");
60         }
61     }
62
63     /* (non-Javadoc)
64      * @see javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
65      */

66     public void include(ServletRequest JavaDoc request, ServletResponse JavaDoc response)
67     {
68         if (!(response instanceof FakeHttpServletResponse))
69         {
70             throw new IllegalArgumentException JavaDoc("FakeRequestDispatcher requires FakeHttpServletResponse");
71         }
72
73         ((FakeHttpServletResponse) response).setIncludedUrl(this.url);
74
75         if (log.isDebugEnabled())
76         {
77             log.debug("FakeRequestDispatcher: including URL [" + this.url + "]");
78         }
79     }
80
81     private final String JavaDoc url;
82
83     /**
84      * The log stream
85      */

86     private static final Logger log = Logger.getLogger(FakeRequestDispatcher.class);
87 }
88
Popular Tags