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.component;
17
18 import org.seasar.framework.util.StringUtil;
19 import org.seasar.uruma.binding.enables.EnablesDependingDef;
20 import org.seasar.uruma.binding.enables.EnablesForType;
21 import org.seasar.uruma.context.WidgetHandle;
22 import org.seasar.uruma.context.WindowContext;
23 import org.seasar.uruma.core.UrumaMessageCodes;
24 import org.seasar.uruma.exception.NotFoundException;
25
26 /**
27 * コンポーネントツリーを走査して、 {@link EnablesDependable} の登録を行うための {@link UIElementVisitor}
28 * です。<br />
29 *
30 * @author y-komori
31 */
32 public class EnablesDependableVisitor implements UIElementVisitor,
33 UrumaMessageCodes {
34 private WindowContext context;
35
36 /**
37 * {@link EnablesDependableVisitor} を構築します。<br />
38 *
39 * @param context
40 */
41 public EnablesDependableVisitor(final WindowContext context) {
42 this.context = context;
43 }
44
45 /*
46 * @see org.seasar.uruma.component.UIElementVisitor#visit(org.seasar.uruma.component.UIElement)
47 */
48 public void visit(final UIElement element) {
49 if ((element instanceof UIComponent)
50 && (element instanceof EnablesDependable)) {
51 EnablesDependable dependable = (EnablesDependable) element;
52 String id = ((UIComponent) element).getId();
53
54 if (id != null) {
55
56 String enablesDependingId = dependable.getEnablesDependingId();
57 String enablesForType = dependable.getEnablesFor();
58
59 if (!StringUtil.isEmpty(enablesDependingId)) {
60 EnablesForType type = EnablesForType.SELECTION;
61 if (!StringUtil.isEmpty(enablesForType)) {
62 type = EnablesForType.valueOf(enablesForType);
63 }
64
65 WidgetHandle handle = context.getWidgetHandle(id);
66 if (handle != null) {
67 EnablesDependingDef def = new EnablesDependingDef(
68 handle, enablesDependingId, type);
69 context.addEnablesDependingDef(def);
70 } else {
71 throw new NotFoundException(UICOMPONENT_NOT_FOUND, id);
72 }
73 }
74 }
75 }
76 }
77
78 /*
79 * @see org.seasar.uruma.component.UIElementVisitor#visit(org.seasar.uruma.component.UIElementContainer)
80 */
81 public void visit(final UIElementContainer container) {
82 for (UIElement element : container.getChildren()) {
83 element.accept(this);
84 }
85 }
86
87 /*
88 * @see org.seasar.uruma.component.UIElementVisitor#visit(org.seasar.uruma.component.Template)
89 */
90 public void visit(final Template template) {
91 // Do nothing.
92 }
93 }