View Javadoc
1   /**
2   The contents of this file are subject to the Mozilla Public License Version 1.1 
3   (the "License"); you may not use this file except in compliance with the License. 
4   You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
5   Software distributed under the License is distributed on an "AS IS" basis, 
6   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
7   specific language governing rights and limitations under the License. 
8   
9   The Original Code is "CommandParse.java".  Description: 
10  "This class parses the command line argument for the command line tool ConfGen.java" 
11  
12  The Initial Developer of the Original Code is University Health Network. Copyright (C) 
13  2001.  All Rights Reserved. 
14  
15  Contributor(s): James Agnew
16                  Paul Brohman
17                  Mitch Delachevrotiere
18                  Shawn Dyck
19    				Cory Metcalf
20    				
21  Alternatively, the contents of this file may be used under the terms of the 
22  GNU General Public License (the  ?GPL?), in which case the provisions of the GPL are 
23  applicable instead of those above.  If you wish to allow use of your version of this 
24  file only under the terms of the GPL and not to allow others to use your version 
25  of this file under the MPL, indicate your decision by deleting  the provisions above 
26  and replace  them with the notice and other provisions required by the GPL License.  
27  If you do not delete the provisions above, a recipient may use your version of 
28  this file under either the MPL or the GPL. 
29  
30  */
31  package ca.uhn.hl7v2.conf.classes.generator.builders;
32  
33  import java.util.ArrayList;
34  import java.util.List;
35  
36  /** This class parses the command line argument for the command line tool ConfGen.java
37   * @author <table><tr>James Agnew</tr>
38   *                <tr>Paul Brohman</tr>
39   *                <tr>Mitch Delachevrotiere</tr>
40   *                <tr>Shawn Dyck</tr>
41   * 				  <tr>Cory Metcalf</tr></table>
42   */
43  public class CommandParser {
44     private boolean errFlag = false;
45     private String errorType;
46     private boolean helpFlag = false;
47     private final List<String> params;
48  
49     // option flags
50     private boolean testFlag = false;
51     private boolean verbFlag = false;
52  
53     /** creates a new vector to store the command line arguments into 
54      */
55     public CommandParser() {
56        this.params = new ArrayList<>();
57     }
58  
59     /** returns the location where the genrated files are going to be stored into 
60      * @return the location where the genrated files are going to be stored into   
61      */
62     public String getDest() {
63        return params.get(1);
64     }
65     /** returns true if the error flag is set or false if it is not
66      * @return true if the error flag is set or false if it is not  
67      */
68     public boolean getErrFlag() {
69        return errFlag;
70     }
71  
72     /** returns the error type if there is an error in the command line arguments 
73      * @return the error type if there is an error in the command line arguments 
74      */
75     public String getError() {
76        return errorType;
77     }
78  
79     /** returns true if the help flag is set or false if it is not
80      * @return true if the help flag is set or false if it is not  
81      */
82     public boolean getHelpFlag() {
83        return helpFlag;
84     }
85     
86     /** returns the pakage name to use for the generated source 
87      * @return the pakage name to use for the generated source 
88      */
89     public String getPackage() {
90        return params.get(2);
91     }
92  
93     /** returns the location of the XML profile 
94      * @return the location of the XML profile  
95      */
96     public String getSource() {
97        return params.get(0);
98     }
99     /** returns true if the test flag is set or false if it is not
100     * @return true if the test flag is set or false if it is not  
101     */
102    public boolean getTestFlag() {
103       return testFlag;
104    }
105 
106    /** returns true if the verbose flag is set or false if it is not
107     * @return true if the verbose flag is set or false if it is not  
108     */
109    public boolean getVerbFlag() {
110       return verbFlag;
111    }
112 
113    /** this method parses the command line for the ConfGen.java command line tool
114     * @param args the commnad line arguments
115     */
116    public void parse(String[] args) {
117       int i = 0;
118       String arg;
119       char flag;
120 
121       while (i < args.length && args[i].startsWith("-")) {
122          arg = args[i++];
123 
124          // use this type of check for a series of flag arguments			
125          for (int j = 1; j < arg.length(); j++) {
126             flag = arg.charAt(j);
127             switch (flag) {
128                case 'v' : // -v = verbose
129                   verbFlag = true;
130                   break;
131                case 'h' : // -h = help
132                   helpFlag = true;
133                   break;
134                case 't' : // -t = test
135                   testFlag = true;
136                   break;
137                default :
138                   errFlag = true;
139                   errorType = "invalid command line argument";
140                   break;
141             }
142          }
143       }
144 
145       while (i < args.length && params.size() < 3) {
146          params.add(args[i++]);
147       }
148 
149       if (params.size() < 3) {
150          errFlag = true;
151          errorType = "invalid parameters, source destination and package required";
152       }
153    }
154 }