1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.context.impl;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.seasar.uruma.context.ApplicationContext;
26 import org.seasar.uruma.context.ContextFactory;
27 import org.seasar.uruma.context.WindowContext;
28 import org.seasar.uruma.exception.DuplicateComponentIdException;
29 import org.seasar.uruma.util.AssertionUtil;
30
31
32
33
34
35
36 public class ApplicationContextImpl implements ApplicationContext {
37 private List<WindowContext> windowContextList = new ArrayList<WindowContext>();
38
39 private Map<String, Object> valueMap = new HashMap<String, Object>();
40
41
42
43
44
45
46 public ApplicationContextImpl() {
47 super();
48 }
49
50
51
52
53 public WindowContext getWindowContext(final String windowName) {
54 for (WindowContext context : windowContextList) {
55 if (context.getName().equals(windowName)) {
56 return context;
57 }
58 }
59 return null;
60 }
61
62
63
64
65 public Collection<WindowContext> getWindowContexts() {
66 return Collections.unmodifiableCollection(windowContextList);
67 }
68
69
70
71
72
73
74
75
76
77 public void addWindowContext(final WindowContext context) {
78 AssertionUtil.assertNotNull("context", context);
79
80 if (getWindowContext(context.getName()) == null) {
81 windowContextList.add(context);
82 } else {
83 throw new DuplicateComponentIdException(context.getName());
84 }
85 }
86
87
88
89
90
91
92
93 public void disposeWindowContext(final String windowName) {
94 WindowContext context = getWindowContext(windowName);
95 if (context != null) {
96 windowContextList.remove(context);
97 }
98 }
99
100
101
102
103 public Object getValue(final String name) {
104 return valueMap.get(name);
105 }
106
107
108
109
110
111 public void setValue(final String name, final Object value) {
112 AssertionUtil.assertNotEmpty("name", name);
113 valueMap.put(name, value);
114 }
115 }