1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }