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.PortletException;
020
021/**
022 * Exception to be thrown on error conditions that should forward
023 * to a specific view with a specific model.
024 *
025 * <p>Can be thrown at any time during handler processing.
026 * This includes any template methods of pre-built controllers.
027 * For example, a form controller might abort to a specific error page
028 * if certain parameters do not allow to proceed with the normal workflow.
029 *
030 * @author Juergen Hoeller
031 * @since 2.0
032 */
033@SuppressWarnings("serial")
034public class ModelAndViewDefiningException extends PortletException {
035
036        private ModelAndView modelAndView;
037
038
039        /**
040         * Create new ModelAndViewDefiningException with the given ModelAndView,
041         * typically representing a specific error page.
042         * @param modelAndView ModelAndView with view to forward to and model to expose
043         */
044        public ModelAndViewDefiningException(ModelAndView modelAndView) {
045                if (modelAndView == null) {
046                        throw new IllegalArgumentException("modelAndView must not be null in ModelAndViewDefiningException");
047                }
048                this.modelAndView = modelAndView;
049        }
050
051        /**
052         * Return the ModelAndView that this exception contains for forwarding to.
053         */
054        public ModelAndView getModelAndView() {
055                return modelAndView;
056        }
057
058}