final Object fromCompositeData(CompositeData cd, String[] itemNames, MXBeanMapping[] converters) { final Class<?> targetClass = getTargetClass(); return Proxy.newProxyInstance(targetClass.getClassLoader(), new Class<?>[] {targetClass}, new CompositeDataInvocationHandler(cd)); }
static boolean equal(Object o1, Object o2, NamedMXBeans namedMXBeans) { if (o1 == o2) return true; if (o1 == null || o2 == null) return false; if (o1.getClass().isArray()) { if (!o2.getClass().isArray()) return false; return deepEqual(o1, o2, namedMXBeans); } if (o1 instanceof Map) { if (!(o2 instanceof Map)) return false; return equalMap((Map) o1, (Map) o2, namedMXBeans); } if (o1 instanceof CompositeData && o2 instanceof CompositeData) { return compositeDataEqual((CompositeData) o1, (CompositeData) o2, namedMXBeans); } if (Proxy.isProxyClass(o1.getClass())) { if (Proxy.isProxyClass(o2.getClass())) return proxyEqual(o1, o2, namedMXBeans); InvocationHandler ih = Proxy.getInvocationHandler(o1); // if (ih instanceof MXBeanInvocationHandler) { // return proxyEqualsObject((MXBeanInvocationHandler) ih, // o2, namedMXBeans); if (ih instanceof MBeanServerInvocationHandler) { return true; } else if (ih instanceof CompositeDataInvocationHandler) { return o2.equals(o1); // We assume the other object has a reasonable equals method } } else if (Proxy.isProxyClass(o2.getClass())) return equal(o2, o1, namedMXBeans); return o1.equals(o2); }
private static boolean proxyEqual(Object proxy1, Object proxy2, NamedMXBeans namedMXBeans) { if (proxy1.getClass() != proxy2.getClass()) return proxy1.equals(proxy2); InvocationHandler ih1 = Proxy.getInvocationHandler(proxy1); InvocationHandler ih2 = Proxy.getInvocationHandler(proxy2); if (!(ih1 instanceof CompositeDataInvocationHandler) || !(ih2 instanceof CompositeDataInvocationHandler)) return proxy1.equals(proxy2); CompositeData cd1 = ((CompositeDataInvocationHandler) ih1).getCompositeData(); CompositeData cd2 = ((CompositeDataInvocationHandler) ih2).getCompositeData(); return compositeDataEqual(cd1, cd2, namedMXBeans); }
final Object fromCompositeData(CompositeData cd, String[] itemNames, OpenTypeConverter[] converters) { final Class targetClass = getTargetClass(); return Proxy.newProxyInstance(targetClass.getClassLoader(), new Class[] {targetClass}, new CompositeDataInvocationHandler(cd)); }