View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: Page.java,v 1.9 2002/09/05 15:41:50 ludovicc Exp $ 37 */ 38 package org.scopemvc.view.servlet; 39 40 import java.util.HashMap; 41 import java.util.List; 42 import org.apache.commons.logging.Log; 43 import org.apache.commons.logging.LogFactory; 44 import org.scopemvc.core.Control; 45 import org.scopemvc.core.Controller; 46 import org.scopemvc.core.View; 47 48 /*** 49 * <P> 50 * 51 * Base class for views used by servlet implementation. </P> <P> 52 * 53 * Pages in a browser do not communicate with the web server, so this class does 54 * not implement ModelChangeListener. Model objects in a web application 55 * shouldn't bother to implement ModelChangeEventSource unless change 56 * notification is used for some purpose other than updating Views. </P> <P> 57 * 58 * In a servlet application, a Controller must use a {@link ServletView} that 59 * contains all possible {@link Page}s that the Controller can show. </P> <P> 60 * 61 * Pages must be created with unique View IDs to allow incoming requests to be 62 * linked to the correct parent View instance in ScopeServlet. eg <PRE>http://localhost/scope/servlet/Test?view=TestView&action=TestControl</PRE> 63 * causes the View with ID "TestView" to issue a Control whose ID is 64 * "TestControl". </P> <P> 65 * 66 * The concrete implementation will need to support the appropriate ViewContext: 67 * for example a JSPPage is tailored for use by the JSPContext whereas a 68 * ServletXSLPage offers a different API to the XSLServletContext. </P> 69 * 70 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A> 71 * @created 05 September 2002 72 * @version $Revision: 1.9 $ $Date: 2002/09/05 15:41:50 $ 73 */ 74 public abstract class Page implements View { 75 76 private final static Log LOG = LogFactory.getLog(Page.class); 77 78 /*** 79 * Unique ID. 80 */ 81 private String id; 82 83 /*** 84 * ServletView that contains this Page. 85 */ 86 private ServletView parent; 87 88 89 /*** 90 * Create with a unique ID. 91 * 92 * @param inViewID TODO: Describe the Parameter 93 */ 94 protected Page(String inViewID) { 95 id = inViewID; 96 } 97 98 99 /*** 100 * Gets the ID 101 * 102 * @return The iD value 103 */ 104 public final String getID() { 105 return id; 106 } 107 108 109 /*** 110 * Gets the parent 111 * 112 * @return The parent value 113 */ 114 public final ServletView getParent() { 115 return parent; 116 } 117 118 119 // -------------- implement View ------------------ 120 121 /*** 122 * Gets the bound model 123 * 124 * @return The boundModel value 125 */ 126 public final Object getBoundModel() { 127 if (getParent() == null) { 128 return null; 129 } 130 return parent.getBoundModel(); 131 } 132 133 134 /*** 135 * Gets the controller 136 * 137 * @return The controller value 138 */ 139 public final Controller getController() { 140 if (getParent() == null) { 141 return null; 142 } 143 return parent.getController(); 144 } 145 146 147 /*** 148 * Issue Control via the parent ServletView. 149 * 150 * @param inControl TODO: Describe the Parameter 151 */ 152 public void issueControl(Control inControl) { 153 if (LOG.isDebugEnabled()) { 154 LOG.debug("issueControl: " + inControl); 155 } 156 157 if (getController() == null) { 158 throw new UnsupportedOperationException("Can't issue Control because can't find a Controller for Page with ID: " + getID()); 159 } 160 161 getController().handleControl(inControl); 162 } 163 164 165 /*** 166 * Sets the parent 167 * 168 * @param inServletView The new parent value 169 */ 170 public final void setParent(ServletView inServletView) { 171 parent = inServletView; 172 } 173 174 175 /*** 176 * Parent ServletView is bound to a model, not each Page. 177 * 178 * @param inModel The new boundModel value 179 */ 180 public final void setBoundModel(Object inModel) { 181 throw new UnsupportedOperationException("Can't setBoundModel on Page: setBoundModel on parent ServletView instead."); 182 } 183 184 185 /*** 186 * Parent ServletView has a Controller, not each Page. 187 * 188 * @param inController The new controller value 189 */ 190 public final void setController(Controller inController) { 191 throw new UnsupportedOperationException("Can't setController on Page: setController on parent ServletView instead."); 192 } 193 194 195 /*** 196 * TODO: document the method 197 * 198 * @param inID TODO: Describe the Parameter 199 * @return TODO: Describe the Return Value 200 */ 201 public final boolean equalsID(String inID) { 202 if (id == null && inID == null) { 203 return true; 204 } else if (id != null && id.equals(inID)) { 205 return true; 206 } else { 207 return false; 208 } 209 } 210 211 212 // ----------- support ScopeServlet ------------ 213 214 /*** 215 * <P> 216 * 217 * Called from {@link org.scopemvc.controller.servlet.ScopeServlet#doPost 218 * ScopeServlet.doPost}. </P> <P> 219 * 220 * Implementing this method is optional -- Pages don't have to support 221 * population of their model. The default implementation here does nothing. 222 * </P> 223 * 224 * @param inParameters TODO: Describe the Parameter 225 * @return List list of ValidationFailures or null if none 226 */ 227 public List populateModel(HashMap inParameters) { 228 return null; 229 } 230 }

This page was automatically generated by Maven