This project has retired. For details please refer to its Attic page.
AbstractClientRequest xref
View Javadoc

1   /*
2    * $Id: AbstractClientRequest.java 1332134 2012-04-30 09:23:19Z mck $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.tiles.request;
22  
23  import java.io.IOException;
24  import java.util.List;
25  import java.util.Map;
26  
27  
28  /**
29   * Base class for "client" requests, i.e. requests that come unchanged by the
30   * container, such as ServletRequest and PortletRequest.
31   *
32   * @version $Rev: 1332134 $ $Date: 2012-04-30 19:23:19 +1000 (Mon, 30 Apr 2012) $
33   */
34  public abstract class AbstractClientRequest extends AbstractRequest {
35  
36      /**
37       * The application context.
38       */
39      private ApplicationContext applicationContext;
40  
41      /**
42       * Constructor.
43       *
44       * @param applicationContext The application context.
45       */
46      public AbstractClientRequest(ApplicationContext applicationContext) {
47          this.applicationContext = applicationContext;
48      }
49  
50  
51      @Override
52      public void dispatch(String path) throws IOException {
53          if (isForceInclude()) {
54              doInclude(path);
55          } else {
56              setForceInclude(true);
57              doForward(path);
58          }
59      }
60  
61      @Override
62      public void include(String path) throws IOException {
63          setForceInclude(true);
64          doInclude(path);
65      }
66  
67      @Override
68      public ApplicationContext getApplicationContext() {
69          return applicationContext;
70      }
71  
72      /**
73       * Returns the application scope.
74       *
75       * @return The application scope.
76       */
77      public Map<String, Object> getApplicationScope() {
78          return applicationContext.getApplicationScope();
79      }
80  
81      /**
82       * Forwards to a path.
83       *
84       * @param path The path to forward to.
85       * @throws IOException If something goes wrong when forwarding.
86       */
87      protected abstract void doForward(String path) throws IOException;
88  
89      /**
90       * Includes the result of a path.
91       *
92       * @param path The path to forward to.
93       * @throws IOException If something goes wrong when forwarding.
94       */
95      protected abstract void doInclude(String path) throws IOException;
96  
97  }