KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > ClassManager


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: ClassManager.java,v 1.8 2002/12/29 11:15:56 per_nyfelt Exp $
8

9 package org.ozoneDB.core;
10
11 import org.ozoneDB.OzoneClassNotFoundException;
12 import org.ozoneDB.util.LogWriter;
13
14
15 /**
16  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
17  * @version $Revision: 1.8 $Date: 2002/12/29 11:15:56 $
18  */

19 public final class ClassManager extends ServerComponent {
20
21     protected ClassLoader JavaDoc classLoader;
22
23
24     public ClassManager( Env _env ) {
25         super( _env );
26     }
27
28
29     public void startup() throws Exception JavaDoc {
30         env.logWriter.newEntry( this, "startup...", LogWriter.INFO );
31         dropClasses();
32     }
33
34
35     public void shutdown() throws Exception JavaDoc {
36         env.logWriter.newEntry( this, "shutdown...", LogWriter.INFO );
37     }
38
39
40     public void save() throws Exception JavaDoc {
41     }
42
43
44     public Class JavaDoc classForName( String JavaDoc name ) throws OzoneClassNotFoundException {
45         if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {
46             env.logWriter.newEntry( this, "classForName(): " + name, LogWriter.DEBUG3 );
47         }
48         try {
49             // TODO: remove this if the classLoader works
50
// as long as the OzoneClassLoader does not work as expected and does
51
// not allow to drop classes we can directly use the context loader
52
// of the thread to avoid problems in managed environments like
53
// servlets
54
//Class cl;
55
// If we do not use OzoneClassLoader, we have to care for primitive types ourselves
56
//cl = OzoneClassLoader.primitiveType(name);
57
//if (cl==null) {
58
// cl = Thread.currentThread().getContextClassLoader().loadClass( name );
59
//}
60

61            Class JavaDoc cl = classLoader.loadClass( name );
62
63             if (env.logWriter.hasTarget( LogWriter.DEBUG3 )) {
64                 env.logWriter.newEntry( this, " class: " + cl.getName() + ", " + cl.hashCode(), LogWriter.DEBUG3 );
65             }
66             return cl;
67         }
68         catch (ClassNotFoundException JavaDoc e) {
69             throw new OzoneClassNotFoundException( e.getMessage() );
70         }
71     }
72
73
74     public void dropClasses() throws Exception JavaDoc {
75         env.logWriter.newEntry( this, "dropClasses()", LogWriter.DEBUG3 );
76         classLoader = new OzoneClassLoader();
77     }
78 }
79
80
81
Popular Tags