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


Java ProxyFactory.setSuperclass方法代码示例

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


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

示例1: createStyledTextRenderer

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
private static /* org.eclipse.swt.custom.StyledTextRenderer */ Object createStyledTextRenderer(
		StyledText styledText, ILineSpacingProvider lineSpacingProvider) throws Exception {
	// get the org.eclipse.swt.custom.StyledTextRenderer instance of
	// StyledText
	/* org.eclipse.swt.custom.StyledTextRenderer */ Object originalRenderer = getRendererField(styledText)
			.get(styledText);

	// Create a Javassist proxy
	ProxyFactory factory = new ProxyFactory();
	factory.setSuperclass(originalRenderer.getClass());
	StyledTextRenderer renderer = new StyledTextRenderer(styledText, originalRenderer.getClass());
	renderer.setLineSpacingProvider(lineSpacingProvider);
	factory.setHandler(renderer);
	return factory.create(new Class[] { Device.class, StyledText.class },
			new Object[] { styledText.getDisplay(), styledText });
}
 
开发者ID:angelozerr,项目名称:codelens-eclipse,代码行数:17,代码来源:StyledTextPatcher.java

示例2: getProxyFactory

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
public static Class getProxyFactory(
		Class persistentClass,
		Class[] interfaces) throws HibernateException {
	// note: interfaces is assumed to already contain HibernateProxy.class

	try {
		ProxyFactory factory = new ProxyFactory();
		factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
		factory.setInterfaces( interfaces );
		factory.setFilter( FINALIZE_FILTER );
		return factory.createClass();
	}
	catch ( Throwable t ) {
		LOG.error(LOG.javassistEnhancementFailed(persistentClass.getName()), t);
		throw new HibernateException(LOG.javassistEnhancementFailed(persistentClass.getName()), t);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:JavassistLazyInitializer.java

示例3: getProxyFactory

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
public static Class getProxyFactory(
		Class persistentClass,
        Class[] interfaces) throws HibernateException {
	// note: interfaces is assumed to already contain HibernateProxy.class

	try {
		ProxyFactory factory = new ProxyFactory();
		factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
		factory.setInterfaces( interfaces );
		factory.setFilter( FINALIZE_FILTER );
		return factory.createClass();
	}
	catch ( Throwable t ) {
		LogFactory.getLog( BasicLazyInitializer.class ).error(
				"Javassist Enhancement failed: "
				+ persistentClass.getName(), t
		);
		throw new HibernateException(
				"Javassist Enhancement failed: "
				+ persistentClass.getName(), t
		);
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:24,代码来源:JavassistLazyInitializer.java

示例4: of

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
 * Constructs a partial instance of abstract type {@code cls}, passing {@code args} into its
 * constructor.
 *
 * <p>The returned object will throw an {@link UnsupportedOperationException} from any
 * unimplemented methods.
 */
public static <T> T of(Class<T> cls, Object... args) {
  checkIsValidPartial(cls);
  try {
    Constructor<?> constructor = cls.getDeclaredConstructors()[0];
    ProxyFactory factory = new ProxyFactory();
    factory.setSuperclass(cls);
    factory.setFilter(new MethodFilter() {
      @Override public boolean isHandled(Method m) {
        return Modifier.isAbstract(m.getModifiers());
      }
    });
    @SuppressWarnings("unchecked")
    T partial = (T) factory.create(
        constructor.getParameterTypes(), args, new ThrowingMethodHandler());
    return partial;
  } catch (Exception e) {
    throw new RuntimeException("Failed to instantiate " + cls, e);
  }
}
 
开发者ID:google,项目名称:FreeBuilder,代码行数:27,代码来源:Partial.java

示例5: getInstance

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
 * Get an instance of a rest proxy instance for the service class.
 *
 * @param serviceClass
 *            the service class.
 * @return the proxy implementation that invokes the remote service.
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public <T> T getInstance(@NonNull final Class<T> serviceClass) throws Exception {
    final ProxyFactory factory = new ProxyFactory();
    if (serviceClass.isInterface()) {
        factory.setInterfaces(new Class[] { serviceClass });
    } else {
        factory.setSuperclass(serviceClass);
    }
    factory.setFilter(new MethodFilter() {
        @Override
        public boolean isHandled(final Method method) {
            return Modifier.isPublic(method.getModifiers());
        }
    });

    final Class<?> klass = factory.createClass();
    final Object instance = objenesis.getInstantiatorOf(klass).newInstance();
    ((ProxyObject) instance).setHandler(new RestMethodInvocationHandler(baseUri,
            clientProvider, interfaceAnalyzer.analyze(serviceClass), responseToThrowableMapper,
            builderFilter));
    return (T) instance;
}
 
开发者ID:strandls,项目名称:alchemy-rest-client-generator,代码行数:31,代码来源:AlchemyRestClientFactory.java

示例6: build

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
 * Creates a proxy object out of the specified root object and the specified interfaces
 * and implementations.
 *
 * @return a proxy object that is still of type T but additionally implements all specified
 * interfaces.
 * @throws ProxyException if the proxy could not be created.
 */
public T build() throws ProxyException {

  if (this.root == null) {
    throw new IllegalArgumentException("root must not be null!");
  }

  if (this.interfacesToImplementations.isEmpty()) {
    // nothing to proxy
    return this.root;
  }

  try {
    ProxyMethodHandler methodHandler = new ProxyMethodHandler(root,
            interfacesToImplementations);
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setSuperclass(root.getClass());
    proxyFactory.setInterfaces(interfacesToImplementations.keySet().toArray(new Class[]{}));
    return (T) proxyFactory.create(new Class[0], new Object[0], methodHandler);
  } catch (Exception e) {
    throw new ProxyException(e);
  }
}
 
开发者ID:thombergs,项目名称:docx-stamper,代码行数:31,代码来源:ProxyBuilder.java

示例7: createTheProxy

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> Class<T> createTheProxy(Class<?> mainClass) {
	ProxyFactory f = new ProxyFactory();
	f.setSuperclass(mainClass);
	f.setInterfaces(new Class[] {NoSqlProxy.class});
	f.setFilter(new MethodFilter() {
		public boolean isHandled(Method m) {
			// ignore finalize()
			if(m.getName().equals("finalize"))
				return false;
			else if(m.getName().equals("equals"))
				return false;
			else if(m.getName().equals("hashCode"))
				return false;
			return true;
		}
	});
	Class<T> clazz = f.createClass();
	testInstanceCreation(clazz);
	
	return clazz;
}
 
开发者ID:guci314,项目名称:playorm,代码行数:23,代码来源:ScannerForClass.java

示例8: nullSafe

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
public static <T> T nullSafe(Class<T> klass, final Object instance){
    try {
        if (Modifier.isFinal(klass.getModifiers())) return (T)instance;
        ProxyFactory factory = new ProxyFactory();
        factory.setSuperclass(klass);
        Class clazz = factory.createClass();
        MethodHandler handler = (self, overridden, forwarder, args) -> {
            Object returnval = (instance != null) ? overridden.invoke(instance, args) : null;
            return nullSafe(overridden.getReturnType(), returnval);

        };
        Object proxyInstance = clazz.newInstance();
        ((ProxyObject) proxyInstance).setHandler(handler);
        return (T) proxyInstance;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:ChristinGorman,项目名称:kjempenyttig,代码行数:19,代码来源:Elvis.java

示例9: getProxyClass

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
private static PyObjectValueProxyClass getProxyClass(PyObject pyObject) throws Exception {
    String proxyClassName = pyObject.getClass() + PROXY_CLASS_SUFFIX;
    PyObjectValueProxyClass proxyClass = proxyClasses.get(proxyClassName);
    if (proxyClass == null) {
        writeLock.lock();
        try {
            proxyClass = proxyClasses.get(proxyClassName);
            if (proxyClass == null) {
                ProxyFactory factory = new ProxyFactory();
                factory.setSuperclass(pyObject.getClass());
                factory.setInterfaces(new Class[]{PyObjectValue.class});
                factory.setFilter(new PyObjectValueMethodFilter());
                factory.setUseWriteReplace(false);
                proxyClasses.putIfAbsent(proxyClassName, createProxyClass(factory.createClass(), pyObject));
                proxyClass = proxyClasses.get(proxyClassName);
            }
        } finally {
            writeLock.unlock();
        }
    }
    return proxyClass;
}
 
开发者ID:CloudSlang,项目名称:cloud-slang,代码行数:23,代码来源:PyObjectValueProxyFactory.java

示例10: newJavassistProxy

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
static NonTrivialBean newJavassistProxy() 
        throws InstantiationException, IllegalAccessException {
  ProxyFactory f = new ProxyFactory();
  f.setSuperclass(NonTrivialBean.class);
  Class<?> c = f.createClass();
  MethodHandler mi = new MethodHandler() {
    // delegate to source methods
    public Object invoke(Object self, Method m, Method proceed, 
        Object[] args) throws Throwable {
      return proceed.invoke(self, args);
    }
  };
  NonTrivialBean b = (NonTrivialBean) c.newInstance();
  ((Proxy) b).setHandler(mi);
  return b;
}
 
开发者ID:Salauyou,项目名称:Java-Utils,代码行数:17,代码来源:TestBeanHelper.java

示例11: benchmarkJavassist

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
 * Performs a benchmark for a trivial class creation using javassist proxies.
 *
 * @return The created instance, in order to avoid JIT removal.
 */
@Benchmark
public Class<?> benchmarkJavassist() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setUseCache(false);
    ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {
        @Override
        public ClassLoader get(ProxyFactory proxyFactory) {
            return newClassLoader();
        }
    };
    proxyFactory.setSuperclass(baseClass);
    proxyFactory.setFilter(new MethodFilter() {
        public boolean isHandled(Method method) {
            return false;
        }
    });
    return proxyFactory.createClass();
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:24,代码来源:TrivialClassCreationBenchmark.java

示例12: create

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public static <T> T create(final Object obj, final ProxyCallback onSuccess, final ProxyCallback onException) throws Exception {
	ProxyFactory factory = new ProxyFactory();
	Class<T> origClass = (Class<T>) obj.getClass();
	factory.setSuperclass(origClass);
	Class clazz = factory.createClass();
	MethodHandler handler = new MethodHandler() {

		@Override
		public Object invoke(Object self, Method overridden, Method forwarder,
				Object[] args) throws Throwable {
			try {
				Object returnVal = overridden.invoke(obj, args);
				if (null != onSuccess) onSuccess.execute();
				return returnVal;
			} catch (Throwable tr) {
				if (null != onException) onException.execute();
				throw tr;
			}
		}
	};
	Object instance = clazz.newInstance();
	((ProxyObject) instance).setHandler(handler);
	return (T) instance;
}
 
开发者ID:persado,项目名称:stevia,代码行数:26,代码来源:ProxyHelper.java

示例13: proxify

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
@Override
public <T> T proxify(Class<T> type, MethodInvocation<? super T> handler) {
	final ProxyFactory factory = new ProxyFactory();
	factory.setFilter(IGNORE_BRIDGE_AND_OBJECT_METHODS);
	Class<?> rawType = extractRawType(type);

	if (type.isInterface()) {
		factory.setInterfaces(new Class[] { rawType });
	} else {
		factory.setSuperclass(rawType);
	}

	Object instance = createInstance(type, handler, factory);
	logger.debug("a proxy for {} was created as {}", type, instance.getClass());

	return (T) instance;
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:18,代码来源:JavassistProxifier.java

示例14: create

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
public static <T> T create(Class<T> classs) throws Exception {
    ProxyFactory factory = new ProxyFactory();
    factory.setSuperclass(classs);
    Class clazz = factory.createClass();
    MethodHandler handler = new MethodHandler() {

        public Object invoke(Object self, Method overridden, Method forwarder, Object[] args) throws Throwable {
            return forwarder.invoke(self, args);
        }
    };
    Object instance = clazz.newInstance();
    ((ProxyObject) instance).setHandler(handler);
    return (T) instance;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:ProxyTest.java

示例15: create

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
public static LineNumberChangeRulerColumn create(ISharedTextColors sharedColors) {
	try {
		ProxyFactory factory = new ProxyFactory();
		factory.setSuperclass(LineNumberChangeRulerColumn.class);
		factory.setHandler(new LineNumberChangeRulerColumnMethodHandler());
		return (LineNumberChangeRulerColumn) factory.create(new Class[] { ISharedTextColors.class },
				new Object[] { sharedColors });
	} catch (Exception e) {
		e.printStackTrace();
		return new LineNumberChangeRulerColumn(sharedColors);
	}
}
 
开发者ID:angelozerr,项目名称:codelens-eclipse,代码行数:13,代码来源:LineNumberChangeRulerColumnPatch.java


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