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 4795 2013-04-21 09:09:02Z schulte $
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 ⁑ Option Factory</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:cs@schulte.it">Christian Schulte</a> 1.0
55 * @version 1.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.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
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.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
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 @SuppressWarnings("unused")
122 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
123 private java.util.Locale getLocale()
124 {
125 final java.util.Locale _d = (java.util.Locale) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "Locale" );
126 assert _d != null : "'Locale' dependency not found.";
127 return _d;
128 }
129 // </editor-fold>
130 // SECTION-END
131 // SECTION-START[Properties]
132 // <editor-fold defaultstate="collapsed" desc=" Generated Properties ">
133 /**
134 * Gets the value of the {@code <Long Opt>} property.
135 * <p><dl>
136 * <dt><b>Final:</b></dt><dd>No</dd>
137 * </dl></p>
138 * @return Long name of the option.
139 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
140 */
141 @SuppressWarnings("unused")
142 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
143 private java.lang.String getLongOpt()
144 {
145 final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Long Opt" );
146 assert _p != null : "'Long Opt' property not found.";
147 return _p;
148 }
149 /**
150 * Gets the value of the {@code <Number Of Args>} property.
151 * <p><dl>
152 * <dt><b>Final:</b></dt><dd>No</dd>
153 * </dl></p>
154 * @return Number of argument values the option can take.
155 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
156 */
157 @SuppressWarnings("unused")
158 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
159 private int getNumberOfArgs()
160 {
161 final java.lang.Integer _p = (java.lang.Integer) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Number Of Args" );
162 assert _p != null : "'Number Of Args' property not found.";
163 return _p.intValue();
164 }
165 /**
166 * Gets the value of the {@code <Opt>} property.
167 * <p><dl>
168 * <dt><b>Final:</b></dt><dd>No</dd>
169 * </dl></p>
170 * @return Name of the option.
171 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
172 */
173 @SuppressWarnings("unused")
174 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
175 private java.lang.String getOpt()
176 {
177 final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Opt" );
178 assert _p != null : "'Opt' property not found.";
179 return _p;
180 }
181 /**
182 * Gets the value of the {@code <Optional Arg>} property.
183 * <p><dl>
184 * <dt><b>Final:</b></dt><dd>No</dd>
185 * </dl></p>
186 * @return Query to see if the option can have an optional argument.
187 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
188 */
189 @SuppressWarnings("unused")
190 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
191 private boolean isOptionalArg()
192 {
193 final java.lang.Boolean _p = (java.lang.Boolean) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Optional Arg" );
194 assert _p != null : "'Optional Arg' property not found.";
195 return _p.booleanValue();
196 }
197 /**
198 * Gets the value of the {@code <Required>} property.
199 * <p><dl>
200 * <dt><b>Final:</b></dt><dd>No</dd>
201 * </dl></p>
202 * @return Query to see if the option is required.
203 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
204 */
205 @SuppressWarnings("unused")
206 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
207 private boolean isRequired()
208 {
209 final java.lang.Boolean _p = (java.lang.Boolean) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Required" );
210 assert _p != null : "'Required' property not found.";
211 return _p.booleanValue();
212 }
213 /**
214 * Gets the value of the {@code <Value Separator>} property.
215 * <p><dl>
216 * <dt><b>Final:</b></dt><dd>No</dd>
217 * </dl></p>
218 * @return Value separator of the option.
219 * @throws org.jomc.ObjectManagementException if getting the property instance fails.
220 */
221 @SuppressWarnings("unused")
222 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
223 private char getValueSeparator()
224 {
225 final java.lang.Character _p = (java.lang.Character) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Value Separator" );
226 assert _p != null : "'Value Separator' property not found.";
227 return _p.charValue();
228 }
229 // </editor-fold>
230 // SECTION-END
231 // SECTION-START[Messages]
232 // <editor-fold defaultstate="collapsed" desc=" Generated Messages ">
233 /**
234 * Gets the text of the {@code <Argument Description>} message.
235 * <p><dl>
236 * <dt><b>Languages:</b></dt>
237 * <dd>English (default)</dd>
238 * <dt><b>Final:</b></dt><dd>No</dd>
239 * </dl></p>
240 * @param locale The locale of the message to return.
241 * @return Display name for the argument value of the option.
242 * @throws org.jomc.ObjectManagementException if getting the message instance fails.
243 */
244 @SuppressWarnings("unused")
245 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
246 private String getArgumentDescription( final java.util.Locale locale )
247 {
248 final String _m = org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getMessage( this, "Argument Description", locale );
249 assert _m != null : "'Argument Description' message not found.";
250 return _m;
251 }
252 /**
253 * Gets the text of the {@code <Description>} message.
254 * <p><dl>
255 * <dt><b>Languages:</b></dt>
256 * <dd>English (default)</dd>
257 * <dt><b>Final:</b></dt><dd>No</dd>
258 * </dl></p>
259 * @param locale The locale of the message to return.
260 * @param valueSeparator Format argument.
261 * @return Display description of the option.
262 * @throws org.jomc.ObjectManagementException if getting the message instance fails.
263 */
264 @SuppressWarnings("unused")
265 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
266 private String getDescription( final java.util.Locale locale, final java.lang.String valueSeparator )
267 {
268 final String _m = org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getMessage( this, "Description", locale, valueSeparator );
269 assert _m != null : "'Description' message not found.";
270 return _m;
271 }
272 // </editor-fold>
273 // SECTION-END
274 }