001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.portlet; 018 019import javax.portlet.ActionRequest; 020import javax.portlet.ActionResponse; 021import javax.portlet.EventRequest; 022import javax.portlet.EventResponse; 023import javax.portlet.RenderRequest; 024import javax.portlet.RenderResponse; 025import javax.portlet.ResourceRequest; 026import javax.portlet.ResourceResponse; 027 028/** 029 * Portlet MVC framework SPI interface, allowing parameterization of core MVC workflow. 030 * 031 * <p>Interface that must be implemented for each handler type to handle a request. 032 * This interface is used to allow the DispatcherPortlet to be indefinitely 033 * extensible. The DispatcherPortlet accesses all installed handlers through this 034 * interface, meaning that it does not contain code specific to any handler type. 035 * 036 * <p>Note that a handler can be of type Object. This is to enable handlers from 037 * other frameworks to be integrated with this framework without custom coding. 038 * 039 * <p>This interface is not intended for application developers. It is available 040 * to handlers who want to develop their own web workflow. 041 * 042 * <p>Note: Implementations can implement the Ordered interface to be able to 043 * specify a sorting order and thus a priority for getting applied by 044 * DispatcherPortlet. Non-Ordered instances get treated as lowest priority. 045 * 046 * @author John A. Lewis 047 * @since 2.0 048 * @see org.springframework.web.portlet.mvc.SimpleControllerHandlerAdapter 049 */ 050public interface HandlerAdapter { 051 052 /** 053 * Given a handler instance, return whether or not this HandlerAdapter can 054 * support it. Typical HandlerAdapters will base the decision on the handler 055 * type. HandlerAdapters will usually only support one handler type each. 056 * <p>A typical implementation: 057 * <p>{@code 058 * return (handler instanceof MyHandler); 059 * } 060 * @param handler handler object to check 061 * @return whether or not this object can use the given handler 062 */ 063 boolean supports(Object handler); 064 065 /** 066 * Use the given handler to handle this action request. 067 * The workflow that is required may vary widely. 068 * @param request current action request 069 * @param response current action response 070 * @param handler handler to use. This object must have previously been passed 071 * to the {@code supports} method of this interface, which must have 072 * returned true. 073 * @throws Exception in case of errors 074 * @see javax.portlet.Portlet#processAction 075 */ 076 void handleAction(ActionRequest request, ActionResponse response, Object handler) throws Exception; 077 078 /** 079 * Use the given handler to handle this render request. 080 * The workflow that is required may vary widely. 081 * @param request current render request 082 * @param response current render response 083 * @param handler handler to use. This object must have previously been passed 084 * to the {@code supports} method of this interface, which must have 085 * returned {@code true}. 086 * @throws Exception in case of errors 087 * @return ModelAndView object with the name of the view and the required 088 * model data, or {@code null} if the request has been handled directly 089 * @see javax.portlet.Portlet#render 090 */ 091 ModelAndView handleRender(RenderRequest request, RenderResponse response, Object handler) throws Exception; 092 093 /** 094 * Use the given handler to handle this resource request. 095 * The workflow that is required may vary widely. 096 * @param request current render request 097 * @param response current render response 098 * @param handler handler to use. This object must have previously been passed 099 * to the {@code supports} method of this interface, which must have 100 * returned {@code true}. 101 * @throws Exception in case of errors 102 * @return ModelAndView object with the name of the view and the required 103 * model data, or {@code null} if the request has been handled directly 104 * @see javax.portlet.ResourceServingPortlet#serveResource 105 */ 106 ModelAndView handleResource(ResourceRequest request, ResourceResponse response, Object handler) throws Exception; 107 108 /** 109 * Use the given handler to handle this event request. 110 * The workflow that is required may vary widely. 111 * @param request current action request 112 * @param response current action response 113 * @param handler handler to use. This object must have previously been passed 114 * to the {@code supports} method of this interface, which must have 115 * returned true. 116 * @throws Exception in case of errors 117 * @see javax.portlet.EventPortlet#processEvent 118 */ 119 void handleEvent(EventRequest request, EventResponse response, Object handler) throws Exception; 120 121}