KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > framework > CliUtil


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * $Id: CliUtil.java,v 1.3 2005/12/25 03:46:55 tcfujii Exp $
26  */

27
28 package com.sun.enterprise.cli.framework;
29
30 import java.io.*;
31
32 /**
33  * This is a CLI utility class that uses the cliutil native code.
34  * @author Jane Young
35  */

36 public class CliUtil
37 {
38     // the getEnv method only return variables that start with AS_ADMIN_
39
public native String JavaDoc[] getEnv(String JavaDoc prefix);
40     // added method for use in ProcessLauncher to get CLASSPATH env Variable
41
public native String JavaDoc[] getAllEnv();
42     public native String JavaDoc getPassword();
43
44         /**
45          * This function prompts the user for the password without echoing
46          * the characters to the terminal.
47          * @param prompt - prompt to display
48          * @return the password entered by the user
49          **/

50     public String JavaDoc getPassword(String JavaDoc prompt){
51         InputsAndOutputs.getInstance().getUserOutput().print( prompt );
52         return getPassword();
53     }
54
55     static
56     {
57         System.loadLibrary("cliutil");
58     }
59
60     public static void main(String JavaDoc[] args)
61     {
62         String JavaDoc sEnvPrefix = "PS_ADMIN_";
63         System.out.println("Menu");
64         System.out.println("[1] get environment");
65         String JavaDoc line = getText();
66
67         if (line.equals("1"))
68     {
69             String JavaDoc [] sEnvVal = new CliUtil().getEnv(sEnvPrefix);
70             for (int ii=0; ii<sEnvVal.length; ii++)
71         {
72                 //check for prefix AS_ADMIN
73
String JavaDoc sName = sEnvVal[ii];
74                 if (sName.regionMatches(true, 0, sEnvPrefix, 0,
75                                         sEnvPrefix.length()))
76         {
77                     System.out.println(sName);
78                 }
79             }
80         }
81         else
82     {
83             System.out.println("You did not entered the right option.");
84         }
85       
86    }
87
88     private static String JavaDoc getText()
89     {
90         String JavaDoc s = null;
91
92         try
93         {
94             BufferedReader in;
95             in = new BufferedReader(new InputStreamReader(System.in));
96             s = in.readLine();
97         }
98         catch (IOException exc)
99         {
100             System.err.println("Caught exception: " + exc);
101         }
102
103         return (s);
104     }
105 }
106
107
Popular Tags