Menu

[r678]: / javaontracks / src / net / jot / web / JOTFlowClassCache.java  Maximize  Restore  History

Download this file

55 lines (46 with data), 1.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
------------------------------------
JavaOnTracks Thibaut Colar
tcolar-jot AT colar DOT net
Artistic Licence 2.0
http://www.javaontracks.net
------------------------------------
*/
package net.jot.web;
import java.util.Hashtable;
import net.jot.logger.JOTLogger;
/**
* Cache that stores "Class" objects requested by flow.conf (ie: controllers and views)
* Such as class.forName won't have to be called repeatedly.
* @author thibautc
*/
public class JOTFlowClassCache
{
private static Hashtable cache=new Hashtable();
public static Class getClass(String className) throws Exception
{
try
{
if(!cache.containsKey(className))
{
synchronized(JOTFlowClassCache.class)
{
if(!cache.containsKey(className))
{
Class theClass=Class.forName(className);
cache.put(className, theClass);
}
}
JOTLogger.log(JOTLogger.CAT_FLOW,JOTLogger.DEBUG_LEVEL, JOTFlowClassCache.class, "Loaded class in cache: "+className);
}
JOTLogger.log(JOTLogger.CAT_FLOW,JOTLogger.TRACE_LEVEL, JOTFlowClassCache.class, "Fetched class from cache: "+className);
}
catch(ClassNotFoundException e)
{
JOTLogger.log(JOTLogger.CAT_FLOW,JOTLogger.ERROR_LEVEL, JOTFlowClassCache.class, "!! Could not find class: "+className);
Exception e2=new Exception("!! Could not find class: "+className,e);
throw(e2);
}
return (Class)cache.get(className);
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.