2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shale.usecases.view;
19  
20  import java.util.Map;
21  import org.apache.shale.view.AbstractViewController;
22  
23  /***
24   * <p>Test implementation of <code>Viewcontroller</code> for use by
25   * <code>ViewControllerTestCase</code>.  Event history is accumulated
26   * under a request scope attribute named by symbolic constant
27   * <code>ATTRIBUTES</code>.</p>
28   */
29  public class TestViewController extends AbstractViewController {
30      
31      /*** Creates a new instance of TestViewController */
32      public TestViewController() {
33      }
34      
35      // The request scope attribute under which we accumulate events
36      public static final String ATTRIBUTE =
37              "org.apache.shale.usecases.systest.TestViewController.EVENTS";
38  
39  
40      // ------------------------------------------------------- Public Properties
41  
42  
43      /***
44       * <p>Return the accumuated history string.</p>
45       */
46      public String getText() {
47          String history = (String) getExternalContext().getRequestMap().get(ATTRIBUTE);
48          if (history == null) {
49              history = "";
50          }
51          return history;
52      }
53  
54  
55      // ---------------------------------------------------------- Event Handlers
56  
57  
58      /***
59       * <p>Do-nothing submit method.</p>
60       */
61      public String submit() {
62          event("submit");
63          return null;
64      }
65  
66  
67      // ------------------------------------------------------- Lifecycle Methods
68  
69  
70      public void init() {
71          event("init");
72      }
73  
74  
75      public void preprocess() {
76          event("preprocess");
77      }
78  
79  
80      public void prerender() {
81          event("prerender");
82      }
83  
84  
85      public void destroy() {
86          event("destroy");
87      }
88  
89  
90      // --------------------------------------------------------- Support Methods
91  
92  
93      private Map map = null;
94  
95  
96      /***
97       * <p>Record the specified event, a slash, the state of the postback flag,
98       * and another slash.</p>
99       */
100     private void event(String event) {
101         System.out.println("TestViewController.event(" + event + "," + isPostBack() + ")");
102         if ("init".equals(event) || "destroy".equals(event)) {
103             try {
104                 throw new IllegalArgumentException("Trace source of event '" + event + "'");
105             } catch (IllegalArgumentException e) {
106                 e.printStackTrace();
107             }
108         }
109         if (map == null) {
110             map = getExternalContext().getRequestMap();
111         }
112         String history = (String) map.get(ATTRIBUTE);
113         if (history == null) {
114             history = "";
115         }
116         map.put(ATTRIBUTE, history + event + "/" + isPostBack() + "/");
117     }
118 
119 
120 
121 }