KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > cli > jmx > cmd > SetenvCmd


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  * $Header: /cvs/glassfish/admin-cli/cli-api/src/java/com/sun/cli/jmx/cmd/SetenvCmd.java,v 1.3 2005/12/25 03:45:40 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:45:40 $
28  */

29  
30 package com.sun.cli.jmx.cmd;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.Iterator JavaDoc;
34
35 import com.sun.cli.util.stringifier.IteratorStringifier;
36
37 import com.sun.cli.jmx.spi.JMXConnectorProvider;
38
39 public class SetenvCmd extends JMXCmd
40 {
41         public
42     SetenvCmd( final CmdEnv env )
43     {
44         super( env );
45     }
46     
47         int
48     getNumRequiredOperands()
49     {
50         return( 0 );
51     }
52     
53     
54         String JavaDoc
55     getUsage()
56     {
57         return( CmdStrings.SETENV_HELP.toString() );
58         //return( CmdStrings.SETENV_HELP.toString() );
59
}
60     
61     public final static String JavaDoc NAME = "setenv";
62     
63         public static String JavaDoc []
64     getNames( )
65     {
66         return( new String JavaDoc [] { NAME } );
67     }
68     
69     
70     static private final String JavaDoc OPTIONS_INFO = "";
71         
72     
73         ArgHelper.OptionsInfo
74     getOptionInfo()
75         throws ArgHelper.IllegalOptionException
76     {
77         return( new ArgHelperOptionsInfo( OPTIONS_INFO ) );
78     }
79
80
81         void
82     displayEnv()
83     {
84         final Iterator JavaDoc iter = getEnvKeys().iterator();
85         
86         while ( iter.hasNext() )
87         {
88             final String JavaDoc name = (String JavaDoc)iter.next();
89             
90             final Object JavaDoc value = envGet( name );
91             
92             if ( value instanceof String JavaDoc )
93             {
94                 println( name + "=" + value );
95             }
96         }
97     }
98     
99     public final static char DELIM = '=';
100     
101         void
102     executeInternal()
103         throws Exception JavaDoc
104     {
105         final String JavaDoc [] operands = getOperands();
106         
107         if ( operands.length == 0 )
108         {
109             displayEnv();
110         }
111         else if ( operands.length == 1 )
112         {
113             final String JavaDoc oper = operands[ 0 ];
114             final int delimIndex = oper.indexOf( DELIM );
115             
116                 
117             if ( delimIndex > 0 )
118             {
119                 final String JavaDoc name = oper.substring( 0, delimIndex );
120                 final String JavaDoc value = oper.substring( delimIndex + 1, oper.length() );
121                 
122                 envPut( name, value, true );
123             }
124             else
125             {
126                 if ( envGet( oper ) != null )
127                 {
128                     envRemove( oper );
129                     println( "Variable " + oper + " removed." );
130                 }
131                 else
132                 {
133                     println( "Variable " + oper + " does not exist." );
134                 }
135             }
136         }
137         else
138         {
139             printUsage();
140         }
141     }
142 }
143
144
145
146
147
148
149
Popular Tags