本文整理汇总了Java中java.lang.reflect.Proxy.getInvocationHandler方法的典型用法代码示例。如果您正苦于以下问题:Java Proxy.getInvocationHandler方法的具体用法?Java Proxy.getInvocationHandler怎么用?Java Proxy.getInvocationHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Proxy
的用法示例。
在下文中一共展示了Proxy.getInvocationHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: checkInstallation
import java.lang.reflect.Proxy; //导入方法依赖的package包/类
@BeforeClass public static void checkInstallation() throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException {
try {
CondomProcess.installExcept(((Application) InstrumentationRegistry.getTargetContext().getApplicationContext()),
new CondomOptions().addKit(new NullDeviceIdKit()), "");
fail("CondomKit is incompatible with CondomProcess");
} catch (final IllegalArgumentException ignored) {}
// Install in default process intentionally, since test cases cannot run in secondary process.
CondomProcess.installExcept(((Application) InstrumentationRegistry.getTargetContext().getApplicationContext()), new CondomOptions(), "");
// Check IActivityManager proxy
@SuppressLint("PrivateApi") final Object am_proxy = Class.forName("android.app.ActivityManagerNative").getMethod("getDefault").invoke(null);
assertTrue(Proxy.isProxyClass(am_proxy.getClass()));
sCondomProcessActivityManager = (CondomProcess.CondomProcessActivityManager) Proxy.getInvocationHandler(am_proxy);
assertEquals(CondomProcess.CondomProcessActivityManager.class, sCondomProcessActivityManager.getClass());
// Check IPackageManager proxy
final PackageManager pm = context().getPackageManager();
assertEquals("android.app.ApplicationPackageManager", pm.getClass().getName());
final Field ApplicationPackageManager_mPm = pm.getClass().getDeclaredField("mPM");
ApplicationPackageManager_mPm.setAccessible(true);
final Object pm_proxy = ApplicationPackageManager_mPm.get(pm);
assertTrue(Proxy.isProxyClass(pm_proxy.getClass()));
sCondomProcessPackageManager = (CondomProcess.CondomProcessPackageManager) Proxy.getInvocationHandler(pm_proxy);
assertEquals(CondomProcess.CondomProcessPackageManager.class, sCondomProcessPackageManager.getClass());
}
示例3: cleanupConnection
import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
* <p>
* Cleanup the given database connection. This means restoring
* any modified auto commit or transaction isolation connection
* attributes, and then closing the underlying connection.
* </p>
*
* <p>
* This is separate from closeConnection() because the Spring
* integration relies on being able to overload closeConnection() and
* expects the same connection back that it originally returned
* from the datasource.
* </p>
*
* @see #closeConnection(Connection)
*/
protected void cleanupConnection(Connection conn) {
if (conn != null) {
if (conn instanceof Proxy) {
Proxy connProxy = (Proxy)conn;
InvocationHandler invocationHandler =
Proxy.getInvocationHandler(connProxy);
if (invocationHandler instanceof AttributeRestoringConnectionInvocationHandler) {
AttributeRestoringConnectionInvocationHandler connHandler =
(AttributeRestoringConnectionInvocationHandler)invocationHandler;
connHandler.restoreOriginalAtributes();
closeConnection(connHandler.getWrappedConnection());
return;
}
}
// Wan't a Proxy, or was a Proxy, but wasn't ours.
closeConnection(conn);
}
}
示例4: getSelectedProtocol
import java.lang.reflect.Proxy; //导入方法依赖的package包/类
public String getSelectedProtocol(SSLSocket socket) {
String str = null;
try {
JettyNegoProvider provider = (JettyNegoProvider) Proxy.getInvocationHandler(this
.getMethod.invoke(null, new Object[]{socket}));
if (!provider.unsupported && provider.selected == null) {
Internal.logger.log(Level.INFO, "ALPN callback dropped: SPDY and HTTP/2 are " +
"disabled. Is alpn-boot on the boot class path?");
} else if (!provider.unsupported) {
str = provider.selected;
}
return str;
} catch (InvocationTargetException e) {
throw new AssertionError();
} catch (IllegalAccessException e2) {
throw new AssertionError();
}
}
示例5: makeNotificationEmitter
import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
* Transfroms a proxy implementing T in a proxy implementing T plus
* NotificationEmitter
*
**/
public static <T> T makeNotificationEmitter(T proxy,
Class<T> mbeanInterface) {
if (proxy instanceof NotificationEmitter)
return proxy;
if (proxy == null) return null;
if (!(proxy instanceof Proxy))
throw new IllegalArgumentException("not a "+Proxy.class.getName());
final Proxy p = (Proxy) proxy;
final InvocationHandler handler =
Proxy.getInvocationHandler(proxy);
if (!(handler instanceof MBeanServerInvocationHandler))
throw new IllegalArgumentException("not a JMX Proxy");
final MBeanServerInvocationHandler h =
(MBeanServerInvocationHandler)handler;
final ObjectName name = h.getObjectName();
final MBeanServerConnection mbs = h.getMBeanServerConnection();
final boolean isMXBean = h.isMXBean();
final T newProxy;
if (isMXBean)
newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true);
else
newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true);
return newProxy;
}
示例6: monitorNotifications
import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
* Test the monitor notifications.
*/
public int monitorNotifications() throws Exception {
server = MBeanServerFactory.newMBeanServer();
MBeanServerForwarderInvocationHandler mbsfih =
(MBeanServerForwarderInvocationHandler)
Proxy.getInvocationHandler(server);
mbsfih.setGetAttributeException(
new RuntimeException("Test RuntimeException"));
domain = server.getDefaultDomain();
obsObjName = ObjectName.getInstance(domain + ":type=ObservedObject");
server.registerMBean(new ObservedObject(), obsObjName);
echo(">>> ----------------------------------------");
int error = counterMonitorNotification();
echo(">>> ----------------------------------------");
error += gaugeMonitorNotification();
echo(">>> ----------------------------------------");
error += stringMonitorNotification();
echo(">>> ----------------------------------------");
return error;
}
示例7: equals
import java.lang.reflect.Proxy; //导入方法依赖的package包/类
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (other == null) {
return false;
}
if (Proxy.isProxyClass(other.getClass())) {
InvocationHandler ih = Proxy.getInvocationHandler(other);
if (ih instanceof JDKHandler) {
return reference.equals(((JDKHandler) ih).reference);
}
}
return false;
}
示例8: invokeObjectMethod
import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
* Handles java.lang.Object methods.
**/
private Object invokeObjectMethod(Object proxy,
Method method,
Object[] args)
{
String name = method.getName();
if (name.equals("hashCode")) {
return hashCode();
} else if (name.equals("equals")) {
Object obj = args[0];
InvocationHandler hdlr;
return
proxy == obj ||
(obj != null &&
Proxy.isProxyClass(obj.getClass()) &&
(hdlr = Proxy.getInvocationHandler(obj)) instanceof RemoteObjectInvocationHandler &&
this.equals(hdlr));
} else if (name.equals("toString")) {
return proxyToString(proxy);
} else {
throw new IllegalArgumentException(
"unexpected Object method: " + method);
}
}
示例9: getObjectName
import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
* Returns the ObjectName of the MBean that a proxy object
* is proxying.
**/
public static ObjectName getObjectName(Object proxy) {
if (!(proxy instanceof Proxy))
throw new IllegalArgumentException("not a "+Proxy.class.getName());
final Proxy p = (Proxy) proxy;
final InvocationHandler handler =
Proxy.getInvocationHandler(proxy);
if (handler instanceof MBeanServerInvocationHandler)
return ((MBeanServerInvocationHandler)handler).getObjectName();
throw new IllegalArgumentException("not a JMX Proxy");
}
示例10: getProtocolMetaInfoProxy
import java.lang.reflect.Proxy; //导入方法依赖的package包/类
private static ProtocolMetaInfoPB getProtocolMetaInfoProxy(Object proxy,
Configuration conf) throws IOException {
RpcInvocationHandler inv = (RpcInvocationHandler) Proxy
.getInvocationHandler(proxy);
return RPC
.getProtocolEngine(ProtocolMetaInfoPB.class, conf)
.getProtocolMetaInfoProxy(inv.getConnectionId(), conf,
NetUtils.getDefaultSocketFactory(conf)).getProxy();
}
示例11: 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));
}
示例12: createProxy
import java.lang.reflect.Proxy; //导入方法依赖的package包/类
public static IInterface createProxy(boolean external, String authority, IInterface provider) {
if (provider instanceof Proxy && Proxy.getInvocationHandler(provider) instanceof ProviderHook) {
return provider;
}
ProviderHook.HookFetcher fetcher = ProviderHook.fetchHook(authority);
if (fetcher != null) {
ProviderHook hook = fetcher.fetch(external, provider);
IInterface proxyProvider = ProviderHook.createProxy(provider, hook);
if (proxyProvider != null) {
provider = proxyProvider;
}
}
return provider;
}
示例13: marshal
import java.lang.reflect.Proxy; //导入方法依赖的package包/类
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final InvocationHandler invocationHandler = Proxy.getInvocationHandler(source);
addInterfacesToXml(source, writer);
writer.startNode("handler");
final String attributeName = mapper.aliasForSystemAttribute("class");
if (attributeName != null) {
writer.addAttribute(attributeName, mapper.serializedClass(invocationHandler.getClass()));
}
context.convertAnother(invocationHandler);
writer.endNode();
}
示例14: 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));
}
示例15: equals
import java.lang.reflect.Proxy; //导入方法依赖的package包/类
private boolean equals(Object proxy, Object other) {
if (other == null)
return false;
final Class<?> proxyClass = proxy.getClass();
final Class<?> otherClass = other.getClass();
if (proxyClass != otherClass)
return false;
InvocationHandler otherih = Proxy.getInvocationHandler(other);
if (!(otherih instanceof CompositeDataInvocationHandler))
return false;
CompositeDataInvocationHandler othercdih =
(CompositeDataInvocationHandler) otherih;
return compositeData.equals(othercdih.compositeData);
}