Java Code Examples for org.springframework.cglib.core.ReflectUtils#newInstance()
The following examples show how to use
org.springframework.cglib.core.ReflectUtils#newInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Enhancer.java From spring-analysis-note with MIT License | 6 votes |
/** * Creates proxy instance for given argument types, and assigns the callbacks. * Ideally, for each proxy class, just one set of argument types should be used, * otherwise it would have to spend time on constructor lookup. * Technically, it is a re-implementation of {@link Enhancer#createUsingReflection(Class)}, * with "cache {@link #setThreadCallbacks} and {@link #primaryConstructor}" * @param argumentTypes constructor argument types * @param arguments constructor arguments * @param callbacks callbacks to set for the new instance * @return newly created proxy * @see #createUsingReflection(Class) */ public Object newInstance(Class[] argumentTypes, Object[] arguments, Callback[] callbacks) { setThreadCallbacks(callbacks); try { // Explicit reference equality is added here just in case Arrays.equals does not have one if (primaryConstructorArgTypes == argumentTypes || Arrays.equals(primaryConstructorArgTypes, argumentTypes)) { // If we have relevant Constructor instance at hand, just call it // This skips "get constructors" machinery return ReflectUtils.newInstance(primaryConstructor, arguments); } // Take a slow path if observing unexpected argument types return ReflectUtils.newInstance(generatedClass, argumentTypes, arguments); } finally { // clear thread callbacks to allow them to be gc'd setThreadCallbacks(null); } }
Example 2
Source File: Enhancer.java From spring-analysis-note with MIT License | 6 votes |
/** * Instantiates a proxy instance and assigns callback values. * Implementation detail: java.lang.reflect instances are not cached, so this method should not * be used on a hot path. * This method is used when {@link #setUseCache(boolean)} is set to {@code false}. * @param type class to instantiate * @return newly created instance */ private Object createUsingReflection(Class type) { setThreadCallbacks(type, callbacks); try { if (argumentTypes != null) { return ReflectUtils.newInstance(type, argumentTypes, arguments); } else { return ReflectUtils.newInstance(type); } } finally { // clear thread callbacks to allow them to be gc'd setThreadCallbacks(type, null); } }
Example 3
Source File: Enhancer.java From java-technology-stack with MIT License | 6 votes |
/** * Creates proxy instance for given argument types, and assigns the callbacks. * Ideally, for each proxy class, just one set of argument types should be used, * otherwise it would have to spend time on constructor lookup. * Technically, it is a re-implementation of {@link Enhancer#createUsingReflection(Class)}, * with "cache {@link #setThreadCallbacks} and {@link #primaryConstructor}" * @param argumentTypes constructor argument types * @param arguments constructor arguments * @param callbacks callbacks to set for the new instance * @return newly created proxy * @see #createUsingReflection(Class) */ public Object newInstance(Class[] argumentTypes, Object[] arguments, Callback[] callbacks) { setThreadCallbacks(callbacks); try { // Explicit reference equality is added here just in case Arrays.equals does not have one if (primaryConstructorArgTypes == argumentTypes || Arrays.equals(primaryConstructorArgTypes, argumentTypes)) { // If we have relevant Constructor instance at hand, just call it // This skips "get constructors" machinery return ReflectUtils.newInstance(primaryConstructor, arguments); } // Take a slow path if observing unexpected argument types return ReflectUtils.newInstance(generatedClass, argumentTypes, arguments); } finally { // clear thread callbacks to allow them to be gc'd setThreadCallbacks(null); } }
Example 4
Source File: Enhancer.java From java-technology-stack with MIT License | 6 votes |
/** * Instantiates a proxy instance and assigns callback values. * Implementation detail: java.lang.reflect instances are not cached, so this method should not * be used on a hot path. * This method is used when {@link #setUseCache(boolean)} is set to {@code false}. * @param type class to instantiate * @return newly created instance */ private Object createUsingReflection(Class type) { setThreadCallbacks(type, callbacks); try { if (argumentTypes != null) { return ReflectUtils.newInstance(type, argumentTypes, arguments); } else { return ReflectUtils.newInstance(type); } } finally { // clear thread callbacks to allow them to be gc'd setThreadCallbacks(type, null); } }
Example 5
Source File: ApiGateway.java From rebuild with GNU General Public License v3.0 | 5 votes |
/** * @param apiName * @return */ protected BaseApi createApi(String apiName) { if (!API_CLASSES.containsKey(apiName)) { throw new ApiInvokeException(ApiInvokeException.ERR_BADAPI, "Unknown API : " + apiName); } return (BaseApi) ReflectUtils.newInstance(API_CLASSES.get(apiName)); }
Example 6
Source File: ApiGateway.java From rebuild with GNU General Public License v3.0 | 5 votes |
/** * @param clazz */ public static void registerApi(Class<? extends BaseApi> clazz) { BaseApi api = (BaseApi) ReflectUtils.newInstance(clazz); String apiName = api.getApiName(); if (API_CLASSES.containsKey(apiName)) { LOG.error("Replaced API : " + apiName); } API_CLASSES.put(apiName, clazz); LOG.info("New API registered : " + apiName + " : " + clazz.getName()); }