KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > classycle > AnalyserCommandLine


1 /*
2  * Copyright (c) 2003-2006, Franz-Josef Elmer, All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
15  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */

25 package classycle;
26
27
28
29 /**
30  * Process command line arguments and options for the main application
31  * {@link Analyser}.
32  *
33  * @author Franz-Josef Elmer
34  */

35 public class AnalyserCommandLine extends CommandLine
36 {
37   private static final String JavaDoc XML_FILE = "-xmlFile=";
38   private static final String JavaDoc CSV_FILE = "-csvFile=";
39   private static final String JavaDoc TITLE = "-title=";
40   private boolean _packagesOnly;
41   private boolean _raw;
42   private boolean _cycles;
43   private boolean _strong;
44   private String JavaDoc _title;
45   private String JavaDoc _xmlFile;
46   private String JavaDoc _csvFile;
47   public AnalyserCommandLine(String JavaDoc[] args)
48   {
49     super(args);
50     if (_title == null && _classFiles.length > 0)
51     {
52       _title = _classFiles[0];
53     }
54   }
55   
56   protected void handleOption(String JavaDoc argument)
57   {
58     if (argument.equals("-raw"))
59     {
60       _raw = true;
61     } else if (argument.equals("-packagesOnly"))
62     {
63       _packagesOnly = true;
64     } else if (argument.equals("-cycles"))
65     {
66       _cycles = true;
67     } else if (argument.equals("-strong"))
68     {
69       _strong = true;
70     } else if (argument.startsWith(TITLE))
71     {
72       _title = argument.substring(TITLE.length());
73       if (_title.length() == 0)
74       {
75         _valid = false;
76       }
77     } else if (argument.startsWith(XML_FILE))
78     {
79       _xmlFile = argument.substring(XML_FILE.length());
80       if (_xmlFile.length() == 0)
81       {
82         _valid = false;
83       }
84     } else if (argument.startsWith(CSV_FILE))
85     {
86       _csvFile = argument.substring(CSV_FILE.length());
87       if (_csvFile.length() == 0)
88       {
89         _valid = false;
90       }
91     } else
92     {
93       super.handleOption(argument);
94     }
95   }
96
97   /** Returns the usage of correct command line arguments and options. */
98   public String JavaDoc getUsage()
99   {
100     return "[-raw] [-packagesOnly] [-cycles|-strong] "
101         + "[" + XML_FILE + "<file>] [" + CSV_FILE + "<file>] "
102         + "[" + TITLE + "<title>] " + super.getUsage();
103   }
104   
105   /** Returns <tt>true</tt> if the option <tt>-cycles</tt> has been set. */
106   public boolean isCycles()
107   {
108     return _cycles;
109   }
110
111   /** Returns <tt>true</tt> if the option <tt>-package</tt> has been set. */
112   public boolean isPackagesOnly()
113   {
114     return _packagesOnly;
115   }
116
117   /** Returns <tt>true</tt> if the option <tt>-raw</tt> has been set. */
118   public boolean isRaw()
119   {
120     return _raw;
121   }
122
123   /** Returns <tt>true</tt> if the option <tt>-strong</tt> has been set. */
124   public boolean isStrong()
125   {
126     return _strong;
127   }
128
129   /**
130    * Returns the name of the CSV file as defined by the option
131    * <tt>-csvFile</tt>.
132    * @return <tt>null</tt> if undefined.
133    */

134   public String JavaDoc getCsvFile()
135   {
136     return _csvFile;
137   }
138
139   /**
140    * Returns the title by the option <tt>-title</tt>.
141    * If undefined {@link #getClassFiles()}<tt>[0]</tt> will be used.
142    * @return String
143    */

144   public String JavaDoc getTitle()
145   {
146     return _title;
147   }
148
149   /**
150    * Returns the name of the XML file as defined by the option
151    * <tt>-xmlFile</tt>.
152    * @return <tt>null</tt> if undefined.
153    */

154   public String JavaDoc getXmlFile()
155   {
156     return _xmlFile;
157   }
158 }
159
Popular Tags