本文整理汇总了Java中net.sf.cglib.reflect.FastClass类的典型用法代码示例。如果您正苦于以下问题:Java FastClass类的具体用法?Java FastClass怎么用?Java FastClass使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FastClass类属于net.sf.cglib.reflect包,在下文中一共展示了FastClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGetter
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
/**
* Return getter for the given method and CGLIB FastClass.
*
* @param method to return getter for
* @param fastClass is the CGLIB fast classs to make FastMethod for
* @param eventAdapterService factory for event beans and event types
* @return property getter
*/
public static EventPropertyGetterSPI getGetter(Method method, FastClass fastClass, EventAdapterService eventAdapterService) {
// Get CGLib fast method handle
FastMethod fastMethod = null;
try {
if (fastClass != null) {
fastMethod = fastClass.getMethod(method);
}
} catch (Throwable ex) {
log.warn(".getAccessAccessorsForges Unable to obtain CGLib fast method implementation, msg=" + ex.getMessage());
}
// Construct the appropriate property getter CGLib or reflect
EventPropertyGetterSPI getter;
if (fastMethod != null) {
getter = new CGLibPropertyGetter(method, fastMethod, eventAdapterService);
} else {
getter = new ReflectionPropMethodGetter(method, eventAdapterService);
}
return getter;
}
示例2: handle
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
private Object handle(RpcRequest request) throws Throwable {
String className = request.getClassName();
Object serviceBean = handlerMap.get(className);
Class<?> serviceClass = serviceBean.getClass();
String methodName = request.getMethodName();
Class<?>[] parameterTypes = request.getParameterTypes();
Object[] parameters = request.getParameters();
/*
* Method method = serviceClass.getMethod(methodName, parameterTypes);
* method.setAccessible(true); return method.invoke(serviceBean,
* parameters);
*/
FastClass serviceFastClass = FastClass.create(serviceClass);
FastMethod serviceFastMethod = serviceFastClass.getMethod(methodName, parameterTypes);
return serviceFastMethod.invoke(serviceBean, parameters);
}
示例3: resolveType
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
private Class< ? > resolveType(IExpression[] exprs)
{
//获得函数参数类型
Class< ? >[] paramTypes = new Class[exprs.length];
for (int i = 0; i < paramTypes.length; i++)
{
paramTypes[i] = exprs[i].getType();
}
//获得相应方法
Method method = MethodResolver.resolveMethod(declareClass, methodName, paramTypes);
if (null == method)
{
UDFAnnotation annotation = declareClass.getAnnotation(UDFAnnotation.class);
String functionName = annotation == null ? declareClass.getSimpleName() : annotation.value();
StreamingRuntimeException exception =
new StreamingRuntimeException(ErrorCode.FUNCTION_UNSUPPORTED_PARAMETERS, functionName);
LOG.error(ErrorCode.FUNCTION_UNSUPPORTED_PARAMETERS.getFullMessage(functionName));
throw exception;
}
FastClass declaringClass =
FastClass.create(Thread.currentThread().getContextClassLoader(), method.getDeclaringClass());
FastMethod md = declaringClass.getMethod(method);
return warpDataType(md.getReturnType());
}
示例4: invoke
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
/**
* �������AOP���
*
* @param methodName ��������
* @param className ��ȫ��
* @param dao BaseDAO
* @param aspectData AOP xml�����ļ�����
* @param queryWrapper ��ѯ����
* @param queryEnumType ��ѯ����
* @return �Ƿ����ִ��
*/
private boolean invoke(String methodName, String className, SqlSession dao, AspectData aspectData,
QueryAspectWrapper queryWrapper, QueryEnumType queryEnumType)
{
if (getJavaClass(className) == null || aepectObj == null)
return false;
Class<?>[] params = {SqlSession.class, AspectData.class, QueryAspectWrapper.class, QueryEnumType.class};
try
{
FastClass fastClass = ReflectHelper.getFastClass(aspectClass);
FastMethod mt = ReflectHelper.getFastMethod(fastClass, methodName, params);
if (mt == null)
return false;
Boolean ret = (Boolean)mt.invoke(aepectObj, new Object[] {dao, aspectData, queryWrapper, queryEnumType});
return ret;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
示例5: init
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
@Setup
public void init() {
try {
simpleMethod = clazz.getMethod("getAStatic", null);
Method method = clazz.getMethod("getBStatic", null);
method.setAccessible(true);
methodAccessible = method;
fastMethod = FastClass.create(clazz).getMethod("getCStatic", null);
methodHandle = MethodHandles.lookup().findStatic(clazz, "getDStatic", MethodType.methodType(Integer.class));
} catch (Exception e) {
// do nothing
}
}
示例6: init
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
@Setup
public void init() {
try {
testedObject = new TestedClass();
simpleMethod = clazz.getMethod("getA", null);
Method method = clazz.getMethod("getB", null);
method.setAccessible(true);
methodAccessible = method;
fastMethod = FastClass.create(clazz).getMethod("getC", null);
methodHandle = MethodHandles.lookup().findVirtual(clazz, "getD", MethodType.methodType(Integer.class));
} catch (Exception e) {
// do nothing
}
}
示例7: buildGettersMap
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
private static Map<String, FastMethod> buildGettersMap(Class<?> clazz) {
Map<String, FastMethod> result = new HashMap<>();
FastClass fastClass = getFastClass(clazz);
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (!Modifier.isStatic(method.getModifiers())) {
String property = getGetterProperty(method);
if (property != null) {
result.put(property, fastClass.getMethod(method));
}
}
}
return result;
}
示例8: buildSettersMap
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
private static Map<String, FastMethod> buildSettersMap(Class<?> clazz) {
Map<String, FastMethod> result = new HashMap<>();
FastClass fastClass = getFastClass(clazz);
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (!Modifier.isStatic(method.getModifiers())) {
String property = getSetterProperty(method);
if (property != null) {
result.put(property, fastClass.getMethod(method));
}
}
}
return result;
}
示例9: test
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
private void test() throws InvocationTargetException {
FastClass fastClass = FastClass.create(Source.class);
Source sourceClass = (Source) fastClass.newInstance();
fastClass.invoke("setIntValue", new Class[] { int.class }, sourceClass, new Object[] { 200 });
Object getIntValue = fastClass.invoke("getIntValue", new Class[] {}, sourceClass, new Object[] {});
System.out.println("intValue : " + getIntValue.toString());
FastMethod setIntValueMethod = fastClass.getMethod("setIntValue", new Class[] { int.class });
System.out.println("method name :" + setIntValueMethod.getJavaMethod().getName() + " index:"
+ setIntValueMethod.getIndex());
FastMethod getIntValueMethod = fastClass.getMethod("getIntValue", new Class[] {});
System.out.println("method name :" + getIntValueMethod.getJavaMethod().getName() + " index:"
+ getIntValueMethod.getIndex());
}
示例10: doconfirmorcancel
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
private void doconfirmorcancel(Class<?> clazz, String lookup, String method, //
Class<?>[] mParamsTypes, Object[] args) throws Exception {
Class<?> confirmclass = GuiceDI.getInstance(ServiceInfosHolder.class).getImplClass(clazz, lookup);
FastClass confrimfast = FastClass.create(confirmclass);
// fast class反射调用
Object confirmtarget = confrimfast.newInstance();
FastMethod confirmmethod = confrimfast.getMethod(method, mParamsTypes);
confirmmethod.invoke(confirmtarget, args);
}
示例11: build
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
private static FastMethodInvoker build(final Class<?> clz, Method method) {
FastClass fastClz = MapUtil.createIfAbsent(fastClassMap, clz, new ValueCreator<FastClass>() {
@Override
public FastClass get() {
return FastClass.create(clz);
}
});
return new FastMethodInvoker(fastClz.getMethod(method));
}
示例12: add
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
public void add(String prefix, String serviceName, Object serviceBean) {
Class<?> serviceClass = serviceBean.getClass();
FastClass serviceFastClass = FastClass.create(serviceClass);
Method[] methods = serviceClass.getDeclaredMethods();
for (Method method : methods) {
method.setAccessible(true);
FastMethod fastMethod = serviceFastClass.getMethod(method);
MethodInvoker methodInvoker = new MethodInvoker(serviceBean, fastMethod);
methodInvokerMap.put(prefix + "/" + serviceName + "/" + method.getName().toLowerCase(), methodInvoker);
}
}
示例13: handleRequest
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
protected Object handleRequest(RpcRequest request) throws Exception {
Class<?> serviceClass = serviceBean.getClass();
String methodName = request.getMethodName();
Class<?>[] parameterTypes = request.getParameterTypes();
Object[] parameters = request.getParameters();
// use cglib go to invoke
FastClass serviceFastClass = FastClass.create(serviceClass);
FastMethod serviceFastMethod = serviceFastClass.getMethod(methodName, parameterTypes);
return serviceFastMethod.invoke(serviceBean, parameters);
}
示例14: initialize
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
/**
* Initializes the dispatcher table. This maps every type
* to precisely the method which handles it. At lookup time we
* will incrementally populate the table with additional entries
* for super-types.
*/
private void initialize(Class<? extends Annotation> marker, Class<?> provider) {
Class<?> providerSuper = provider.getSuperclass();
if (providerSuper != null && providerSuper != Object.class) {
// First get methods from super class. They can be overridden later.
initialize(marker, providerSuper);
}
// Now get methods from this provider.
FastClass fastProvider = FastClass.create(provider);
for (Method method : provider.getDeclaredMethods()) {
Annotation dispatched = method.getAnnotation(marker);
if (dispatched == null) {
continue;
}
Preconditions.checkState((method.getModifiers() & Modifier.STATIC) == 0,
"%s must not be static", method);
Preconditions.checkState(method.getParameterTypes().length == 1,
"%s must have exactly one parameter", method);
@SuppressWarnings("unchecked") // checked at runtime
Class<? extends BaseType> dispatchedOn =
(Class<? extends BaseType>) method.getParameterTypes()[0];
Preconditions.checkState(baseType.isAssignableFrom(dispatchedOn),
"%s parameter must be assignable to %s", method, baseType);
Optional<FastMethod> oldMethod = dispatchTable.getIfPresent(dispatchedOn);
if (oldMethod != null && oldMethod.get().getDeclaringClass() == provider) {
throw new IllegalStateException(String.format(
"%s clashes with already configured %s from same class %s",
method, oldMethod.get().getJavaMethod(), provider));
}
dispatchTable.put(dispatchedOn, Optional.of(fastProvider.getMethod(method)));
}
}
示例15: createPropertyConstructors
import net.sf.cglib.reflect.FastClass; //导入依赖的package包/类
private Map<String, FastConstructor> createPropertyConstructors(Map<String, Object> propertyTypes) {
Map<String, FastConstructor> constructors = new HashMap<String, FastConstructor>();
Class[] parameterTypes = new Class[]{String.class};
for (String property : propertyTypes.keySet()) {
log.debug(".createPropertyConstructors property==" + property + ", type==" + propertyTypes.get(property));
Class clazz = JavaClassHelper.getBoxedType((Class) propertyTypes.get(property));
FastClass fastClass = FastClass.create(FastClassClassLoaderProviderDefault.INSTANCE.classloader(clazz), clazz);
FastConstructor constructor = fastClass.getConstructor(parameterTypes);
constructors.put(property, constructor);
}
return constructors;
}