View Javadoc
1   /*
2    * $Header: /cvsroot/sinon/sinon/src/java/eteg/sinon/Main.java,v 1.5 2005/08/25 02:54:43 thiagohp Exp $
3    * $Revision: 1.5 $
4    * $Date: 2005/08/25 02:54:43 $
5    * $Author: thiagohp $
6    *
7    * =============================================================================
8    *
9    * Copyright 2004-2005 Eteg Internet Ltda. (http://www.eteg.com.br)
10   *
11   * Licensed under the Apache License, Version 2.0 (the "License");
12   * you may not use this file except in compliance with the License.
13   * You may obtain a copy of the License at
14   *
15   *     http://www.apache.org/licenses/LICENSE-2.0
16   *
17   * Unless required by applicable law or agreed to in writing, software
18   * distributed under the License is distributed on an "AS IS" BASIS,
19   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   * See the License for the specific language governing permissions and
21   * limitations under the License.
22   */
23  package eteg.sinon;
24  
25  import eteg.sinon.core.Catalog;
26  import eteg.sinon.core.Collector;
27  import eteg.sinon.dao.xml.XMLCollectorDAO;
28  import eteg.sinon.exception.SinonException;
29  import eteg.sinon.executor.CollectorExecutor;
30  
31  import java.io.File;
32  
33  /***
34   * Class used to run Sinon in a standalone manner.
35   * <p/>
36   * <pre>
37   * $Header: /cvsroot/sinon/sinon/src/java/eteg/sinon/Main.java,v 1.5 2005/08/25 02:54:43 thiagohp Exp $
38   * </pre>
39   *
40   * @author Thiago H. de Paula Figueiredo (last modification by $Author: thiagohp $)
41   * @version $Revision: 1.5 $
42   * @since 20/09/2004.
43   */
44  public class Main {
45  
46      public static void main(String[] args) {
47          try {
48              if (args.length == 2) {
49                  System.out.println("Executting [" + args[0]
50                          + "] catalog [" + args[1] + "]");
51                  runCollector(args[0], args[1]);
52              }
53              else if (args.length == 1) {
54                  System.out.println("Executting [" + args[0] + "]");
55                  runCollector(args[0], null);
56              }
57              else {
58                  System.out.println("Usage: java -cp <classpath> " +
59                          "-jar sinon-[version].jar " +
60                          "<collector name> [catalog name]");
61              }
62          } catch (Exception e) {
63              e.printStackTrace();
64          }
65      }
66  
67      private static void runCollector(String idCollector, String catalogName)
68              throws Exception {
69  
70          XMLCollectorDAO xmlCollectorDAO = new XMLCollectorDAO(new File("."));
71          Collector collector = xmlCollectorDAO.load(idCollector);
72          final CollectorExecutor executor = new CollectorExecutor(collector);
73  
74  
75          try {
76  
77          	if (catalogName != null) {
78  
79                  Catalog catalog = collector.getCatalog(catalogName);
80                  executor.execute(new Catalog[]{catalog});
81  
82              }
83              else {
84                  executor.execute();
85              }
86  
87          } catch (SinonException e) {
88          }
89  
90      }
91  
92  }