1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.applications.commandline;
12
13 import org.astrogrid.applications.beans.v1.parameters.types.ParameterTypes;
14 import org.astrogrid.applications.beans.v1.types.SwitchTypes;
15 import org.astrogrid.applications.description.base.BaseParameterDescription;
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20 /*** extended parameter description for commandline - contains further fields loaded from config - flag format, etc.
21 *
22 */
23 public class CommandLineParameterDescription extends BaseParameterDescription {
24 /*** Construct a new CommandLineParameterDescription
25 *
26 */
27 public CommandLineParameterDescription() {
28 super();
29 }
30
31
32 /***
33 * The string that makes up the command switch. If this is not specified then it is assumed that the switch is the same as the name
34 */
35 private String commandSwitch=null;
36 /***
37 * The switchtype can be "normal" i.e. it is a -switch form or "keyword" where is is of the form switch=par
38 */
39 private SwitchTypes switchType = SwitchTypes.NORMAL;
40 /***
41 * The commandPosition indicates where on the command line the parameter is to be placed - The first parameter position is 1. If this value is specified then it means that no switch will be output, but the parameter value will be placed directly on the command line at that position.
42 */
43 private int commandPosition = -1;
44
45
46 /*** flag that indicates application expects a file-reference containing this parameter in the arguments, rather than the parameter value itself. NB This default should match the schema default*/
47 private boolean fileRef = true;
48
49 /*** if non-null, then the application will always write output to a file with this name */
50 private String localFileName = null;
51
52 /***
53 * Adds any necessary switches to the commandline parameter. This is controlled by the @link #commandPosition, @link #commandSwitch and @link #switchType fields.
54 * If the commandPosition is anything other than -1 then no adornment is added. If a switch string is to be added then the style is controlled by switchType and the
55 * string for the switch is given by commandSwitch, or if that is null the parameter name is used.
56 * @param val
57 * @return stringbuffer containing original value, plus any required adornments.
58 */
59 public List addCmdlineAdornment(String val)
60 {
61 List cmdarg = new ArrayList();
62
63 if (commandPosition == -1) {
64
65 String sw = name;
66 if(commandSwitch != null)
67 {
68 sw = commandSwitch;
69 }
70
71 if (!sw.equals("---"))
72 {
73 if (switchType.equals(SwitchTypes.NORMAL)) {
74 cmdarg.add("-" + sw);
75 cmdarg.add(val);
76
77 }
78 else if (switchType.equals(SwitchTypes.KEYWORD)) {
79 cmdarg.add(sw + "=" + val);
80 }
81 }
82 else
83 {
84
85 }
86 }
87 else
88 {
89 cmdarg.add(val);
90 }
91
92 return cmdarg;
93 }
94
95 /***
96 * @return
97 */
98 public int getCommandPosition() {
99 return commandPosition;
100 }
101
102 /***
103 * @return
104 */
105 public String getCommandSwitch() {
106 return commandSwitch;
107 }
108
109 /***
110 * Returns the SwitchType as a enumerated type.
111 * @TODO Daft name...
112 * @return
113 */
114 public SwitchTypes getSwitchTypeType() {
115 return switchType;
116 }
117
118 /***
119 * @param i
120 *
121 */
122 public void setCommandPosition(int i) {
123 commandPosition = i;
124 }
125
126 /***
127 * @param string
128 *
129 */
130 public void setCommandSwitch(String string) {
131 commandSwitch = string;
132 }
133
134 /***
135 * Set the switchType.
136 * To allow the digester to work we need the argument to be a string (and the pseudo getter needs to be present), even though internally this is set to @link SwitchTypes.
137 * @param string
138 *
139 */
140 public void setSwitchType(String string) {
141 try {
142 switchType = SwitchTypes.valueOf(string);
143 }
144 catch (RuntimeException e) {
145
146 logger.warn("Invalid SwitchType - " + string + "defaulting to NORMAL for parameter "+ name , e);
147 switchType = SwitchTypes.NORMAL;
148 }
149 }
150 public String getSwitchType()
151 {
152 return switchType.toString();
153 }
154
155
156 /*** setter method to set superclasses 'type' field from a string - used within the digester parsing of the configuration file */
157 public void setTypeString(String arg0) {
158 super.setType(ParameterTypes.valueOf(arg0));
159 }
160
161 public boolean isFileRef() {
162 return fileRef;
163 }
164
165 public void setFileRef(boolean isFile) {
166 this.fileRef = isFile;
167 }
168
169 public String getLocalFileName() {
170 return localFileName;
171 }
172 public void setLocalFileName(String localFileName) {
173 this.localFileName = localFileName;
174 }
175 }
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205