01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.uilib.event;
16:
17: import java.lang.reflect.Method;
18: import org.apache.commons.logging.Log;
19: import org.apache.commons.logging.LogFactory;
20: import org.araneaframework.Widget;
21: import org.araneaframework.core.Assert;
22: import org.araneaframework.core.util.ProxiedHandlerUtil;
23:
24: /**
25: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
26: */
27: public class ProxyOnClickEventListener implements OnClickEventListener {
28: public static final Log log = LogFactory
29: .getLog(ProxyOnClickEventListener.class);
30:
31: protected Widget eventTarget;
32:
33: protected String eventId;
34:
35: public ProxyOnClickEventListener(Widget eventTarget, String eventId) {
36: this .eventTarget = eventTarget;
37: this .eventId = eventId;
38: }
39:
40: public void onClick() throws Exception {
41: Method eventHandler;
42: // lets try to find a handle method with an empty argument
43: try {
44: eventHandler = ProxiedHandlerUtil.getEventHandler(eventId,
45: eventTarget);
46: eventHandler.invoke(eventTarget, new Object[] {});
47: return;
48: } catch (NoSuchMethodException e) {/* OK */
49: }
50:
51: // lets try to find a method with a String type argument
52: try {
53: eventHandler = ProxiedHandlerUtil.getEventHandler(eventId,
54: eventTarget, new Class[] { String.class });
55: eventHandler.invoke(eventTarget, new Object[] { null });
56: return;
57: } catch (NoSuchMethodException e) {/* OK */
58: }
59:
60: if (log.isWarnEnabled()) {
61: log
62: .warn("Widget '"
63: + eventTarget.getScope()
64: + "' cannot deliver event as no event listeners were registered for the event id '"
65: + eventId + "'!"
66: + Assert.thisToString(eventTarget));
67: }
68: }
69: }
|