Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GORA-72] Made all artifacts proper OSGi bundles. Added ClassLoadingU…
…tils which will fallback to thread context classloader if Class.forName fails. git-svn-id: https://svn.apache.org/repos/asf/incubator/gora/trunk@1227229 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
13 changed files
with
138 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
gora-core/src/main/java/org/apache/gora/util/ClassLoadingUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.apache.gora.util; | ||
|
||
public class ClassLoadingUtils { | ||
|
||
private ClassLoadingUtils() { | ||
//Utility Class | ||
} | ||
|
||
/** | ||
* Loads a class using the class loader. | ||
* 1. The class loader of the current class is being used. | ||
* 2. The thread context class loader is being used. | ||
* If both approaches fail, returns null. | ||
* | ||
* @param className The name of the class to load. | ||
* @return The class or null if no class loader could load the class. | ||
*/ | ||
public static Class<?> loadClass(String className) throws ClassNotFoundException { | ||
return ClassLoadingUtils.loadClass(ClassLoadingUtils.class,className); | ||
} | ||
|
||
/** | ||
* Loads a class using the class loader. | ||
* 1. The class loader of the context class is being used. | ||
* 2. The thread context class loader is being used. | ||
* If both approaches fail, returns null. | ||
* | ||
* @param contextClass The name of a context class to use. | ||
* @param className The name of the class to load | ||
* @return The class or null if no class loader could load the class. | ||
*/ | ||
public static Class<?> loadClass(Class<?> contextClass, String className) throws ClassNotFoundException { | ||
Class<?> clazz = null; | ||
if (contextClass.getClassLoader() != null) { | ||
clazz = loadClass(className, contextClass.getClassLoader()); | ||
} | ||
if (clazz == null && Thread.currentThread().getContextClassLoader() != null) { | ||
clazz = loadClass(className, Thread.currentThread().getContextClassLoader()); | ||
} | ||
if (clazz == null) { | ||
throw new ClassNotFoundException("Failed to load class" + className); | ||
} | ||
return clazz; | ||
} | ||
|
||
/** | ||
* Loads a {@link Class} from the specified {@link ClassLoader} without throwing {@ClassNotFoundException}. | ||
* | ||
* @param className | ||
* @param classLoader | ||
* @return | ||
*/ | ||
private static Class<?> loadClass(String className, ClassLoader classLoader) { | ||
Class<?> clazz = null; | ||
if (classLoader != null && className != null) { | ||
try { | ||
clazz = classLoader.loadClass(className); | ||
} catch (ClassNotFoundException e) { | ||
//Ignore and return null | ||
} | ||
} | ||
return clazz; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters