home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / javax / script / SimpleScriptContext.class (.txt) < prev   
Encoding:
Java Class File  |  2006-11-29  |  2.9 KB  |  153 lines

  1. package javax.script;
  2.  
  3. import java.io.InputStreamReader;
  4. import java.io.PrintWriter;
  5. import java.io.Reader;
  6. import java.io.Writer;
  7. import java.util.ArrayList;
  8. import java.util.Collections;
  9. import java.util.List;
  10.  
  11. public class SimpleScriptContext implements ScriptContext {
  12.    protected Writer writer;
  13.    protected Writer errorWriter;
  14.    protected Reader reader;
  15.    protected Bindings engineScope = new SimpleBindings();
  16.    protected Bindings globalScope = null;
  17.    private static List<Integer> scopes = new ArrayList(2);
  18.  
  19.    public SimpleScriptContext() {
  20.       this.reader = new InputStreamReader(System.in);
  21.       this.writer = new PrintWriter(System.out, true);
  22.       this.errorWriter = new PrintWriter(System.err, true);
  23.    }
  24.  
  25.    public void setBindings(Bindings var1, int var2) {
  26.       switch (var2) {
  27.          case 100:
  28.             if (var1 == null) {
  29.                throw new NullPointerException("Engine scope cannot be null.");
  30.             }
  31.  
  32.             this.engineScope = var1;
  33.             break;
  34.          case 200:
  35.             this.globalScope = var1;
  36.             break;
  37.          default:
  38.             throw new IllegalArgumentException("Invalid scope value.");
  39.       }
  40.  
  41.    }
  42.  
  43.    public Object getAttribute(String var1) {
  44.       if (this.engineScope.containsKey(var1)) {
  45.          return this.getAttribute(var1, 100);
  46.       } else {
  47.          return this.globalScope != null && this.globalScope.containsKey(var1) ? this.getAttribute(var1, 200) : null;
  48.       }
  49.    }
  50.  
  51.    public Object getAttribute(String var1, int var2) {
  52.       switch (var2) {
  53.          case 100:
  54.             return this.engineScope.get(var1);
  55.          case 200:
  56.             if (this.globalScope != null) {
  57.                return this.globalScope.get(var1);
  58.             }
  59.  
  60.             return null;
  61.          default:
  62.             throw new IllegalArgumentException("Illegal scope value.");
  63.       }
  64.    }
  65.  
  66.    public Object removeAttribute(String var1, int var2) {
  67.       switch (var2) {
  68.          case 100:
  69.             if (this.getBindings(100) != null) {
  70.                return this.getBindings(100).remove(var1);
  71.             }
  72.  
  73.             return null;
  74.          case 200:
  75.             if (this.getBindings(200) != null) {
  76.                return this.getBindings(200).remove(var1);
  77.             }
  78.  
  79.             return null;
  80.          default:
  81.             throw new IllegalArgumentException("Illegal scope value.");
  82.       }
  83.    }
  84.  
  85.    public void setAttribute(String var1, Object var2, int var3) {
  86.       switch (var3) {
  87.          case 100:
  88.             this.engineScope.put(var1, var2);
  89.             return;
  90.          case 200:
  91.             if (this.globalScope != null) {
  92.                this.globalScope.put(var1, var2);
  93.             }
  94.  
  95.             return;
  96.          default:
  97.             throw new IllegalArgumentException("Illegal scope value.");
  98.       }
  99.    }
  100.  
  101.    public Writer getWriter() {
  102.       return this.writer;
  103.    }
  104.  
  105.    public Reader getReader() {
  106.       return this.reader;
  107.    }
  108.  
  109.    public void setReader(Reader var1) {
  110.       this.reader = var1;
  111.    }
  112.  
  113.    public void setWriter(Writer var1) {
  114.       this.writer = var1;
  115.    }
  116.  
  117.    public Writer getErrorWriter() {
  118.       return this.errorWriter;
  119.    }
  120.  
  121.    public void setErrorWriter(Writer var1) {
  122.       this.errorWriter = var1;
  123.    }
  124.  
  125.    public int getAttributesScope(String var1) {
  126.       if (this.engineScope.containsKey(var1)) {
  127.          return 100;
  128.       } else {
  129.          return this.globalScope != null && this.globalScope.containsKey(var1) ? 200 : -1;
  130.       }
  131.    }
  132.  
  133.    public Bindings getBindings(int var1) {
  134.       if (var1 == 100) {
  135.          return this.engineScope;
  136.       } else if (var1 == 200) {
  137.          return this.globalScope;
  138.       } else {
  139.          throw new IllegalArgumentException("Illegal scope value.");
  140.       }
  141.    }
  142.  
  143.    public List<Integer> getScopes() {
  144.       return scopes;
  145.    }
  146.  
  147.    static {
  148.       scopes.add(100);
  149.       scopes.add(200);
  150.       scopes = Collections.unmodifiableList(scopes);
  151.    }
  152. }
  153.