Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/scopemvc/view/servlet/Page.java


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