{
if (name == null)
{
// Avoid the NPE and just throw a "not resolved"
String msg = LOCALISER.msg("001000", name);
throw new ClassNotResolvedException(msg);
}
if (name.equals(ClassNameConstants.BYTE))
{
return byte.class;
}
else if (name.equals(ClassNameConstants.CHAR))
{
return char.class;
}
else if (name.equals(ClassNameConstants.INT))
{
return int.class;
}
else if (name.equals(ClassNameConstants.LONG))
{
return long.class;
}
else if (name.equals(ClassNameConstants.DOUBLE))
{
return double.class;
}
else if (name.equals(ClassNameConstants.FLOAT))
{
return float.class;
}
else if (name.equals(ClassNameConstants.SHORT))
{
return short.class;
}
else if (name.equals(ClassNameConstants.BOOLEAN))
{
return boolean.class;
}
else if (name.equals(ClassNameConstants.JAVA_LANG_STRING))
{
return String.class;
}
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
String cacheKey = newCacheKey(name, primary, contextClassLoader);
//lookup in loaded and unloaded classes cache
Class cls = (Class) loadedClasses.get(cacheKey);
if (cls != null)
{
return cls;
}
cls = (Class) unloadedClasses.get(cacheKey);
if (cls != null)
{
return cls;
}
// Try the supplied loader first
if (cls == null)
{
cls = classOrNull(name, primary);
}
// Try the primary for this current thread
if (cls == null && this.primary.get() != null)
{
cls = classOrNull(name, (ClassLoader) this.primary.get());
}
// Try the loader for the current thread
if (cls == null)
{
cls = classOrNull(name, contextClassLoader);
}
// Try the loader for the PM context
if (cls == null)
{
cls = classOrNull(name, pmContextLoader);
}
// Try the registered loader for runtime created classes
if (cls == null && registeredLoader != null)
{
cls = classOrNull(name, registeredLoader);
}
// Try the user registered loader for classes
if (cls == null && userRegisteredLoader != null)
{
cls = classOrNull(name, userRegisteredLoader);
}
if (cls == null)
{
if (JPOXLogger.CLASSLOADING.isDebugEnabled())
{
// Log the class loading failure in case its of use in debugging
if (JavaUtils.isJRE1_4OrAbove())
{
StackTraceElement[] traceElements = new Exception().getStackTrace();
StackTraceElement element = null;
int i = 0;
boolean processingClassLoaderResolverCalls = false;
while (element == null)
{
if (processingClassLoaderResolverCalls &&
traceElements[i].getClassName().indexOf(this.getClass().getName()) < 0)
{
// Next class in the stack trace after the JDOClassLoaderResolver calls
element = traceElements[i];
}
else if (traceElements[i].getClassName().startsWith("org.jpox"))
{
processingClassLoaderResolverCalls = true;
}
i++;
}
// Dont give stack trace, just the method that asked for class-resolving
JPOXLogger.CLASSLOADING.debug(LOCALISER.msg("001004", name,
element.getClassName() + "." + element.getMethodName(), "" + element.getLineNumber()));
}
else
{
JPOXLogger.CLASSLOADING.debug(LOCALISER.msg("001005", name));
}
}
String msg = LOCALISER.msg("001000", name);
throw new ClassNotResolvedException(msg);
}
//put in unloaded cache, since it was not loaded here
unloadedClasses.put(cacheKey, cls);