1 16 package org.apache.cocoon.forms.event.impl; 17 18 import org.apache.avalon.framework.context.Context; 19 import org.apache.avalon.framework.context.ContextException; 20 import org.apache.avalon.framework.context.Contextualizable; 21 import org.apache.avalon.framework.thread.ThreadSafe; 22 import org.apache.cocoon.forms.event.ActionListener; 23 import org.apache.cocoon.forms.event.CreateListener; 24 import org.apache.cocoon.forms.event.ValueChangedListener; 25 import org.apache.cocoon.forms.event.WidgetListener; 26 import org.apache.cocoon.forms.event.WidgetListenerBuilder; 27 import org.apache.cocoon.forms.formmodel.tree.TreeSelectionListener; 28 import org.apache.cocoon.forms.util.JavaScriptHelper; 29 import org.mozilla.javascript.Function; 30 import org.w3c.dom.Element ; 31 32 48 public class JavaScriptWidgetListenerBuilder implements WidgetListenerBuilder, ThreadSafe, Contextualizable { 49 50 private Context context; 51 52 public void contextualize(Context context) throws ContextException { 53 this.context = context; 54 } 55 56 public WidgetListener buildListener(Element element, Class listenerClass) throws Exception { 57 58 Function func = JavaScriptHelper.buildFunction(element, "handleEvent", new String []{"widget", "event"}); 59 60 if (listenerClass == ActionListener.class) { 61 return new JavaScriptWidgetListener.JSActionListener(func, context); 62 } else if (listenerClass == CreateListener.class) { 63 return new JavaScriptWidgetListener.JSCreateListener(func, context); 64 } else if (listenerClass == ValueChangedListener.class) { 65 return new JavaScriptWidgetListener.JSValueChangedListener(func, context); 66 } else if (listenerClass == TreeSelectionListener.class) { 67 return new JavaScriptWidgetListener.JSTreeSelectionListener(func, context); 68 } else { 69 throw new Exception ("Unkonwn event class: " + listenerClass); 70 } 71 } 72 } 73 | Popular Tags |