1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.uruma.binding.method; |
17 | |
|
18 | |
import java.lang.reflect.Method; |
19 | |
import java.util.List; |
20 | |
import java.util.Set; |
21 | |
|
22 | |
import org.seasar.uruma.annotation.EventListener; |
23 | |
import org.seasar.uruma.context.PartContext; |
24 | |
import org.seasar.uruma.context.WidgetHandle; |
25 | |
import org.seasar.uruma.context.WindowContext; |
26 | |
import org.seasar.uruma.core.UrumaMessageCodes; |
27 | |
import org.seasar.uruma.desc.PartActionDesc; |
28 | |
import org.seasar.uruma.exception.UnsupportedClassException; |
29 | |
import org.seasar.uruma.exception.WidgetNotFoundException; |
30 | |
import org.seasar.uruma.log.UrumaLogger; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class MethodBindingSupport implements UrumaMessageCodes { |
38 | 4 | private static final UrumaLogger logger = UrumaLogger |
39 | |
.getLogger(MethodBindingSupport.class); |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
public static void createAllListeners(final WindowContext context) { |
49 | 0 | createListeners((PartContext) context); |
50 | 0 | for (PartContext partContext : context.getPartContextList()) { |
51 | 0 | createListeners(partContext); |
52 | |
} |
53 | 0 | } |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public static void createListeners(final PartContext context) { |
74 | 112 | Object actionObj = context.getPartActionObject(); |
75 | 112 | if (actionObj != null) { |
76 | 112 | PartActionDesc actionDesc = context.getPartActionDesc(); |
77 | |
|
78 | 112 | List<EventListenerDef> eDefList = actionDesc |
79 | |
.getEventListenerDefList(); |
80 | 112 | for (EventListenerDef def : eDefList) { |
81 | 428 | createListener(context, def); |
82 | |
} |
83 | |
} |
84 | 112 | } |
85 | |
|
86 | |
private static void createListener(final PartContext context, |
87 | |
final EventListenerDef def) { |
88 | 428 | Method targetMethod = def.getTargetMethod(); |
89 | |
|
90 | 428 | String[] ids = def.getId(); |
91 | 856 | for (String id : ids) { |
92 | |
|
93 | 428 | Set<WidgetHandle> handles = context.getWindowContext() |
94 | |
.findWidgetHandles(id); |
95 | |
|
96 | 428 | if (handles.size() > 0) { |
97 | |
|
98 | 428 | for (WidgetHandle handle : handles) { |
99 | 428 | ListenerBinder binder = ListenerBinderFactory |
100 | |
.getListenerBinder(handle, def.getType()); |
101 | |
|
102 | 428 | bindMethod(binder, id, handle, context, def); |
103 | 428 | } |
104 | |
} else { |
105 | 0 | String className = targetMethod.getDeclaringClass().getName(); |
106 | 0 | throw new WidgetNotFoundException(id, className); |
107 | |
} |
108 | |
} |
109 | 428 | } |
110 | |
|
111 | |
private static void bindMethod(final ListenerBinder binder, |
112 | |
final String id, final WidgetHandle handle, |
113 | |
final PartContext context, final EventListenerDef def) { |
114 | 428 | if (binder != null) { |
115 | 428 | MethodBinding binding = MethodBindingFactory.createMethodBinding( |
116 | |
context.getPartActionObject(), def.getTargetMethod(), |
117 | |
handle, def.getAsyncMethod()); |
118 | 428 | Class<?> listenerClass = binder.bindListener(handle, context, |
119 | |
binding, def); |
120 | |
|
121 | 428 | if (logger.isDebugEnabled()) { |
122 | 0 | logger.log(CREATE_METHOD_BINDING, id, def.getType(), binding, |
123 | |
listenerClass.getName()); |
124 | |
} |
125 | 428 | } else { |
126 | 0 | throw new UnsupportedClassException(handle.getWidgetClass()); |
127 | |
} |
128 | 428 | } |
129 | |
} |