001// SECTION-START[License Header] 002// <editor-fold defaultstate="collapsed" desc=" Generated License "> 003/* 004 * Java Object Management and Configuration 005 * Copyright (C) Christian Schulte, 2005-206 006 * All rights reserved. 007 * 008 * Redistribution and use in source and binary forms, with or without 009 * modification, are permitted provided that the following conditions 010 * are met: 011 * 012 * o Redistributions of source code must retain the above copyright 013 * notice, this list of conditions and the following disclaimer. 014 * 015 * o Redistributions in binary form must reproduce the above copyright 016 * notice, this list of conditions and the following disclaimer in 017 * the documentation and/or other materials provided with the 018 * distribution. 019 * 020 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 021 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 022 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 023 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, 024 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 025 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 026 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 027 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 029 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 030 * 031 * $JOMC: OptionFactory.java 4756 2013-01-04 08:01:00Z schulte $ 032 * 033 */ 034// </editor-fold> 035// SECTION-END 036package org.jomc.cli.model; 037 038import java.io.File; 039import org.apache.commons.cli.Option; 040 041// SECTION-START[Documentation] 042// <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> 043/** 044 * 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. 045 * 046 * <dl> 047 * <dt><b>Identifier:</b></dt><dd>JOMC ⁑ CLI ⁑ Option Factory</dd> 048 * <dt><b>Name:</b></dt><dd>JOMC ⁑ CLI ⁑ Option Factory</dd> 049 * <dt><b>Abstract:</b></dt><dd>Yes</dd> 050 * <dt><b>Final:</b></dt><dd>No</dd> 051 * <dt><b>Stateless:</b></dt><dd>No</dd> 052 * </dl> 053 * 054 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.0 055 * @version 1.4.1 056 */ 057// </editor-fold> 058// SECTION-END 059// SECTION-START[Annotations] 060// <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> 061@javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 062// </editor-fold> 063// SECTION-END 064public final class OptionFactory 065{ 066 // SECTION-START[OptionFactory] 067 068 public Option getObject() 069 { 070 final char valueSeparator = this.getValueSeparator() == ':' ? File.pathSeparatorChar : this.getValueSeparator(); 071 072 final Option option = 073 new Option( this.getOpt(), this.getDescription( this.getLocale(), Character.toString( valueSeparator ) ) ); 074 075 option.setArgs( this.getNumberOfArgs() ); 076 option.setLongOpt( this.getLongOpt() ); 077 option.setOptionalArg( this.isOptionalArg() ); 078 option.setRequired( this.isRequired() ); 079 080 if ( ( option.getArgs() > 0 || option.getArgs() == Option.UNLIMITED_VALUES ) 081 && this.getArgumentDescription( this.getLocale() ).trim().length() > 0 ) 082 { 083 option.setArgName( this.getArgumentDescription( this.getLocale() ) ); 084 } 085 086 if ( option.getArgs() > 1 || option.getArgs() == Option.UNLIMITED_VALUES ) 087 { 088 option.setValueSeparator( valueSeparator ); 089 } 090 091 return option; 092 } 093 094 // SECTION-END 095 // SECTION-START[Constructors] 096 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> 097 /** Creates a new {@code OptionFactory} instance. */ 098 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 099 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 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}