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.HashSet;
19 import java.util.Set;
20
21 import org.seasar.uruma.context.ContextFactory;
22 import org.seasar.uruma.context.PartContext;
23 import org.seasar.uruma.context.WidgetHandle;
24 import org.seasar.uruma.context.WindowContext;
25 import org.seasar.uruma.desc.FormDesc;
26 import org.seasar.uruma.desc.PartActionDesc;
27
28 /**
29 * {@link PartContext} の実装クラスです。<br />
30 *
31 * @author y-komori
32 */
33 public class PartContextImpl extends AbstractWidgetHolder implements
34 PartContext {
35 private String partName;
36
37 private PartActionDesc partActionDesc;
38
39 private Object partActionObj;
40
41 private FormDesc formDesc;
42
43 private Object formObj;
44
45 private WindowContextImpl parent;
46
47 /**
48 * {@link PartContextImpl} を構築します。<br />
49 * 本クラスのインスタンスを生成するには、{@link ContextFactory#createPartContext(org.seasar.uruma.context.WindowContext, String)}
50 * メソッドを利用してください。
51 *
52 * @param partName
53 * パート名称
54 * @param parent
55 * 親 {@link WindowContext}
56 */
57 public PartContextImpl(final String partName, final WindowContext parent) {
58 super();
59
60 this.partName = partName;
61 this.parent = (WindowContextImpl) parent;
62 }
63
64 /**
65 * 親 {@link WindowContext} が管理するすべての {@link PartContext} から、指定された
66 * {@link WidgetHandle} を検索して返します。<br />
67 *
68 * @param handleId
69 * ハンドル ID
70 * @return 見つかった {@link WidgetHandle} のリスト。
71 */
72 public Set<WidgetHandle> findWidgetHandle(final String handleId) {
73 Set<WidgetHandle> result = new HashSet<WidgetHandle>();
74 WidgetHandle handle = super.getWidgetHandle(handleId);
75 if (handle != null) {
76 result.add(handle);
77 } else if (parent != null) {
78 result = parent.findWidgetHandles(handleId);
79 }
80 return result;
81 }
82
83 /*
84 * @see org.seasar.uruma.context.impl.AbstractWidgetHolder#getWidgetHandle(java.lang.String)
85 */
86 @Override
87 public WidgetHandle getWidgetHandle(final String handleId) {
88 WidgetHandle handle = super.getWidgetHandle(handleId);
89 if ((handle == null) && (parent != null)) {
90 handle = parent.getWidgetHandle(handleId);
91 }
92 return handle;
93 }
94
95 /*
96 * @see org.seasar.uruma.context.impl.AbstractWidgetHolder#hasWidgetHandle(java.lang.String)
97 */
98 @Override
99 public boolean hasWidgetHandle(final String handleId) {
100 boolean result = super.hasWidgetHandle(handleId);
101 if (!result && (parent != null)) {
102 result = parent.hasWidgetHandle(handleId);
103 }
104 return result;
105 }
106
107 /*
108 * @see org.seasar.uruma.context.PartContext#getFormDesc()
109 */
110 public FormDesc getFormDesc() {
111 return this.formDesc;
112 }
113
114 /*
115 * @see org.seasar.uruma.context.PartContext#getFormObject()
116 */
117 public Object getFormObject() {
118 return this.formObj;
119 }
120
121 /*
122 * @see org.seasar.uruma.context.PartContext#getPartActionDesc()
123 */
124 public PartActionDesc getPartActionDesc() {
125 return this.partActionDesc;
126 }
127
128 /*
129 * @see org.seasar.uruma.context.PartContext#getPartActionObject()
130 */
131 public Object getPartActionObject() {
132 return this.partActionObj;
133 }
134
135 /*
136 * @see org.seasar.uruma.context.PartContext#getPartName()
137 */
138 public String getName() {
139 return this.partName;
140 }
141
142 /*
143 * @see org.seasar.uruma.context.PartContext#setFormDesc(org.seasar.uruma.desc.FormDesc)
144 */
145 public void setFormDesc(final FormDesc desc) {
146 this.formDesc = desc;
147 }
148
149 /*
150 * @see org.seasar.uruma.context.PartContext#setFormObject(java.lang.Object)
151 */
152 public void setFormObject(final Object object) {
153 this.formObj = object;
154 }
155
156 /*
157 * @see org.seasar.uruma.context.PartContext#setPartActionDesc(org.seasar.uruma.desc.PartActionDesc)
158 */
159 public void setPartActionDesc(final PartActionDesc desc) {
160 this.partActionDesc = desc;
161 }
162
163 /*
164 * @see org.seasar.uruma.context.PartContext#setPartActionObject(java.lang.Object)
165 */
166 public void setPartActionObject(final Object object) {
167 this.partActionObj = object;
168 }
169
170 /*
171 * @see org.seasar.uruma.context.PartContext#getWindowContext()
172 */
173 public WindowContext getWindowContext() {
174 return parent;
175 }
176
177 /**
178 * この {@link PartContext} を親 {@link WindowContext} から削除します。<br />
179 */
180 public void dispose() {
181 parent.disposePartContext(partName);
182 parent = null;
183 }
184
185 }