View Javadoc

1   /*
2    * Copyright 2004-2005 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package net.sf.morph.context.contexts;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import net.sf.morph.context.Context;
22  
23  /**
24   * A simple Context backed by a Map.
25   * 
26   * @author Matt Sgarlata
27   * @since Nov 21, 2004
28   */
29  public class MapContext extends ReflectorHierarchicalContext {
30  
31  	/**
32  	 * Creates a new, empty context.
33  	 */
34  	public MapContext() {
35  		super();
36  		super.setDelegate(new HashMap());
37  	}
38  
39  	/**
40  	 * Creates a new context with the given context as parent.
41  	 * 
42  	 * @param parentContext
43  	 *            the parent context
44  	 */
45  	public MapContext(Context parentContext) {
46  		super(parentContext);
47  		super.setDelegate(new HashMap());
48  	}
49  
50  	/**
51  	 * Creates a new context with the values taken from the supplied Map. Only
52  	 * the map entries that have String keys will be exposed as properties.
53  	 * 
54  	 * @param map
55  	 *            the map used to populate this context with initial values
56  	 */
57  	public MapContext(Map map) {
58  		super();
59  		super.setDelegate(map);
60  	}
61  
62  	/**
63  	 * Creates a new context with the given parent context and initial values
64  	 * taken from the supplied Map. Only the map entries that have String keys
65  	 * will be exposed as properties.
66  	 * 
67  	 * @param parentContext
68  	 *            the parent context
69  	 * @param map
70  	 *            the map used to populate this context with initial values
71  	 */
72  	public MapContext(Context parentContext, Map map) {
73  		super(parentContext);
74  		super.setDelegate(map);
75  	}
76  
77  }