View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of 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,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.context.impl;
17  
18  import java.util.ArrayList;
19  import java.util.Collections;
20  import java.util.HashSet;
21  import java.util.List;
22  import java.util.Set;
23  
24  import org.seasar.uruma.binding.enables.EnablesDependingDef;
25  import org.seasar.uruma.context.ApplicationContext;
26  import org.seasar.uruma.context.PartContext;
27  import org.seasar.uruma.context.WidgetHandle;
28  import org.seasar.uruma.context.WindowContext;
29  import org.seasar.uruma.desc.FormDesc;
30  import org.seasar.uruma.desc.PartActionDesc;
31  import org.seasar.uruma.exception.DuplicateComponentIdException;
32  import org.seasar.uruma.util.AssertionUtil;
33  
34  /**
35   * {@link WindowContext} の実装クラスです。<br />
36   * 
37   * @author y-komori
38   */
39  public class WindowContextImpl extends AbstractWidgetHolder implements
40          WindowContext {
41  
42      private String windowName;
43  
44      private List<PartContext> partContextList = new ArrayList<PartContext>();
45  
46      private ApplicationContextImpl parent;
47  
48      private List<EnablesDependingDef> enablesDependingDefList = new ArrayList<EnablesDependingDef>();
49  
50      private Object partActionObj;
51  
52      private PartActionDesc partActionDesc;
53  
54      /**
55       * {@link WindowContextImpl} を構築します。<br />
56       * 
57       * @param windowName
58       *            ウィンドウ名称
59       * @param parent
60       *            親 {@link ApplicationContext}
61       */
62      public WindowContextImpl(final String windowName,
63              final ApplicationContext parent) {
64          super();
65  
66          this.windowName = windowName;
67          this.parent = (ApplicationContextImpl) parent;
68      }
69  
70      /*
71       * @see org.seasar.uruma.context.WindowContext#getWindowName()
72       */
73      public String getName() {
74          return this.windowName;
75      }
76  
77      /*
78       * @see org.seasar.uruma.context.WindowContext#getPartContext()
79       */
80      public PartContext getPartContext() {
81          if ((partContextList != null) && (partContextList.size() > 0)) {
82              return partContextList.get(0);
83          } else {
84              return null;
85          }
86      }
87  
88      /*
89       * @see org.seasar.uruma.context.WindowContext#getPartContext(java.lang.String)
90       */
91      public PartContext getPartContext(final String partName) {
92          for (PartContext context : partContextList) {
93              if (context.getName().equals(partName)) {
94                  return context;
95              }
96          }
97          return null;
98      }
99  
100     /*
101      * @see org.seasar.uruma.context.WindowContext#getPartContextList()
102      */
103     public List<PartContext> getPartContextList() {
104         return Collections.unmodifiableList(partContextList);
105     }
106 
107     /*
108      * @see org.seasar.uruma.context.WindowContext#getApplicationContext()
109      */
110     public ApplicationContext getApplicationContext() {
111         return parent;
112     }
113 
114     /**
115      * {@link PartContext} オブジェクトを追加します。<br />
116      * 
117      * @param context
118      *            {@link PartContext} オブジェクト
119      * @throws DuplicateComponentIdException
120      *             パート名称が既に登録されている場合
121      */
122     public void addPartContext(final PartContext context) {
123         if (getPartContext(context.getName()) == null) {
124             partContextList.add(context);
125         } else {
126             throw new DuplicateComponentIdException(context.getName());
127         }
128     }
129 
130     /**
131      * {@link PartContext} オブジェクトを削除します。<br />
132      * 
133      * @param partName
134      *            パート名称
135      */
136     public void disposePartContext(final String partName) {
137         PartContext partContext = getPartContext(partName);
138         if (partContext != null) {
139             partContextList.remove(partContext);
140         }
141     }
142 
143     /**
144      * この {@link WindowContext} を親 {@link ApplicationContext} から削除します。<br />
145      */
146     public void dispose() {
147         for (PartContext part : partContextList) {
148             disposePartContext(part.getName());
149         }
150         parent.disposeWindowContext(windowName);
151         parent = null;
152     }
153 
154     /*
155      * @see org.seasar.uruma.context.WindowContext#findWidgetHandles(java.lang.String)
156      */
157     public Set<WidgetHandle> findWidgetHandles(final String handleId) {
158         Set<WidgetHandle> results = new HashSet<WidgetHandle>();
159 
160         WidgetHandle handle = getWidgetHandle(handleId);
161         if (handle != null) {
162             results.add(handle);
163         }
164 
165         for (PartContext part : getPartContextList()) {
166             handle = part.getWidgetHandle(handleId);
167             if (handle != null) {
168                 results.add(handle);
169             }
170         }
171         return results;
172     }
173 
174     /*
175      * @see org.seasar.uruma.context.WindowContext#getAllWidgetHandles(java.lang.Class)
176      */
177     public Set<WidgetHandle> getAllWidgetHandles(final Class<?> clazz) {
178         Set<WidgetHandle> handles = new HashSet<WidgetHandle>();
179         handles.addAll(getWidgetHandles(clazz));
180 
181         for (PartContext part : getPartContextList()) {
182             handles.addAll(part.getWidgetHandles(clazz));
183         }
184 
185         return handles;
186     }
187 
188     /*
189      * @see org.seasar.uruma.context.WindowContext#addEnablesDependingDef(org.seasar
190      *      .uruma.binding.enables.EnablesDependingDef)
191      */
192     public void addEnablesDependingDef(
193             final EnablesDependingDef enablesDependingDef) {
194         AssertionUtil.assertNotNull("enablesDependingDef", enablesDependingDef);
195         enablesDependingDefList.add(enablesDependingDef);
196     }
197 
198     /*
199      * @see org.seasar.uruma.context.WindowContext#getEnablesDependingDefList()
200      */
201     public List<EnablesDependingDef> getEnablesDependingDefList() {
202         return Collections.unmodifiableList(enablesDependingDefList);
203     }
204 
205     /*
206      * @see org.seasar.uruma.context.PartContext#getPartActionObject()
207      */
208     public Object getPartActionObject() {
209         return this.partActionObj;
210     }
211 
212     /*
213      * @see org.seasar.uruma.context.PartContext#getPartActionObject()
214      */
215     public void setPartActionDesc(final PartActionDesc desc) {
216         this.partActionDesc = desc;
217     }
218 
219     /*
220      * @see org.seasar.uruma.context.PartContext#setPartActionObject(java.
221      *      lang.Object)
222      */
223     public void setPartActionObject(final Object partActionObj) {
224         this.partActionObj = partActionObj;
225     }
226 
227     /*
228      * @see org.seasar.uruma.context.PartContext#getPartActionDesc()
229      */
230     public PartActionDesc getPartActionDesc() {
231         return this.partActionDesc;
232     }
233 
234     /*
235      * @see org.seasar.uruma.context.PartContext#getPartActionDesc()
236      */
237     public WindowContext getWindowContext() {
238         return this;
239     }
240 
241     /*
242      * @see org.seasar.uruma.context.PartContext#getFormDesc()
243      */
244     public FormDesc getFormDesc() {
245         // Do noting
246         return null;
247     }
248 
249     /*
250      * @see org.seasar.uruma.context.PartContext#getFormObject()
251      */
252     public Object getFormObject() {
253         // Do noting
254         return null;
255     }
256 
257     /*
258      * @see org.seasar.uruma.context.PartContext#setFormDesc()
259      */
260     public void setFormDesc(final FormDesc desc) {
261         // Do noting
262     }
263 
264     /*
265      * @see org.seasar.uruma.context.PartContext#setFormObject()
266      */
267     public void setFormObject(final Object object) {
268         // Do noting
269     }
270 
271 }