KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > verifier > Main


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.verifier;
23
24 /*
25  * Class org.jboss.verifier.Main;
26  * Copyright (C) 2000 Juha Lindfors
27  *
28  * This library is free software; you can redistribute it and/or
29  * modify it under the terms of the GNU Lesser General Public
30  * License as published by the Free Software Foundation; either
31  * version 2 of the License, or (at your option) any later version
32  *
33  * This library is distributed in the hope that it will be useful,
34  * but WITHOUT ANY WARRANTY; without even the implied warranty of
35  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36  * Lesser General Public License for more details.
37  *
38  * You should have received a copy of the GNU Lesser General Public
39  * License along with this library; if not, write to the Free Software
40  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41  *
42  * This package and its source code is available at www.jboss.org
43  * $Id: Main.java 37459 2005-10-30 00:04:02Z starksm $
44  *
45  * You can reach the author by sending email to jplindfo@helsinki.fi.
46  */

47
48 // standard imports
49
import java.io.File JavaDoc;
50 import java.net.URL JavaDoc;
51 import java.net.URLClassLoader JavaDoc;
52
53 // non-standard class dependencies
54
import org.jboss.verifier.event.VerificationListener;
55 import org.jboss.verifier.event.VerificationEvent;
56
57 import org.jboss.metadata.XmlFileLoader;
58
59 /**
60  * Main class for bean verifier.
61  *
62  * For more detailed documentation, refer to the
63  * <a HREF="http://www.ejboss.org">JBoss project</a>
64  *
65  * @author Juha Lindfors
66  * @version $Revision: 37459 $
67  * @since JDK 1.3
68  */

69 public class Main
70 {
71    public final static int OK = 0;
72    public final static int WARNING = 1;
73
74    static int returnCode = OK;
75
76    /**
77     * Starts the application.
78     *
79     * @param args argument strings
80     */

81    public static void main(String JavaDoc[] args)
82    {
83       try
84       {
85          if( args.length < 1 )
86          {
87             throw new IllegalArgumentException JavaDoc(
88                "Usage: beanverifier mybeans.jar");
89          }
90
91          URL JavaDoc url = new File JavaDoc(args[0]).toURL();
92          URLClassLoader JavaDoc cl = new URLClassLoader JavaDoc( new URL JavaDoc[] {url},
93             Thread.currentThread().getContextClassLoader());
94          XmlFileLoader xfl = new XmlFileLoader();
95          BeanVerifier verifier = new BeanVerifier();
96
97          xfl.setClassLoader(cl);
98          verifier.addVerificationListener(new Listener());
99
100          verifier.verify(url, xfl.load(null));
101       }
102       catch (Exception JavaDoc e)
103       {
104          System.err.println("Problem starting the application:");
105          System.err.println("Exception: " + e);
106          System.err.println("Message: " + e.getMessage());
107          e.printStackTrace();
108
109          System.exit(-1);
110       }
111
112       System.exit(returnCode);
113    }
114 }
115
116 class Listener
117    implements VerificationListener
118 {
119    public void specViolation(VerificationEvent event)
120    {
121       System.out.println(event.getVerbose());
122
123       Main.returnCode = Main.WARNING;
124    }
125
126    public void beanChecked(VerificationEvent event)
127    {
128       System.out.println(event.getMessage());
129    }
130 }
131 /*
132 vim:ts=3:sw=3:et
133 */

134
Popular Tags