/[classpath]/cp-tools/src/gnu/classpath/tools/SerialVer.java
ViewVC logotype

Diff of /cp-tools/src/gnu/classpath/tools/SerialVer.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by cbj, Tue Aug 3 01:51:30 2004 UTC revision 1.3 by cbj, Sun Jan 30 02:21:06 2005 UTC
# Line 1  Line 1 
1  /* gnu.classpath.tools.SerialVer  /* gnu.classpath.tools.SerialVer
2     Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.   Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.   This file is part of GNU Classpath.
5    
6  GNU Classpath is free software; you can redistribute it and/or modify   GNU Classpath is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by   it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2, or (at your option)   the Free Software Foundation; either version 2, or (at your option)
9  any later version.   any later version.
10    
11  GNU Classpath is distributed in the hope that it will be useful, but   GNU Classpath is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of   WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  General Public License for more details.   General Public License for more details.
15    
16  You should have received a copy of the GNU General Public License   You should have received a copy of the GNU General Public License
17  along with GNU Classpath; see the file COPYING.  If not, write to the   along with GNU Classpath; see the file COPYING.  If not, write to the
18  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19  02111-1307 USA. */   02111-1307 USA. */
   
20  package gnu.classpath.tools;  package gnu.classpath.tools;
21    
22  import java.io.ObjectStreamClass;  import java.io.ObjectStreamClass;
23    
24  /**  /**
25     This class is an implementation of the `serialver' program.  Any   * This class is an implementation of the `serialver' program. Any number of
26     number of class names can be passed as arguments, and the serial   * class names can be passed as arguments, and the serial version unique
27     version unique identitfier for each class will be printed in a   * identitfier for each class will be printed in a manner suitable for cuting
28     manner suitable for cuting and pasting into a Java source file.   * and pasting into a Java source file.
29  */   */
30  public class SerialVer  public class SerialVer
31  {  {
32    public static void main(String[] args)    public static void main(String[] args)
33    {    {
34      if (args.length == 0)      if (args.length == 0)
35      {        {
36        System.out.println("Usage: serialver [CLASS]...");          System.out.println("Usage: serialver [CLASS]...");
37        return;          return;
38      }        }
   
39      Class clazz;      Class clazz;
40      ObjectStreamClass osc;      ObjectStreamClass osc;
41      for (int i = 0; i < args.length; i++)      for (int i = 0; i < args.length; i++)
     {  
       try  
       {  
         clazz = Class.forName(args[i]);  
         osc = ObjectStreamClass.lookup(clazz);  
   
         if (osc != null)  
           System.out.println(  
             clazz.getName()  
               + ": "  
               + "static final long serialVersionUID = "  
               + osc.getSerialVersionUID()  
               + "L;");  
         else  
           System.err.println("Class " + args[i] + " is not serializable");  
       }  
       catch (ClassNotFoundException e)  
42        {        {
43          System.err.println("Class for " + args[i] + " not found");          try
44              {
45                clazz = Class.forName(args[i]);
46                osc = ObjectStreamClass.lookup(clazz);
47                if (osc != null)
48                  System.out.println(clazz.getName() + ": "
49                                     + "static final long serialVersionUID = "
50                                     + osc.getSerialVersionUID() + "L;");
51                else
52                  System.err.println("Class " + args[i] + " is not serializable");
53              }
54            catch (ClassNotFoundException e)
55              {
56                System.err.println("Class for " + args[i] + " not found");
57              }
58        }        }
     }  
59    }    }
60  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26