Java Code Examples for org.springframework.cglib.proxy.Enhancer#setInterfaces()
The following examples show how to use
org.springframework.cglib.proxy.Enhancer#setInterfaces() .
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: CglibStaticConfigurationInstanceCreator.java From conf4j with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") public <T> T createInstance(ConfigurationModel configurationModel, ClassLoader classLoader) { Class<?> configurationType = configurationModel.getConfigurationType(); Enhancer enhancer = new Enhancer(); enhancer.setClassLoader(classLoader); enhancer.setNamingPolicy(Conf4jNamingPolicy.INSTANCE); enhancer.setInterceptDuringConstruction(false); if (configurationType.isInterface()) { enhancer.setInterfaces(new Class<?>[]{configurationType, Serializable.class}); } else { enhancer.setSuperclass(configurationType); enhancer.setInterfaces(new Class<?>[]{Serializable.class}); } enhancer.setCallbackFilter(new ProxyCallbackFilter(configurationModel)); enhancer.setCallbacks(new Callback[]{ new CglibStaticConfigurationMethodInterceptor(configurationModel), new SerializableNoOp(), }); return (T) enhancer.create(); }
Example 2
Source File: CglibDynamicConfigurationInstanceCreator.java From conf4j with MIT License | 6 votes |
@Override public <T> T createInstance(ConfigurationModel configurationModel, ClassLoader classLoader) { Class<?> configurationType = configurationModel.getConfigurationType(); Enhancer enhancer = new Enhancer(); enhancer.setClassLoader(classLoader); enhancer.setNamingPolicy(Conf4jNamingPolicy.INSTANCE); enhancer.setInterceptDuringConstruction(false); if (configurationType.isInterface()) { enhancer.setInterfaces(new Class<?>[]{configurationType, DynamicConfiguration.class}); } else { enhancer.setSuperclass(configurationType); enhancer.setInterfaces(new Class<?>[]{DynamicConfiguration.class}); } enhancer.setCallbackFilter(new ProxyCallbackFilter(configurationModel)); enhancer.setCallbacks(new Callback[]{ new CglibDynamicConfigurationMethodInterceptor(configurationModel), new SerializableNoOp() }); @SuppressWarnings("unchecked") T instance = (T) enhancer.create(); return instance; }
Example 3
Source File: Recordings.java From syndesis with Apache License 2.0 | 6 votes |
static public <T> T recorder(Object object, Class<T> as) { if (as.isInterface()) { // If it's just an interface, use standard java reflect proxying return as.cast(Proxy.newProxyInstance(as.getClassLoader(), new Class<?>[] { as }, new RecordingInvocationHandler(object))); } // If it's a class then use gclib to implement a subclass to implement proxying RecordingInvocationHandler ih = new RecordingInvocationHandler(object); Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(as); enhancer.setInterfaces(new Class<?>[]{RecordingProxy.class}); enhancer.setCallback(new org.springframework.cglib.proxy.InvocationHandler() { @Override public Object invoke(Object o, Method method, Object[] objects) throws Throwable { return ih.invoke(o, method, objects); } }); return as.cast(enhancer.create()); }
Example 4
Source File: EnhancerUtil.java From specification-arg-resolver with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") static <T> T wrapWithIfaceImplementation(final Class<T> iface, final Specification<Object> targetSpec) { Enhancer enhancer = new Enhancer(); enhancer.setInterfaces(new Class[] { iface }); enhancer.setCallback(new MethodInterceptor() { @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { if ("toString".equals(method.getName())) { return iface.getSimpleName() + "[" + proxy.invoke(targetSpec, args) + "]"; } return proxy.invoke(targetSpec, args); } }); return (T) enhancer.create(); }
Example 5
Source File: ConfigurationClassEnhancer.java From spring-analysis-note with MIT License | 5 votes |
/** * Creates a new CGLIB {@link Enhancer} instance. */ private Enhancer newEnhancer(Class<?> configSuperClass, @Nullable ClassLoader classLoader) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(configSuperClass); enhancer.setInterfaces(new Class<?>[] {EnhancedConfiguration.class}); enhancer.setUseFactory(false); enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE); enhancer.setStrategy(new BeanFactoryAwareGeneratorStrategy(classLoader)); enhancer.setCallbackFilter(CALLBACK_FILTER); enhancer.setCallbackTypes(CALLBACK_FILTER.getCallbackTypes()); return enhancer; }
Example 6
Source File: ConfigurationClassEnhancer.java From java-technology-stack with MIT License | 5 votes |
/** * Creates a new CGLIB {@link Enhancer} instance. */ private Enhancer newEnhancer(Class<?> configSuperClass, @Nullable ClassLoader classLoader) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(configSuperClass); enhancer.setInterfaces(new Class<?>[] {EnhancedConfiguration.class}); enhancer.setUseFactory(false); enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE); enhancer.setStrategy(new BeanFactoryAwareGeneratorStrategy(classLoader)); enhancer.setCallbackFilter(CALLBACK_FILTER); enhancer.setCallbackTypes(CALLBACK_FILTER.getCallbackTypes()); return enhancer; }
Example 7
Source File: AbstractResolver.java From spring-data with Apache License 2.0 | 5 votes |
private Class<?> enhancedTypeFor(final Class<?> type) { final Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(type); enhancer.setCallbackType(org.springframework.cglib.proxy.MethodInterceptor.class); enhancer.setInterfaces(new Class[] { LazyLoadingProxy.class }); return enhancer.createClass(); }
Example 8
Source File: ConfigurationClassEnhancer.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Creates a new CGLIB {@link Enhancer} instance. */ private Enhancer newEnhancer(Class<?> superclass, ClassLoader classLoader) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(superclass); enhancer.setInterfaces(new Class<?>[] {EnhancedConfiguration.class}); enhancer.setUseFactory(false); enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE); enhancer.setStrategy(new BeanFactoryAwareGeneratorStrategy(classLoader)); enhancer.setCallbackFilter(CALLBACK_FILTER); enhancer.setCallbackTypes(CALLBACK_FILTER.getCallbackTypes()); return enhancer; }
Example 9
Source File: ConfigurationClassEnhancer.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Creates a new CGLIB {@link Enhancer} instance. */ private Enhancer newEnhancer(Class<?> superclass, ClassLoader classLoader) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(superclass); enhancer.setInterfaces(new Class<?>[] {EnhancedConfiguration.class}); enhancer.setUseFactory(false); enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE); enhancer.setStrategy(new BeanFactoryAwareGeneratorStrategy(classLoader)); enhancer.setCallbackFilter(CALLBACK_FILTER); enhancer.setCallbackTypes(CALLBACK_FILTER.getCallbackTypes()); return enhancer; }