Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,309 additions
and
421 deletions.
There are no files selected for viewing
41 changes: 38 additions & 3 deletions
41
future/symmetric3-core/src/main/java/org/jumpmind/symmetric/core/common/ClassUtils.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 |
---|---|---|
@@ -1,20 +1,55 @@ | ||
package org.jumpmind.symmetric.core.common; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
|
||
public class ClassUtils { | ||
|
||
public static ClassLoader getDefaultClassLoader() { | ||
ClassLoader cl = null; | ||
try { | ||
cl = Thread.currentThread().getContextClassLoader(); | ||
} | ||
catch (Throwable ex) { | ||
// Cannot access thread context ClassLoader - falling back to system class loader... | ||
} catch (Throwable ex) { | ||
// Cannot access thread context ClassLoader - falling back to system | ||
// class loader... | ||
} | ||
if (cl == null) { | ||
// No thread context class loader -> use class loader of this class. | ||
cl = ClassUtils.class.getClassLoader(); | ||
} | ||
return cl; | ||
} | ||
|
||
/** | ||
* Attempt to find a {@link Method} on the supplied class with the supplied | ||
* name and parameter types. Searches all superclasses up to | ||
* <code>Object</code>. | ||
* <p> | ||
* Returns <code>null</code> if no {@link Method} can be found. | ||
* | ||
* @param clazz | ||
* the class to introspect | ||
* @param name | ||
* the name of the method | ||
* @param paramTypes | ||
* the parameter types of the method (may be <code>null</code> to | ||
* indicate any signature) | ||
* @return the Method object, or <code>null</code> if none found | ||
*/ | ||
public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) { | ||
Class<?> searchType = clazz; | ||
while (searchType != null) { | ||
Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType | ||
.getDeclaredMethods()); | ||
for (Method method : methods) { | ||
if (name.equals(method.getName()) | ||
&& (paramTypes == null || Arrays.equals(paramTypes, | ||
method.getParameterTypes()))) { | ||
return method; | ||
} | ||
} | ||
searchType = searchType.getSuperclass(); | ||
} | ||
return null; | ||
} | ||
} |
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
Oops, something went wrong.