KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > event > impl > JavaClassWidgetListenerBuilder


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.forms.event.impl;
17
18 import org.apache.cocoon.forms.event.WidgetListener;
19 import org.apache.cocoon.forms.event.WidgetListenerBuilder;
20 import org.apache.cocoon.forms.util.DomHelper;
21 import org.apache.cocoon.util.ClassUtils;
22 import org.apache.avalon.framework.thread.ThreadSafe;
23 import org.w3c.dom.Element JavaDoc;
24
25 /**
26  * A {@link WidgetListenerBuilder} that creates java classes.
27  * <p>
28  * The syntax for this listener is as follows :<br/>
29  * <pre>
30  * &lt;java class="com.my.SuperListener"/&gt;
31  * </pre>
32  *
33  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
34  * @version $Id: JavaClassWidgetListenerBuilder.java 151179 2005-02-03 16:55:16Z tim $
35  */

36 public class JavaClassWidgetListenerBuilder implements WidgetListenerBuilder, ThreadSafe {
37
38     public WidgetListener buildListener(Element JavaDoc element, Class JavaDoc listenerClass) throws Exception JavaDoc {
39
40         String JavaDoc name = DomHelper.getAttribute(element, "class");
41
42         Object JavaDoc listener = ClassUtils.newInstance(name);
43         if (listenerClass.isAssignableFrom(listener.getClass())) {
44             // FIXME : apply filecyclehelper
45
return (WidgetListener)listener;
46         } else {
47             throw new Exception JavaDoc("Class " + listener.getClass() + " is not a " + listenerClass);
48         }
49     }
50 }
51
Popular Tags