KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > S1ASCommand


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 package com.sun.enterprise.cli.commands;
25
26 import com.sun.enterprise.cli.framework.*;
27 import com.sun.enterprise.deployment.client.ServerConnectionIdentifier;
28 import javax.management.Attribute JavaDoc;
29 import javax.management.AttributeList JavaDoc;
30 import javax.management.remote.JMXServiceURL JavaDoc;
31 import javax.management.remote.JMXConnector JavaDoc;
32 import javax.management.remote.JMXConnectorFactory JavaDoc;
33 import javax.management.MBeanServerConnection JavaDoc;
34 import javax.management.ObjectName JavaDoc;
35 import javax.management.MalformedObjectNameException JavaDoc;
36 import javax.management.InstanceNotFoundException JavaDoc;
37 import javax.management.IntrospectionException JavaDoc;
38 import javax.management.ReflectionException JavaDoc;
39
40 import com.sun.appserv.management.util.misc.ExceptionUtil;
41
42 import com.sun.enterprise.admin.jmx.remote.DefaultConfiguration;
43
44 import com.sun.enterprise.admin.servermgmt.RepositoryConfig;
45 import com.sun.enterprise.admin.servermgmt.RepositoryManager;
46 import com.sun.enterprise.admin.servermgmt.RepositoryException;
47 import com.sun.enterprise.util.SystemPropertyConstants;
48 import com.sun.enterprise.util.ASenvPropertyReader;
49
50 import com.sun.appserv.management.client.prefs.LoginInfo;
51 import com.sun.appserv.management.client.prefs.LoginInfoStore;
52 import com.sun.appserv.management.client.prefs.LoginInfoStoreFactory;
53
54
55 import java.util.Vector JavaDoc;
56 import java.util.HashMap JavaDoc;
57 import java.util.Map JavaDoc;
58 import java.util.logging.Level JavaDoc;
59 import java.net.MalformedURLException JavaDoc;
60 import java.io.IOException JavaDoc;
61 import java.util.StringTokenizer JavaDoc;
62 import java.util.Properties JavaDoc;
63 import java.util.Enumeration JavaDoc;
64 import java.io.File JavaDoc;
65 import java.util.List JavaDoc;
66 import java.util.Iterator JavaDoc;
67
68
69 /**
70  * This is an abstract class extended from Command.
71  * This class contains the method to create the JMX connector.
72  * @version $Revision: 1.25 $
73  */

74 public abstract class S1ASCommand extends Command
75 {
76
77     public final static String JavaDoc JMX_PROTOCOL = "jmxmp";
78     public final static String JavaDoc TERSE = "terse";
79     public final static String JavaDoc INTERACTIVE = "interactive";
80     public final static String JavaDoc PASSWORDFILE = "passwordfile";
81     public final static String JavaDoc ECHO = "echo";
82     public final static String JavaDoc HOST = "host";
83     public final static String JavaDoc PORT = "port";
84     public final static String JavaDoc USER = "user";
85     public final static String JavaDoc PASSWORD = "password";
86     public final static String JavaDoc SECURE = "secure";
87     public final static String JavaDoc MAPPED_PASSWORD = "mappedpassword";
88     public final static String JavaDoc OBJECT_NAME = "objectname";
89     public final static String JavaDoc ARGUMENTS = "arguments";
90     public final static String JavaDoc OPERATION = "operation";
91     public final static String JavaDoc PARAMS = "params";
92     public final static String JavaDoc PARAM_TYPES = "paramtypes";
93     public final static String JavaDoc RETURN_TYPE = "returntype";
94     public final static String JavaDoc DISPLAY_TYPE = "displaytype";
95     public final static String JavaDoc PROPERTY = "property.";
96     public final static String JavaDoc DOMAIN = "domain";
97     
98     public final static String JavaDoc ATTRIBUTE_LIST_CLASS = AttributeList JavaDoc.class.getName();
99     public final static String JavaDoc PROPERTIES_CLASS = Properties JavaDoc.class.getName();
100     public final static String JavaDoc BOOLEAN_CLASS = Boolean JavaDoc.class.getName();
101     public final static String JavaDoc PRIMITIVE_BOOLEAN_CLASS = boolean.class.getName();
102     public final static String JavaDoc STRING_ARRAY = (new String JavaDoc[]{}).getClass().getName();
103     public final static String JavaDoc MAP_CLASS = Map JavaDoc.class.getName();
104     public final static String JavaDoc LONG_CLASS = Long JavaDoc.class.getName();
105     public final static String JavaDoc PRIMITIVE_LONG_CLASS = long.class.getName();
106     public final static String JavaDoc INTEGER_CLASS = Integer JavaDoc.class.getName();
107     public final static String JavaDoc PRIMITIVE_INTEGER_CLASS = int.class.getName();
108     public final static String JavaDoc OBJECT_CLASS = Object JavaDoc.class.getName();
109         
110     public final static String JavaDoc PARAM_DELIMITER = ",";
111     public final static String JavaDoc PARAM_VALUE_DELIMITER = "=";
112     public final static String JavaDoc PROPERTY_DELIMITER = ":";
113  
114     protected final static String JavaDoc ASADMINPREFS = ".asadminprefs";
115
116     /** these constants are for the hack for reading properties **/
117     protected final static String JavaDoc SHORTHAND_DELIMETER = ":";
118     protected final static char ESCAPE_CHAR = '\\';
119     protected static final String JavaDoc SET_DELIMETER = "=";
120
121     protected final static String JavaDoc ENV_PREFIX = "AS_ADMIN_";
122     protected static String JavaDoc NOT_DEPRECATED_PASSWORDFILE_OPTIONS =
123         "password|adminpassword|userpassword|masterpassword|aliaspassword|mappedpassword";
124     protected final static String JavaDoc COMMENT_PREFIX = "#";
125
126
127     public final static String JavaDoc LIST_JMS_RESOURCES = "list-jms-resources";
128
129     //these are global variables so that .asadminpref file does not need to be read
130
//each time getUser or getPassword get invoked.
131
private String JavaDoc userValue = null;
132     private boolean warningDisplayed = false;
133
134
135     public S1ASCommand()
136     {
137         //Use asenv.conf/bat to set up necessary system properties
138
final ASenvPropertyReader reader = new ASenvPropertyReader(
139             System.getProperty(SystemPropertyConstants.CONFIG_ROOT_PROPERTY));
140         reader.setSystemProperties();
141     }
142     
143
144     /**
145      * An abstract method that validates the options
146      * on the specification in the xml properties file
147      * This method verifies for the correctness of number of
148      * operands and if all the required options are supplied by the client.
149      * @return boolean returns true if success else returns false
150      */

151     public boolean validateOptions() throws CommandValidationException
152     {
153         setLoggerLevel();
154         
155         // echo the command if echo is turned on
156
if (getBooleanOption(ECHO))
157         {
158             CLILogger.getInstance().printMessage(this.toString());
159         }
160         //Throw an error when password options are used on commandline
161
// or ignore them when set through environment variables
162
HashMap JavaDoc options = getOptions();
163         Iterator JavaDoc optionNames = options.keySet().iterator();
164         while (optionNames.hasNext())
165         {
166             final String JavaDoc optionKey = (String JavaDoc) optionNames.next();
167             if (optionKey.matches(NOT_DEPRECATED_PASSWORDFILE_OPTIONS))
168                 validatePasswordOption(optionKey);
169         }
170         return true;
171     }
172
173     
174     private void validatePasswordOption(String JavaDoc passwordOptionName)
175                      throws CommandValidationException
176     {
177         //As per sun security policy reusable passwords should not be allowed on
178
//command line (give an exception) or environment variables (ignore).
179
if (getCLOption(passwordOptionName) != null)
180             throw new CommandValidationException(getLocalizedString("PasswordsNotAllowedOnCommandLine",
181                                                     new Object JavaDoc[]{passwordOptionName}));
182         if (getENVOption(passwordOptionName) != null)
183             CLILogger.getInstance().printWarning(getLocalizedString("PasswordsNotAllowedInEnvironment",
184                                                         new Object JavaDoc[]{passwordOptionName}));
185     }
186     /**
187      * This method sets the logger level depending on the terse option.
188      * If terse is true, then the logger level is set to INFO.
189      * If terse is false, then the logger level is set to FINE.
190      */

191     protected void setLoggerLevel()
192     {
193         final boolean terse = getBooleanOption(TERSE);
194
195         if (terse)
196         {
197             //set the logger level to INFO
198
CLILogger.getInstance().setOutputLevel(java.util.logging.Level.INFO);
199         }
200         else
201         {
202             //set the logger level to FINE
203
CLILogger.getInstance().setOutputLevel(java.util.logging.Level.FINE);
204         }
205     }
206    
207
208     /**
209      * This method returns the MBeanServerConnection to used to invoke the
210      * MBean methods
211      * @param protocol - the protocol part of the URL. If null, defaults to jmxmp.
212      * @param host - the host part of the URL. If null, defaults to the local host
213      * name, as determined by InetAddress.getLocalHost().getHostName(). If it is a
214      * numeric IPv6 address, it can optionally be enclosed in square brackets [].
215      * @port - the port part of the URL.
216      * @user - the user name for authenticating with MBeanServer
217      * @password - the password for authenticating with MBeanServer
218      * @return MBeanServerConnection
219      */

220     protected MBeanServerConnection JavaDoc getMBeanServerConnection(String JavaDoc protocol,
221                                         String JavaDoc host, int port,
222                                         String JavaDoc user, String JavaDoc password)
223                                         throws CommandException
224     {
225         //Create a JMXMP connector client and
226
//connect it to the JMXMP connector server
227
final JMXServiceURL JavaDoc url = getJMXServiceURL(protocol, host, port);
228         try
229         {
230             final JMXConnector JavaDoc jmxc = JMXConnectorFactory.connect(url);
231   
232             //Get an MBeanSErverConnection
233
CLILogger.getInstance().printDebugMessage("Get an MBeanSErverConnection");
234             return jmxc.getMBeanServerConnection();
235         }
236         catch(IOException JavaDoc ioe)
237         {
238             throw new CommandException(ioe);
239         }
240     }
241
242     
243     /**
244      * This method creates the JMXServiceURL
245      * @param protocol
246      * @param host
247      * @param port
248      */

249     private JMXServiceURL JavaDoc getJMXServiceURL(String JavaDoc protocol, String JavaDoc host, int port)
250     throws CommandException
251     {
252         try
253         {
254             CLILogger.getInstance().printDebugMessage(
255                 "Create a JMXMP connector client and " +
256                 "connect it to the JMXMP connector server");
257
258             final JMXServiceURL JavaDoc url = new JMXServiceURL JavaDoc(protocol, host, port);
259             CLILogger.getInstance().printDebugMessage("url = " + url.toString());
260             return url;
261         }
262         catch(MalformedURLException JavaDoc mue)
263         {
264             throw new CommandException(mue);
265         }
266     }
267
268
269     /**
270      * This method returns the MBeanServerConnection to used to invoke the
271      * MBean methods via HTPP connector.
272      * @param host - the host part of the URL. If null, defaults to the local
273      * host name, as determined by InetAddress.getLocalHost().getHostName().
274      * If it is a numeric IPv6 address, it can optionally be enclosed in square
275      * brackets [].
276      * @port - the port part of the URL.
277      * @user - the user name for authenticating with MBeanServer
278      * @password - the password for authenticating with MBeanServer
279      * @return MBeanServerConnection
280      */

281     protected MBeanServerConnection JavaDoc getMBeanServerConnection(String JavaDoc host, int port,
282                                         String JavaDoc user, String JavaDoc password)
283     throws CommandException, CommandValidationException
284     {
285         try
286         {
287             String JavaDoc jmxProtocol = null;
288             
289             if (getBooleanOption(SECURE)) {
290                 jmxProtocol = DefaultConfiguration.S1_HTTPS_PROTOCOL;
291             } else {
292                 jmxProtocol = DefaultConfiguration.S1_HTTP_PROTOCOL;
293             }
294
295             final JMXServiceURL JavaDoc url = new JMXServiceURL JavaDoc(jmxProtocol, host, port);
296             final JMXConnector JavaDoc conn = JMXConnectorFactory.connect(url,
297                 initEnvironment(user, password));
298             return conn.getMBeanServerConnection();
299         }
300         catch (Exception JavaDoc e)
301         {
302             throw new CommandException(e);
303         }
304     }
305
306     /**
307      * This method returns the ServerConnectionIdentifier to used to invoke the
308      * MBean methods via HTTP(S) connector.
309      * @param host - the host part of the URL. If null, defaults to the local
310      * host name, as determined by InetAddress.getLocalHost().getHostName().
311      * If it is a numeric IPv6 address, it can optionally be enclosed in square
312      * brackets [].
313      * @port - the port part of the URL.
314      * @user - the user name for authenticating with MBeanServer
315      * @password - the password for authenticating with MBeanServer
316      * @return ServerConnectionIdentifier
317      */

318     protected ServerConnectionIdentifier createServerConnectionIdentifier(
319             String JavaDoc host, int port, String JavaDoc user, String JavaDoc password)
320     throws CommandException, CommandValidationException
321     {
322         ServerConnectionIdentifier conn =
323             new ServerConnectionIdentifier();//getHost(), getPort(), getUser(), getPassword());
324
conn.setHostName(host);
325         conn.setHostPort(port);
326         conn.setUserName(user);
327         conn.setPassword(password);
328
329         if (getBooleanOption(SECURE)) {
330             conn.setSecure(true);
331         } else {
332             conn.setSecure(false);
333         }
334
335         return conn;
336     }
337
338
339     /**
340      * This method initialize the environment for creating the JMXConnector.
341      * @return Map - HashMap of environemtn
342      */

343     private Map JavaDoc initEnvironment(String JavaDoc user, String JavaDoc password)
344         throws CommandValidationException, CommandException
345     {
346         final Map JavaDoc env = new HashMap JavaDoc();
347         final String JavaDoc PKGS = "com.sun.enterprise.admin.jmx.remote.protocol";
348
349         env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_CLASS_LOADER,
350                 this.getClass().getClassLoader());
351         env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, PKGS);
352         env.put(DefaultConfiguration.ADMIN_USER_ENV_PROPERTY_NAME, user);
353         env.put(DefaultConfiguration.ADMIN_PASSWORD_ENV_PROPERTY_NAME, password);
354         env.put(DefaultConfiguration.HTTP_AUTH_PROPERTY_NAME,
355         DefaultConfiguration.DEFAULT_HTTP_AUTH_SCHEME);
356         return ( env );
357     }
358
359   
360     /*
361      * Returns the host option value
362      * @return host returns host option value
363      */

364     protected String JavaDoc getHost()
365     {
366         return getOption(HOST);
367     }
368
369
370     /*
371      * Returns the port option value
372      * @return port returns port option value
373      */

374     protected int getPort() throws CommandValidationException
375     {
376         String JavaDoc port = getOption(PORT);
377         
378         try
379         {
380             int portInt = 0;
381             portInt = Integer.parseInt(port);
382             return portInt;
383         }
384         catch(Exception JavaDoc e)
385         {
386             throw new CommandValidationException(getLocalizedString("InvalidPortNumber",
387                               new Object JavaDoc[] {port}), e);
388         }
389     }
390
391
392     /*
393      * Returns the user option value
394      * @return user returns user option value
395      * @throws CommandValidationException if the following is true:
396      * 1. --user option not on command line
397      * 2. user option not specified in environment
398      * 3. user option not specified in ASADMINPREFS file
399      * 4. user option not specified in .asadminpass file
400      * 5. --interactive is false, and no prompting is possible
401      */

402     protected String JavaDoc getUser() throws CommandValidationException
403     {
404         if (getOption(USER) == null && userValue == null)
405         {
406             // read from .asadminpass
407
userValue = getUserFromASADMINPASS();
408             if (userValue != null)
409                 return userValue;
410             
411             // read from .asadminprefs
412
userValue= getValuesFromASADMINPREFS(USER);
413             if (userValue != null)
414             {
415                 CLILogger.getInstance().printDebugMessage(
416                                 "user value read from " + ASADMINPREFS);
417                 return userValue;
418             }
419             else if (getBooleanOption(INTERACTIVE))
420             {
421                 //prompt for user
422
try {
423                     InputsAndOutputs.getInstance().getUserOutput().print(
424                                         getLocalizedString("AdminUserPrompt"));
425                     return InputsAndOutputs.getInstance().getUserInput().getLine();
426                 }
427                 catch (IOException JavaDoc ioe)
428                 {
429                     throw new CommandValidationException(
430                                 getLocalizedString("CannotReadOption",
431                                                         new Object JavaDoc[]{"user"}));
432                 }
433             }
434         }
435         else if (getOption(USER) != null)
436             return getOption(USER);
437
438         else if (userValue != null)
439             return userValue;
440
441         //if all else fails, then throw an exception
442
throw new CommandValidationException(getLocalizedString("OptionIsRequired",
443                                                                 new Object JavaDoc[] {USER}));
444     }
445
446
447     /**
448      * get user or password from ASADMINPREFS file
449      * @params nameOfValue
450      * @return user or password value from .asadminprefs file
451      * if file not found then return null
452      */

453     protected String JavaDoc getUserFromASADMINPASS()
454     {
455         String JavaDoc userValue = null;
456         int port;
457         String JavaDoc host = getHost();
458         try
459         {
460             //will be null for start-domain/node-agent/appserv commands
461
port = getPort();
462         }
463         catch(CommandValidationException cve)
464         {
465             // exception only for start-domain/node-agent/appserv commands
466
// ignore the exception since we are trying to get user, not port
467
// and dont read the .asadminpass
468
return userValue;
469         }
470
471         // get the user value from .asadminpass
472
try
473         {
474             final LoginInfoStore store = LoginInfoStoreFactory.getStore(null);
475             if (store.exists(host, port))
476             {
477                 LoginInfo login = store.read(host, port);
478                 userValue = login.getUser();
479                 if (userValue != null)
480                 {
481                     CLILogger.getInstance().printDebugMessage(
482                                     "user value read from " + store.getName());
483                 }
484             }
485         }
486         catch(final Exception JavaDoc e) {
487             final Object JavaDoc[] params = new String JavaDoc[] {host, "" + port};
488             final String JavaDoc msg = getLocalizedString("LoginInfoCouldNotBeRead", params);
489             CLILogger.getInstance().printWarning(msg);
490             CLILogger.getInstance().printExceptionStackTrace(e);
491         }
492         return userValue;
493     }
494         
495     
496     /**
497      * get user or password from ASADMINPREFS file
498      * @params nameOfValue
499      * @return user or password value from .asadminprefs file
500      * if file not found then return null
501      */

502     protected String JavaDoc getValuesFromASADMINPREFS(String JavaDoc nameOfValue)
503     {
504         String JavaDoc returnVal = null;
505         java.io.BufferedReader JavaDoc reader = null;
506         try
507         {
508             File JavaDoc file = checkForFileExistence(System.getProperty("user.home"), ASADMINPREFS);
509             reader = new java.io.BufferedReader JavaDoc(new java.io.FileReader JavaDoc(file));
510             String JavaDoc line = reader.readLine();
511             while (!(line == null) && returnVal==null)
512             {
513                 //check for prefix AS_ADMIN_
514
if (line.regionMatches(true, 0, ENV_PREFIX, 0, ENV_PREFIX.length()))
515                 {
516                     //extract AS_ADMIN_
517
final String JavaDoc[] nameAndValue = splitNameValuePairs(line);
518                     if (nameAndValue[0].equalsIgnoreCase(nameOfValue))
519                         returnVal = nameAndValue[1];
520
521                 }
522                 line = reader.readLine();
523             }
524             reader.close();
525             return returnVal;
526         }
527         catch (Exception JavaDoc e)
528         {
529             return null;
530         }
531     }
532
533
534     /**
535      * this method will split the nameValueParis into two strings
536      * the name value pairs must begin with AS_ADMIN_
537      * @param nameValuePairs - the string to split
538      * @return splitted string
539      */

540     private String JavaDoc[] splitNameValuePairs(String JavaDoc nameValuePairs)
541     {
542         //extract AS_ADMIN
543
final String JavaDoc tempStr = nameValuePairs.substring(ENV_PREFIX.length());
544         int idx = tempStr.indexOf(PARAM_VALUE_DELIMITER);
545         if (idx>0 && idx<tempStr.length()-1 ) {
546             String JavaDoc name=tempStr.substring(0,idx);
547             String JavaDoc value=tempStr.substring(idx+1);
548             String JavaDoc[] nameAndValue = new String JavaDoc[] {name,value};
549             return nameAndValue;
550         }
551         return new String JavaDoc[] {"",""};
552     }
553
554
555     /**
556      * Returns the password option value. This is used by all asadmin commands that accept the --password
557      * option.
558      * @return password returns password option value
559      */

560     protected String JavaDoc getPassword() throws CommandValidationException, CommandException
561     {
562         //getPassword(optionName, allowedOnCommandLine, readPrefsFile, readPasswordOptionFromPrefs, readMasterPasswordFile, mgr, config,
563
//promptUser, confirm, validate)
564
return getPassword(PASSWORD, "AdminPasswordPrompt", "AdminPasswordConfirmationPrompt",
565                             true, true, false, false, null, null, true, false, false, true);
566     }
567     
568      
569     protected boolean isPasswordValid(String JavaDoc passwd) {
570         if (passwd.length() < 8) {
571             return false;
572         } else {
573             return true;
574         }
575     }
576
577     protected String JavaDoc getPassword(String JavaDoc optionName,
578         boolean allowedOnCommandLine,
579         boolean readPrefsFile,
580         boolean readPasswordOptionFromPrefs,
581         boolean readMasterPasswordFile, RepositoryManager mgr, RepositoryConfig config,
582         boolean promptUser, boolean confirm, boolean validate, boolean displayWarning)
583             throws CommandValidationException, CommandException
584     {
585         return getPassword(optionName, "InteractiveOptionPrompt", "InteractiveOptionConfirmationPrompt",
586             allowedOnCommandLine, readPrefsFile, readPasswordOptionFromPrefs,
587             readMasterPasswordFile, mgr, config, promptUser, confirm, validate, displayWarning);
588     }
589     
590     /**
591      * this methods returns a password
592      * first it checks if the password option is specified on command line.
593      * if not, then it'll try to get the password from the password file and
594      * optionally from the ./asadminprefs file.
595      * if all else fails, then prompt the user for the password if interactive=true.
596      * @param readPrefsFile indicates whether the preferences file should be searched
597      * for the option.
598      * @param readPasswordOptionFromPrefs indicates whether the AS_ADMIN_PASSWORD option
599      * should be used from the prefs file before prompting.
600      * @param readMasterPasswordFile indicates whether the password should be read from the
601      * master password file (valid only for the master password)
602      * @param mgr is needed if readMasterPasswordFile is true and is used to locate the
603      * master password file.
604      * @param config is needed if readMasterPasswordFile is true and is used to locate
605      * the master password file.
606      * @param promptUser indicates whether the user should be prompted for the password.
607      * @param confirm indicate whether the password should be confirmed (i.e. the user is
608      * prompted for it 2x and must enter the same value.
609      * @param validate indicates whether the password should be validated
610      * @return admin password
611      * @throws CommandValidationException if could not get adminpassword option
612      */

613     protected String JavaDoc getPassword(String JavaDoc optionName,
614         String JavaDoc promptMsg,
615         String JavaDoc confirmationPromptMsg,
616         boolean allowedOnCommandLine,
617         boolean readPrefsFile,
618         boolean readPasswordOptionFromPrefs,
619         boolean readMasterPasswordFile, RepositoryManager mgr, RepositoryConfig config,
620         boolean promptUser, boolean confirm, boolean validate, boolean displayWarning)
621             throws CommandValidationException, CommandException
622     {
623         String JavaDoc passwordVal;
624         //try to read the password from the password file
625
if (getOption(PASSWORDFILE) != null) {
626             loadPasswordFileOptions(optionName);
627         }
628         // read the password which was just read from the passwordfile,
629
// making sure its not read from the environment which is not supported.
630
passwordVal = getCLOption(optionName);
631
632         if (passwordVal == null)
633         {
634             //Next try the preferences file .asadminpass
635
if (readPrefsFile)
636             {
637                 // Read only when we are dealing with the --port not the
638
// --adminport (in the case of create-domain).
639
if (getOption(PORT) != null)
640                 {
641                     String JavaDoc host = getHost();
642                     int port = getPort();
643                     try
644                     {
645                         final LoginInfoStore store = LoginInfoStoreFactory.getStore(null);
646                         if (store.exists(host, port))
647                         {
648                             LoginInfo login = store.read(host, port);
649                             passwordVal = login.getPassword();
650                             if (passwordVal != null)
651                             {
652                                 CLILogger.getInstance().printDebugMessage(
653                                         "password value read from " + store.getName());
654                             }
655                         }
656                     }
657                     catch(final Exception JavaDoc e)
658                     {
659                         final Object JavaDoc[] params = new String JavaDoc[] {host, "" + port};
660                         final String JavaDoc msg = getLocalizedString("LoginInfoCouldNotBeRead", params);
661                         CLILogger.getInstance().printWarning(msg);
662                         CLILogger.getInstance().printExceptionStackTrace(e);
663                     }
664                 }
665                 // now read from the .asadminprefs file
666
if (passwordVal == null)
667                 {
668                     passwordVal = getValuesFromASADMINPREFS(optionName);
669                     if (passwordVal != null)
670                     {
671                         CLILogger.getInstance().printDebugMessage(
672                                 "password value read from " + ASADMINPREFS);
673                     }
674                 }
675             }
676             if (passwordVal == null)
677             {
678                 //Next try the password element of the preferences file
679
if (readPrefsFile && readPasswordOptionFromPrefs)
680                 {
681                     passwordVal = getValuesFromASADMINPREFS(PASSWORD);
682                 }
683                 if (passwordVal == null)
684                 {
685                     //Next try the master password file
686
if (readMasterPasswordFile && mgr != null && config != null)
687                     {
688                         try
689                         {
690                             passwordVal = mgr.readMasterPasswordFile(config);
691                         } catch (RepositoryException ex)
692                         {
693                             throw new CommandException(ex);
694                         }
695                     }
696                     if (passwordVal == null)
697                     {
698                         //Finally prompt the user if all else fails. A confimation indicates that
699
//the user must enter the password 2x to confirm its value.
700
if (promptUser)
701                         {
702                             if (confirm)
703                             {
704                                 passwordVal = getInteractiveOptionWithConfirmation(optionName,
705                                     getLocalizedString(promptMsg, new Object JavaDoc[] {optionName}),
706                                     getLocalizedString(confirmationPromptMsg, new Object JavaDoc[] {optionName}),
707                                     validate);
708                             } else
709                             {
710                                 passwordVal = getInteractiveOption(optionName,
711                                     getLocalizedString(promptMsg, new Object JavaDoc[] {optionName}));
712                             }
713                         }
714                     }
715                 }
716             }
717         }
718         //Validate the password
719
if (validate && passwordVal != null && !isPasswordValid(passwordVal))
720         {
721             throw new CommandValidationException(getLocalizedString("PasswordLimit",
722                 new Object JavaDoc[]{optionName}));
723         }
724         return passwordVal;
725     }
726     
727     /**
728      * If interactive is true, then prompt the user for the option value. The
729      * user is then prompted to enter the option (i.e. a password) again and the
730      * two values must match.
731      * @return option value
732      * @param validatePassword -- true if the option should be validated as a
733      * password. This gives us the ability to fail before prompting twice
734      * @param optionName - name of option.
735      * @throws CommandValidationException is interactive is false and the option
736      * value is null or if the two values entered do not match.
737      */

738     protected String JavaDoc getInteractiveOptionWithConfirmation(String JavaDoc optionName, String JavaDoc prompt,
739         String JavaDoc confirmationPrompt, boolean validatePassword)
740         throws CommandValidationException
741     {
742         String JavaDoc optionValue = getInteractiveOption(optionName, prompt);
743         if (validatePassword && !isPasswordValid(optionValue)) {
744             throw new CommandValidationException(getLocalizedString("PasswordLimit",
745                 new Object JavaDoc[]{optionName}));
746         }
747         String JavaDoc optionValueAgain = getInteractiveOption(optionName, confirmationPrompt);
748         if (!optionValue.equals(optionValueAgain)) {
749             throw new CommandValidationException(getLocalizedString("OptionsDoNotMatch",
750                 new Object JavaDoc[] {optionName}));
751         }
752         return optionValue;
753     }
754         
755     /**
756      * If interactive is true, then prompt the user for the option value.
757      * @param optionName - name of option.
758      * @param prompt -- the string that will be used to prompt the user
759      * @throws CommandException if option value cannot be read in interactive mode.
760      * @throws CommandValidationException is interactive is false and the option
761      * value is null.
762      * @return option value
763      */

764     protected String JavaDoc getInteractiveOption(String JavaDoc optionName, String JavaDoc prompt)
765         throws CommandValidationException
766     {
767         //String optionValue = getOption(optionName);
768
String JavaDoc optionValue;
769         //if option value is null and interactive option is true
770
//then prompt the user for the password.
771
//if (optionValue == null && getBooleanOption(INTERACTIVE) )
772
if (getBooleanOption(INTERACTIVE))
773         {
774             try
775             {
776                 InputsAndOutputs.getInstance().getUserOutput().print(prompt);
777                 optionValue = new CliUtil().getPassword();
778             }
779             catch (java.lang.NoClassDefFoundError JavaDoc e)
780             {
781                 optionValue = readInput();
782             }
783             catch (java.lang.UnsatisfiedLinkError JavaDoc e)
784             {
785                 optionValue = readInput();
786             }
787             catch (Exception JavaDoc e)
788             {
789                 throw new CommandValidationException(e);
790             }
791         }
792         //else if ((optionValue == null) && !getBooleanOption(INTERACTIVE))
793
else
794             throw new CommandValidationException(getLocalizedString("OptionIsRequired",
795                                                                   new Object JavaDoc[] {optionName}));
796         return optionValue;
797     }
798
799     
800     /**
801      * Get input from user.
802      */

803     protected String JavaDoc readInput()
804     {
805         try {
806             return InputsAndOutputs.getInstance().getUserInput().getLine();
807         }
808         catch (IOException JavaDoc ioe)
809         {
810             return null;
811         }
812     }
813     
814     
815
816     
817     /**
818      * Load the passwords from the password file.
819      * This method should be called before checkInteractiveOption();
820      */

821     private void loadPasswordFileOptions(String JavaDoc optionName) throws CommandException
822     {
823         try
824         {
825             final String JavaDoc passwordFileName = getOption(PASSWORDFILE);
826             File JavaDoc file = checkForFileExistence(null, passwordFileName);
827             java.io.BufferedReader JavaDoc reader = new java.io.BufferedReader JavaDoc(
828                 new java.io.FileReader JavaDoc(file));
829             String JavaDoc line = reader.readLine();
830             boolean displayWarning = false;
831             
832             while (!(line == null))
833             {
834                 //do not want to read empty string
835
if (line.length() > 0) {
836                     displayWarning = checkPasswordFileOptions(line, optionName) || displayWarning;
837                 }
838                 
839                 line = reader.readLine();
840             }
841             reader.close();
842             if (displayWarning && !warningDisplayed)
843             {
844                 CLILogger.getInstance().printWarning(getLocalizedString(
845                                                          "DeprecatedOptionsFromPasswordfile"));
846                 warningDisplayed = true;
847             }
848         }
849         catch (CommandException ce)
850         {
851            throw ce;
852         }
853         catch (Exception JavaDoc e)
854         {
855            throw new CommandException(e);
856         }
857     }
858
859
860     /**
861      * This method extracts the prefix AS_ADMIN_ from the String
862      * and retrieve the option name and value and then set it in
863      * the option list in the command class.
864      * @param line = line to perform the checkPasswordFileOptions
865      * @return true is password file contains options that are nonpassword
866      * else return false.
867      */

868     private boolean checkPasswordFileOptions(String JavaDoc line, String JavaDoc optionName)
869     {
870         //check for prefix AS_ADMIN
871
if (line.regionMatches(true, 0, ENV_PREFIX, 0, ENV_PREFIX.length()))
872         {
873             final String JavaDoc[] envNameAndValue = splitNameValuePairs(line);
874
875             if (optionName == null || optionName.equalsIgnoreCase(envNameAndValue[0])) {
876                 if (getOption(optionName) == null &&
877                     envNameAndValue.length > 1)
878                 {
879                     //set the option name and value in the options list
880
setOption(optionName, envNameAndValue[1]);
881                 }
882                 if (optionName.matches(NOT_DEPRECATED_PASSWORDFILE_OPTIONS))
883                     return false;
884                 else
885                     return true;
886             } else {
887                 return false;
888             }
889         }
890         else if (line.regionMatches(true, 0, COMMENT_PREFIX, 0, COMMENT_PREFIX.length()))
891         {
892             return false;
893         }
894         return true;
895     }
896     
897
898     /**
899      * Check for the existence of the file in the file system
900      * @param parent - the parent directory containing the file
901      * @param fileName - the name of the file to check for existence
902      * @return File handler
903      */

904     protected File JavaDoc checkForFileExistence(String JavaDoc parent, String JavaDoc fileName)
905         throws CommandException
906     {
907         if (fileName == null) return null;
908         File JavaDoc file = null;
909         if (parent == null)
910             file = new File JavaDoc(fileName);
911         else
912             file = new File JavaDoc(parent, fileName);
913         if ( file.canRead() == false )
914         {
915             throw new CommandException(getLocalizedString("FileDoesNotExist",
916                                                           new Object JavaDoc[] {fileName}));
917         }
918         return file;
919     }
920
921
922     /**
923      * Returns the Object name string from the properties
924      * @return Object name else returns null
925      */

926     protected String JavaDoc getObjectName() throws CommandException
927     {
928         final String JavaDoc objectName = (String JavaDoc)((Vector JavaDoc)getProperty(OBJECT_NAME)).get(0);
929         final String JavaDoc objectNameStr = replacePattern(objectName);
930         CLILogger.getInstance().printDebugMessage("Object Name = [" +
931                           objectNameStr + "]");
932         return objectNameStr;
933     }
934
935     
936     /*
937      * Returns the Params from the properties
938      * @return params returns params
939      */

940     protected Object JavaDoc[] getParamsInfo()throws CommandException, CommandValidationException
941     {
942         final Vector JavaDoc params = (Vector JavaDoc) getProperty(PARAMS);
943         final String JavaDoc[] typesInfo = getTypesInfo();
944         Object JavaDoc[] paramsInfo = params==null?null:new Object JavaDoc[params.size()];
945
946         if(typesInfo != null && paramsInfo != null && paramsInfo.length != typesInfo.length)
947         {
948             throw new CommandException(getLocalizedString("BadDescriptorXML"));
949         }
950         for (int i = 0; params != null && i < params.size(); i++)
951         {
952             String JavaDoc paramStr = (String JavaDoc) params.get(i);
953             
954             CLILogger.getInstance().printDebugMessage("Types Info ["+i+"] = " + typesInfo[i]);
955             //CLILogger.getInstance().printDebugMessage("ATTRIBUTE_LIST_CLASS = " +
956
// this.ATTRIBUTE_LIST_CLASS);
957
if (typesInfo[i].equals(ATTRIBUTE_LIST_CLASS))
958             {
959                 paramsInfo[i] = getAttributeList(paramStr);
960             }
961             else if (typesInfo[i].equals(PROPERTIES_CLASS))
962             {
963                 paramsInfo[i] = createPropertiesParam((String JavaDoc)params.get(i));
964             }
965             else if (typesInfo[i].equals(BOOLEAN_CLASS) ||
966                      typesInfo[i].equals(PRIMITIVE_BOOLEAN_CLASS))
967             {
968                 if (createBooleanVal((String JavaDoc)params.get(i)) != null)
969                     paramsInfo[i] = createBooleanVal((String JavaDoc)params.get(i));
970             }
971             else if (typesInfo[i].equals(LONG_CLASS) ||
972                      typesInfo[i].equals(PRIMITIVE_LONG_CLASS))
973             {
974                 if (createLongVal((String JavaDoc)params.get(i)) != null)
975                     paramsInfo[i] = createLongVal((String JavaDoc)params.get(i));
976             }
977             else if (typesInfo[i].equals(INTEGER_CLASS) ||
978                      typesInfo[i].equals(PRIMITIVE_INTEGER_CLASS))
979             {
980                 if (createIntegerVal((String JavaDoc)params.get(i)) != null)
981                     paramsInfo[i] = createIntegerVal((String JavaDoc)params.get(i));
982             }
983             else if (typesInfo[i].equals(STRING_ARRAY))
984             {
985                 CLILogger.getInstance().printDebugMessage("Creating String Array");
986                 paramsInfo[i] = createStringArrayParam((String JavaDoc)params.get(i));
987             }
988             else if (typesInfo[i].equals(MAP_CLASS))
989             {
990                 CLILogger.getInstance().printDebugMessage("Creating Map Class");
991                 paramsInfo[i] = createMapParam(paramStr);
992             }
993             else if (typesInfo[i].equals(OBJECT_CLASS))
994             {
995                 CLILogger.getInstance().printDebugMessage("Creating Object Class");
996                 paramsInfo[i] = (Object JavaDoc) replacePattern(paramStr);
997                 CLILogger.getInstance().printDebugMessage("param value = " + paramsInfo[i]);
998             }
999             else
1000            {
1001                CLILogger.getInstance().printDebugMessage((String JavaDoc) params.get(i));
1002                paramsInfo[i] = replacePattern((String JavaDoc)params.get(i));
1003            
1004                CLILogger.getInstance().printDebugMessage("ParamsInfo = " + paramsInfo[i]);
1005            }
1006        }
1007        return paramsInfo;
1008    }
1009
1010    
1011    /*
1012     * Returns the Param types from the properties
1013     * @return paramTypes returns param types
1014     */

1015    protected String JavaDoc[] getTypesInfo()
1016    {
1017        Vector JavaDoc typesList = (Vector JavaDoc) getProperty(PARAM_TYPES);
1018        String JavaDoc types[] = typesList==null?null:new String JavaDoc[typesList.size()];
1019        CLILogger.getInstance().printDebugMessage("Types = ");
1020        for (int i = 0; typesList != null && i < typesList.size(); i++)
1021        {
1022            types[i] = (String JavaDoc) typesList.get(i);
1023            CLILogger.getInstance().printDebugMessage(types[i]+",");
1024        }
1025        CLILogger.getInstance().printDebugMessage("");
1026        return types;
1027    }
1028
1029    
1030    /*
1031     * Returns the Operation name from the properties
1032     * @return operationName returns operation name
1033     */

1034    protected String JavaDoc getOperationName() throws CommandException
1035    {
1036        String JavaDoc operationName = (String JavaDoc) ((Vector JavaDoc) getProperty(OPERATION)).get(0);
1037        String JavaDoc operationNameStr = replacePattern(operationName);
1038        CLILogger.getInstance().printDebugMessage("OperationName = " + operationNameStr);
1039        return operationNameStr;
1040    }
1041
1042    
1043    /*
1044     * Returns the Return type from the properties
1045     * @return returnType returns return type
1046     */

1047    protected String JavaDoc getReturnType()
1048    {
1049        String JavaDoc returnType = (String JavaDoc) ((Vector JavaDoc) getProperty(RETURN_TYPE)).get(0);
1050        CLILogger.getInstance().printDebugMessage("ReturnType = " + returnType);
1051        return returnType;
1052    }
1053
1054    
1055    /*
1056     * Formulate and Returns the attributes list from the given string
1057     * @return AttributeList returns attributes list
1058     */

1059    private AttributeList JavaDoc getAttributeList(String JavaDoc paramStr)
1060        throws CommandException
1061    {
1062        AttributeList JavaDoc attrList = new AttributeList JavaDoc();
1063        StringTokenizer JavaDoc paramsTokenizer = new StringTokenizer JavaDoc(paramStr, PARAM_DELIMITER);
1064        int size = paramsTokenizer.countTokens();
1065        for (int i = 0; i < size; i++)
1066        {
1067            final String JavaDoc nameValue = paramsTokenizer.nextToken();
1068            final String JavaDoc nameValueStr = replacePattern(nameValue);
1069            if (nameValueStr == null) continue;
1070            final int index = getDelimeterIndex(nameValueStr, PARAM_VALUE_DELIMITER, 0);
1071            final String JavaDoc attrName = nameValueStr.substring(0, index);
1072            final String JavaDoc attrValue = nameValueStr.substring(index+1);
1073            CLILogger.getInstance().printDebugMessage("**Attr Name = " + attrName +
1074                                                      ", Value = " + attrValue);
1075            attrList.add( new Attribute JavaDoc(attrName, attrValue) );
1076        }
1077        return attrList;
1078    }
1079
1080
1081    /**
1082     * Formulate and Returns Properties from the given string
1083     * @return Properties
1084     */

1085    protected Properties JavaDoc createPropertiesParam(String JavaDoc propertyVal)
1086        throws CommandException, CommandValidationException
1087    {
1088        final String JavaDoc propertyStr = replacePattern(propertyVal);
1089        if (propertyStr == null) return null;
1090        Properties JavaDoc properties = new Properties JavaDoc();
1091        final CLITokenizer propertyTok = new CLITokenizer(propertyStr, PROPERTY_DELIMITER);
1092        while (propertyTok.hasMoreTokens()) {
1093            final String JavaDoc nameAndvalue = propertyTok.nextToken();
1094            final CLITokenizer nameTok = new CLITokenizer(nameAndvalue, PARAM_VALUE_DELIMITER);
1095            if (nameTok.countTokens() == 2)
1096            {
1097                properties.setProperty(nameTok.nextTokenWithoutEscapeAndQuoteChars(),
1098                                       nameTok.nextTokenWithoutEscapeAndQuoteChars());
1099            }
1100            else
1101            {
1102                throw new CommandValidationException(getLocalizedString("InvalidPropertySyntax"));
1103            }
1104        }
1105        return properties;
1106    }
1107
1108
1109    /**
1110     * Formulate and Returns Map class from the given string
1111     * @return Map
1112     */

1113    private Map JavaDoc createMapParam(final String JavaDoc paramVal)
1114        throws CommandException, CommandValidationException
1115    {
1116        if (paramVal == null) return null;
1117        Map JavaDoc mapParam = new HashMap JavaDoc();
1118        try {
1119            StringTokenizer JavaDoc paramsTokenizer = new StringTokenizer JavaDoc(paramVal,
1120                                                                 PARAM_DELIMITER);
1121            int size = paramsTokenizer.countTokens();
1122            for (int ii = 0; ii < size; ii++)
1123            {
1124                final String JavaDoc nameValue = paramsTokenizer.nextToken();
1125                final String JavaDoc nameValueStr = replacePattern(nameValue);
1126
1127                if (nameValueStr == null) continue;
1128                
1129                if (nameValueStr.startsWith(PROPERTY)) {
1130                        //if it starts with "property." then it is a
1131
//a property value.
1132
//need to add 1 to the length to accomodate the "="
1133
String JavaDoc propertyStr = nameValueStr.substring(PROPERTY.length()+1);
1134                        //make sure that there is a property value
1135
if (propertyStr.length()>0) {
1136                        final CLITokenizer propertyTok = new CLITokenizer(propertyStr, PROPERTY_DELIMITER);
1137                        while (propertyTok.hasMoreTokens()) {
1138                            final String JavaDoc nameAndvalue = propertyTok.nextToken();
1139                            final CLITokenizer nameTok = new CLITokenizer(nameAndvalue, PARAM_VALUE_DELIMITER);
1140                            if (nameTok.countTokens() == 2)
1141                            {
1142                                    // need to prepend "property" and save to map
1143
// this is how AMX takes property values
1144
mapParam.put(PROPERTY+nameTok.nextTokenWithoutEscapeAndQuoteChars(),
1145                                         nameTok.nextTokenWithoutEscapeAndQuoteChars());
1146                            }
1147                            else
1148                            {
1149                                throw new CommandValidationException(getLocalizedString("InvalidPropertySyntax"));
1150                            }
1151                        }
1152                        
1153                    }
1154                    
1155                } else {
1156                    
1157                    final int index = getDelimeterIndex(nameValueStr,
1158                                                        PARAM_VALUE_DELIMITER, 0);
1159                    if (index > 0) {
1160                        final String JavaDoc mapKey = nameValueStr.substring(0, index);
1161                        final String JavaDoc mapValue = nameValueStr.substring(index+1);
1162                            //do not add to map if value is empty
1163
if (mapValue.length() > 0)
1164                        {
1165                            CLILogger.getInstance().printDebugMessage("**Map Key = " +
1166                                                                      mapKey +
1167                                                                      ", Value = " +
1168                                                                      mapValue);
1169                            mapParam.put( mapKey, mapValue);
1170                        }
1171                        
1172                    }
1173                }
1174                
1175            }
1176        }
1177        catch (Exception JavaDoc e) {
1178            throw new CommandException(e);
1179        }
1180        return mapParam;
1181    }
1182
1183
1184    /**
1185     * Formulate and Returns Boolean from the given string
1186     * @param booleanVal
1187     * @return Boolean
1188     */

1189    private Boolean JavaDoc createBooleanVal(String JavaDoc booleanVal)
1190        throws CommandException
1191    {
1192        String JavaDoc booleanStr = replacePattern(booleanVal);
1193        return Boolean.valueOf(booleanStr);
1194    }
1195
1196
1197    /**
1198     * Formulate and Returns Long from the given string
1199     * @param longVal
1200     * @return Long
1201     */

1202    private Long JavaDoc createLongVal(String JavaDoc longVal)
1203        throws CommandException
1204    {
1205        String JavaDoc longStr = replacePattern(longVal);
1206        return Long.valueOf(longStr);
1207    }
1208
1209    
1210    /**
1211     * Formulate and Returns Integer from the given string
1212     * @param integerVal
1213     * @return Integer
1214     */

1215    private Integer JavaDoc createIntegerVal(String JavaDoc integerVal)
1216        throws CommandException
1217    {
1218        String JavaDoc integerStr = replacePattern(integerVal);
1219        return Integer.valueOf(integerStr);
1220    }
1221
1222    
1223    /**
1224     * Formulate and Returns StringArray from the given string
1225     * @return Properties
1226     */

1227    protected String JavaDoc[] createStringArrayParam(String JavaDoc str)
1228    throws CommandException
1229    {
1230        final String JavaDoc strArrayVal = replacePattern(str);
1231        CLILogger.getInstance().printDebugMessage("strArrayVal value = \""+ strArrayVal + "\"");
1232        if ((strArrayVal == null) || (strArrayVal.equals("")) || (strArrayVal.equals("null")))
1233            return null;
1234
1235        final CLITokenizer cliTokenizer = new CLITokenizer(strArrayVal, PROPERTY_DELIMITER);
1236        String JavaDoc[] strArray = new String JavaDoc[cliTokenizer.countTokens()];
1237        int ii=0;
1238        while (cliTokenizer.hasMoreTokens())
1239        {
1240            strArray[ii++] = cliTokenizer.nextTokenWithoutEscapeAndQuoteChars();
1241        }
1242        return strArray;
1243    }
1244
1245    
1246    public void displayExceptionMessage(Exception JavaDoc e) throws CommandException
1247    {
1248        //get the root cause of the exception
1249
Throwable JavaDoc rootException = ExceptionUtil.getRootCause(e);
1250
1251        if (rootException.getLocalizedMessage() != null)
1252            CLILogger.getInstance().printDetailMessage(rootException.getLocalizedMessage());
1253        throw new CommandException(getLocalizedString("CommandUnSuccessful",
1254                                                          new Object JavaDoc[] {name} ), e);
1255    }
1256    
1257
1258
1259    /**
1260     * handles return value from mbean
1261     * @param returnval
1262     */

1263    protected void handleReturnValue(Object JavaDoc returnval)
1264    {
1265        if (returnval == null)
1266            return;
1267        Class JavaDoc cl = returnval.getClass();
1268        if (cl.isArray())
1269        {
1270            if (cl == new ObjectName JavaDoc[0].getClass())
1271            {
1272                final ObjectName JavaDoc[] objs = (ObjectName JavaDoc[])returnval;
1273                if (objs.length == 0)
1274                {
1275                    CLILogger.getInstance().printDetailMessage(
1276                                                getLocalizedString("NoElementsToList"));
1277                    return;
1278                }
1279
1280                final String JavaDoc displayType = (String JavaDoc)((Vector JavaDoc)getProperty(DISPLAY_TYPE)).get(0);
1281                for (int ii=0; ii<objs.length; ii++)
1282                {
1283                    ObjectName JavaDoc objectName = (ObjectName JavaDoc)objs[ii];
1284                    CLILogger.getInstance().printDebugMessage("ObjectName = " + objectName);
1285                    CLILogger.getInstance().printMessage(objectName.getKeyProperty(displayType));
1286                }
1287            }
1288            else
1289            {
1290                final Object JavaDoc[] objs = (Object JavaDoc[])returnval;
1291                if (objs.length == 0)
1292                {
1293                    CLILogger.getInstance().printDetailMessage(
1294                                                getLocalizedString("NoElementsToList"));
1295                    return;
1296                }
1297
1298                for (int ii=0; ii<objs.length; ii++)
1299                {
1300                    CLILogger.getInstance().printMessage(
1301                        objs[ii].toString());
1302                }
1303            }
1304        }
1305        else if (cl.getName().equals(List JavaDoc.class.getName()) || returnval instanceof List JavaDoc)
1306        {
1307            final List JavaDoc returnList = (List JavaDoc)returnval;
1308            if (returnList.size() > 0)
1309            {
1310                for (int i = 0; i<returnList.size(); i++)
1311                {
1312                    CLILogger.getInstance().printMessage(
1313                                    returnList.get(i).toString());
1314                }
1315            }
1316            else
1317                CLILogger.getInstance().printDebugMessage(
1318                                        "Return list is empty");
1319        }
1320    }
1321}
1322
Popular Tags