当前位置: 首页>>代码示例>>Java>>正文


Java Enhancer.setSuperclass方法代码示例

本文整理汇总了Java中net.sf.cglib.proxy.Enhancer.setSuperclass方法的典型用法代码示例。如果您正苦于以下问题:Java Enhancer.setSuperclass方法的具体用法?Java Enhancer.setSuperclass怎么用?Java Enhancer.setSuperclass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sf.cglib.proxy.Enhancer的用法示例。


在下文中一共展示了Enhancer.setSuperclass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: cglibcreate

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static <T> T cglibcreate(T o, OrientElement oe, Transaction transaction ) {
    // this is the main cglib api entry-point
    // this object will 'enhance' (in terms of CGLIB) with new capabilities
    // one can treat this class as a 'Builder' for the dynamic proxy
    Enhancer e = new Enhancer();

    // the class will extend from the real class
    e.setSuperclass(o.getClass());
    // we have to declare the interceptor  - the class whose 'intercept'
    // will be called when any method of the proxified object is called.
    ObjectProxy po = new ObjectProxy(o.getClass(),oe, transaction);
    e.setCallback(po);
    e.setInterfaces(new Class[]{IObjectProxy.class});

    // now the enhancer is configured and we'll create the proxified object
    T proxifiedObj = (T) e.create();
    
    po.___setProxyObject(proxifiedObj);
    
    // the object is ready to be used - return it
    return proxifiedObj;
}
 
开发者ID:mdre,项目名称:odbogm,代码行数:23,代码来源:ObjectProxyFactory.java

示例2: createProxy

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static Object createProxy(Object realObject) {
    try {
        MethodInterceptor interceptor = new HammerKiller();
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(realObject.getClass());
        enhancer.setCallbackType(interceptor.getClass());
        Class classForProxy = enhancer.createClass();
        Enhancer.registerCallbacks(classForProxy, new Callback[]{interceptor});
        Object createdProxy = classForProxy.newInstance();

        for (Field realField : FieldUtils.getAllFieldsList(realObject.getClass())) {
            if (Modifier.isStatic(realField.getModifiers()))
                continue;
            realField.setAccessible(true);

            realField.set(createdProxy, realField.get(realObject));
        }
        CreeperKiller.LOG.info("Removed HammerCore main menu hook, ads will no longer be displayed.");
        return createdProxy;
    } catch (Exception e) {
        CreeperKiller.LOG.error("Failed to create a proxy for HammerCore ads, they will not be removed.", e);
    }
    return realObject;
}
 
开发者ID:darkevilmac,项目名称:CreeperKiller,代码行数:25,代码来源:HammerKiller.java

示例3: 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);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:17,代码来源:ReflectiveParserManifest.java

示例4: getJedisProxy

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
/**
 * 使用 cglib 库创建 JedisProxy 的代理对象
 *
 * @return JedisProxy 代理
 */
public JedisProxy getJedisProxy() {
    if (jedisProxy != null) {
        return jedisProxy;
    }
    synchronized (JedisMethodInterceptor.class) {
        if (jedisProxy != null) {
            return jedisProxy;
        }
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(JedisProxy.class);
        enhancer.setCallback(this);
        jedisProxy = (JedisProxy) enhancer.create();
    }
    return jedisProxy;
}
 
开发者ID:ganpengyu,项目名称:gedis,代码行数:21,代码来源:JedisMethodInterceptor.java

示例5: main

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public static void main(String[] args) {
	while(true) {
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(ClassPermGenOOM.class);
		enhancer.setUseCache(Boolean.FALSE);
		
		enhancer.setCallback(new MethodInterceptor() {
			
			@Override
			public Object intercept(Object arg0, Method arg1, Object[] arg2,
					MethodProxy arg3) throws Throwable {
				return arg3.invokeSuper(arg0, arg2);
			}
		});
		enhancer.create();
	}
}
 
开发者ID:hdcuican,项目名称:java_learn,代码行数:18,代码来源:ClassPermGenOOM.java

示例6: postProcessBeforeInstantiation

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@Override
public Object postProcessBeforeInstantiation(final Class<?> beanClass, final String beanName) throws BeansException {
    if (_interceptors != null && _interceptors.size() > 0) {
        if (ComponentMethodInterceptable.class.isAssignableFrom(beanClass)) {
            final Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(beanClass);
            enhancer.setCallbacks(getCallbacks());
            enhancer.setCallbackFilter(getCallbackFilter());
            enhancer.setNamingPolicy(ComponentNamingPolicy.INSTANCE);

            final Object bean = enhancer.create();
            return bean;
        }
    }
    return null;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:ComponentInstantiationPostProcessor.java

示例7: NaviDataServiceProxy

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public NaviDataServiceProxy(IBaseDataService realService, Class<?> inter) {
    this.realService = realService;
    Class<?>[] inters = realService.getClass().getInterfaces();
    //直接实现目标的接口的情况下使用java原生动态代理,否则使用cglib
    if (find(inters, inter)) {
        this.proxyService = Proxy.newProxyInstance(
            realService.getClass().getClassLoader(), realService.getClass().getInterfaces(), this
        );
    } else {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(this.realService.getClass());
        // 回调方法
        enhancer.setCallback(this);
        // 创建代理对象
        this.proxyService = enhancer.create();
    }
}
 
开发者ID:sunguangran,项目名称:navi,代码行数:18,代码来源:NaviDataServiceProxy.java

示例8: decode

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public T decode(final BitBuffer buffer, final Resolver resolver,
                final Builder builder) throws DecodingException {
    final int size = wrapped.getSize().eval(resolver);
    final long pos = buffer.getBitPos();
    ClassLoader loader = this.getClass().getClassLoader();
    Enhancer enhancer = new Enhancer();
    enhancer.setClassLoader(loader);
    enhancer.setSuperclass(type);
    enhancer.setCallback(new MethodInterceptor() {

        private Object actual;

        public Object intercept(Object target, Method method,
                                Object[] args, MethodProxy proxy) throws Throwable {
            if (actual == null) {
                buffer.setBitPos(pos);
                actual = wrapped.decode(buffer, resolver, builder);
            }
            return proxy.invoke(actual, args);
        }
    });
    buffer.setBitPos(pos + size);
    return (T) enhancer.create();
}
 
开发者ID:skaterkamp,项目名称:md380codeplug-tool,代码行数:26,代码来源:LazyLoadingCodecDecorator.java

示例9: createDynamicProxy

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@Override
public <T> T createDynamicProxy(Class<T> type, Supplier<T> targetSupplier, String descriptionPattern, Object... descriptionParams) {
    final String description = String.format(descriptionPattern, descriptionParams);
    final Enhancer enhancer = new Enhancer();
    enhancer.setClassLoader(new DelegatingClassLoader(type.getClassLoader(), Enhancer.class.getClassLoader()));
    enhancer.setInterfaces(new Class[]{type});
    enhancer.setSuperclass(Object.class);
    enhancer.setCallbackFilter(FILTER);
    enhancer.setCallbacks(new Callback[]{
            (Dispatcher) targetSupplier::get,
            (MethodInterceptor) (proxy, method, params, methodProxy) -> proxy == params[0],
            (MethodInterceptor) (proxy, method, params, methodProxy) -> System.identityHashCode(proxy),
            (MethodInterceptor) (proxy, method, params, methodProxy) -> description
    });
    return type.cast(enhancer.create());
}
 
开发者ID:Microbule,项目名称:microbule,代码行数:17,代码来源:CglibDynamicProxyStrategy.java

示例10: doBuild

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
/**
 * Build CGLIB <i>implementee</i> bean.
 * 
 * @param implementation
 * @param implementorBeanFactory
 * @return
 */
protected Object doBuild(
		Implementation<?> implementation,
		ImplementorBeanFactory implementorBeanFactory)
{
	InvocationHandler invocationHandler = new CglibImplementeeInvocationHandler(
			implementation, implementorBeanFactory,
			implementeeMethodInvocationFactory);

	Enhancer enhancer = new Enhancer();
	enhancer.setInterfaces(new Class[] { CglibImplementee.class });
	enhancer.setSuperclass(implementation.getImplementee());
	enhancer.setCallback(invocationHandler);

	return enhancer.create();
}
 
开发者ID:ximplementation,项目名称:ximplementation-spring,代码行数:23,代码来源:CglibImplementeeBeanBuilder.java

示例11: 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" );
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:26,代码来源:ProxyFactoryFactoryImpl.java

示例12: wrapIfDirty

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
/**
 * @return A proxy object whose getters will return null for unchanged entity's properties
 * (and new values for changed properties), or the entity itself if the entity was not
 * enhanced for dirty checking.
 * @throws com.currencycloud.client.CurrencyCloudClient.NoChangeException if the entity was dirty-checked
 * but there were no changes.
 */
static <E extends Entity> E wrapIfDirty(E entity, Class<E> entityClass) throws NoChangeException {
    if (entity != null) {
        Map<String, Object> values = getDirtyProperties(entity);
        if (values != null) {
            if (values.isEmpty()) {
                throw new NoChangeException();
            }
            values = new HashMap<>(values);
            values.put("id", entity.getId());
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(entityClass);
            enhancer.setCallback(new ModifiedValueProvider(values));
            return (E) enhancer.create();
        }
    }
    return entity;
}
 
开发者ID:CurrencyCloud,项目名称:currencycloud-java,代码行数:25,代码来源:CurrencyCloudClient.java

示例13: create

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T create(final Class<T> clazz) {
    checkNotNull(clazz, "clazz cannot be null");

    if (!isAbstract(clazz)) {
        return null;
    }

    checkIfSupported(clazz);

    final Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(clazz);
    enhancer.setCallback(handler);

    return (T) enhancer.create();
}
 
开发者ID:leakingtapan,项目名称:rof,代码行数:18,代码来源:AbstractClassProxyFactory.java

示例14: testSupportForClassBasedProxyWithAdditionalInterface

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void testSupportForClassBasedProxyWithAdditionalInterface()
    throws NullPointerException {
    final Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(HashMap.class);
    enhancer.setCallback(NoOp.INSTANCE);
    enhancer.setInterfaces(new Class[]{Runnable.class});
    final Map orig = (Map)enhancer.create();
    final String xml = ""
        + "<CGLIB-enhanced-proxy>\n"
        + "  <type>java.util.HashMap</type>\n"
        + "  <interfaces>\n"
        + "    <java-class>java.lang.Runnable</java-class>\n"
        + "  </interfaces>\n"
        + "  <hasFactory>true</hasFactory>\n"
        + "  <net.sf.cglib.proxy.NoOp_-1/>\n"
        + "</CGLIB-enhanced-proxy>";

    final Object serialized = assertBothWays(orig, xml);
    assertTrue(serialized instanceof HashMap);
    assertTrue(serialized instanceof Map);
    assertTrue(serialized instanceof Runnable);
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:23,代码来源:CglibCompatibilityTest.java

示例15: testSupportProxiesWithMultipleCallbackSetToNull

import net.sf.cglib.proxy.Enhancer; //导入方法依赖的package包/类
public void testSupportProxiesWithMultipleCallbackSetToNull() throws NullPointerException {
    final Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(HashMap.class);
    enhancer.setCallback(NoOp.INSTANCE);
    final HashMap orig = (HashMap)enhancer.create();
    ((Factory)orig).setCallback(0, null);
    final String xml = ""
        + "<CGLIB-enhanced-proxy>\n"
        + "  <type>java.util.HashMap</type>\n"
        + "  <interfaces/>\n"
        + "  <hasFactory>true</hasFactory>\n"
        + "  <null/>\n"
        + "</CGLIB-enhanced-proxy>";

    assertBothWays(orig, xml);
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:17,代码来源:CglibCompatibilityTest.java


注:本文中的net.sf.cglib.proxy.Enhancer.setSuperclass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。