KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > utils > CLOptionDescriptor


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 // This file is pulled from package org.apache.avalon.excalibur.cli Excalibur
17
// version 4.1 (Jan 30, 2002). Only the package name has been changed.
18
package org.apache.axis.utils;
19
20 /**
21  * Basic class describing an type of option.
22  * Typically, one creates a static array of <code>CLOptionDescriptor</code>s,
23  * and passes it to {@link CLArgsParser#CLArgsParser(String[], CLOptionDescriptor[])}.
24  *
25  * @author <a HREF="mailto:peter@apache.org">Peter Donald</a>
26  * @since 4.0
27  */

28 public final class CLOptionDescriptor
29 {
30     /** Flag to say that one argument is required */
31     public static final int ARGUMENT_REQUIRED = 1 << 1;
32     /** Flag to say that the argument is optional */
33     public static final int ARGUMENT_OPTIONAL = 1 << 2;
34     /** Flag to say this option does not take arguments */
35     public static final int ARGUMENT_DISALLOWED = 1 << 3;
36     /** Flag to say this option requires 2 arguments */
37     public static final int ARGUMENTS_REQUIRED_2 = 1 << 4;
38     /** Flag to say this option may be repeated on the command line */
39     public static final int DUPLICATES_ALLOWED = 1 << 5;
40
41     private final int m_id;
42     private final int m_flags;
43     private final String JavaDoc m_name;
44     private final String JavaDoc m_description;
45     private final int[] m_incompatible;
46
47     /**
48      * Constructor.
49      *
50      * @param name the name/long option
51      * @param flags the flags
52      * @param id the id/character option
53      * @param description description of option usage
54      */

55     public CLOptionDescriptor( final String JavaDoc name,
56                                final int flags,
57                                final int id,
58                                final String JavaDoc description )
59     {
60         this( name, flags, id, description,
61             ((flags & CLOptionDescriptor.DUPLICATES_ALLOWED) > 0)
62                 ? new int[] {}
63                 : new int[] { id } );
64     }
65
66     /**
67      * Constructor.
68      *
69      * @param name the name/long option
70      * @param flags the flags
71      * @param id the id/character option
72      * @param description description of option usage
73      */

74     public CLOptionDescriptor( final String JavaDoc name,
75                                final int flags,
76                                final int id,
77                                final String JavaDoc description,
78                                final int[] incompatable )
79     {
80         m_id = id;
81         m_name = name;
82         m_flags = flags;
83         m_description = description;
84         m_incompatible = incompatable;
85     }
86
87     /**
88      * @deprecated Use the correctly spelled {@link #getIncompatible} instead.
89      */

90     protected final int[] getIncompatble()
91     {
92         return getIncompatible();
93     }
94
95     protected final int[] getIncompatible()
96     {
97         return m_incompatible;
98     }
99
100     /**
101      * Retrieve textual description.
102      *
103      * @return the description
104      */

105     public final String JavaDoc getDescription()
106     {
107         return m_description;
108     }
109
110     /**
111      * Retrieve flags about option.
112      * Flags include details such as whether it allows parameters etc.
113      *
114      * @return the flags
115      */

116     public final int getFlags()
117     {
118         return m_flags;
119     }
120
121     /**
122      * Retrieve the id for option.
123      * The id is also the character if using single character options.
124      *
125      * @return the id
126      */

127     public final int getId()
128     {
129         return m_id;
130     }
131
132     /**
133      * Retrieve name of option which is also text for long option.
134      *
135      * @return name/long option
136      */

137     public final String JavaDoc getName()
138     {
139         return m_name;
140     }
141
142     /**
143      * Convert to String.
144      *
145      * @return the converted value to string.
146      */

147     public final String JavaDoc toString()
148     {
149         return
150             new StringBuffer JavaDoc()
151             .append("[OptionDescriptor ").append(m_name)
152             .append(", ").append(m_id).append(", ").append(m_flags)
153             .append(", ").append(m_description).append(" ]").toString();
154     }
155 }
156
Popular Tags