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


Java Proxy.isProxyClass方法代码示例

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


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

示例1: getDescriptiveType

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * Return a descriptive name for the given object's type: usually simply
 * the class name, but component type class name + "[]" for arrays,
 * and an appended list of implemented interfaces for JDK proxies.
 * @param value the value to introspect
 * @return the qualified name of the class
 */
public static String getDescriptiveType(Object value) {
	if (value == null) {
		return null;
	}
	Class<?> clazz = value.getClass();
	if (Proxy.isProxyClass(clazz)) {
		StringBuilder result = new StringBuilder(clazz.getName());
		result.append(" implementing ");
		Class<?>[] ifcs = clazz.getInterfaces();
		for (int i = 0; i < ifcs.length; i++) {
			result.append(ifcs[i].getName());
			if (i < ifcs.length - 1) {
				result.append(',');
			}
		}
		return result.toString();
	}
	else if (clazz.isArray()) {
		return getQualifiedNameForArray(clazz);
	}
	else {
		return clazz.getName();
	}
}
 
开发者ID:drinkjava2,项目名称:jDialects,代码行数:32,代码来源:ClassUtils.java

示例2: selectMethods

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * Select handler methods for the given handler type.
 * <p>Callers define handler methods of interest through the {@link MethodFilter} parameter.
 * @param handlerType the handler type to search handler methods on
 * @param handlerMethodFilter a {@link MethodFilter} to help recognize handler methods of interest
 * @return the selected methods, or an empty set
 */
public static Set<Method> selectMethods(final Class<?> handlerType, final MethodFilter handlerMethodFilter) {
	final Set<Method> handlerMethods = new LinkedHashSet<Method>();
	Set<Class<?>> handlerTypes = new LinkedHashSet<Class<?>>();
	Class<?> specificHandlerType = null;
	if (!Proxy.isProxyClass(handlerType)) {
		handlerTypes.add(handlerType);
		specificHandlerType = handlerType;
	}
	handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
	for (Class<?> currentHandlerType : handlerTypes) {
		final Class<?> targetClass = (specificHandlerType != null ? specificHandlerType : currentHandlerType);
		ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
			@Override
			public void doWith(Method method) {
				Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
				Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
				if (handlerMethodFilter.matches(specificMethod) &&
						(bridgedMethod == specificMethod || !handlerMethodFilter.matches(bridgedMethod))) {
					handlerMethods.add(specificMethod);
				}
			}
		}, ReflectionUtils.USER_DECLARED_METHODS);
	}
	return handlerMethods;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:HandlerMethodSelector.java

示例3: checkProxyMethod

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
     * Check if the given method is a method declared in the proxy interface
     * implemented by the given proxy instance.
     *
     * @param proxy a proxy instance
     * @param method an interface method dispatched to a InvocationHandler
     *
     * @throws IllegalArgumentException if the given proxy or method is invalid.
     */
    public static void checkProxyMethod(Object proxy, Method method) {
        // check if it is a valid proxy instance
        if (proxy == null || !Proxy.isProxyClass(proxy.getClass())) {
            throw new IllegalArgumentException("Not a Proxy instance");
}
        if (Modifier.isStatic(method.getModifiers())) {
            throw new IllegalArgumentException("Can't handle static method");
        }

        Class<?> c = method.getDeclaringClass();
        if (c == Object.class) {
            String name = method.getName();
            if (name.equals("hashCode") || name.equals("equals") || name.equals("toString")) {
                return;
            }
        }

        if (isSuperInterface(proxy.getClass(), c)) {
            return;
        }

        // disallow any method not declared in one of the proxy intefaces
        throw new IllegalArgumentException("Can't handle: " + method);
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:ReflectUtil.java

示例4: invoke

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
public Object invoke(Object target, Method method, Object[] parameters) throws Throwable {
    if (method.getName().equals("equals")) {
        Object parameter = parameters[0];
        if (parameter == null || !Proxy.isProxyClass(parameter.getClass())) {
            return false;
        }
        Object handler = Proxy.getInvocationHandler(parameter);
        if (!DispatchingInvocationHandler.class.isInstance(handler)) {
            return false;
        }

        DispatchingInvocationHandler otherHandler = (DispatchingInvocationHandler) handler;
        return otherHandler.type.equals(type) && otherHandler.dispatch == dispatch;
    }

    if (method.getName().equals("hashCode")) {
        return dispatch.hashCode();
    }
    if (method.getName().equals("toString")) {
        return type.getSimpleName() + " broadcast";
    }
    dispatch.dispatch(new MethodInvocation(method, parameters));
    return null;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:25,代码来源:ProxyDispatchAdapter.java

示例5: getDescriptiveType

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * Return a descriptive name for the given object's type: usually simply the class name, but component type class name + "[]" for arrays, and an
 * appended list of implemented interfaces for JDK proxies.
 * 
 * @param value
 *            the value to introspect
 * @return the qualified name of the class
 */
public static String getDescriptiveType(Object value) {
	if (value == null) {
		return null;
	}
	Class<?> clazz = value.getClass();
	if (Proxy.isProxyClass(clazz)) {
		StringBuilder result = new StringBuilder(clazz.getName());
		result.append(" implementing ");
		Class<?>[] ifcs = clazz.getInterfaces();
		for (int i = 0; i < ifcs.length; i++) {
			result.append(ifcs[i].getName());
			if (i < ifcs.length - 1) {
				result.append(',');
			}
		}
		return result.toString();
	} else if (clazz.isArray()) {
		return getQualifiedNameForArray(clazz);
	} else {
		return clazz.getName();
	}
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:31,代码来源:ClassUtils.java

示例6: run

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
public void run() {
    System.out.println(this.num + ". Start cancelling at " + new Date().getTime());

    if (Proxy.isProxyClass(this.c.getClass())) {
        try {
            if (this.num == 7 || this.num == 10) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, Connection.class.getMethod("close", new Class[] {}), null);
            } else if (this.num == 8 || this.num == 11) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, MySQLConnection.class.getMethod("abortInternal", new Class[] {}), null);
            } else if (this.num == 9 || this.num == 12) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, com.mysql.jdbc.Connection.class.getMethod("abort", new Class[] { Executor.class }),
                        new Object[] { new ThreadPerTaskExecutor() });
            }

            ConnectionRegressionTest.this.testServerPrepStmtDeadlockCounter++;
            System.out.println(this.num + ". Done!");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:22,代码来源:ConnectionRegressionTest.java

示例7: getRealClass

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
private static <T> Class<T> getRealClass(Class<T> clazz) {
	if (isProxyClass(clazz)) {
		if (Proxy.isProxyClass(clazz)) {
			Class<?>[] interfaces = clazz.getInterfaces();
			if (interfaces.length != 1) {
				throw new IllegalArgumentException("Unexpected number of interfaces: " + interfaces.length);
			}
			@SuppressWarnings("unchecked")
			Class<T> proxiedInterface = (Class<T>) interfaces[0];
			return proxiedInterface;
		}
		@SuppressWarnings("unchecked")
		Class<T> superclass = (Class<T>) clazz.getSuperclass();
		return getRealClass(superclass);
	}
	return clazz;
}
 
开发者ID:cronn-de,项目名称:reflection-util,代码行数:18,代码来源:ClassUtils.java

示例8: getSerialFields

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * Returns ObjectStreamField array describing the serializable fields of
 * the given class.  Serializable fields backed by an actual field of the
 * class are represented by ObjectStreamFields with corresponding non-null
 * Field objects.  Throws InvalidClassException if the (explicitly
 * declared) serializable fields are invalid.
 */
private static ObjectStreamField[] getSerialFields(Class<?> cl)
    throws InvalidClassException
{
    ObjectStreamField[] fields;
    if (Serializable.class.isAssignableFrom(cl) &&
        !Externalizable.class.isAssignableFrom(cl) &&
        !Proxy.isProxyClass(cl) &&
        !cl.isInterface())
    {
        if ((fields = getDeclaredSerialFields(cl)) == null) {
            fields = getDefaultSerialFields(cl);
        }
        Arrays.sort(fields);
    } else {
        fields = NO_FIELDS;
    }
    return fields;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:ObjectStreamClass.java

示例9: unpack

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * Unpacks the source object from a given view object.
 */
public Object unpack(Object viewObject) {
    if (!Proxy.isProxyClass(viewObject.getClass()) || !(Proxy.getInvocationHandler(viewObject) instanceof InvocationHandlerImpl)) {
        throw new IllegalArgumentException("The given object is not a view object");
    }
    InvocationHandlerImpl handler = (InvocationHandlerImpl) Proxy.getInvocationHandler(viewObject);
    return handler.sourceObject;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:11,代码来源:ProtocolToModelAdapter.java

示例10: isProxyForSameBshObject

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
private boolean isProxyForSameBshObject(Object other) {
	if (!Proxy.isProxyClass(other.getClass())) {
		return false;
	}
	InvocationHandler ih = Proxy.getInvocationHandler(other);
	return (ih instanceof BshObjectInvocationHandler &&
			this.xt.equals(((BshObjectInvocationHandler) ih).xt));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:BshScriptUtils.java

示例11: isProxyForSameRubyObject

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
private boolean isProxyForSameRubyObject(Object other) {
	if (!Proxy.isProxyClass(other.getClass())) {
		return false;
	}
	InvocationHandler ih = Proxy.getInvocationHandler(other);
	return (ih instanceof RubyObjectInvocationHandler &&
			this.rubyObject.equals(((RubyObjectInvocationHandler) ih).rubyObject));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:JRubyScriptUtils.java

示例12: isNonPublicProxyClass

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * Test if the given class is a proxy class that implements
 * non-public interface.  Such proxy class may be in a non-restricted
 * package that bypasses checkPackageAccess.
 */
public static boolean isNonPublicProxyClass(Class<?> cls) {
    String name = cls.getName();
    int i = name.lastIndexOf('.');
    String pkg = (i != -1) ? name.substring(0, i) : "";
    return Proxy.isProxyClass(cls) && !pkg.equals(PROXY_PACKAGE);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:ReflectUtil.java

示例13: realTarget

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * 获得真正的处理对象,可能多层代理.
 */
public static Object realTarget(Object target) {
    if (Proxy.isProxyClass(target.getClass())) {
        MetaObject metaObject = SystemMetaObject.forObject(target);
        return realTarget(metaObject.getValue("h.target"));
    }
    return target;
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:11,代码来源:PluginUtils.java

示例14: equals

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
public boolean equals(Object obj)
{
    if (obj != null && Proxy.isProxyClass(obj.getClass()))
    {
        InvocationHandler handler = Proxy.getInvocationHandler(obj);
        if (handler instanceof SingleHandler)
        {
            return ((SingleHandler)handler).policyInterface.equals(policyInterface);
        }
    }
    
    return obj.equals(policyInterface);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:14,代码来源:PolicyFactory.java

示例15: ObjectStreamClass

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
private ObjectStreamClass(java.lang.Class<?> cl, ObjectStreamClass superdesc,
                          boolean serial, boolean extern)
{
    ofClass = cl;           /* created from this class */

    if (Proxy.isProxyClass(cl)) {
        forProxyClass = true;
    }

    name = cl.getName();
    isEnum = Enum.class.isAssignableFrom(cl);
    superclass = superdesc;
    serializable = serial;
    if (!forProxyClass) {
        // proxy classes are never externalizable
        externalizable = extern;
    }

    /*
     * Enter this class in the table of known descriptors.
     * Otherwise, when the fields are read it may recurse
     * trying to find the descriptor for itself.
     */
    insertDescriptorFor(this);

    /*
     * The remainder of initialization occurs in init(), which is called
     * after the lock on the global class descriptor table has been
     * released.
     */
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:ObjectStreamClass.java


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