View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.geronimo.ews.ws4j2ee.toWs;
18  
19  import org.apache.axis.utils.CLArgsParser;
20  import org.apache.axis.utils.CLOption;
21  import org.apache.axis.utils.CLOptionDescriptor;
22  
23  import java.util.List;
24  
25  /***
26   * @author hemapani
27   */
28  public class Ws4J2eeCLOptionParser {
29      // Define our short one-letter option identifiers.
30      protected static final int SERVER_OPT = 's';
31      protected static final int SKELETON_DEPLOY_OPT = 'S';
32      protected static final int NAMESPACE_OPT = 'N';
33      protected static final int NAMESPACE_FILE_OPT = 'f';
34      protected static final int OUTPUT_OPT = 'o';
35      protected static final int SCOPE_OPT = 'd';
36      protected static final int TEST_OPT = 't';
37      protected static final int PACKAGE_OPT = 'p';
38      protected static final int ALL_OPT = 'a';
39      protected static final int TYPEMAPPING_OPT = 'T';
40      protected static final int FACTORY_CLASS_OPT = 'F';
41      protected static final int HELPER_CLASS_OPT = 'H';
42      protected static final int USERNAME_OPT = 'U';
43      protected static final int PASSWORD_OPT = 'P';
44      protected static final int IMPL_STYLE_OPT = 'E';
45      protected static final int CONTAINER_OPT = 'J';
46  
47      private String wscffile;
48      private String outputDirectory = ".";
49      private boolean isServerSide = false;
50      private String userName;
51      private String password;
52      private String implStyle = GenerationConstants.USE_LOCAL_AND_REMOTE;
53      private String contanier = GenerationConstants.JBOSS_CONTAINER;
54  
55      protected static final CLOptionDescriptor[] options = new CLOptionDescriptor[]{
56          new CLOptionDescriptor("server-side",
57                  CLOptionDescriptor.ARGUMENT_OPTIONAL,
58                  SERVER_OPT,
59                  "Genarate Server side codes"),
60          new CLOptionDescriptor("output",
61                  CLOptionDescriptor.ARGUMENT_REQUIRED,
62                  OUTPUT_OPT,
63                  "output Directory "),
64          new CLOptionDescriptor("user",
65                  CLOptionDescriptor.ARGUMENT_REQUIRED,
66                  USERNAME_OPT,
67                  "user name"),
68          new CLOptionDescriptor("password",
69                  CLOptionDescriptor.ARGUMENT_REQUIRED,
70                  PASSWORD_OPT,
71                  "password"),
72          new CLOptionDescriptor("implStyle",
73                  CLOptionDescriptor.ARGUMENT_REQUIRED,
74                  IMPL_STYLE_OPT,
75                  "impelemtation Style"),
76          new CLOptionDescriptor("container",
77                  CLOptionDescriptor.ARGUMENT_REQUIRED,
78                  CONTAINER_OPT,
79                  "the J2EE contianer")
80      };
81  
82      public Ws4J2eeCLOptionParser(String[] args) {
83          CLArgsParser argsParser = new CLArgsParser(args, options);
84  
85          // Print parser errors, if any
86          if (null != argsParser.getErrorString()) {
87              System.err.println(argsParser.getErrorString());
88              //printUsage();
89          }
90  
91          // Get a list of parsed options
92          List clOptions = argsParser.getArguments();
93          int size = clOptions.size();
94          try {
95              // Parse the options and configure the emitter as appropriate.
96              for (int i = 0; i < size; i++) {
97                  parseOption((CLOption) clOptions.get(i));
98              }
99  
100             // validate argument combinations
101             //
102             //validateOptions();
103 
104             //parser.run(wsdlURI);
105 
106             // everything is good
107             //System.exit(0);
108         } catch (Throwable t) {
109             t.printStackTrace();
110             System.exit(1);
111         }
112     }
113 
114     protected void parseOption(CLOption option) {
115         switch (option.getId()) {
116             case SERVER_OPT:
117                 isServerSide = true;
118                 break;
119             case OUTPUT_OPT:
120                 outputDirectory = option.getArgument();
121                 break;
122             case USERNAME_OPT:
123                 userName = option.getArgument();
124                 break;
125             case PASSWORD_OPT:
126                 password = option.getArgument();
127                 break;
128             case CLOption.TEXT_ARGUMENT:
129                 if (wscffile != null) {
130                     throw new UnrecoverableGenerationFault("Only one arguement allowed ");
131                     //printUsage();
132                 }
133                 wscffile = option.getArgument();
134                 break;
135             case IMPL_STYLE_OPT:
136                 this.implStyle = option.getArgument();
137                 break;
138             case CONTAINER_OPT:
139                 this.contanier = option.getArgument();
140                 break;
141             default:
142                 throw new UnrecoverableGenerationFault("unknown option");
143         }
144     } // parseOption
145 
146     /***
147      * @return
148      */
149     public String getWscffile() {
150         return wscffile;
151     }
152 
153     /***
154      * @param string
155      */
156     public void setWscffile(String string) {
157         wscffile = string;
158     }
159 
160     /***
161      * @return
162      */
163     public boolean isServerSide() {
164         return isServerSide;
165     }
166 
167     /***
168      * @return
169      */
170     public String getOutputDirectory() {
171         return outputDirectory;
172     }
173 
174     /***
175      * @return
176      */
177     public String getPassword() {
178         return password;
179     }
180 
181     /***
182      * @return
183      */
184     public String getUserName() {
185         return userName;
186     }
187 
188     /***
189      * @param b
190      */
191     public void setServerSide(boolean b) {
192         isServerSide = b;
193     }
194 
195     /***
196      * @param string
197      */
198     public void setOutputDirectory(String string) {
199         outputDirectory = string;
200     }
201 
202     /***
203      * @param string
204      */
205     public void setPassword(String string) {
206         password = string;
207     }
208 
209     /***
210      * @param string
211      */
212     public void setUserName(String string) {
213         userName = string;
214     }
215 
216     /***
217      * @return
218      */
219     public String getImplStyle() {
220         return implStyle;
221     }
222 
223     /***
224      * @param string
225      */
226     public void setImplStyle(String string) {
227         implStyle = string;
228     }
229 
230     /***
231      * @return
232      */
233     public String getContanier() {
234         return contanier;
235     }
236 
237     /***
238      * @param string
239      */
240     public void setContanier(String string) {
241         contanier = string;
242     }
243 
244 }