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


Java Factory类代码示例

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


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

示例1: getProxy

import net.sf.cglib.proxy.Factory; //导入依赖的package包/类
public static HibernateProxy getProxy(
	final Factory factory, 
	final Class persistentClass, 
	final Class[] interfaces, 
	final Method getIdentifierMethod, 
	final Method setIdentifierMethod, 
	final Serializable id, 
	final SessionImplementor session) 
throws HibernateException {
	final CGLIBLazyInitializer instance = new CGLIBLazyInitializer(
		persistentClass, interfaces, id, getIdentifierMethod, setIdentifierMethod, session
	);
	final HibernateProxy proxy = (HibernateProxy) factory.newInstance(instance);
	instance.constructed = true;
	return proxy;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:17,代码来源:CGLIBLazyInitializer.java

示例2: getProxyFactory

import net.sf.cglib.proxy.Factory; //导入依赖的package包/类
public static Factory getProxyFactory(Class persistentClass, Class[] interfaces) throws HibernateException {
	//note: interfaces is assumed to already contain HibernateProxy.class
	try {
		return (Factory) Enhancer.create(
			(interfaces.length==1) ?
				persistentClass :
				null,
			interfaces,
			NULL_METHOD_INTERCEPTOR
		);
	}
	catch (Throwable t) {
		LogFactory.getLog(LazyInitializer.class).error("CGLIB Enhancement failed", t);
		throw new HibernateException( "CGLIB Enhancement failed", t );
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:17,代码来源:CGLIBLazyInitializer.java

示例3: shouldGetBlogsWithAuthorsAndPostsEagerly

import net.sf.cglib.proxy.Factory; //导入依赖的package包/类
@Test
public void shouldGetBlogsWithAuthorsAndPostsEagerly() {
  SqlSession session = sqlSessionFactory.openSession();
  try {
    BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
    List<Blog> blogs = mapper.selectBlogsWithAutorAndPostsEagerly();
    assertEquals(2, blogs.size());
    assertFalse(blogs.get(0) instanceof Factory);
    assertEquals(101, blogs.get(0).getAuthor().getId());
    assertEquals(1, blogs.get(0).getPosts().size());
    assertEquals(1, blogs.get(0).getPosts().get(0).getId());
    assertFalse(blogs.get(1) instanceof Factory);      
    assertEquals(102, blogs.get(1).getAuthor().getId());
    assertEquals(1, blogs.get(1).getPosts().size());
    assertEquals(2, blogs.get(1).getPosts().get(0).getId());
  } finally {
    session.close();
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:20,代码来源:BindingTest.java

示例4: shouldGetValuesUsingProxyWrapper

import net.sf.cglib.proxy.Factory; //导入依赖的package包/类
@Test
public void shouldGetValuesUsingProxyWrapper() {
  BusinessProposal businessProposal = getHibernateObjectOnRepository();

  Negotiation negotiationProxy = BusinessModelProxy.from(businessProposal).proxy(Negotiation.class);
  List<Negotiation> list = new ArrayList<>();


  if (negotiationProxy instanceof Factory) {
    Callback callback = ((Factory) negotiationProxy).getCallback(0);
    Object objectModel = ((ProxyInterceptor) callback).getObjectModel();
    Object hibernateEntity = ((ProxyInterceptor) callback).getHibernateEntity();
    System.out.println("testet");
    System.out.println("testet");
    System.out.println("testet");
    System.out.println("testet");
  }


  assertThat(negotiationProxy.getId(), Matchers.is(1l));
  assertThat(negotiationProxy.getIntroduction(), Matchers.is("test introduction"));
  assertThat(negotiationProxy.getCareOf(), Matchers.is("Smith"));
}
 
开发者ID:mmaico,项目名称:ddd-reflection,代码行数:24,代码来源:ProxyInterceptorGETTest.java

示例5: getProxiedTypeIfProxy

import net.sf.cglib.proxy.Factory; //导入依赖的package包/类
/**
 * @param object The object to check
 * @return The proxied type, null if the object is not a proxy
 */
public static Class<?> getProxiedTypeIfProxy(Object object) {
    if (object == null) {
        return null;
    }
    if (object instanceof Factory) {
        Callback[] callbacks = ((Factory) object).getCallbacks();
        if (callbacks == null || callbacks.length == 0) {
            return null;
        }
        if (callbacks[0] instanceof CglibProxyMethodInterceptor) {
            return ((CglibProxyMethodInterceptor) callbacks[0]).getProxiedType();
        }
    }
    return null;
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:20,代码来源:ProxyUtils.java

示例6: getMockName

import net.sf.cglib.proxy.Factory; //导入依赖的package包/类
/**
 * note: don't remove, used through reflection from {@link org.unitils.core.util.ObjectFormatter}
 *
 * @param object The object to check
 * @return The proxied type, null if the object is not a proxy or mock
 */
@SuppressWarnings({"UnusedDeclaration"})
public static String getMockName(Object object) {
    if (object == null) {
        return null;
    }
    if (object instanceof MockObject) {
        return ((MockObject) object).getName();
    }
    if (object instanceof Factory) {
        Callback callback = ((Factory) object).getCallback(0);
        if (callback instanceof CglibProxyMethodInterceptor) {
            return ((CglibProxyMethodInterceptor) callback).getMockName();
        }
    }
    return null;
}
 
开发者ID:linux-china,项目名称:unitils,代码行数:23,代码来源:ProxyUtils.java

示例7: equalsTest

import net.sf.cglib.proxy.Factory; //导入依赖的package包/类
@Test
public void equalsTest() throws Throwable
{
	Implementation<Implementee> implementation = this.implementationResolver
			.resolve(Implementee.class, Implementor0.class,
					Implementor1.class);
	ImplementorBeanFactory implementorBeanFactory = SimpleImplementorBeanFactory
			.valueOf(new Implementor0(), new Implementor1());

	Implementee implementee = this.cglibImplementeeBeanBuilder
			.build(implementation, implementorBeanFactory);

	CglibImplementeeInvocationHandler handler = (CglibImplementeeInvocationHandler) (((Factory) implementee)
			.getCallback(0));

	Assert.assertTrue(handler.equals(handler));
	Assert.assertFalse(handler.equals(null));
	Assert.assertTrue(handler
			.equals(new CglibImplementeeInvocationHandler(implementation,
					implementorBeanFactory, this.cglibImplementeeBeanBuilder
							.getImplementeeMethodInvocationFactory())));
	Assert.assertTrue(handler.equals(implementee));
	Assert.assertFalse(handler.equals(new Object()));
}
 
开发者ID:ximplementation,项目名称:ximplementation-spring,代码行数:25,代码来源:CglibImplementeeBeanInvocationHandlerTest.java

示例8: intercept

import net.sf.cglib.proxy.Factory; //导入依赖的package包/类
@Override
public Object intercept(final Object proxy, final Method method, final Object[] args, final MethodProxy methodProxy) throws Throwable {
    final Object other = args[0];

    if (proxy == other) {
        return true;
    } else if (other instanceof Factory) {
        for (final Callback callback : ((Factory) other).getCallbacks()) {
            if (callback.getClass().isAssignableFrom(EqualsInterceptor.class)) {
                return target.equals(((EqualsInterceptor) callback).target);
            }
        }
    }

    return target.equals(other);
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:17,代码来源:EqualsInterceptor.java

示例9: create

import net.sf.cglib.proxy.Factory; //导入依赖的package包/类
/**
 * Creates the scoped proxy object using the given provider.
 *
 * @param injector The injector.
 * @return The scoped proxy object.
 */
@SuppressWarnings("unchecked")
public T create(Injector injector) {
    Preconditions.checkNotNull(injector, "injector");
    Preconditions.checkState(this.dispatcher != null, "no provider set");

    this.enhancer.setCallbackType(this.dispatcher.getClass());
    final Class<T> enhancedClass = this.enhancer.createClass();
    final Errors errors = new Errors();
    final T proxyInstance = this.constructionStrategy
            .createInstance(enhancedClass, injector, errors);

    errors.throwProvisionExceptionIfErrorsExist();
    final Factory factory = (Factory) proxyInstance;
    factory.setCallback(CALLBACK_INDEX, this.dispatcher);
    return proxyInstance;
}
 
开发者ID:skuzzle,项目名称:guice-scoped-proxy-extension,代码行数:23,代码来源:InstanceBuilder.java

示例10: BasicProxyFactoryImpl

import net.sf.cglib.proxy.Factory; //导入依赖的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

示例11: testSupportProxiesWithMultipleCallbackSetToNull

import net.sf.cglib.proxy.Factory; //导入依赖的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

示例12: create

import net.sf.cglib.proxy.Factory; //导入依赖的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;
}
 
开发者ID:sterodium,项目名称:sterodium-rmi,代码行数:23,代码来源:RemoteObjectProxyFactory.java

示例13: create

import net.sf.cglib.proxy.Factory; //导入依赖的package包/类
/**
 * Creates a new instance of the given class, using the supplied interceptor.
 * Uses the EasyMock ClassInstantiatorFactory in order to avoid the cglib
 * limitation that prevents us from creating instances of classes that do not
 * have public default constructors.
 */
private Object create(Class<?> clss, Interceptor interceptor) {
  Enhancer e = new Enhancer();
  e.setSuperclass(clss);
  e.setCallbackType(interceptor.getClass());
  Class<?> controlClass = e.createClass();
  Enhancer.registerCallbacks(controlClass, new Callback[] { interceptor });

  Factory result = (Factory) objenesis.newInstance(controlClass);

  // This call is required to work around a cglib feature. See the comment in
  // org.easymock.classextension.internal.ClassProxyFactory, which uses the
  // same approach.
  result.getCallback(0);

  // And this call is required to work around a memory leak in cglib, which
  // sticks references to the class in a ThreadLocal that is never cleared.
  // See http://opensource.atlassian.com/projects/hibernate/browse/HHH-2481
  Enhancer.registerCallbacks(controlClass, null);

  return result;
}
 
开发者ID:google,项目名称:thread-weaver,代码行数:28,代码来源:MethodRecorder.java

示例14: decorateInstance

import net.sf.cglib.proxy.Factory; //导入依赖的package包/类
@Override
protected void decorateInstance(T result, final MethodIntercept methodIntercept) {
    MethodInterceptor methodInterceptor = new MethodInterceptor() {
        public Object intercept(final Object proxy, Method method, Object[] args, final MethodProxy superProxy) throws Throwable {
            return methodIntercept.intercept(proxy, new MethodAdapter(method), args, new MethodIntercept.SuperInvoker() {
                public Object invokeSuper(Object[] superArgs) throws Throwable {
                    return superProxy.invokeSuper(proxy, superArgs);
                }
            });
        }
    };
    Factory factory = (Factory) result;
    int callbackCount = factory.getCallbacks().length;
    for(int i = 0; i < callbackCount; i++) {
        factory.setCallback(i, methodInterceptor);
    }
}
 
开发者ID:pobrelkey,项目名称:moxiemocks,代码行数:18,代码来源:CGLIBProxyFactory.java

示例15: newProxyByCglib

import net.sf.cglib.proxy.Factory; //导入依赖的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;
}
 
开发者ID:maciejmikosik,项目名称:testory,代码行数:22,代码来源:CglibProxer.java


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