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

Quick Search    Search Deep

Source code: org/infohazard/maverick/view/DocumentView.java


1   /*
2    * $Id: DocumentView.java,v 1.4 2003/10/22 11:13:49 thusted Exp $
3    * $Source: /cvsroot/mav/maverick/src/java/org/infohazard/maverick/view/DocumentView.java,v $
4    */
5   
6   package org.infohazard.maverick.view;
7   
8   import java.io.IOException;
9   import java.util.Iterator;
10  import java.util.Map;
11  
12  import javax.servlet.ServletException;
13  
14  import org.apache.commons.logging.Log;
15  import org.apache.commons.logging.LogFactory;
16  import org.infohazard.maverick.flow.View;
17  import org.infohazard.maverick.flow.ViewContext;
18  
19  /**
20   * <p>
21   * DocumentView is the base class for the default Maverick "document" view type.
22   * </p>
23   * <p>
24   * A DocumentView is a {@link View} that sets up a "model" object in request
25   * or session scope and forwards to another resource to render the final
26   * response.
27   * The "model" object exposes dynamic data so that it can be rendered as part
28   * of the response.
29   * </p>
30   * <p>
31   * This class is used by the Maverick {@link  DocumentViewFactory}.
32   * The DocumentViewFactory defines the abstract SetAttribute method
33   * for each instance according to the parameters passed through the View XML
34   * element.
35   * </p>
36   * <p>
37   * By default, a DocumentView will be associated with a
38   * {@link DispatchedViewFactory DispatchedView} that uses the
39   * {@link javax.servlet.RequestDispatcher RequestDispatcher} to forward control
40   * to another resource (e.g. service or servlet that renders a server page).
41   * </p>
42   */
43  public abstract class DocumentView implements View
44  {
45      private static Log log = LogFactory.getLog(DocumentView.class);
46  
47      /**
48       * <p>
49       * The name of the bean in the appropriate scope attributes.
50       * </p>
51       */
52      protected String beanName;
53  
54      /**
55       * <p>
56       * Convenience constructor to pass the "model" object name and the
57       * aggregated {@link View}.
58       * </p>
59       * @param beanName The name of the bean in the appropriate scope attributes.
60       */
61      public DocumentView(String beanName)
62      {
63          this.beanName = beanName;
64      }
65  
66      /**
67       * <p>
68       * Entry method that initiates the View rendering process.
69       * Here, the DocumentView sets the the "model" object to the appropriate
70       * scope and invokes the {@link #forward} View to complete the response.
71       * </p>
72       * @param vctx is placed in an attribute collection.
73       * @throws IOException
74       * @throws ServletException
75       * @see View#go
76       */
77      public void go(ViewContext vctx)  throws IOException, ServletException
78      {
79          // Should we put the null in the collection?
80          if (vctx.getModel() != null)
81              this.setAttribute(vctx);
82  
83          // Put any params in the request attributes
84          if (vctx.getViewParams() != null)
85          {
86              if (log.isDebugEnabled())
87                  log.debug("Setting " + vctx.getViewParams().size() + " params");
88  
89              Iterator entryIt = vctx.getViewParams().entrySet().iterator();
90              while (entryIt.hasNext())
91              {
92                  Map.Entry entry = (Map.Entry)entryIt.next();
93                  vctx.getRequest().setAttribute((String)entry.getKey(), entry.getValue());
94              }
95          }
96          vctx.getNextStep().go("");
97      }
98  
99      /**
100      * <p>
101      * Template method that can be used to place the "model" object in
102      * whatever scope is appropriate for this View element instance.
103      * </p>
104      * <p>
105      * The {@link DocumentViewFactory} provides an implementation of this
106      * method appropriate to the View parameters passed from the Maverick
107      * configuration document.
108      * </p>
109      * @param vctx provides access to request and session scope collections,
110      *   if needed.
111      */
112     protected abstract void setAttribute(ViewContext vctx);
113 }