View Javadoc

1   /*
2    *  Copyright (C) 2004  The Concord Consortium, Inc.,
3    *  10 Concord Crossing, Concord, MA 01741
4    *
5    *  Web Site: http://www.concord.org
6    *  Email: info@concord.org
7    *
8    *  This library is free software; you can redistribute it and/or
9    *  modify it under the terms of the GNU Lesser General Public
10   *  License as published by the Free Software Foundation; either
11   *  version 2.1 of the License, or (at your option) any later version.
12   *
13   *  This library is distributed in the hope that it will be useful,
14   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   *  Lesser General Public License for more details.
17   *
18   *  You should have received a copy of the GNU Lesser General Public
19   *  License along with this library; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21   *
22   */
23  
24  package net.sf.sail.core.activity.model;
25  
26  import java.beans.beancontext.BeanContext;
27  import java.beans.beancontext.BeanContextServicesSupport;
28  import java.util.ArrayList;
29  import java.util.List;
30  
31  import javax.script.ScriptException;
32  
33  public class ScriptBeanContext
34  extends BeanContextServicesSupport
35  implements IScriptBean, INavElement
36  {
37  	private static final long serialVersionUID = 3691043183652124210L;
38  	protected ScriptBeanSupport support;
39  	protected INavElement navParent;
40  	
41  	@SuppressWarnings("unchecked")
42  	public ScriptBeanContext(BeanContext parent)
43  	{
44  		if (parent != null)
45  			parent.add(this);
46  	}
47  	
48  	@Override
49  	public void initialize()
50  	{
51  		super.initialize();
52  	    support = new ScriptBeanSupport();
53  		BeanContext parent = getScriptParent();
54          setScriptParent(parent);
55          if (parent instanceof INavElement)
56          {
57          	navParent = (INavElement) parent;
58          }
59  	}
60  	
61  	
62  	public ScriptBeanContext()
63  	{
64  		this(null);
65  	}
66  	
67  	@Override
68  	public String toString()
69  	{
70  		return support.getName();
71  	}
72  	
73  	@Override
74  	public void clear()
75  	{
76          List<ScriptBeanContext> contextList = new ArrayList<ScriptBeanContext>(this);
77          for (ScriptBeanContext childContext : contextList) {
78              remove(childContext);
79  		}
80          contextList.clear();
81  	}
82  	
83  	public void removeAll()
84  	{
85  	    clear();
86  	}
87  	
88  	public static void main(String [] args)
89  	{
90  		ScriptBeanContext sbc = new ScriptBeanContext();
91  		try
92  		{
93  			if (args.length > 0)
94  			{
95  				Class customizer = Class.forName(args[0]);
96  				sbc.setCustomizerClass(customizer);
97  			}
98  		}
99  		catch (ClassNotFoundException cnfe)
100 		{
101 			System.out.println("ScriptBeanContext.main(): " + cnfe);
102 		}
103 	}
104 
105     public String getName()
106     {
107         return support.getName();
108     }
109 
110     public void setName(String value)
111     {
112         support.setName(value);
113     }
114 
115     public Object evaluate()
116     throws ScriptException
117     {
118         return support.evaluate();
119     }
120 
121     public Class getCustomizerClass()
122     {
123          return support.getCustomizerClass();
124     }
125 
126     public void setCustomizerClass(Class customizer)
127     {
128         support.setCustomizerClass(customizer);
129     }
130 
131     public IScript getScript()
132     {
133         return support.getScript();
134     }
135 
136     public void setScript(IScript script)
137     {
138         support.setScript(script);
139     }
140 
141 	public BeanContext getScriptParent()
142 	{
143 		return support.getScriptParent();
144 	}
145 
146     public void setScriptParent(BeanContext beanContext)
147     {
148         support.setScriptParent(beanContext);        
149     }
150 
151 	public INavElement getRootElement()
152 	{
153 		return navParent.getRootElement();
154 	}
155 
156 	public INavElement getParentElement()
157 	{
158 		return navParent;
159 	}
160 
161 	public void setParentElement(INavElement element)
162 	{
163 		navParent = element;
164 	}
165 
166 	public void close()
167 	{
168 		// TODO Auto-generated method stub
169 		
170 	}
171 }