Java Code Examples for net.sf.cglib.proxy.Enhancer#setCallbackType()
The following examples show how to use
net.sf.cglib.proxy.Enhancer#setCallbackType() .
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: CglibProxy.java From festival with Apache License 2.0 | 6 votes |
@Override public Object getProxy(ClassLoader classLoader) { Enhancer enhancer = new Enhancer(); enhancer.setClassLoader(classLoader); enhancer.setCallbackType(MethodInterceptor.class); Class<?> targetClass = support.getBeanClass(); enhancer.setSuperclass(targetClass); enhancer.setInterfaces(new Class[]{FestivalProxy.class, TargetClassAware.class}); Class<?> proxyClass = enhancer.createClass(); Objenesis objenesis = new ObjenesisStd(); ObjectInstantiator<?> instantiator = objenesis.getInstantiatorOf(proxyClass); Object proxyInstance = instantiator.newInstance(); ((Factory) proxyInstance).setCallbacks(new Callback[]{new CglibMethodInterceptor(support)}); return proxyInstance; }
Example 2
Source File: ReflectiveParserManifest.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
ReflectiveParserImpl(Class<?> base, List<Property<?, ?>> properties) { InjectionChecks.checkInjectableCGLibProxyBase(base); this.properties = properties; this.propertyNames = properties.stream() .flatMap(property -> property.parser.names().stream()) .collect(Collectors.toImmutableSet()); final Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(base); enhancer.setInterfaces(new Class[]{ type.getRawType() }); enhancer.setCallbackType(MethodInterceptor.class); enhancer.setUseFactory(true); this.impl = enhancer.createClass(); this.injector = getMembersInjector((Class<T>) impl); }
Example 3
Source File: LibCGDecoratorGenerator.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override public <T, D extends Decorator<T>> DecoratorGenerator.Meta<T, D> implement(Class<T> type, Class<D> decorator) { final Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(decorator); enhancer.setCallbackType(MethodInterceptor.class); final Class<? extends D> impl = enhancer.createClass(); enhancer.setCallback(new Callback<>(type, decorator)); return new CGMeta(type, decorator, impl, enhancer); }
Example 4
Source File: SerializationTest.java From monasca-common with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static <T> T proxyFor(Class<T> type) throws Exception { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(TestCommand.class); enhancer.setCallbackType(NoOp.class); Class<T> enhanced = enhancer.createClass(); return enhanced.newInstance(); }
Example 5
Source File: TrivialClassCreationBenchmark.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Performs a benchmark for a trivial class creation using cglib. * * @return The created instance, in order to avoid JIT removal. */ @Benchmark public Class<?> benchmarkCglib() { Enhancer enhancer = new Enhancer(); enhancer.setUseCache(false); enhancer.setClassLoader(newClassLoader()); enhancer.setSuperclass(baseClass); enhancer.setCallbackType(NoOp.class); return enhancer.createClass(); }
Example 6
Source File: ConcurrentGetInstantiator.java From objenesis with Apache License 2.0 | 5 votes |
@Setup public void setUp() { for(int i = 0; i < COUNT; i++) { Enhancer enhancer = new Enhancer(); enhancer.setUseCache(false); // deactivate the cache to get a new instance each time enhancer.setCallbackType(NoOp.class); Class<?> c = enhancer.createClass(); toInstantiate[i] = c; } }