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.BeanContextServicesSupport;
29 import java.util.ArrayList;
30 import java.util.List;
31
32 import javax.script.ScriptException;
33
34 public class ScriptBeanContext
35 extends BeanContextServicesSupport
36 implements IScriptBean, INavElement
37 {
38 private static final long serialVersionUID = 3691043183652124210L;
39 protected ScriptBeanSupport support;
40 protected INavElement navParent;
41
42 @SuppressWarnings("unchecked")
43 public ScriptBeanContext(BeanContext parent)
44 {
45 if (parent != null)
46 parent.add(this);
47 }
48
49 @Override
50 public void initialize()
51 {
52 super.initialize();
53 support = new ScriptBeanSupport();
54 BeanContext parent = getScriptParent();
55 setScriptParent(parent);
56 if (parent instanceof INavElement)
57 {
58 navParent = (INavElement) parent;
59 }
60 }
61
62
63 public ScriptBeanContext()
64 {
65 this(null);
66 }
67
68 @Override
69 public String toString()
70 {
71 return support.getName();
72 }
73
74 @Override
75 public void clear()
76 {
77 List<ScriptBeanContext> contextList = new ArrayList<ScriptBeanContext>(this);
78 for (ScriptBeanContext childContext : contextList) {
79 remove(childContext);
80 }
81 contextList.clear();
82 }
83
84 @SuppressWarnings("unchecked")
85 public static void main(String [] args)
86 {
87 ScriptBeanContext sbc = new ScriptBeanContext();
88 try
89 {
90 if (args.length > 0)
91 {
92 Class<? extends Customizer> customizer = (Class<? extends Customizer>) Class.forName(args[0]);
93 sbc.setCustomizerClass(customizer);
94 }
95 }
96 catch (ClassNotFoundException cnfe)
97 {
98 System.out.println("ScriptBeanContext.main(): " + cnfe);
99 }
100 }
101
102 public String getName()
103 {
104 return support.getName();
105 }
106
107 public void setName(String value)
108 {
109 support.setName(value);
110 }
111
112 public Object evaluate()
113 throws ScriptException
114 {
115 return support.evaluate();
116 }
117
118 public Class<? extends Customizer> getCustomizerClass()
119 {
120 return support.getCustomizerClass();
121 }
122
123 public void setCustomizerClass(Class<? extends Customizer> customizer)
124 {
125 support.setCustomizerClass(customizer);
126 }
127
128 public IScript getScript()
129 {
130 return support.getScript();
131 }
132
133 public void setScript(IScript script)
134 {
135 support.setScript(script);
136 }
137
138 public BeanContext getScriptParent()
139 {
140 return support.getScriptParent();
141 }
142
143 public void setScriptParent(BeanContext beanContext)
144 {
145 support.setScriptParent(beanContext);
146 }
147
148 public INavElement getRootElement()
149 {
150 return navParent.getRootElement();
151 }
152
153 public INavElement getParentElement()
154 {
155 return navParent;
156 }
157
158 public void setParentElement(INavElement element)
159 {
160 navParent = element;
161 }
162
163 public void close()
164 {
165
166
167 }
168 }