View Javadoc
1   /*
2    * $Id$
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.struts.chain.contexts;
22  
23  import org.apache.commons.chain.Context;
24  
25  import java.util.Collection;
26  import java.util.Map;
27  import java.util.Set;
28  
29  /**
30   * Provide a base class for any Context Implementation which is primarily
31   * intended for use in a subchain.
32   *
33   * <p>Classes which extend {@code ContextWrapper} may implement typesafe
34   * property methods which also leave their values in the underlying
35   * context.</p>
36   */
37  public class ContextWrapper implements Context {
38      private Context base;
39  
40      /**
41       * <p> Instantiate object as a composite around the given Context. </p>
42       *
43       * @param context Context instance to wrap
44       */
45      public ContextWrapper(Context context) {
46          this.base = context;
47      }
48  
49      /**
50       * Provide the underlying Context for this composite.
51       *
52       * @return The underlying Context
53       */
54      protected Context getBaseContext() {
55          return this.base;
56      }
57  
58      // -------------------------------
59      // Map interface methods
60      // -------------------------------
61      public Set<Map.Entry<String, Object>> entrySet() {
62          return this.base.entrySet();
63      }
64  
65      public Set<String> keySet() {
66          return this.base.keySet();
67      }
68  
69      public Collection<Object> values() {
70          return this.base.values();
71      }
72  
73      public void clear() {
74          this.base.clear();
75      }
76  
77      public void putAll(Map<? extends String, ? extends Object> map) {
78          // ISSUE: Should we check this call to putAll?
79          this.base.putAll(map);
80      }
81  
82      public Object remove(Object key) {
83          return this.base.remove(key);
84      }
85  
86      public Object put(String key, Object value) {
87          // ISSUE: Should we check this call to put?
88          return this.base.put(key, value);
89      }
90  
91      public Object get(Object key) {
92          return this.base.get(key);
93      }
94  
95      public boolean containsValue(Object o) {
96          return this.base.containsValue(o);
97      }
98  
99      public boolean containsKey(Object o) {
100         return this.base.containsKey(o);
101     }
102 
103     public boolean isEmpty() {
104         return this.base.isEmpty();
105     }
106 
107     public int size() {
108         return this.base.size();
109     }
110 }