KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the docs/licenses/apache-1.1.txt file.
7  */

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

20 public final class CLOptionDescriptor
21 {
22    /**
23     * Flag to say that one argument is required
24     */

25    public static final int ARGUMENT_REQUIRED = 1 << 1;
26    /**
27     * Flag to say that the argument is optional
28     */

29    public static final int ARGUMENT_OPTIONAL = 1 << 2;
30    /**
31     * Flag to say this option does not take arguments
32     */

33    public static final int ARGUMENT_DISALLOWED = 1 << 3;
34    /**
35     * Flag to say this option requires 2 arguments
36     */

37    public static final int ARGUMENTS_REQUIRED_2 = 1 << 4;
38    /**
39     * Flag to say this option may be repeated on the command line
40     */

41    public static final int DUPLICATES_ALLOWED = 1 << 5;
42
43    private final int m_id;
44    private final int m_flags;
45    private final String JavaDoc m_name;
46    private final String JavaDoc m_description;
47    private final int[] m_incompatible;
48
49    /**
50     * Constructor.
51     *
52     * @param name the name/long option
53     * @param flags the flags
54     * @param id the id/character option
55     * @param description description of option usage
56     */

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

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

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

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

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

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

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

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