FileDocCategorySizeDatePackage
env.javaAPI DocExample1693Wed Apr 05 11:25:42 BST 2000None

env.java

/*
 * This example is from the book "Java Enterprise in a Nutshell".
 * Copyright (c) 1999 by O'Reilly & Associates.  
 * You may distribute this source code for non-commercial purposes only.
 * You may study, modify, and use this example for any purpose, as long as
 * this notice is retained.  Note that this example is provided "as is",
 * WITHOUT WARRANTY of any kind either expressed or implied.
 */

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

import javax.naming.Context;
import javax.naming.NamingException;

class env implements Command {
    
    public void execute(Context c, Vector v) 
        throws CommandException {
            
        if (c == null)
            throw new CommandException(new Exception(),
                "No current context");
        try {
            Hashtable env = NamingShell.getInitialContext().getEnvironment();
            Enumeration enum = env.keys();
            String key;
            while (enum.hasMoreElements()) {
                key = (String)enum.nextElement();
                System.out.println(key + "\t" + env.get(key));
            }

            Hashtable sysProps = System.getProperties();
            Enumeration sysEnum = sysProps.keys();
            while (sysEnum.hasMoreElements()) {
                key = (String)sysEnum.nextElement();
                System.out.println(key + "\t" + sysProps.get(key));
            }
        }
        catch (NamingException ne) {
            throw new CommandException(ne, "Couldn't get the environment of " 
                + NamingShell.getCurrentContext());
        }
    }
    
    public void help() { System.out.println("Usage: env");
    }
}