KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > api > events > EventDispatchHelper


1 package org.apache.beehive.controls.api.events;
2 /*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * $Header:$
18  */

19
20 import java.lang.reflect.InvocationTargetException JavaDoc;
21
22 import org.apache.beehive.controls.api.context.ControlContainerContext;
23 import org.apache.beehive.controls.api.context.ControlHandle;
24 import org.apache.beehive.controls.api.context.ControlThreadContext;
25
26 /**
27  * The EventDispatchHelper class is a simple implementation of the EventDispatcher interface
28  * that is suitable for use <b>inside</b> the execution context of a control container. It
29  * assumes that you are already running inside the target container instance, and all that is
30  * required is the correct routing of the event to the correct control.
31  */

32 public class EventDispatchHelper implements EventDispatcher
33 {
34     public Object JavaDoc dispatchEvent(ControlHandle target, EventRef event, Object JavaDoc [] args)
35                   throws IllegalAccessException JavaDoc, IllegalArgumentException JavaDoc,
36                          InvocationTargetException JavaDoc
37     {
38         //
39
// Obtain the current active control container context
40
//
41
ControlContainerContext context = ControlThreadContext.getContext();
42         if (context == null)
43             throw new IllegalStateException JavaDoc("No active control container context");
44
45         //
46
// Dispatch the event using it.
47
//
48
return context.dispatchEvent(target, event, args);
49     }
50 }
51
Popular Tags