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


Java ProxyFactory.create方法代码示例

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


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

示例3: 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

示例4: 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

示例5: createInternal

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected <E> E createInternal(final Class<E> klass) {
	
	try {
	
   		ProxyFactory factory = new ProxyFactory();
   		factory.setSuperclass(klass);
   		
   		factory.setFilter(new MethodFilter() {
   
   			@Override
               public boolean isHandled(Method m) {
   				return getPropName(m) != null;
   			}
   		});
   		
   		MethodHandler handler = new MethodHandler() {
   	        
   			@Override
   	        public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
   				
   				return DefaultProxy.this.invoke(self, thisMethod, args);
   	        }
   	    };
   	    
   	    return (E) factory.create(new Class[0], new Object[0], handler);
   	    
	} catch(Exception e) {
		throw new BeanException(e);
	}
}
 
开发者ID:saoj,项目名称:mentabean,代码行数:33,代码来源:DefaultProxy.java

示例6: newInstance

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
 * Creates a proxy class of bean and returns an instance of that class.
 *
 * @param context the activity context
 * @param beanRule the bean rule
 * @param constructorArgs the arguments passed to a constructor
 * @param constructorArgTypes the parameter types for a constructor
 * @return a new proxy bean object
 */
public static Object newInstance(ActivityContext context, BeanRule beanRule, Object[] constructorArgs, Class<?>[] constructorArgTypes) {
    try {
        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.setSuperclass(beanRule.getBeanClass());
        MethodHandler methodHandler = new JavassistDynamicBeanProxy(context, beanRule);
        return proxyFactory.create(constructorArgTypes, constructorArgs, methodHandler);
    } catch (Exception e) {
        throw new ProxyBeanInstantiationException(beanRule.getBeanClass(), e);
    }
}
 
开发者ID:aspectran,项目名称:aspectran,代码行数:20,代码来源:JavassistDynamicBeanProxy.java

示例7: newInstance

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
private <T> T newInstance(final Object entity, final Session em,
		final MainInstance principal, final Class<T> fieldType)
		throws NoSuchMethodException, InstantiationException,
		IllegalAccessException, InvocationTargetException {

	ProxyFactory factory = new ProxyFactory();
	factory.setSuperclass(fieldType);
	MethodHandler handler = new MainInstanceMethodHandler<T>(em, principal,
			entity, fieldType);

	return (T) factory.create(new Class<?>[0], new Object[0], handler);
}
 
开发者ID:fpuna-cia,项目名称:karaku,代码行数:13,代码来源:MainInstanceHelper.java

示例8: checkForCreateListTypeType

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
private void checkForCreateListTypeType(Configuration conf, final Class<?> propertyType) throws NoSuchMethodException,
		IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
	if (!listTypeProxyCreatedSet.contains(propertyType)) {
		ProxyFactory factory = new ProxyFactory();
		factory.setSuperclass(ListTypeUserType.class);
		factory.setFilter(new MethodFilter() {

			@Override
			public boolean isHandled(Method method) {
				return Modifier.isAbstract(method.getModifiers());
			}
		});
		MethodHandler handler = new MethodHandler() {

			@Override
			public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
				if (thisMethod.getName().equals("returnedClass") && args.length == 0) {
					LOG.debug("Handling method returnedClass() of type ListTypeUserType", thisMethod);
					return propertyType;
				} else {
					throw new UnsupportedOperationException();
				}
			}

		};
		Object type = factory.create(new Class<?>[0], new Object[0], handler);
		conf.registerTypeOverride((UserType) type, new String[] { propertyType.getSimpleName(), propertyType.getName() });
		listTypeProxyCreatedSet.add(propertyType);
	}
}
 
开发者ID:frincon,项目名称:openeos,代码行数:31,代码来源:BundleModelClassConfigurator.java

示例9: createInstance

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
private <T> Object createInstance(Class<T> type, MethodInvocation<? super T> handler, ProxyFactory factory) {
	try {
		return factory.create(null, null, new MethodInvocationAdapter<>(handler));
	} catch (ReflectiveOperationException | IllegalArgumentException e) {
		logger.error("An error occurs when create a proxy for type " + type, e);
		throw new ProxyCreationException(e);
	}
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:9,代码来源:JavassistProxifier.java

示例10: iface

import javassist.util.proxy.ProxyFactory; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * <p>
 * iface.
 * </p>
 */
@SuppressWarnings("unchecked")
@Override
public <X extends TServiceClient> X iface(Class<X> ifaceClass,
        Function<TTransport, TProtocol> protocolProvider, int hash) {
    List<ThriftServerInfo> servers = serverInfoProvider.get();
    if (servers == null || servers.isEmpty()) {
        throw new NoBackendException();
    }
    hash = Math.abs(hash);
    hash = hash < 0 ? 0 : hash;
    ThriftServerInfo selected = servers.get(hash % servers.size());
    logger.trace("get connection for [{}]->{} with hash:{}", ifaceClass, selected, hash);

    TTransport transport = poolProvider.getConnection(selected);
    TProtocol protocol = protocolProvider.apply(transport);

    ProxyFactory factory = new ProxyFactory();
    factory.setSuperclass(ifaceClass);
    factory.setFilter(m -> ThriftClientUtils.getInterfaceMethodNames(ifaceClass).contains(
            m.getName()));
    try {
        X x = (X) factory.create(new Class[] { org.apache.thrift.protocol.TProtocol.class },
                new Object[] { protocol });
        ((Proxy) x).setHandler((self, thisMethod, proceed, args) -> {
            boolean success = false;
            try {
                Object result = proceed.invoke(self, args);
                success = true;
                return result;
            } finally {
                if (success) {
                    poolProvider.returnConnection(selected, transport);
                } else {
                    poolProvider.returnBrokenConnection(selected, transport);
                }
            }
        });
        return x;
    } catch (NoSuchMethodException | IllegalArgumentException | InstantiationException
            | IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException("fail to create proxy.", e);
    }
}
 
开发者ID:ngayngo9x,项目名称:q-thrift,代码行数:51,代码来源:ThriftClientImpl.java


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