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.util.Map;
27  
28  import javax.script.SimpleNamespace;
29  
30  public class ScopeNamespace
31  extends SimpleNamespace
32  {
33  	protected ScopeNamespace parentScope;
34  	
35  	public ScopeNamespace(ScopeNamespace parent, Map map)
36  	{
37  		super(map);
38  		parentScope = parent;
39  	}
40  	
41  	public ScopeNamespace(ScopeNamespace parent)
42  	{
43  		super();
44  		setParent(parent);
45  	}
46  	
47  	public ScopeNamespace(Map map)
48  	{
49  		super(map);
50  	}
51  
52  	public ScopeNamespace()
53  	{
54  		super();
55  	}
56  	
57  	public void setParent(ScopeNamespace parent)
58  	{
59  		parentScope = parent;
60  	}
61  	
62  	protected Object scopeFind(Object key, Object value)
63  	{
64  	    Object oldValue = super.get(key);
65  	    if (oldValue == null)
66  	    {
67  	        if (parentScope != null)
68  	            oldValue = parentScope.scopeFind(key, value);
69  	    }
70  	    else
71  	    {
72  	        if (value != null)
73  	            oldValue =  super.put(key, value);
74  	    }
75  	    return oldValue;
76  	}
77  	
78  	@Override
79  	public Object get(Object key)
80  	{
81  	    return scopeFind(key, null);
82  	}
83  }