{
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 = loadedClasses.get(cacheKey);
if (cls != null)
{
return cls;
}
cls = unloadedClasses.get(cacheKey);
if (cls != null)
{
return cls;
}
if (cls == null)
{
// Try the supplied loader first
cls = classOrNull(name, primary);
}
if (cls == null && this.primary.get() != null)
{
// Try the primary for this current thread
cls = classOrNull(name, (ClassLoader) this.primary.get());
}
if (cls == null)
{
// Try the loader for the current thread
cls = classOrNull(name, contextClassLoader);
}
if (cls == null)
{
// Try the loader for the PM context
cls = classOrNull(name, pmContextLoader);
}
if (cls == null && runtimeLoader != null)
{
// Try the registered loader for runtime created classes
cls = classOrNull(name, runtimeLoader);
}
if (cls == null && userRegisteredLoader != null)
{
// Try the user registered loader for classes
cls = classOrNull(name, userRegisteredLoader);
}
if (cls == null)
{
if (NucleusLogger.CLASSLOADING.isDebugEnabled())
{
// Log the class loading failure in case its of use in debugging
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.datanucleus"))
{
processingClassLoaderResolverCalls = true;
}
i++;
}
// Don't give stack trace, just the method that asked for class-resolving
NucleusLogger.CLASSLOADING.debug(LOCALISER.msg("001004", name,
element.getClassName() + "." + element.getMethodName(), "" + element.getLineNumber()));
}
String msg = LOCALISER.msg("001000", name);
throw new ClassNotResolvedException(msg);
}
//put in unloaded cache, since it was not loaded here
unloadedClasses.put(cacheKey, cls);