KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > gumby > tags > script > MethodTag


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 /**
10  * @author Yanick Duchesne
11  *
12  * <dl>
13  * <dt><b>Copyright: </b>
14  * <dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open
15  * Source Software </a>. All Rights Reserved.</dd>
16  * </dt>
17  * <dt><b>License: </b>
18  * <dd>Read the license.txt file of the jar or visit the <a
19  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the Sapia
20  * OSS web site</dd>
21  * </dt>
22  * </dl>
23  */

24 public class MethodTag implements ObjectCreationCallback {
25
26   private String JavaDoc _name, _lang, _text;
27   private Script _script;
28
29   public void setName(String JavaDoc name) {
30     _name = name;
31   }
32
33   public void setLang(String JavaDoc lang) {
34     _lang = lang;
35   }
36
37   public String JavaDoc getName() {
38     return _name;
39   }
40
41   public void setText(String JavaDoc script) {
42     _text = script;
43   }
44
45   /**
46    * @see org.sapia.util.xml.confix.ObjectCreationCallback#onCreate()
47    */

48   public Object JavaDoc 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 JavaDoc e) {
61       throw new ConfigurationException("Could not parse script", e);
62     }
63     return this;
64   }
65
66   public Object JavaDoc execute(RenderContext context, Object JavaDoc[] args) throws Exception JavaDoc {
67     return _script.execute(context, args);
68   }
69
70 }
71
Popular Tags