1 | // SECTION-START[License Header] |
2 | // <editor-fold defaultstate="collapsed" desc=" Generated License "> |
3 | /* |
4 | * Java Object Management and Configuration |
5 | * Copyright (C) Christian Schulte, 2005-206 |
6 | * All rights reserved. |
7 | * |
8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions |
10 | * are met: |
11 | * |
12 | * o Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. |
14 | * |
15 | * o Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in |
17 | * the documentation and/or other materials provided with the |
18 | * distribution. |
19 | * |
20 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
21 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
22 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
23 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, |
24 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
29 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | * |
31 | * $JOMC: OptionFactory.java 4463 2012-03-28 00:46:22Z schulte2005 $ |
32 | * |
33 | */ |
34 | // </editor-fold> |
35 | // SECTION-END |
36 | package org.jomc.cli.model; |
37 | |
38 | import java.io.File; |
39 | import org.apache.commons.cli.Option; |
40 | |
41 | // SECTION-START[Documentation] |
42 | // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> |
43 | /** |
44 | * Creates {@code Option} objects describing a single command-line option by maintaining information regarding the short-name, the long-name, a flag indicating if an argument is required, and a self-documenting description. |
45 | * |
46 | * <dl> |
47 | * <dt><b>Identifier:</b></dt><dd>JOMC CLI Option Factory</dd> |
48 | * <dt><b>Name:</b></dt><dd>JOMC CLI</dd> |
49 | * <dt><b>Abstract:</b></dt><dd>Yes</dd> |
50 | * <dt><b>Final:</b></dt><dd>No</dd> |
51 | * <dt><b>Stateless:</b></dt><dd>No</dd> |
52 | * </dl> |
53 | * |
54 | * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 |
55 | * @version 1.2.5 |
56 | */ |
57 | // </editor-fold> |
58 | // SECTION-END |
59 | // SECTION-START[Annotations] |
60 | // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> |
61 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) |
62 | // </editor-fold> |
63 | // SECTION-END |
64 | public final class OptionFactory |
65 | { |
66 | // SECTION-START[OptionFactory] |
67 | |
68 | public Option getObject() |
69 | { |
70 | final char valueSeparator = this.getValueSeparator() == ':' ? File.pathSeparatorChar : this.getValueSeparator(); |
71 | |
72 | final Option option = |
73 | new Option( this.getOpt(), this.getDescription( this.getLocale(), Character.toString( valueSeparator ) ) ); |
74 | |
75 | option.setArgs( this.getNumberOfArgs() ); |
76 | option.setLongOpt( this.getLongOpt() ); |
77 | option.setOptionalArg( this.isOptionalArg() ); |
78 | option.setRequired( this.isRequired() ); |
79 | |
80 | if ( ( option.getArgs() > 0 || option.getArgs() == Option.UNLIMITED_VALUES ) |
81 | && this.getArgumentDescription( this.getLocale() ).trim().length() > 0 ) |
82 | { |
83 | option.setArgName( this.getArgumentDescription( this.getLocale() ) ); |
84 | } |
85 | |
86 | if ( option.getArgs() > 1 || option.getArgs() == Option.UNLIMITED_VALUES ) |
87 | { |
88 | option.setValueSeparator( valueSeparator ); |
89 | } |
90 | |
91 | return option; |
92 | } |
93 | |
94 | // SECTION-END |
95 | // SECTION-START[Constructors] |
96 | // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> |
97 | /** Creates a new {@code OptionFactory} instance. */ |
98 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) |
99 | public OptionFactory() |
100 | { |
101 | // SECTION-START[Default Constructor] |
102 | super(); |
103 | // SECTION-END |
104 | } |
105 | // </editor-fold> |
106 | // SECTION-END |
107 | // SECTION-START[Dependencies] |
108 | // <editor-fold defaultstate="collapsed" desc=" Generated Dependencies "> |
109 | /** |
110 | * Gets the {@code <Locale>} dependency. |
111 | * <p> |
112 | * This method returns the {@code <default>} object of the {@code <java.util.Locale>} specification at specification level 1.1. |
113 | * That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance. |
114 | * </p> |
115 | * <dl> |
116 | * <dt><b>Final:</b></dt><dd>No</dd> |
117 | * </dl> |
118 | * @return The {@code <Locale>} dependency. |
119 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
120 | */ |
121 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) |
122 | private java.util.Locale getLocale() |
123 | { |
124 | final java.util.Locale _d = (java.util.Locale) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "Locale" ); |
125 | assert _d != null : "'Locale' dependency not found."; |
126 | return _d; |
127 | } |
128 | // </editor-fold> |
129 | // SECTION-END |
130 | // SECTION-START[Properties] |
131 | // <editor-fold defaultstate="collapsed" desc=" Generated Properties "> |
132 | /** |
133 | * Gets the value of the {@code <longOpt>} property. |
134 | * <p><dl> |
135 | * <dt><b>Final:</b></dt><dd>No</dd> |
136 | * </dl></p> |
137 | * @return Long name of the option. |
138 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
139 | */ |
140 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) |
141 | private java.lang.String getLongOpt() |
142 | { |
143 | final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "longOpt" ); |
144 | assert _p != null : "'longOpt' property not found."; |
145 | return _p; |
146 | } |
147 | /** |
148 | * Gets the value of the {@code <numberOfArgs>} property. |
149 | * <p><dl> |
150 | * <dt><b>Final:</b></dt><dd>No</dd> |
151 | * </dl></p> |
152 | * @return Number of argument values the option can take. |
153 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
154 | */ |
155 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) |
156 | private int getNumberOfArgs() |
157 | { |
158 | final java.lang.Integer _p = (java.lang.Integer) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "numberOfArgs" ); |
159 | assert _p != null : "'numberOfArgs' property not found."; |
160 | return _p.intValue(); |
161 | } |
162 | /** |
163 | * Gets the value of the {@code <opt>} property. |
164 | * <p><dl> |
165 | * <dt><b>Final:</b></dt><dd>No</dd> |
166 | * </dl></p> |
167 | * @return Name of the option. |
168 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
169 | */ |
170 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) |
171 | private java.lang.String getOpt() |
172 | { |
173 | final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "opt" ); |
174 | assert _p != null : "'opt' property not found."; |
175 | return _p; |
176 | } |
177 | /** |
178 | * Gets the value of the {@code <optionalArg>} property. |
179 | * <p><dl> |
180 | * <dt><b>Final:</b></dt><dd>No</dd> |
181 | * </dl></p> |
182 | * @return Query to see if the option can have an optional argument. |
183 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
184 | */ |
185 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) |
186 | private boolean isOptionalArg() |
187 | { |
188 | final java.lang.Boolean _p = (java.lang.Boolean) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "optionalArg" ); |
189 | assert _p != null : "'optionalArg' property not found."; |
190 | return _p.booleanValue(); |
191 | } |
192 | /** |
193 | * Gets the value of the {@code <required>} property. |
194 | * <p><dl> |
195 | * <dt><b>Final:</b></dt><dd>No</dd> |
196 | * </dl></p> |
197 | * @return Query to see if the option is required. |
198 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
199 | */ |
200 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) |
201 | private boolean isRequired() |
202 | { |
203 | final java.lang.Boolean _p = (java.lang.Boolean) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "required" ); |
204 | assert _p != null : "'required' property not found."; |
205 | return _p.booleanValue(); |
206 | } |
207 | /** |
208 | * Gets the value of the {@code <valueSeparator>} property. |
209 | * <p><dl> |
210 | * <dt><b>Final:</b></dt><dd>No</dd> |
211 | * </dl></p> |
212 | * @return Value separator of the option. |
213 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
214 | */ |
215 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) |
216 | private char getValueSeparator() |
217 | { |
218 | final java.lang.Character _p = (java.lang.Character) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "valueSeparator" ); |
219 | assert _p != null : "'valueSeparator' property not found."; |
220 | return _p.charValue(); |
221 | } |
222 | // </editor-fold> |
223 | // SECTION-END |
224 | // SECTION-START[Messages] |
225 | // <editor-fold defaultstate="collapsed" desc=" Generated Messages "> |
226 | /** |
227 | * Gets the text of the {@code <argumentDescription>} message. |
228 | * <p><dl> |
229 | * <dt><b>Languages:</b></dt> |
230 | * <dd>English (default)</dd> |
231 | * <dt><b>Final:</b></dt><dd>No</dd> |
232 | * </dl></p> |
233 | * @param locale The locale of the message to return. |
234 | * @return Display name for the argument value of the option. |
235 | * @throws org.jomc.ObjectManagementException if getting the message instance fails. |
236 | */ |
237 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) |
238 | private String getArgumentDescription( final java.util.Locale locale ) |
239 | { |
240 | final String _m = org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getMessage( this, "argumentDescription", locale ); |
241 | assert _m != null : "'argumentDescription' message not found."; |
242 | return _m; |
243 | } |
244 | /** |
245 | * Gets the text of the {@code <description>} message. |
246 | * <p><dl> |
247 | * <dt><b>Languages:</b></dt> |
248 | * <dd>English (default)</dd> |
249 | * <dt><b>Final:</b></dt><dd>No</dd> |
250 | * </dl></p> |
251 | * @param locale The locale of the message to return. |
252 | * @param valueSeparator Format argument. |
253 | * @return Display description of the option. |
254 | * @throws org.jomc.ObjectManagementException if getting the message instance fails. |
255 | */ |
256 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" ) |
257 | private String getDescription( final java.util.Locale locale, final java.lang.String valueSeparator ) |
258 | { |
259 | final String _m = org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getMessage( this, "description", locale, valueSeparator ); |
260 | assert _m != null : "'description' message not found."; |
261 | return _m; |
262 | } |
263 | // </editor-fold> |
264 | // SECTION-END |
265 | } |