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


Java MethodFilter类代码示例

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


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

示例1: of

import javassist.util.proxy.MethodFilter; //导入依赖的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

示例2: getInstance

import javassist.util.proxy.MethodFilter; //导入依赖的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

示例3: createTheProxy

import javassist.util.proxy.MethodFilter; //导入依赖的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

示例4: benchmarkJavassist

import javassist.util.proxy.MethodFilter; //导入依赖的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

示例5: createProxyAgent

import javassist.util.proxy.MethodFilter; //导入依赖的package包/类
private Agent createProxyAgent(final Agent agent) throws NoSuchMethodException, IllegalArgumentException,
			InstantiationException, IllegalAccessException, InvocationTargetException {
		Class<? extends Agent> clazz = agent.getClass();

		Constructor<?> constructor = clazz.getConstructors()[0];
		Class<?>[] parameterTypes = constructor.getParameterTypes();
//		reflectionFactory = new ProxyFactory();
		factory.setSuperclass(clazz);
		factory.setFilter(new MethodFilter() {

			public boolean isHandled(Method m) {
				if(m.getName().equals("visitActivity")){
					return true;
				}
				return false;
			}
		});

		Object[] params = createParameters(agent, constructor);

		Agent proxyAgent = (Agent) factory.create(parameterTypes, params, createMethodHandler(agent));
		
		clone(agent,proxyAgent,clazz);
		
		return proxyAgent;
	}
 
开发者ID:agents4its,项目名称:mobilitytestbed,代码行数:27,代码来源:AgentProxyFactory.java

示例6: createInternal

import javassist.util.proxy.MethodFilter; //导入依赖的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

示例7: checkForCreateListTypeType

import javassist.util.proxy.MethodFilter; //导入依赖的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

示例8: benchmarkJavassist

import javassist.util.proxy.MethodFilter; //导入依赖的package包/类
/**
 * Performs a benchmark of a class extension using javassist proxies.
 *
 * @return The created instance, in order to avoid JIT removal.
 * @throws java.lang.Exception If the invocation causes an exception.
 */
@Benchmark
public ExampleClass benchmarkJavassist() throws Exception {
    ProxyFactory proxyFactory = new ProxyFactory() {
        @Override
        protected ClassLoader getClassLoader() {
            return newClassLoader();
        }
    };
    proxyFactory.setUseCache(false);
    proxyFactory.setSuperclass(baseClass);
    proxyFactory.setFilter(new MethodFilter() {
        public boolean isHandled(Method method) {
            return method.getDeclaringClass() == baseClass;
        }
    });
    @SuppressWarnings("unchecked")
    Object instance = proxyFactory.createClass().getDeclaredConstructor().newInstance();
    ((javassist.util.proxy.Proxy) instance).setHandler(new MethodHandler() {
        public Object invoke(Object self,
                             Method thisMethod,
                             Method proceed,
                             Object[] args) throws Throwable {
            return proceed.invoke(self, args);
        }
    });
    return (ExampleClass) instance;
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:34,代码来源:ClassByExtensionBenchmark.java

示例9: getPackageFilter

import javassist.util.proxy.MethodFilter; //导入依赖的package包/类
public static MethodFilter getPackageFilter(final String packageName) {
    return new MethodFilter() {
        public boolean isHandled(final Method method) {
            return method.getDeclaringClass().getName().contains(packageName) &&
                    method.getAnnotation(Publish.class) != null;
        }
    };
}
 
开发者ID:atinfo,项目名称:at.info-knowledge-base,代码行数:9,代码来源:ReflectionUtils.java

示例10: benchmarkJavassist

import javassist.util.proxy.MethodFilter; //导入依赖的package包/类
/**
 * Performs a benchmark of an interface implementation using javassist proxies.
 *
 * @return The created instance, in order to avoid JIT removal.
 * @throws java.lang.Exception If the reflective invocation causes an exception.
 */
@Benchmark
public ExampleInterface benchmarkJavassist() throws Exception {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setUseCache(false);
    ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {
        @Override
        public ClassLoader get(ProxyFactory proxyFactory) {
            return newClassLoader();
        }
    };
    proxyFactory.setSuperclass(Object.class);
    proxyFactory.setInterfaces(new Class<?>[]{baseClass});
    proxyFactory.setFilter(new MethodFilter() {
        public boolean isHandled(Method method) {
            return true;
        }
    });
    @SuppressWarnings("unchecked")
    Object instance = proxyFactory.createClass().getDeclaredConstructor().newInstance();
    ((javassist.util.proxy.Proxy) instance).setHandler(new MethodHandler() {
        public Object invoke(Object self,
                             Method thisMethod,
                             Method proceed,
                             Object[] args) throws Throwable {
            Class<?> returnType = thisMethod.getReturnType();
            if (returnType.isPrimitive()) {
                if (returnType == boolean.class) {
                    return defaultBooleanValue;
                } else if (returnType == byte.class) {
                    return defaultByteValue;
                } else if (returnType == short.class) {
                    return defaultShortValue;
                } else if (returnType == char.class) {
                    return defaultCharValue;
                } else if (returnType == int.class) {
                    return defaultIntValue;
                } else if (returnType == long.class) {
                    return defaultLongValue;
                } else if (returnType == float.class) {
                    return defaultFloatValue;
                } else {
                    return defaultDoubleValue;
                }
            } else {
                return defaultReferenceValue;
            }
        }
    });
    return (ExampleInterface) instance;
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:57,代码来源:ClassByImplementationBenchmark.java


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