FileDocCategorySizeDatePackage
SearchCommands.javaAPI DocGlassfish v2 API5136Fri May 04 22:25:22 BST 2007com.sun.enterprise.cli.framework

SearchCommands

public class SearchCommands extends Object
SearchCommands.java This class cannot be instantiated. Given a pattern, this class will search for the commands that match the pattern.
version
$Revision: 1.3 $

Fields Summary
private Map
allCommandsMap
Constructors Summary
private SearchCommands()


    
        //private constructor cannot be instantiated
       
    
        final CLIDescriptorsReader cdr = CLIDescriptorsReader.getInstance();
        final ValidCommandsList vcl = cdr.getCommandsList();
        final Iterator<ValidCommand> commands = vcl.getCommands();
        allCommandsMap = new Hashtable<String, String>();
        while (commands.hasNext())
        {
            final ValidCommand command = (ValidCommand)commands.next();
            //System.out.println("command = " + command.getName());
            final String  usageText = command.getUsageText();

            //Do not want to include the hiddden commands
            //the hidden commands have empty usageText
            if (usageText != null && usageText.length()>0)
                allCommandsMap.put(command.getName(), command.getUsageText());
        }
    
Methods Summary
private java.lang.String[]allCommands()

        final Set<String> set = allCommandsMap.keySet();
        return (String[])set.toArray(new String[set.size()]);
    
private java.lang.String[]findCommands(java.lang.String pattern)

        try 
        {
            List<String> allCommandsList = new Vector<String>(allCommandsMap.keySet());
                //sort commands in alphabetical order
            Collections.sort(allCommandsList);

            List<String> matchedCommands = new Vector();
            for (int ii=0; ii+1<allCommandsList.size();ii++)
            {
//                System.out.println("Matching pattern : " + allCommandsList.get(ii) + "  " + pattern);
                if (allCommandsList.get(ii).matches(pattern)) {
                    matchedCommands.add(allCommandsList.get(ii));
                }
            }
            return (String[])matchedCommands.toArray(new String[matchedCommands.size()]);
        }
        catch (PatternSyntaxException pse)
        {
            throw new CommandException("InvalidPattern", pse);
        }
        catch (Exception e){
            throw new CommandException(e);
        }
    
public static java.lang.String[]getAllCommands()
returns all the valid commands

        return new SearchCommands().allCommands();
    
public static java.lang.String[]getMatchedCommands(java.lang.String pattern)
returns commands that matches the pattern

        return new SearchCommands().findCommands(pattern);