FileDocCategorySizeDatePackage
CliUtil.javaAPI DocGlassfish v2 API5242Fri May 04 22:25:20 BST 2007com.sun.enterprise.cli.framework

CliUtil

public class CliUtil extends Object
This is a CLI utility class that uses the cliutil native code.
author
Jane Young

Fields Summary
Constructors Summary
Methods Summary
public native java.lang.String[]getAllEnv()

public native java.lang.String[]getEnv(java.lang.String prefix)

public native chargetKeyboardInput()

public native java.lang.StringgetPassword()

public java.lang.StringgetPassword(java.lang.String prompt)
This function prompts the user for the password without echoing the characters to the terminal.

param
prompt - prompt to display
return
the password entered by the user

	    InputsAndOutputs.getInstance().getUserOutput().print( prompt );
	    return getPassword();
    
private static java.lang.StringgetText()

        String s = null;

        try
        {
            BufferedReader in;
            in = new BufferedReader(new InputStreamReader(System.in));
            s = in.readLine();
        }
        catch (IOException exc)
        {
            System.err.println("Caught exception: " + exc);
        }

        return (s);
    
public static voidmain(java.lang.String[] args)

        System.loadLibrary("cliutil");
    
        final String sEnvPrefix = "PS_ADMIN_";
        boolean bContinue = true;

        while (bContinue) {
            System.out.println("Menu");
            System.out.println("[1] get environment");
            System.out.println("[2] get password");
            System.out.println("[3] get keyboard press");
            System.out.println("[4] get all environment");
            System.out.println("[5] exit");
        
            String line = getText();

            if (line.equals("1")) {
                String [] sEnvVal = new CliUtil().getEnv(sEnvPrefix);
                for (int ii=0; ii<sEnvVal.length; ii++) {
                        //check for prefix AS_ADMIN
                    String sName = sEnvVal[ii];
                    if (sName.regionMatches(true, 0, sEnvPrefix, 0,
                                            sEnvPrefix.length())) {
                        System.out.println(sName);
                    }
                }
            }
            else if (line.equals("2")) {
                String sPassword = new CliUtil().getPassword("Enter password>");
                System.out.println("Password entered = " + sPassword);
            }
            else if (line.equals("3")) {
                char c = new CliUtil().getKeyboardInput();
                System.out.println("\n key entered = " + c);
            }
            else if (line.equals("4")) {
                String[] envs = new CliUtil().getAllEnv();
                System.out.println("Get All Environment");
                for (String env : envs) {
                    System.out.println(env);
                }
            }
            else if (line.equals("5")) {
                bContinue =false;
            }
            else {
                System.out.println("You did not entered the right option.");
            }
        }