Source Code Cross Referenced for ArgumentParser.java in  » Testing » MockCreator » net » sf » mockcreator » utils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » MockCreator » net.sf.mockcreator.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sf.mockcreator.utils;
002:
003:        import java.io.IOException;
004:        import java.io.PrintStream;
005:        import java.util.ArrayList;
006:        import java.util.Enumeration;
007:        import java.util.LinkedList;
008:        import java.util.List;
009:        import java.util.StringTokenizer;
010:        import java.util.jar.JarEntry;
011:        import java.util.jar.JarFile;
012:
013:        /**
014:         * TODO: usage?
015:         * TODO: tests?
016:         */
017:        public class ArgumentParser {
018:
019:            public static void help(PrintStream out) {
020:                out.println("Available options are:");
021:                out
022:                        .println("-o dir   output directory (default is current dir)");
023:                out
024:                        .println("-d dirs  java style separated list of source directories, like foo:bar:baz or foo;bar;baz");
025:                out.println("-p pkg   target package (default is autodetect)");
026:                out
027:                        .println("-u       update; generate mock even if up-to-date");
028:                out
029:                        .println("-f N     generate also fake superclasses ('dumbies') up to N depth ('all' means infinite depth)");
030:                out.println("No option is required though.");
031:            }
032:
033:            private String[] args;
034:            private List directories = new ArrayList();
035:            private int firstInterfacePos = 0;
036:
037:            private List classNames = new ArrayList();
038:            private String outputPath = ".";
039:            private String pkg = "";
040:            private boolean skipUptodate = true;
041:            private int fakeDepth = 0;
042:
043:            public ArgumentParser(String[] args) throws IOException {
044:                if (args == null || args.length == 0)
045:                    return;
046:                this .args = args;
047:
048:                outputPath = getOptionValue("-o");
049:                if (outputPath == null || outputPath.equals("")) {
050:                    outputPath = ".";
051:                }
052:
053:                pkg = getOptionValue("-p");
054:                if (pkg == null) {
055:                    pkg = "";
056:                }
057:
058:                String depth = getOptionValue("-f");
059:                if (depth != null) {
060:                    if ("all".equals(depth)) {
061:                        fakeDepth = Integer.MAX_VALUE;
062:                    } else {
063:                        fakeDepth = Integer.parseInt(depth);
064:                    }
065:                }
066:
067:                skipUptodate = !getStandaloneBooleanOption("-u");
068:
069:                getDirectories();
070:                checkUnknownOptions();
071:                getInterfaces();
072:            }
073:
074:            private void checkUnknownOptions() {
075:                for (int n = firstInterfacePos; n < args.length; ++n) {
076:                    if (args[n] != null && args[n].startsWith("-"))
077:                        throw new IllegalArgumentException("unknown option:"
078:                                + args[n]);
079:                }
080:            }
081:
082:            private void getInterfaces() throws IOException {
083:                for (int n = firstInterfacePos; n < args.length; ++n) {
084:                    if (args[n] != null) {
085:                        classNames.add(args[n]);
086:                    }
087:                }
088:
089:                for (int n = 0; n < firstInterfacePos; ++n) {
090:                    if (args[n] != null) {
091:                        throw new IllegalArgumentException(
092:                                "parameter in wrong position:" + args[n]);
093:                    }
094:                }
095:            }
096:
097:            public List getClassNames() {
098:                return classNames;
099:            }
100:
101:            public String getOutputPath() {
102:                return outputPath;
103:            }
104:
105:            public boolean getSkipUptodate() {
106:                return skipUptodate;
107:            }
108:
109:            public List getSourceDirectories() {
110:                return directories;
111:            }
112:
113:            public String getTargetPackage() {
114:                return pkg;
115:            }
116:
117:            public int getFakeDepth() {
118:                return fakeDepth;
119:            }
120:
121:            private boolean getStandaloneBooleanOption(String option) {
122:                for (int idx = 0; idx < args.length; idx++) {
123:                    String argument = args[idx];
124:                    if (argument == null)
125:                        continue;
126:
127:                    if (argument.equals(option)) {
128:                        args[idx] = null;
129:                        firstInterfacePos = Math
130:                                .max(firstInterfacePos, idx + 1);
131:                        return true;
132:                    } else if (argument.startsWith(option)) {
133:                        throw new IllegalArgumentException("option " + option
134:                                + " shall not have parameters");
135:                    }
136:                }
137:
138:                return false;
139:            }
140:
141:            private String getOptionValue(String option) {
142:                String val = null;
143:
144:                for (int idx = 0; idx < args.length; idx++) {
145:                    String argument = args[idx];
146:                    if (argument == null)
147:                        continue;
148:
149:                    if (option.equals(argument)) {
150:                        args[idx] = null;
151:                        idx++;
152:                        if (idx >= args.length)
153:                            throw new IllegalArgumentException(
154:                                    "no required parameter given for " + option);
155:                        val = args[idx];
156:                        args[idx] = null;
157:                        firstInterfacePos = Math
158:                                .max(firstInterfacePos, idx + 1);
159:                    } else if (argument.startsWith(option)) {
160:                        val = argument.substring(option.length());
161:                        args[idx] = null;
162:                        firstInterfacePos = Math
163:                                .max(firstInterfacePos, idx + 1);
164:                    }
165:                }
166:
167:                return val;
168:            }
169:
170:            private void getDirectories() {
171:                directories = new LinkedList();
172:
173:                String dirs = getOptionValue("-d");
174:
175:                if (dirs != null) {
176:                    StringTokenizer dt = new StringTokenizer(dirs, ":;");
177:
178:                    while (dt.hasMoreTokens()) {
179:                        String directory = dt.nextToken();
180:                        directories.add(directory);
181:                    }
182:                }
183:            }
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.