OSDN Git Service

* gnu/gcj/runtime/FirstThread.java (getMain): Fixed indentation.
[pf3gnuchains/gcc-fork.git] / libjava / gnu / gcj / runtime / FirstThread.java
1 // FirstThread.java - Implementation of very first thread.
2
3 /* Copyright (C) 1998, 1999, 2000, 2001, 2003  Free Software Foundation
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 package gnu.gcj.runtime;
12
13 import java.util.jar.*;
14
15 /**
16  * @author Tom Tromey <tromey@cygnus.com>
17  * @date August 24, 1998 
18  */
19
20 final class FirstThread extends Thread
21 {
22   public FirstThread (Class k, String[] args)
23   {
24     super (null, null, "main");
25     klass = k;
26     this.args = args;
27   }
28
29   public FirstThread (String class_name, String[] args, boolean is_jar)
30   {
31     super (null, null, "main");
32     klass_name = class_name;
33     this.args = args;
34     this.is_jar = is_jar;
35   }
36
37   public void run()
38   {
39     if (is_jar)
40       klass_name = getMain(klass_name);
41
42     if (klass == null)
43       {
44         try
45           {
46             klass = Class.forName(klass_name);
47           }
48         catch (ClassNotFoundException x)
49           {
50             throw new NoClassDefFoundError(klass_name);
51           }
52       }
53
54     call_main();
55   }
56
57   private String getMain (String name)
58   {
59     String mainName = null;
60     try
61       {
62         JarFile j = new JarFile(name);
63         Attributes a = j.getManifest().getMainAttributes();
64         mainName = a.getValue(Attributes.Name.MAIN_CLASS);
65       }
66     catch (Exception e)
67       {
68         // Ignore.
69       }
70
71     if (mainName == null)
72       {
73         System.err.println("Failed to load Main-Class manifest attribute from "
74                            + name);
75         System.exit(1);
76       }
77     return mainName;
78   }
79
80   private native void call_main ();
81
82   // Private data.
83   private Class klass;
84   private String klass_name;
85   private Object args;
86   private boolean is_jar;
87
88   // If the user links statically then we need to ensure that these
89   // classes are linked in.  Otherwise bootstrapping fails.  These
90   // classes are only referred to via Class.forName(), so we add an
91   // explicit mention of them here.
92   static final Class Kcert = java.security.cert.Certificate.class;
93   static final Class Kfile = gnu.gcj.protocol.file.Handler.class;
94   static final Class Khttp = gnu.gcj.protocol.http.Handler.class;
95   static final Class Kjar  = gnu.gcj.protocol.jar.Handler.class;
96 }