KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > portlet > handler > SimplePortletHandlerAdapter


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.web.portlet.handler;
18
19 import javax.portlet.ActionRequest;
20 import javax.portlet.ActionResponse;
21 import javax.portlet.Portlet;
22 import javax.portlet.RenderRequest;
23 import javax.portlet.RenderResponse;
24
25 import org.springframework.web.portlet.HandlerAdapter;
26 import org.springframework.web.portlet.ModelAndView;
27
28 /**
29  * Adapter to use the Portlet interface with the generic DispatcherPortlet.
30  * Calls the Portlet's <code>render</code> and <code>processAction</code>
31  * methods to handle a request.
32  *
33  * <p>This adapter is not activated by default; it needs to be defined as a
34  * bean in the DispatcherPortlet context. It will automatically apply to
35  * mapped handler beans that implement the Portlet interface then.
36  *
37  * <p>Note that Portlet instances defined as bean will not receive initialization
38  * and destruction callbacks, unless a special post-processor such as
39  * SimplePortletPostProcessor is defined in the DispatcherPortlet context.
40  *
41  * <p><b>Alternatively, consider wrapping a Portlet with Spring's
42  * PortletWrappingController.</b> This is particularly appropriate for
43  * existing Portlet classes, allowing to specify Portlet initialization
44  * parameters, etc.
45  *
46  * @author John A. Lewis
47  * @since 2.0
48  * @see javax.portlet.Portlet
49  * @see SimplePortletPostProcessor
50  * @see org.springframework.web.portlet.mvc.PortletWrappingController
51  */

52 public class SimplePortletHandlerAdapter implements HandlerAdapter {
53     
54     public boolean supports(Object JavaDoc handler) {
55         return (handler instanceof Portlet);
56     }
57
58     public void handleAction(ActionRequest request, ActionResponse response, Object JavaDoc handler)
59             throws Exception JavaDoc {
60
61         ((Portlet) handler).processAction(request, response);
62     }
63
64     public ModelAndView handleRender(RenderRequest request, RenderResponse response, Object JavaDoc handler)
65             throws Exception JavaDoc {
66
67         ((Portlet) handler).render(request, response);
68         return null;
69     }
70
71 }
72
Popular Tags