KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > launching > SootThread


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 package ca.mcgill.sable.soot.launching;
21
22
23 import java.io.PrintStream JavaDoc;
24 import java.util.*;
25 import java.lang.reflect.*;
26
27 import org.eclipse.swt.widgets.Display;
28 import soot.*;
29 import soot.toolkits.graph.interaction.*;
30 import ca.mcgill.sable.soot.interaction.*;
31
32
33 public class SootThread extends Thread JavaDoc {
34
35     private Display display;
36     private String JavaDoc mainClass;
37     private ArrayList cfgList;
38     private IInteractionListener listener;
39     private SootRunner parent;
40     
41     /**
42      * Constructor for SootThread.
43      */

44     public SootThread(Display display, String JavaDoc mainClass, SootRunner parent) {
45         super();
46         setDisplay(display);
47         
48         setMainClass(mainClass);
49         
50         InteractionController controller = new InteractionController();
51         controller.setDisplay(getDisplay());
52         controller.setSootThread(this);
53         setListener(controller);
54         setParent(parent);
55         this.setName("soot thread");
56             
57     }
58
59     
60     
61     private String JavaDoc [] cmd;
62     private PrintStream JavaDoc sootOut;
63
64     
65     public void run() {
66         final String JavaDoc [] cmdFinal = getCmd();
67         final PrintStream JavaDoc sootOutFinal = getSootOut();
68         try {
69             
70             soot.G.v().reset();
71             soot.G.v().out = sootOutFinal;
72            
73             InteractionHandler.v().setInteractionListener(getListener());
74             
75             Class JavaDoc toRun = Class.forName(getMainClass());
76             Method [] meths = toRun.getDeclaredMethods();
77             Object JavaDoc [] args = new Object JavaDoc [1];
78             args[0] = cmdFinal;
79             for (int i = 0; i < meths.length; i++){
80                 if (meths[i].getName().equals("main")){
81                     Class JavaDoc [] fields = meths[i].getParameterTypes();
82                     if (fields.length == 1){
83                     meths[i].invoke(toRun, args);
84                     }
85                 }
86             }
87             setCfgList(soot.Scene.v().getPkgList());
88             getParent().setCfgList(getCfgList());
89             
90         }
91         catch (Exception JavaDoc e) {
92             System.out.println("Soot exception: "+e);
93             e.printStackTrace(sootOutFinal);
94             System.out.println(e.getCause());
95         }
96     }
97     /**
98      * Returns the cmd.
99      * @return String
100      */

101     public String JavaDoc [] getCmd() {
102         return cmd;
103     }
104
105     /**
106      * Returns the sootOut.
107      * @return PrintStream
108      */

109     public PrintStream JavaDoc getSootOut() {
110         return sootOut;
111     }
112
113     /**
114      * Sets the cmd.
115      * @param cmd The cmd to set
116      */

117     public void setCmd(String JavaDoc [] cmd) {
118         this.cmd = cmd;
119     }
120
121     /**
122      * Sets the sootOut.
123      * @param sootOut The sootOut to set
124      */

125     public void setSootOut(PrintStream JavaDoc sootOut) {
126         this.sootOut = sootOut;
127     }
128
129     /**
130      * Returns the display.
131      * @return Display
132      */

133     public Display getDisplay() {
134         return display;
135     }
136
137     /**
138      * Sets the display.
139      * @param display The display to set
140      */

141     public void setDisplay(Display display) {
142         this.display = display;
143     }
144
145     /**
146      * @return
147      */

148     public String JavaDoc getMainClass() {
149         return mainClass;
150     }
151
152     /**
153      * @param string
154      */

155     public void setMainClass(String JavaDoc string) {
156         mainClass = string;
157     }
158
159     /**
160      * @return
161      */

162     public ArrayList getCfgList() {
163         return cfgList;
164     }
165
166     /**
167      * @param list
168      */

169     public void setCfgList(ArrayList list) {
170         cfgList = list;
171     }
172
173     /**
174      * @return
175      */

176     public IInteractionListener getListener() {
177         return listener;
178     }
179
180     /**
181      * @param listener
182      */

183     public void setListener(IInteractionListener listener) {
184         this.listener = listener;
185     }
186
187     /**
188      * @return
189      */

190     public SootRunner getParent() {
191         return parent;
192     }
193
194     /**
195      * @param runner
196      */

197     public void setParent(SootRunner runner) {
198         parent = runner;
199     }
200
201 }
202
Popular Tags