KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > bcel > internal > verifier > VerifierAppFrame


1 package com.sun.org.apache.bcel.internal.verifier;
2
3 /* ====================================================================
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 2001 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowledgment may appear in the software itself,
26  * if and wherever such third-party acknowledgments normally appear.
27  *
28  * 4. The names "Apache" and "Apache Software Foundation" and
29  * "Apache BCEL" must not be used to endorse or promote products
30  * derived from this software without prior written permission. For
31  * written permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache",
34  * "Apache BCEL", nor may "Apache" appear in their name, without
35  * prior written permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation. For more
53  * information on the Apache Software Foundation, please see
54  * <http://www.apache.org/>.
55  */

56
57 import java.awt.*;
58 import java.awt.event.*;
59 import javax.swing.*;
60 import javax.swing.event.*;
61 import com.sun.org.apache.bcel.internal.*;
62 import com.sun.org.apache.bcel.internal.classfile.*;
63 import com.sun.org.apache.bcel.internal.verifier.*;
64
65 /**
66  * This class implements a machine-generated frame for use with
67  * the GraphicalVerfifier.
68  *
69  * @version $Id: VerifierAppFrame.java,v 1.1.1.1 2001/10/29 20:00:32 jvanzyl Exp $
70  * @author Enver Haase
71  * @see GraphicalVerifier
72  */

73 public class VerifierAppFrame extends JFrame {
74   JPanel contentPane;
75   JSplitPane jSplitPane1 = new JSplitPane();
76   JPanel jPanel1 = new JPanel();
77   JPanel jPanel2 = new JPanel();
78   JSplitPane jSplitPane2 = new JSplitPane();
79   JPanel jPanel3 = new JPanel();
80   JList classNamesJList = new JList();
81   GridLayout gridLayout1 = new GridLayout();
82   JPanel messagesPanel = new JPanel();
83   GridLayout gridLayout2 = new GridLayout();
84   JMenuBar jMenuBar1 = new JMenuBar();
85   JMenu jMenu1 = new JMenu();
86   JScrollPane jScrollPane1 = new JScrollPane();
87   JScrollPane messagesScrollPane = new JScrollPane();
88   JScrollPane jScrollPane3 = new JScrollPane();
89   GridLayout gridLayout4 = new GridLayout();
90   JScrollPane jScrollPane4 = new JScrollPane();
91   CardLayout cardLayout1 = new CardLayout();
92
93   private String JavaDoc JUSTICE_VERSION = "JustIce by Enver Haase";
94   private String JavaDoc current_class;
95   GridLayout gridLayout3 = new GridLayout();
96   JTextPane pass1TextPane = new JTextPane();
97   JTextPane pass2TextPane = new JTextPane();
98   JTextPane messagesTextPane = new JTextPane();
99   JMenuItem newFileMenuItem = new JMenuItem();
100   JSplitPane jSplitPane3 = new JSplitPane();
101   JSplitPane jSplitPane4 = new JSplitPane();
102   JScrollPane jScrollPane2 = new JScrollPane();
103   JScrollPane jScrollPane5 = new JScrollPane();
104   JScrollPane jScrollPane6 = new JScrollPane();
105   JScrollPane jScrollPane7 = new JScrollPane();
106   JList pass3aJList = new JList();
107   JList pass3bJList = new JList();
108   JTextPane pass3aTextPane = new JTextPane();
109   JTextPane pass3bTextPane = new JTextPane();
110   JMenu jMenu2 = new JMenu();
111   JMenuItem whatisMenuItem = new JMenuItem();
112   JMenuItem aboutMenuItem = new JMenuItem();
113
114   /** Constructor. */
115   public VerifierAppFrame() {
116     enableEvents(AWTEvent.WINDOW_EVENT_MASK);
117     try {
118       jbInit();
119     }
120     catch(Exception JavaDoc e) {
121       e.printStackTrace();
122     }
123   }
124   /** Initizalization of the components. */
125   private void jbInit() throws Exception JavaDoc {
126     //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Ihr Symbol]")));
127
contentPane = (JPanel) this.getContentPane();
128     contentPane.setLayout(cardLayout1);
129     this.setJMenuBar(jMenuBar1);
130     this.setSize(new Dimension(708, 451));
131     this.setTitle("JustIce");
132     jPanel1.setMinimumSize(new Dimension(100, 100));
133     jPanel1.setPreferredSize(new Dimension(100, 100));
134     jPanel1.setLayout(gridLayout1);
135     jSplitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT);
136     jPanel2.setLayout(gridLayout2);
137     jPanel3.setMinimumSize(new Dimension(200, 100));
138     jPanel3.setPreferredSize(new Dimension(400, 400));
139     jPanel3.setLayout(gridLayout4);
140     messagesPanel.setMinimumSize(new Dimension(100, 100));
141     messagesPanel.setLayout(gridLayout3);
142     jPanel2.setMinimumSize(new Dimension(200, 100));
143     jMenu1.setText("File");
144
145     jScrollPane1.getViewport().setBackground(Color.red);
146     messagesScrollPane.getViewport().setBackground(Color.red);
147     messagesScrollPane.setPreferredSize(new Dimension(10, 10));
148     classNamesJList.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
149       public void valueChanged(ListSelectionEvent e) {
150         classNamesJList_valueChanged(e);
151       }
152     });
153     classNamesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
154     jScrollPane3.setBorder(BorderFactory.createLineBorder(Color.black));
155     jScrollPane3.setPreferredSize(new Dimension(100, 100));
156     gridLayout4.setRows(4);
157     gridLayout4.setColumns(1);
158     gridLayout4.setHgap(1);
159     jScrollPane4.setBorder(BorderFactory.createLineBorder(Color.black));
160     jScrollPane4.setPreferredSize(new Dimension(100, 100));
161     pass1TextPane.setBorder(BorderFactory.createRaisedBevelBorder());
162     pass1TextPane.setToolTipText("");
163     pass1TextPane.setEditable(false);
164     pass2TextPane.setBorder(BorderFactory.createRaisedBevelBorder());
165     pass2TextPane.setEditable(false);
166     messagesTextPane.setBorder(BorderFactory.createRaisedBevelBorder());
167     messagesTextPane.setEditable(false);
168     newFileMenuItem.setText("New...");
169     newFileMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(78, java.awt.event.KeyEvent.CTRL_MASK, true));
170     newFileMenuItem.addActionListener(new java.awt.event.ActionListener JavaDoc() {
171       public void actionPerformed(ActionEvent e) {
172         newFileMenuItem_actionPerformed(e);
173       }
174     });
175     pass3aTextPane.setEditable(false);
176     pass3bTextPane.setEditable(false);
177     pass3aJList.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
178       public void valueChanged(ListSelectionEvent e) {
179         pass3aJList_valueChanged(e);
180       }
181     });
182     pass3bJList.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
183       public void valueChanged(ListSelectionEvent e) {
184         pass3bJList_valueChanged(e);
185       }
186     });
187     jMenu2.setText("Help");
188     whatisMenuItem.setText("What is...");
189     whatisMenuItem.addActionListener(new java.awt.event.ActionListener JavaDoc() {
190       public void actionPerformed(ActionEvent e) {
191         whatisMenuItem_actionPerformed(e);
192       }
193     });
194     aboutMenuItem.setText("About");
195     aboutMenuItem.addActionListener(new java.awt.event.ActionListener JavaDoc() {
196       public void actionPerformed(ActionEvent e) {
197         aboutMenuItem_actionPerformed(e);
198       }
199     });
200     jSplitPane2.add(messagesPanel, JSplitPane.BOTTOM);
201     messagesPanel.add(messagesScrollPane, null);
202     messagesScrollPane.getViewport().add(messagesTextPane, null);
203     jSplitPane2.add(jPanel3, JSplitPane.TOP);
204     jPanel3.add(jScrollPane3, null);
205     jScrollPane3.getViewport().add(pass1TextPane, null);
206     jPanel3.add(jScrollPane4, null);
207     jPanel3.add(jSplitPane3, null);
208     jSplitPane3.add(jScrollPane2, JSplitPane.LEFT);
209     jScrollPane2.getViewport().add(pass3aJList, null);
210     jSplitPane3.add(jScrollPane5, JSplitPane.RIGHT);
211     jScrollPane5.getViewport().add(pass3aTextPane, null);
212     jPanel3.add(jSplitPane4, null);
213     jSplitPane4.add(jScrollPane6, JSplitPane.LEFT);
214     jScrollPane6.getViewport().add(pass3bJList, null);
215     jSplitPane4.add(jScrollPane7, JSplitPane.RIGHT);
216     jScrollPane7.getViewport().add(pass3bTextPane, null);
217     jScrollPane4.getViewport().add(pass2TextPane, null);
218     jSplitPane1.add(jPanel2, JSplitPane.TOP);
219     jPanel2.add(jScrollPane1, null);
220     jSplitPane1.add(jPanel1, JSplitPane.BOTTOM);
221     jPanel1.add(jSplitPane2, null);
222     jScrollPane1.getViewport().add(classNamesJList, null);
223     jMenuBar1.add(jMenu1);
224     jMenuBar1.add(jMenu2);
225     contentPane.add(jSplitPane1, "jSplitPane1");
226     jMenu1.add(newFileMenuItem);
227     jMenu2.add(whatisMenuItem);
228     jMenu2.add(aboutMenuItem);
229     jSplitPane2.setDividerLocation(300);
230     jSplitPane3.setDividerLocation(150);
231     jSplitPane4.setDividerLocation(150);
232   }
233
234   /** Overridden to stop the application on a closing window. */
235   protected void processWindowEvent(WindowEvent e) {
236     super.processWindowEvent(e);
237     if (e.getID() == WindowEvent.WINDOW_CLOSING) {
238       System.exit(0);
239     }
240   }
241
242   synchronized void classNamesJList_valueChanged(ListSelectionEvent e) {
243     if (e.getValueIsAdjusting()) return;
244     current_class = classNamesJList.getSelectedValue().toString();
245     verify();
246     classNamesJList.setSelectedValue(current_class, true);
247   }
248
249   private void verify(){
250     setTitle("PLEASE WAIT");
251
252     Verifier v = VerifierFactory.getVerifier(current_class);
253     v.flush(); // Don't cache the verification result for this class.
254

255     VerificationResult vr;
256
257     vr = v.doPass1();
258     if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
259       pass1TextPane.setText(vr.getMessage());
260       pass1TextPane.setBackground(Color.red);
261
262       pass2TextPane.setText("");
263       pass2TextPane.setBackground(Color.yellow);
264       pass3aTextPane.setText("");
265       pass3aJList.setListData(new Object JavaDoc[0]);
266       pass3aTextPane.setBackground(Color.yellow);
267
268       pass3bTextPane.setText("");
269       pass3bJList.setListData(new Object JavaDoc[0]);
270       pass3bTextPane.setBackground(Color.yellow);
271
272     }
273     else{ // Must be VERIFIED_OK, Pass 1 does not know VERIFIED_NOTYET
274
pass1TextPane.setBackground(Color.green);
275       pass1TextPane.setText(vr.getMessage());
276
277       vr = v.doPass2();
278       if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
279         pass2TextPane.setText(vr.getMessage());
280         pass2TextPane.setBackground(Color.red);
281
282         pass3aTextPane.setText("");
283         pass3aTextPane.setBackground(Color.yellow);
284         pass3aJList.setListData(new Object JavaDoc[0]);
285         pass3bTextPane.setText("");
286         pass3bTextPane.setBackground(Color.yellow);
287         pass3bJList.setListData(new Object JavaDoc[0]);
288       }
289       else{ // must be Verified_OK, because Pass1 was OK (cannot be Verified_NOTYET).
290
pass2TextPane.setText(vr.getMessage());
291           pass2TextPane.setBackground(Color.green);
292
293           JavaClass jc = Repository.lookupClass(current_class);
294           boolean all3aok = true;
295           boolean all3bok = true;
296           String JavaDoc all3amsg = "";
297           String JavaDoc all3bmsg = "";
298
299           String JavaDoc[] methodnames = new String JavaDoc[jc.getMethods().length];
300           for (int i=0; i<jc.getMethods().length; i++){
301             methodnames[i] = jc.getMethods()[i].toString().replace('\n',' ').replace('\t',' ');
302           }
303           pass3aJList.setListData(methodnames);
304           pass3aJList.setSelectionInterval(0,jc.getMethods().length-1);
305           pass3bJList.setListData(methodnames);
306           pass3bJList.setSelectionInterval(0,jc.getMethods().length-1);
307       }
308
309     }
310     String JavaDoc[] msgs = v.getMessages();
311     messagesTextPane.setBackground(msgs.length == 0? Color.green : Color.yellow);
312     String JavaDoc allmsgs = "";
313     for (int i=0; i<msgs.length; i++){
314       msgs[i] = msgs[i].replace('\n',' ');
315       allmsgs += msgs[i] + "\n\n";
316     }
317     messagesTextPane.setText(allmsgs);
318
319     setTitle(current_class + " - " + JUSTICE_VERSION);
320   }
321
322   void newFileMenuItem_actionPerformed(ActionEvent e) {
323     String JavaDoc classname = JOptionPane.showInputDialog("Please enter the fully qualified name of a class or interface to verify:");
324     if ((classname == null) || (classname.equals(""))) return;
325     VerifierFactory.getVerifier(classname); // let observers do the rest.
326
classNamesJList.setSelectedValue(classname, true);
327   }
328
329   synchronized void pass3aJList_valueChanged(ListSelectionEvent e) {
330
331     if (e.getValueIsAdjusting()) return;
332     Verifier v = VerifierFactory.getVerifier(current_class);
333
334     String JavaDoc all3amsg = "";
335     boolean all3aok = true;
336     boolean rejected = false;
337     for (int i=0; i<pass3aJList.getModel().getSize(); i++){
338
339       if (pass3aJList.isSelectedIndex(i)){
340         VerificationResult vr = v.doPass3a(i);
341
342         if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
343           all3aok = false;
344           rejected = true;
345         }
346         all3amsg += "Method '"+Repository.lookupClass(v.getClassName()).getMethods()[i]+"': "+vr.getMessage().replace('\n',' ')+"\n\n";
347       }
348     }
349     pass3aTextPane.setText(all3amsg);
350     pass3aTextPane.setBackground(all3aok? Color.green : (rejected? Color.red : Color.yellow));
351
352   }
353
354   synchronized void pass3bJList_valueChanged(ListSelectionEvent e) {
355     if (e.getValueIsAdjusting()) return;
356
357     Verifier v = VerifierFactory.getVerifier(current_class);
358
359     String JavaDoc all3bmsg = "";
360     boolean all3bok = true;
361     boolean rejected = false;
362     for (int i=0; i<pass3bJList.getModel().getSize(); i++){
363
364       if (pass3bJList.isSelectedIndex(i)){
365         VerificationResult vr = v.doPass3b(i);
366
367         if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
368           all3bok = false;
369           rejected = true;
370         }
371         all3bmsg += "Method '"+Repository.lookupClass(v.getClassName()).getMethods()[i]+"': "+vr.getMessage().replace('\n',' ')+"\n\n";
372       }
373     }
374     pass3bTextPane.setText(all3bmsg);
375     pass3bTextPane.setBackground(all3bok? Color.green : (rejected? Color.red : Color.yellow));
376
377   }
378
379   void aboutMenuItem_actionPerformed(ActionEvent e) {
380     JOptionPane.showMessageDialog(this,
381             "JustIce is a Java class file verifier.\nIt was implemented by Enver Haase in 2001.\nhttp://bcel.sourceforge.net",
382              JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE);
383   }
384
385   void whatisMenuItem_actionPerformed(ActionEvent e) {
386     JOptionPane.showMessageDialog(this,
387             "The upper four boxes to the right reflect verification passes according to The Java Virtual Machine Specification.\nThese are (in that order): Pass one, Pass two, Pass three (before data flow analysis), Pass three (data flow analysis).\nThe bottom box to the right shows (warning) messages; warnings do not cause a class to be rejected.",
388              JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE);
389   }
390 }
391
Popular Tags