本文整理汇总了Java中net.sf.cglib.proxy.Enhancer.setUseFactory方法的典型用法代码示例。如果您正苦于以下问题:Java Enhancer.setUseFactory方法的具体用法?Java Enhancer.setUseFactory怎么用?Java Enhancer.setUseFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.cglib.proxy.Enhancer
的用法示例。
在下文中一共展示了Enhancer.setUseFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ReflectiveParserImpl
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
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);
}
示例2: createEnhancedClass
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected static <T> Class<T> createEnhancedClass(Class<T> proxiedClass, Class<?>... implementedInterfaces) {
Enhancer enhancer = new Enhancer();
Set<Class<?>> interfaces = new HashSet<Class<?>>();
if (proxiedClass.isInterface()) {
enhancer.setSuperclass(Object.class);
interfaces.add(proxiedClass);
} else {
enhancer.setSuperclass(proxiedClass);
}
if (implementedInterfaces != null && implementedInterfaces.length > 0) {
interfaces.addAll(asList(implementedInterfaces));
}
if (!interfaces.isEmpty()) {
enhancer.setInterfaces(interfaces.toArray(new Class<?>[interfaces.size()]));
}
enhancer.setCallbackType(MethodInterceptor.class);
enhancer.setUseFactory(true);
return enhancer.createClass();
}
示例3: BasicProxyFactoryImpl
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public BasicProxyFactoryImpl(Class superClass, Class[] interfaces) {
if ( superClass == null && ( interfaces == null || interfaces.length < 1 ) ) {
throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" );
}
Enhancer en = new Enhancer();
en.setUseCache( false );
en.setInterceptDuringConstruction( false );
en.setUseFactory( true );
en.setCallbackTypes( CALLBACK_TYPES );
en.setCallbackFilter( FINALIZE_FILTER );
if ( superClass != null ) {
en.setSuperclass( superClass );
}
if ( interfaces != null && interfaces.length > 0 ) {
en.setInterfaces( interfaces );
}
proxyClass = en.createClass();
try {
factory = ( Factory ) proxyClass.newInstance();
}
catch ( Throwable t ) {
throw new HibernateException( "Unable to build CGLIB Factory instance" );
}
}
示例4: create
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T create(Class<T> clazz, String widgetId) {
// creating proxy class
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(clazz);
enhancer.setUseFactory(true);
enhancer.setCallbackType(RemoteObjectMethodInterceptor.class);
if (clazz.getSigners() != null) {
enhancer.setNamingPolicy(NAMING_POLICY_FOR_CLASSES_IN_SIGNED_PACKAGES);
}
Class<?> proxyClass = enhancer.createClass();
// instantiating class without constructor call
ObjenesisStd objenesis = new ObjenesisStd();
Factory proxy = (Factory) objenesis.newInstance(proxyClass);
proxy.setCallbacks(new Callback[]{new RemoteObjectMethodInterceptor(this, invoker, widgetId)});
T widget = (T) proxy;
widgetIds.put(widget, widgetId);
return widget;
}
示例5: getProxyClass
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static Class<?> getProxyClass(Class<?> clazz) {
Enhancer e = new Enhancer();
if (clazz.isInterface()) {
e.setSuperclass(clazz);
} else {
e.setSuperclass(clazz);
e.setInterfaces(clazz.getInterfaces());
}
e.setCallbackTypes(new Class[]{
InvocationHandler.class,
NoOp.class,
});
e.setCallbackFilter(BAD_OBJECT_METHOD_FILTER);
e.setUseFactory(true);
e.setNamingPolicy(new LithiumTestProxyNamingPolicy());
return e.createClass();
}
示例6: newProxyByCglib
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
private static Object newProxyByCglib(Typing typing, Handler handler) {
Enhancer enhancer = new Enhancer() {
/** includes all constructors */
protected void filterConstructors(Class sc, List constructors) {}
};
enhancer.setClassLoader(Thread.currentThread().getContextClassLoader());
enhancer.setUseFactory(true);
enhancer.setSuperclass(typing.superclass);
enhancer.setInterfaces(typing.interfaces.toArray(new Class[0]));
enhancer.setCallbackTypes(new Class[] { MethodInterceptor.class, NoOp.class });
enhancer.setCallbackFilter(new CallbackFilter() {
/** ignores bridge methods */
public int accept(Method method) {
return method.isBridge() ? 1 : 0;
}
});
Class<?> proxyClass = enhancer.createClass();
Factory proxy = (Factory) new ObjenesisStd().newInstance(proxyClass);
proxy.setCallbacks(new Callback[] { asMethodInterceptor(handler), new SerializableNoOp() });
return proxy;
}
示例7: createProxyClass
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@Override
protected Class<?> createProxyClass() {
Enhancer en = new Enhancer();
en.setInterceptDuringConstruction(false);
en.setUseFactory(true);
en.setSuperclass(unproxiedClass);
en.setInterfaces(new Class[] { Persistent.class });
en.setCallbackType(NoOp.class);
en.setStrategy(new DefaultGeneratorStrategy() {
protected ClassGenerator transform(ClassGenerator cg) throws Exception {
return new TransformingClassGenerator(cg, new AddPropertyTransformer(
new String[] { ORIGINAL_ONE, ORIGINAL_THE_OTHER },
new Type[] { Type.getType(String.class), Type.getType(List.class) }
));
}
});
return en.createClass();
}
示例8: getProxyFactory
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static Class getProxyFactory(Class persistentClass, Class[] interfaces)
throws HibernateException {
Enhancer e = new Enhancer();
e.setSuperclass( interfaces.length == 1 ? persistentClass : null );
e.setInterfaces(interfaces);
e.setCallbackTypes(new Class[]{
InvocationHandler.class,
NoOp.class,
});
e.setCallbackFilter(FINALIZE_FILTER);
e.setUseFactory(false);
e.setInterceptDuringConstruction( false );
return e.createClass();
}
示例9: testSupportsClassBasedProxiesWithFactory
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void testSupportsClassBasedProxiesWithFactory()
throws NullPointerException, MalformedURLException {
final Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(HashMap.class);
enhancer.setCallback(new DelegatingHandler(new HashMap()));
enhancer.setUseFactory(true); // true by default
final Map orig = (Map)enhancer.create();
final URL url = new URL("http://xstream.codehaus.org");
orig.put("URL", url);
final String xml = ""
+ "<CGLIB-enhanced-proxy>\n"
+ " <type>java.util.HashMap</type>\n"
+ " <interfaces/>\n"
+ " <hasFactory>true</hasFactory>\n"
+ " <com.thoughtworks.acceptance.CglibCompatibilityTest_-DelegatingHandler>\n"
+ " <delegate class=\"map\">\n"
+ " <entry>\n"
+ " <string>URL</string>\n"
+ " <url>http://xstream.codehaus.org</url>\n"
+ " </entry>\n"
+ " </delegate>\n"
+ " </com.thoughtworks.acceptance.CglibCompatibilityTest_-DelegatingHandler>\n"
+ "</CGLIB-enhanced-proxy>";
final Map serialized = (Map)assertBothWays(orig, xml);
assertEquals(url, serialized.get("URL"));
}
示例10: testSupportsClassBasedProxiesWithoutFactory
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void testSupportsClassBasedProxiesWithoutFactory()
throws NullPointerException, MalformedURLException {
final Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(HashMap.class);
enhancer.setCallback(new DelegatingHandler(new HashMap()));
enhancer.setUseFactory(false);
final Map orig = (Map)enhancer.create();
final URL url = new URL("http://xstream.codehaus.org");
orig.put("URL", url);
final String xml = ""
+ "<CGLIB-enhanced-proxy>\n"
+ " <type>java.util.HashMap</type>\n"
+ " <interfaces/>\n"
+ " <hasFactory>false</hasFactory>\n"
+ " <com.thoughtworks.acceptance.CglibCompatibilityTest_-DelegatingHandler>\n"
+ " <delegate class=\"map\">\n"
+ " <entry>\n"
+ " <string>URL</string>\n"
+ " <url>http://xstream.codehaus.org</url>\n"
+ " </entry>\n"
+ " </delegate>\n"
+ " </com.thoughtworks.acceptance.CglibCompatibilityTest_-DelegatingHandler>\n"
+ "</CGLIB-enhanced-proxy>";
final Map serialized = (Map)assertBothWays(orig, xml);
assertEquals(url, serialized.get("URL"));
}
示例11: testSupportProxiesUsingFactoryWithMultipleCallbacks
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void testSupportProxiesUsingFactoryWithMultipleCallbacks()
throws NullPointerException {
final Enhancer enhancer = new Enhancer();
enhancer.setCallbacks(new Callback[]{
new DelegatingInterceptor(null), new DelegatingHandler(null),
new DelegatingDispatcher(null), NoOp.INSTANCE});
enhancer.setCallbackFilter(new CallbackFilter() {
int i = 1;
public int accept(Method method) {
if (method.getDeclaringClass() == Runnable.class) {
return 0;
}
return i < 3 ? i++ : i;
}
});
enhancer.setInterfaces(new Class[]{Runnable.class});
enhancer.setUseFactory(true);
final Runnable orig = (Runnable)enhancer.create();
final String xml = xstream.toXML(orig);
final Factory deserialized = (Factory)xstream.fromXML(xml);
assertTrue("Not a Runnable anymore", deserialized instanceof Runnable);
Callback[] callbacks = deserialized.getCallbacks();
assertEquals(4, callbacks.length);
assertTrue(callbacks[0] instanceof DelegatingInterceptor);
assertTrue(callbacks[1] instanceof DelegatingHandler);
assertTrue(callbacks[2] instanceof DelegatingDispatcher);
assertTrue(callbacks[3] instanceof NoOp);
}
示例12: testThrowsExceptionForProxiesNotUsingFactoryWithMultipleCallbacks
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void testThrowsExceptionForProxiesNotUsingFactoryWithMultipleCallbacks()
throws NullPointerException {
final Enhancer enhancer = new Enhancer();
enhancer.setCallbacks(new Callback[]{
new DelegatingInterceptor(null), new DelegatingHandler(null),
new DelegatingDispatcher(null), NoOp.INSTANCE});
enhancer.setCallbackFilter(new CallbackFilter() {
int i = 1;
public int accept(Method method) {
if (method.getDeclaringClass() == Runnable.class) {
return 0;
}
return i < 3 ? i++ : i;
}
});
enhancer.setInterfaces(new Class[]{Runnable.class});
enhancer.setUseFactory(false);
final Runnable orig = (Runnable)enhancer.create();
try {
xstream.toXML(orig);
fail("Thrown " + ConversionException.class.getName() + " expected");
} catch (final ConversionException e) {
}
}
示例13: testSupportsInterceptedClassBasedProxies
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void testSupportsInterceptedClassBasedProxies()
throws NullPointerException, MalformedURLException {
final Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(HashMap.class);
enhancer.setCallback(new InterceptingHandler());
enhancer.setUseFactory(true);
final Map orig = (Map)enhancer.create();
orig.put("URL", new URL("http://xstream.codehaus.org"));
final StringBuffer xml = new StringBuffer(""
+ "<CGLIB-enhanced-proxy>\n"
+ " <type>java.util.HashMap</type>\n"
+ " <interfaces/>\n"
+ " <hasFactory>true</hasFactory>\n"
+ " <com.thoughtworks.acceptance.CglibCompatibilityTest_-InterceptingHandler/>\n"
+ " <instance serialization=\"custom\">\n"
+ " <unserializable-parents/>\n"
+ " <map>\n"
+ " <default>\n"
+ " <loadFactor>0.75</loadFactor>\n"
+ " <threshold>$THRESHOLD$</threshold>\n"
+ " </default>\n"
+ " <int>$CAPACITY$</int>\n"
+ " <int>1</int>\n"
+ " <string>URL</string>\n"
+ " <url>http://xstream.codehaus.org</url>\n"
+ " </map>\n"
+ " </instance>\n"
+ "</CGLIB-enhanced-proxy>");
int idx = xml.toString().indexOf(THRESHOLD_PARAM);
xml.replace(idx, idx + THRESHOLD_PARAM.length(), "12");
idx = xml.toString().indexOf(CAPACITY_PARAM);
xml.replace(idx, idx + CAPACITY_PARAM.length(), "16");
Map serialized = (Map)assertBothWays(orig, xml.toString());
assertEquals(orig.toString(), serialized.toString());
}
示例14: createEnhancedClass
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected Class<? extends T> createEnhancedClass(Class<T> clazz, Class[] ancillaryTypes) {
if (clazz == Object.class) {
clazz = (Class<T>) TrivialSubclassOfObjectToWorkAroundCGLIBBug.class;
}
Enhancer e = new Enhancer();
e.setClassLoader(clazz.getClassLoader());
e.setSuperclass(clazz);
e.setInterfaces(ancillaryTypes);
e.setUseFactory(true);
e.setUseCache(true);
e.setCallbackType(MethodInterceptor.class);
return e.createClass();
}
示例15: enhanceServiceEndpointInterface
import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
private Class enhanceServiceEndpointInterface(Class serviceEndpointInterface, ClassLoader classLoader) {
Enhancer enhancer = new Enhancer();
enhancer.setClassLoader(classLoader);
enhancer.setSuperclass(GenericServiceEndpointWrapper.class);
enhancer.setInterfaces(new Class[]{serviceEndpointInterface});
enhancer.setCallbackFilter(new NoOverrideCallbackFilter(GenericServiceEndpointWrapper.class));
enhancer.setCallbackTypes(new Class[]{NoOp.class, MethodInterceptor.class});
enhancer.setUseFactory(false);
enhancer.setUseCache(false);
return enhancer.createClass();
}