KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > mock > web > portlet > MockPortletRequestDispatcher


1 /*
2  * Copyright 2002-2006 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.mock.web.portlet;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.portlet.PortletException;
22 import javax.portlet.PortletRequestDispatcher;
23 import javax.portlet.RenderRequest;
24 import javax.portlet.RenderResponse;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.springframework.util.Assert;
30
31 /**
32  * Mock implementation of the {@link javax.portlet.PortletRequestDispatcher} interface.
33  *
34  * @author John A. Lewis
35  * @author Juergen Hoeller
36  * @since 2.0
37  */

38 public class MockPortletRequestDispatcher implements PortletRequestDispatcher {
39
40     private final Log logger = LogFactory.getLog(getClass());
41
42     private final String JavaDoc url;
43
44
45     /**
46      * Create a new MockPortletRequestDispatcher for the given URL.
47      * @param url the URL to dispatch to.
48      */

49     public MockPortletRequestDispatcher(String JavaDoc url) {
50         Assert.notNull(url, "URL must not be null");
51         this.url = url;
52     }
53
54     
55     public void include(RenderRequest request, RenderResponse response) throws PortletException, IOException JavaDoc {
56         Assert.notNull(request, "Request must not be null");
57         Assert.notNull(response, "Response must not be null");
58         if (!(response instanceof MockRenderResponse)) {
59             throw new IllegalArgumentException JavaDoc("MockPortletRequestDispatcher requires MockRenderResponse");
60         }
61         ((MockRenderResponse) response).setIncludedUrl(this.url);
62         if (logger.isDebugEnabled()) {
63             logger.debug("MockPortletRequestDispatcher: including URL [" + this.url + "]");
64     }
65     }
66
67 }
68
Popular Tags