1 package org.sapia.gumby.tags.script; 2 3 import org.sapia.gumby.RenderContext; 4 import org.sapia.gumby.script.EngineFactory; 5 import org.sapia.gumby.script.Script; 6 import org.sapia.util.xml.confix.ConfigurationException; 7 import org.sapia.util.xml.confix.ObjectCreationCallback; 8 9 24 public class MethodTag implements ObjectCreationCallback { 25 26 private String _name, _lang, _text; 27 private Script _script; 28 29 public void setName(String name) { 30 _name = name; 31 } 32 33 public void setLang(String lang) { 34 _lang = lang; 35 } 36 37 public String getName() { 38 return _name; 39 } 40 41 public void setText(String script) { 42 _text = script; 43 } 44 45 48 public Object onCreate() throws ConfigurationException { 49 if(_name == null) 50 throw new ConfigurationException("Method name not specified"); 51 if(_text == null) 52 throw new ConfigurationException("Script source not specified"); 53 54 try { 55 if(_lang == null) { 56 _script = EngineFactory.getDefaultEngine().parseScript(_text); 57 } else { 58 _script = EngineFactory.getEngineFor(_lang).parseScript(_text); 59 } 60 } catch(Exception e) { 61 throw new ConfigurationException("Could not parse script", e); 62 } 63 return this; 64 } 65 66 public Object execute(RenderContext context, Object [] args) throws Exception { 67 return _script.execute(context, args); 68 } 69 70 } 71 | Popular Tags |