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


Java ObjenesisHelper类代码示例

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


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

示例1: deCerealize

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public J deCerealize(C cereal, ObjectCache objectCache) throws CerealException {
    J object = null;
    try {
        object = type.newInstance();
    } catch (Exception ex) {
        object = (J) ObjenesisHelper.newInstance(type);
    }

    if (object instanceof CerealFactoryAware) {
        ((CerealFactoryAware) object).setCerealFactory(cerealFactory);
    }

    object.applyCereal(cereal);
    return object;
}
 
开发者ID:Comcast,项目名称:cereal,代码行数:17,代码来源:CerealizableCerealizer.java

示例2: anyInstanceOf

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
public static Object anyInstanceOf(Class type) {
	try {
		if (type == null || type == void.class) return null;
		if (type.isArray()) return anyArrayOf(type.getComponentType());
		Object triangulatedInstance = tryToTriangulateFromThisClass(type);
		if (triangulatedInstance != null) return triangulatedInstance;
		if (type.isInterface())
			return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] {type},
					new TriangulatingInvocationHandler());
		if (Modifier.isAbstract(type.getModifiers()))
			return Enhancer.create(type, new TriangulatingInvocationHandler());
		return ObjenesisHelper.newInstance(type);
	} catch (Exception e) {
		throw new NestableRuntimeException(e);
	}
}
 
开发者ID:fmunch,项目名称:transloader,代码行数:17,代码来源:Triangulate.java

示例3: of

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static <T> T of(final Class<?> originalBeanClass, final TypeSafeWicketId parent) {
    final Enhancer enhancer = new Enhancer();
    final List<Class<?>> interfaces = new ArrayList<>();
    if (Modifier.isInterface(originalBeanClass.getModifiers())) {
        interfaces.add(originalBeanClass);
    } else {
        enhancer.setSuperclass(originalBeanClass);
    }
    interfaces.add(TYPE_SAFE_WICKET_ID_INTERFACE);

    final Class<?>[] interfacesAsArray = interfaces.toArray(EMPTY);
    enhancer.setInterfaces(interfacesAsArray);
    enhancer.setCallbackType(InterfaceMethodInterceptor.class);

    final Class<?> proxyClass = enhancer.createClass();
    Enhancer.registerCallbacks(proxyClass, new Callback[] {new InterfaceMethodInterceptor(parent)});

    final T proxy = (T) ObjenesisHelper.newInstance(proxyClass);
    saveProxy((TypeSafeWicketId) proxy);
    return proxy;
}
 
开发者ID:dzwicker,项目名称:wicket-typesafe,代码行数:23,代码来源:CreateId.java

示例4: createProxy

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
private static <T> T createProxy(Class<T> beanClass, InvocationHandler invocationHandler) {
	Class<? extends T> proxyClass = new ByteBuddy()
		.subclass(beanClass, ConstructorStrategy.Default.NO_CONSTRUCTORS)
		.method(isMethod()
			.and(takesArguments(0))
			.and(not(isDeclaredBy(Object.class))))
		.intercept(InvocationHandlerAdapter.of(invocationHandler))
		.make()
		.load(PropertyUtils.class.getClassLoader())
		.getLoaded();

	return ObjenesisHelper.newInstance(proxyClass);
}
 
开发者ID:cronn-de,项目名称:reflection-util,代码行数:14,代码来源:PropertyUtils.java

示例5: createProxy

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> T createProxy(final Class<?> classToMock, final MethodInterceptor interceptor) {
	final Enhancer enhancer = new Enhancer();
	enhancer.setSuperclass(classToMock);
	enhancer.setCallbackType(interceptor.getClass());
	final Class<?> proxyClass = enhancer.createClass();
	Enhancer.registerCallbacks(proxyClass, new Callback[] { interceptor });
	return (T) ObjenesisHelper.newInstance(proxyClass);
}
 
开发者ID:NewTranx,项目名称:newtranx-utils,代码行数:10,代码来源:MapperScannerConfigurer.java

示例6: forClass

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
public static <T> MethodProxy<T> forClass(Class<T> clazz) {
    MethodSignatureInterceptor methodSignatureInterceptor = new MethodSignatureInterceptor();
    final Enhancer enhancer = new Enhancer();
    enhancer.setUseCache(false);
    enhancer.setSuperclass(clazz);
    enhancer.setCallbackType(methodSignatureInterceptor.getClass());
    final Class<?> proxyClass = enhancer.createClass();
    Enhancer.registerCallbacks(proxyClass, new Callback[]{methodSignatureInterceptor});
    T proxied = (T) ObjenesisHelper.newInstance(proxyClass);
    return new MethodProxy<>(methodSignatureInterceptor, proxied);
}
 
开发者ID:Qubite,项目名称:tomoko,代码行数:12,代码来源:MethodProxy.java

示例7: deCerealize

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public J deCerealize(Map<String, Object> cereal, ObjectCache objectCache) throws CerealException {

    if (null == cereal) {
        return null;
    }
    

    J object = (J) objectCache.getReferenceObject(cereal);
    if (null != object) {
        return object;
    }
    
    try {
        if (DEFAULTS.containsKey(javaType)) {
            object = (J) DEFAULTS.get(javaType).newInstance();
        } else {
            object = javaType.newInstance();
        }
    } catch (Exception ex) {
        object = (J) ObjenesisHelper.newInstance(javaType);
    }
    
    /* If this object has an object id, store it now before we continue */
    if (cereal.containsKey(ObjectCache.KEY_ID)) {
        objectCache.cacheById((Integer) cereal.get(ObjectCache.KEY_ID), object);
    }

    applyCereal(cereal, object, false, objectCache);

    return object;
}
 
开发者ID:Comcast,项目名称:cereal,代码行数:33,代码来源:ClassCerealizer.java

示例8: answer

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
public Object answer(InvocationOnMock invocation) throws Throwable {
    Object[] arguments = invocation.getArguments();
    for (int i = 0; i < arguments.length; i++) {
        Object from = arguments[i];
        Object newInstance = ObjenesisHelper.newInstance(from.getClass());
        new LenientCopyTool().copyToRealObject(from, newInstance);
        arguments[i] = newInstance;
    }
    return new ReturnsEmptyValues().answer(invocation);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:ClonesArguments.java

示例9: answer

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
public Object answer(InvocationOnMock invocation) throws Throwable {

        Throwable throwable = (Throwable) ObjenesisHelper.newInstance(throwableClass);
        throwable.fillInStackTrace();
        filter.filter(throwable);
        throw throwable;
    }
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:ThrowsExceptionClass.java

示例10: before

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
@SuppressWarnings({"resource", "deprecation"})
	@Before
	public void before() throws Exception {
		
		final File dataDir = new File("target/classes/");
		final File jar = new File("target/", "skript.jar");
		assumeTrue(jar.exists());
		
		final Logger l = Logger.getLogger(getClass().getCanonicalName());
		l.setParent(SkriptLogger.LOGGER);
		l.setLevel(Level.WARNING);
		
		final Server s = createMock(Server.class);
		s.getLogger();
		expectLastCall().andReturn(l).anyTimes();
		s.isPrimaryThread();
		expectLastCall().andReturn(true).anyTimes();
		s.getName();
		expectLastCall().andReturn("Whatever").anyTimes();
		s.getVersion();
		expectLastCall().andReturn("2.0").anyTimes();
		s.getBukkitVersion();
		expectLastCall().andReturn("2.0").anyTimes();
		replay(s);
		
		Bukkit.setServer(s);
		
		final Skript skript = (Skript) ObjenesisHelper.newInstance(Skript.class); // bypass the class loader check
		final Field instance = Skript.class.getDeclaredField("instance");
		instance.setAccessible(true);
		instance.set(null, skript);
		
		final PluginDescriptionFile pdf = new PluginDescriptionFile(new FileInputStream(new File(dataDir, "plugin.yml")));
		
//	    final void init(PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader) {
		final Method init = JavaPlugin.class.getDeclaredMethod("init", PluginLoader.class, Server.class, PluginDescriptionFile.class, File.class, File.class, ClassLoader.class);
		init.setAccessible(true);
		init.invoke(skript, new JavaPluginLoader(s), s, pdf, dataDir, jar, getClass().getClassLoader());
		
		Skript.getAddonInstance().loadClasses("ch.njol.skript", "entity");
		new JavaClasses();
		new BukkitClasses();
		new BukkitEventValues();
		new SkriptClasses();
		
		final Field r = Skript.class.getDeclaredField("acceptRegistrations");
		r.setAccessible(true);
		r.set(null, false);
		Classes.onRegistrationsStop();
	}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:51,代码来源:ClassesTest.java

示例11: testCanInstantiate

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
@Test
public void testCanInstantiate() throws IOException {
   assertSame(OsgiTest.class, ObjenesisHelper.newInstance(getClass()).getClass());
}
 
开发者ID:easymock,项目名称:objenesis,代码行数:5,代码来源:OsgiTest.java

示例12: testCanInstantiateSerialize

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
@Test
public void testCanInstantiateSerialize() throws IOException {
   assertSame(OsgiTest.class, ObjenesisHelper.newSerializableInstance(getClass()).getClass());
}
 
开发者ID:easymock,项目名称:objenesis,代码行数:5,代码来源:OsgiTest.java

示例13: createProxy

import org.objenesis.ObjenesisHelper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> T createProxy(Class<?> clazz, MethodHandler mh) {

	ProxyFactory factory = new ProxyFactory();
	factory.setSuperclass(clazz);

	Class<T> proxyClass = factory.createClass();

	T proxy = ObjenesisHelper.newInstance(proxyClass);
	((Proxy) proxy).setHandler(mh);

	return proxy;
}
 
开发者ID:terems-org,项目名称:webz-server,代码行数:14,代码来源:WebzTestUtils.java


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