1 15 package org.apache.tapestry.binding; 16 17 import org.apache.bsf.BSFException; 18 import org.apache.bsf.BSFManager; 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.Location; 21 import org.apache.hivemind.util.Defense; 22 import org.apache.tapestry.IActionListener; 23 import org.apache.tapestry.IComponent; 24 import org.apache.tapestry.IEngine; 25 import org.apache.tapestry.IPage; 26 import org.apache.tapestry.IRequestCycle; 27 import org.apache.tapestry.Tapestry; 28 import org.apache.tapestry.coerce.ValueConverter; 29 import org.apache.tapestry.services.BSFManagerFactory; 30 31 39 40 public class ListenerBinding extends AbstractBinding implements IActionListener 41 { 42 private final String _language; 43 44 private final String _script; 45 46 private final IComponent _component; 47 48 49 50 private BSFManagerFactory _managerFactory; 51 52 public ListenerBinding(String description, ValueConverter valueConverter, Location location, 53 IComponent component, String language, String script, 54 BSFManagerFactory managerFactory) 55 { 56 super(description, valueConverter, location); 57 58 Defense.notNull(component, "component"); 59 Defense.notNull(language, "language"); 60 Defense.notNull(script, "script"); 61 62 _component = component; 63 _language = language; 64 _script = script; 65 _managerFactory = managerFactory; 66 } 67 68 71 72 public Object getObject() 73 { 74 return this; 75 } 76 77 89 90 public void actionTriggered(IComponent component, IRequestCycle cycle) 91 { 92 BSFManager bsf = _managerFactory.createBSFManager(); 93 94 Location location = getLocation(); 95 96 try 97 { 98 IPage page = cycle.getPage(); 99 100 bsf.declareBean("component", _component, _component.getClass()); 101 bsf.declareBean("page", page, page.getClass()); 102 bsf.declareBean("cycle", cycle, cycle.getClass()); 103 104 bsf.exec( 105 _language, 106 location.getResource().toString(), 107 location.getLineNumber(), 108 location.getLineNumber(), 109 _script); 110 } 111 catch (BSFException ex) 112 { 113 String message = Tapestry.format("ListenerBinding.bsf-exception", location, ex 114 .getMessage()); 115 116 throw new ApplicationRuntimeException(message, _component, getLocation(), ex); 117 } 118 } 119 120 121 122 public Object getComponent() 123 { 124 return _component; 125 } 126 } | Popular Tags |