1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package net.sf.sail.core.activity.model;
25
26 import java.beans.Customizer;
27 import java.beans.beancontext.BeanContext;
28 import java.beans.beancontext.BeanContextChildSupport;
29
30 import javax.script.Namespace;
31 import javax.script.ScriptContext;
32 import javax.script.ScriptException;
33
34 public class ScriptBeanSupport
35 extends BeanContextChildSupport
36 implements IScriptBean
37 {
38 private static final long serialVersionUID = 1L;
39 protected String name;
40 protected IScript script;
41 protected Class<? extends Customizer> customizerClass;
42
43 public ScriptBeanSupport()
44 {
45 }
46
47 public String getName()
48 {
49 return name;
50 }
51
52 public void setName(String value)
53 {
54 name = value;
55 }
56
57 public void setScriptParent(BeanContext parent)
58 {
59 if (parent instanceof ScriptBeanContext)
60 {
61 ScriptBeanContext scriptBeanContext = (ScriptBeanContext) parent;
62 ScriptContext parentContext = scriptBeanContext.getScript().getScriptContext();
63 ScriptContext context = script.getScriptContext();
64 Namespace parentNamespace = parentContext.getNamespace(ENGINE_SCOPE);
65 Namespace namespace = context.getNamespace(ENGINE_SCOPE);
66 if (namespace instanceof ScopeNamespace)
67 {
68 ((ScopeNamespace) namespace).setParent((ScopeNamespace) parentNamespace);
69 }
70 else if (parentNamespace instanceof ScopeNamespace)
71 {
72 namespace = new ScopeNamespace((ScopeNamespace) parentNamespace);
73 }
74 context.setNamespace(namespace, ENGINE_SCOPE);
75 }
76 }
77
78 public BeanContext getScriptParent()
79 {
80 return getBeanContext();
81 }
82
83 public Object evaluate()
84 throws ScriptException
85 {
86 return (script == null) ? null: script.evaluate();
87 }
88
89 public Class<? extends Customizer> getCustomizerClass()
90 {
91 return customizerClass;
92 }
93
94 public void setCustomizerClass(Class<? extends Customizer> customizer)
95 {
96 customizerClass = customizer;
97 }
98
99
100
101
102 public IScript getScript()
103 {
104 return script;
105 }
106
107
108
109
110 public void setScript(IScript script)
111 {
112 this.script = script;
113 }
114 }