Source Code Cross Referenced for CLOptionDescriptor.java in  » Testing » jakarta-jmeter » org » apache » commons » cli » avalon » 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 » Testing » jakarta jmeter » org.apache.commons.cli.avalon 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed  under the  License is distributed on an "AS IS" BASIS,
013:         * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
014:         * implied.
015:         * 
016:         * See the License for the specific language governing permissions and
017:         * limitations under the License.
018:         */
019:        package org.apache.commons.cli.avalon;
020:
021:        // Renamed from org.apache.avalon.excalibur.cli
022:
023:        /**
024:         * Basic class describing an type of option. Typically, one creates a static
025:         * array of <code>CLOptionDescriptor</code>s, and passes it to
026:         * {@link CLArgsParser#CLArgsParser(String[], CLOptionDescriptor[])}.
027:         * 
028:         * @see CLArgsParser
029:         * @see CLUtil
030:         */
031:        public final class CLOptionDescriptor {
032:            /** Flag to say that one argument is required */
033:            public static final int ARGUMENT_REQUIRED = 1 << 1;
034:
035:            /** Flag to say that the argument is optional */
036:            public static final int ARGUMENT_OPTIONAL = 1 << 2;
037:
038:            /** Flag to say this option does not take arguments */
039:            public static final int ARGUMENT_DISALLOWED = 1 << 3;
040:
041:            /** Flag to say this option requires 2 arguments */
042:            public static final int ARGUMENTS_REQUIRED_2 = 1 << 4;
043:
044:            /** Flag to say this option may be repeated on the command line */
045:            public static final int DUPLICATES_ALLOWED = 1 << 5;
046:
047:            private final int m_id;
048:
049:            private final int m_flags;
050:
051:            private final String m_name;
052:
053:            private final String m_description;
054:
055:            private final int[] m_incompatible;
056:
057:            /**
058:             * Constructor.
059:             * 
060:             * @param name
061:             *            the name/long option
062:             * @param flags
063:             *            the flags
064:             * @param id
065:             *            the id/character option
066:             * @param description
067:             *            description of option usage
068:             */
069:            public CLOptionDescriptor(final String name, final int flags,
070:                    final int id, final String description) {
071:
072:                checkFlags(flags);
073:
074:                m_id = id;
075:                m_name = name;
076:                m_flags = flags;
077:                m_description = description;
078:                m_incompatible = ((flags & DUPLICATES_ALLOWED) > 0) ? new int[0]
079:                        : new int[] { id };
080:            }
081:
082:            /**
083:             * Constructor.
084:             * 
085:             * @param name
086:             *            the name/long option
087:             * @param flags
088:             *            the flags
089:             * @param id
090:             *            the id/character option
091:             * @param description
092:             *            description of option usage
093:             * @param incompatible
094:             *            descriptors for incompatible options
095:             */
096:            public CLOptionDescriptor(final String name, final int flags,
097:                    final int id, final String description,
098:                    final CLOptionDescriptor[] incompatible) {
099:
100:                checkFlags(flags);
101:
102:                m_id = id;
103:                m_name = name;
104:                m_flags = flags;
105:                m_description = description;
106:
107:                m_incompatible = new int[incompatible.length];
108:                for (int i = 0; i < incompatible.length; i++) {
109:                    m_incompatible[i] = incompatible[i].getId();
110:                }
111:            }
112:
113:            private void checkFlags(final int flags) {
114:                int modeCount = 0;
115:                if ((ARGUMENT_REQUIRED & flags) == ARGUMENT_REQUIRED) {
116:                    modeCount++;
117:                }
118:                if ((ARGUMENT_OPTIONAL & flags) == ARGUMENT_OPTIONAL) {
119:                    modeCount++;
120:                }
121:                if ((ARGUMENT_DISALLOWED & flags) == ARGUMENT_DISALLOWED) {
122:                    modeCount++;
123:                }
124:                if ((ARGUMENTS_REQUIRED_2 & flags) == ARGUMENTS_REQUIRED_2) {
125:                    modeCount++;
126:                }
127:
128:                if (0 == modeCount) {
129:                    final String message = "No mode specified for option "
130:                            + this ;
131:                    throw new IllegalStateException(message);
132:                } else if (1 != modeCount) {
133:                    final String message = "Multiple modes specified for option "
134:                            + this ;
135:                    throw new IllegalStateException(message);
136:                }
137:            }
138:
139:            /**
140:             * Get the array of incompatible option ids.
141:             * 
142:             * @return the array of incompatible option ids
143:             */
144:            protected final int[] getIncompatible() {
145:                return m_incompatible;
146:            }
147:
148:            /**
149:             * Retrieve textual description.
150:             * 
151:             * @return the description
152:             */
153:            public final String getDescription() {
154:                return m_description;
155:            }
156:
157:            /**
158:             * Retrieve flags about option. Flags include details such as whether it
159:             * allows parameters etc.
160:             * 
161:             * @return the flags
162:             */
163:            public final int getFlags() {
164:                return m_flags;
165:            }
166:
167:            /**
168:             * Retrieve the id for option. The id is also the character if using single
169:             * character options.
170:             * 
171:             * @return the id
172:             */
173:            public final int getId() {
174:                return m_id;
175:            }
176:
177:            /**
178:             * Retrieve name of option which is also text for long option.
179:             * 
180:             * @return name/long option
181:             */
182:            public final String getName() {
183:                return m_name;
184:            }
185:
186:            /**
187:             * Convert to String.
188:             * 
189:             * @return the converted value to string.
190:             */
191:            public final String toString() {
192:                final StringBuffer sb = new StringBuffer();
193:                sb.append("[OptionDescriptor ");
194:                sb.append(m_name);
195:                sb.append(", ");
196:                sb.append(m_id);
197:                sb.append(", ");
198:                sb.append(m_flags);
199:                sb.append(", ");
200:                sb.append(m_description);
201:                sb.append(" ]");
202:                return sb.toString();
203:            }
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.