| 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 | 128 | private List<WindowContext> windowContextList = new ArrayList<WindowContext>(); |
| 38 | |
|
| 39 | 128 | private Map<String, Object> valueMap = new HashMap<String, Object>(); |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public ApplicationContextImpl() { |
| 47 | 128 | super(); |
| 48 | 128 | } |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
public WindowContext getWindowContext(final String windowName) { |
| 54 | 224 | for (WindowContext context : windowContextList) { |
| 55 | 112 | if (context.getName().equals(windowName)) { |
| 56 | 112 | return context; |
| 57 | |
} |
| 58 | |
} |
| 59 | 112 | return null; |
| 60 | |
} |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public Collection<WindowContext> getWindowContexts() { |
| 66 | 0 | return Collections.unmodifiableCollection(windowContextList); |
| 67 | |
} |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
public void addWindowContext(final WindowContext context) { |
| 78 | 112 | AssertionUtil.assertNotNull("context", context); |
| 79 | |
|
| 80 | 112 | if (getWindowContext(context.getName()) == null) { |
| 81 | 112 | windowContextList.add(context); |
| 82 | |
} else { |
| 83 | 0 | throw new DuplicateComponentIdException(context.getName()); |
| 84 | |
} |
| 85 | 112 | } |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
public void disposeWindowContext(final String windowName) { |
| 94 | 112 | WindowContext context = getWindowContext(windowName); |
| 95 | 112 | if (context != null) { |
| 96 | 112 | windowContextList.remove(context); |
| 97 | |
} |
| 98 | 112 | } |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
public Object getValue(final String name) { |
| 104 | 0 | return valueMap.get(name); |
| 105 | |
} |
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
public void setValue(final String name, final Object value) { |
| 112 | 0 | AssertionUtil.assertNotEmpty("name", name); |
| 113 | 0 | valueMap.put(name, value); |
| 114 | 0 | } |
| 115 | |
} |