KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > ide > Main


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22
23 package org.aspectj.debugger.ide;
24
25 public class Main {
26
27     /**
28      * Override this to return a FullPathSourceShower.
29      * The methods to override are:
30      * - public void showSourceForFullPath(String fullPath);
31      * - public void showLineForCurrentModel(int line, boolean isAtBreakpoint);
32      * - public String getSourceName();
33      */

34     SourceShower getShower() {
35         if (shower != null) {
36             try {
37                 return (SourceShower) Class.forName(shower).newInstance();
38             } catch (Throwable JavaDoc t) {
39                 t.printStackTrace();
40             }
41         }
42         return FullPathSourceShower.proto;
43     }
44
45     IDEInterface getIDE() {
46         if (ide != null) {
47             try {
48                 IDEInterface i = (IDEInterface) Class.forName(ide).newInstance();
49                 System.out.println("i:" + i);
50                 return i;
51             } catch (Throwable JavaDoc t) {
52                 t.printStackTrace();
53             }
54         }
55         return null;
56     }
57
58     String JavaDoc mainClass;
59     String JavaDoc classPath;
60     String JavaDoc sourcePath;
61     String JavaDoc mode;
62     String JavaDoc shower;
63     String JavaDoc ide;
64     boolean verbose = false;
65
66     public static void main(String JavaDoc[] args) {
67         new Main().realMain(args);
68     }
69
70
71     public void realMain(String JavaDoc[] args) {
72         parseArgs(args);
73         IDEDebugger.launch(mainClass, sourcePath, classPath, mode, new String JavaDoc[0], getShower(), getIDE());
74     }
75
76     void parseArgs(String JavaDoc[] args) {
77         String JavaDoc arg = "";
78         String JavaDoc val = "";
79         for (int i = 0; i < args.length; i++) {
80             arg = args[i];
81             if (arg.equals("-mainclass")) {
82                 if (check("mainclass", args, i)) mainClass = args[++i];
83             } else if (arg.equals("-classpath")) {
84                 if (check("classpath", args, i)) classPath = args[++i];
85             } else if (arg.equals("-sourcepath")) {
86                 if (check("sourcepath", args, i)) sourcePath = args[++i];
87             } else if (arg.equals("-mode")) {
88                 if (check("mode", args, i)) mode = args[++i];
89             } else if (arg.equals("-shower")) {
90                 if (check("shower", args, i)) shower = args[++i];
91             } else if (arg.equals("-ide")) {
92                 if (check("ide", args, i)) ide = args[++i];
93             } else if (arg.equals("-verbose")) {
94                 verbose = true;
95             }
96         }
97     }
98
99     boolean check(String JavaDoc arg, String JavaDoc[] args, int i) {
100         if (args == null || args.length < i || args[i+1] == null) {
101             exit("bad argument to " + arg + " i=" + i + " length=" + args.length);
102             return false;
103         }
104         return true;
105     }
106
107     void exit(String JavaDoc msg) {
108         System.err.println(msg);
109         System.exit(1);
110     }
111 }
112
Popular Tags