Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
   *
   * This Source Code Form is subject to the terms of the Mozilla Public
   * License, v. 2.0. If a copy of the MPL was not distributed with this
   * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  
  /*
          Environment.java
  
         Wraps java.lang.System properties.
 
         by Patrick C. Beard <beard@netscape.com>
  */
 
 package org.mozilla.javascript.tools.shell;
 
 
 import java.util.Map;

Environment, intended to be instantiated at global scope, provides a natural way to access System properties from JavaScript.

Author(s):
Patrick C. Beard
 
 public class Environment extends ScriptableObject
 {
     static final long serialVersionUID = -430727378460177065L;
 
     private Environment thePrototypeInstance = null;
 
     public static void defineClass(ScriptableObject scope) {
         try {
             ScriptableObject.defineClass(scopeEnvironment.class);
         } catch (Exception e) {
             throw new Error(e.getMessage());
         }
     }
 
     @Override
     public String getClassName() {
         return "Environment";
     }
 
     public Environment() {
         if ( == null)
              = this;
     }
 
     public Environment(ScriptableObject scope) {
         setParentScope(scope);
         Object ctor = ScriptRuntime.getTopLevelProp(scope"Environment");
         if (ctor != null && ctor instanceof Scriptable) {
             Scriptable s = (Scriptablector;
             setPrototype((Scriptables.get("prototype"s));
         }
     }
 
     @Override
     public boolean has(String nameScriptable start) {
         if (this == )
             return super.has(namestart);
 
         return (System.getProperty(name) != null);
     }
 
     @Override
     public Object get(String nameScriptable start) {
         if (this == )
             return super.get(namestart);
 
         String result = System.getProperty(name);
         if (result != null)
             return ScriptRuntime.toObject(getParentScope(), result);
         else
             return .;
     }
 
     @Override
     public void put(String nameScriptable startObject value) {
         if (this == )
             super.put(namestartvalue);
         else
             System.getProperties().put(name, ScriptRuntime.toString(value));
     }
 
     private Object[] collectIds() {
         Map<Object,Objectprops = System.getProperties();
         return props.keySet().toArray();
     }
 
     @Override
     public Object[] getIds() {
         if (this == )
             return super.getIds();
         return collectIds();
    }
    @Override
    public Object[] getAllIds() {
        if (this == )
            return super.getAllIds();
        return collectIds();
    }
New to GrepCode? Check out our FAQ X