Java Doc for CLIPParser.java in  » Portal » Open-Portal » com » sun » portal » wsrp » consumer » cli » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.wsrp.consumer.cli 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.sun.portal.wsrp.consumer.cli.CLIPParser

CLIPParser
public class CLIPParser (Code)
The CLIPParser implements a Command Line User Interface parser following the Sun ONE UI Style Project Guide 2.1.

It parses the command line arguments according to the CLIP full specification.

Refer to the CLIP specification for more details.

CLIPParser instances are thread-safe.

CLIPParser example with sub commands:

 import com.iplanet.common.util. CLIPParser;
 import com.iplanet.common.util. CLIPException;
 public class CLIPParserTest {
 public static void main(String[] args) throws CLIPException {
 CLIPParser.Option[] options0 = new CLIPParser.Option[2];
 options0[0] = new CLIPParser.Option("user","u",CLIPParser.REGULAR,null,"user name");
 options0[1] = new CLIPParser.Option("password","p",CLIPParser.REGULAR,null,"user password");
 CLIPParser.Option[] options1 = new CLIPParser.Option[4];
 options1[0] = new CLIPParser.Option("user","u",CLIPParser.REGULAR,null,"user name");
 options1[1] = new CLIPParser.Option("password","p",CLIPParser.REGULAR,null,"user password");
 options1[3] = new CLIPParser.Option("owner","o",CLIPParser.REGULAR,"user","elements owner");
 options1[2] = new CLIPParser.Option("verbose","v",CLIPParser.BOOLEAN,"false","echoes actions");
 CLIPParser.Option[] options2 = new CLIPParser.Option[3];
 options2[0] = new CLIPParser.Option("user","u",CLIPParser.REGULAR,null,"user name");
 options2[1] = new CLIPParser.Option("password","p",CLIPParser.REGULAR,null,"user password");
 options2[2] = new CLIPParser.Option("verbose","v",CLIPParser.BOOLEAN,"false","echos actions");
 CLIPParser.SubCommand[] subCommands = new CLIPParser.SubCommand[3];
 subCommands[0] = new CLIPParser.SubCommand("list",options0,0,0,"Lists current elements","");
 subCommands[1] = new CLIPParser.SubCommand("add",options1,1,10000,"Adds new elements","elements to add");
 subCommands[2] = new CLIPParser.SubCommand("remove",options2,1,1000,"Removes existing elements","elemenst to remove");
 CLIPParser clip = new CLIPParser(subCommands,"Super command (w/ sub commands)");
 clip.verifyArguments(args);
 if (clip.needsHelp(args)) {
 System.out.println(clip.getHelp(args));
 }
 else {
 System.out.println(clip.toString(args));
 }
 }
 }
 

author:
   Alejandro Abdelnur

Inner Class :public static class Option
Inner Class :public static class SubCommand

Field Summary
final public static  intBOOLEAN
     Type for boolean options.
final public static  intCOLLECTION
     Type for collection options.
final public static  intREGULAR
     Type for regular options.

Constructor Summary
public  CLIPParser(String commandName, SubCommand[] subCommands, String commandHelpMessage)
     Creates a CLIP parser instance with a set of sub commands.
public  CLIPParser(String commandName, Option[] options, int minOperands, int maxOperands, String commandHelpMessage, String operandsHelp)
     Creates a CLIP parser instance with no sub commands.

Method Summary
public  StringgetHelp(String[] args)
     Returns the Help for the command.

Using the current arguments determines if a full help or a sub command help should be returned.


Parameters:
  args - the current argument array, to determine the type of help to return.

public static  StringgetName(String element)
     Returns the name part of a name/value pair element.

It uses '=' as the name/value separator.


Parameters:
  element - the option or operand name/value pair element.

public  String[]getOperands(String[] args)
     Returns a String array with all the operands of the argument array.

All the operands after the options end or after the operand demarcator "--".


Parameters:
  args - argument array to parse for operands.

public  MapgetOptions(String[] args)
     Returns a Map with all the (key,value) for all the options.

The key is the option long name.

The value is always a String array, it's length is always one except if it's a collection option, then the length is the number of collection values in the option.

If the option is a boolean option (not option value or it a negated option "--no-


Parameters:
  args - argument array to parse for options.

public  StringgetSubCommand(String[] args)
     Returns the sub command from the argument array.


Parameters:
  args - argument array to parse for sub command.

public static  StringgetValue(String element)
     Returns the value part of a name/value pair element.

It uses '=' as the name/value separator.


Parameters:
  element - the option or operand name/value pair element.

public  booleanneedsHelp(String[] args)
     Returns if the command invocation needs help or not.

It may be an exlicit request for help, using the --help (-?) option, or because an invalid argument set has been given.


Parameters:
  args - the array argument.

public  booleanneedsVersion(String[] args)
     Returns if the command invocation needs version or not.

When version is detected anywhere in the options, no further parsing is performed.

public  StringtoString(String[] args)
     String representation of the processed command arguments.
public  voidverifyArguments(String[] args)
     Verifies the argument array is valid for the CLIP parser definition.

Field Detail
BOOLEAN
final public static int BOOLEAN(Code)
Type for boolean options.



COLLECTION
final public static int COLLECTION(Code)
Type for collection options.



REGULAR
final public static int REGULAR(Code)
Type for regular options.




Constructor Detail
CLIPParser
public CLIPParser(String commandName, SubCommand[] subCommands, String commandHelpMessage) throws IllegalArgumentException(Code)
Creates a CLIP parser instance with a set of sub commands.


Parameters:
  commandName - name of the command
Parameters:
  subCommand - array of sub commands for the CLIPParser.
Parameters:
  help - message for the command.
throws:
  IllegalArgumentException - if invalid information is passed.




CLIPParser
public CLIPParser(String commandName, Option[] options, int minOperands, int maxOperands, String commandHelpMessage, String operandsHelp) throws IllegalArgumentException(Code)
Creates a CLIP parser instance with no sub commands.


Parameters:
  options - array with all the valid options for the sub command, or NULL if the sub command expects no options.
Parameters:
  minOperands - minimum number of operands the sub command expects.
Parameters:
  maxOperands - maximum number of operands the sub command expects.
Parameters:
  commandName - name of the command
Parameters:
  commandHelp - help message for the command.
Parameters:
  operandsHelp - help message for the operands.
throws:
  IllegalArgumentException - if invalid information is passed.





Method Detail
getHelp
public String getHelp(String[] args)(Code)
Returns the Help for the command.

Using the current arguments determines if a full help or a sub command help should be returned.


Parameters:
  args - the current argument array, to determine the type of help to return. the help for the command.




getName
public static String getName(String element)(Code)
Returns the name part of a name/value pair element.

It uses '=' as the name/value separator.


Parameters:
  element - the option or operand name/value pair element. the name portion of the name/value pair or the completeelement if there is no value.




getOperands
public String[] getOperands(String[] args) throws CLIPException(Code)
Returns a String array with all the operands of the argument array.

All the operands after the options end or after the operand demarcator "--".


Parameters:
  args - argument array to parse for operands. all the operands from the argument array, if the argument array has no operands it returns an empty array.
throws:
  CLIPException - thrown if the operands can not be process because errors in the options or if the numberof operands in the argument array is outside of the minimum and maximum operand boundaries.




getOptions
public Map getOptions(String[] args) throws CLIPException(Code)
Returns a Map with all the (key,value) for all the options.

The key is the option long name.

The value is always a String array, it's length is always one except if it's a collection option, then the length is the number of collection values in the option.

If the option is a boolean option (not option value or it a negated option "--no-


Parameters:
  args - argument array to parse for options. a Map instance with all the options of the argument array.
throws:
  CLIPException - thrown if there are invalid or incorrect options in the argument array or if mandatory optionsare missing from the argument array.




getSubCommand
public String getSubCommand(String[] args) throws CLIPException(Code)
Returns the sub command from the argument array.


Parameters:
  args - argument array to parse for sub command. the entered sub command or NULL if no sub command was found.
throws:
  CLIPException - thrown if the sub command is invalid.




getValue
public static String getValue(String element)(Code)
Returns the value part of a name/value pair element.

It uses '=' as the name/value separator.


Parameters:
  element - the option or operand name/value pair element. the value portion of the name/value pair or nullif there is not value in the element.




needsHelp
public boolean needsHelp(String[] args)(Code)
Returns if the command invocation needs help or not.

It may be an exlicit request for help, using the --help (-?) option, or because an invalid argument set has been given.


Parameters:
  args - the array argument. true if help is needed, false otherwise.




needsVersion
public boolean needsVersion(String[] args)(Code)
Returns if the command invocation needs version or not.

When version is detected anywhere in the options, no further parsing is performed. A version option is considered to be one of the followings: "-V", "--version" or "--version=true".


Parameters:
  args - the array argument. true if version is needed, false otherwise.




toString
public String toString(String[] args) throws CLIPException(Code)
String representation of the processed command arguments.


Parameters:
  args - argument array String representation.
throws:
  CLIPException - thrown if the argument array could not be processed successfuly.




verifyArguments
public void verifyArguments(String[] args) throws CLIPException(Code)
Verifies the argument array is valid for the CLIP parser definition.


Parameters:
  args - argument array to verify.
throws:
  CLIPException - thrown if the argument array could not be processed successfuly.




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.