src/java.management/share/classes/javax/management/openmbean/CompositeDataInvocationHandler.java
author darcy
Wed, 23 Oct 2019 13:01:40 -0700
changeset 58766 54ffb15c4839
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.* Reviewed-by: rriggs, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21656
diff changeset
     2
 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management.openmbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.jmx.mbeanserver.MXBeanLookup;
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
    29
import com.sun.jmx.mbeanserver.MXBeanMapping;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
    30
import com.sun.jmx.mbeanserver.MXBeanMappingFactory;
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
    31
import com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.reflect.InvocationHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.reflect.Proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
   <p>An {@link InvocationHandler} that forwards getter methods to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
   {@link CompositeData}.  If you have an interface that contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
   only getter methods (such as {@code String getName()} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
   {@code boolean isActive()}) then you can use this class in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
   conjunction with the {@link Proxy} class to produce an implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
   of the interface where each getter returns the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
   corresponding item in a {@code CompositeData}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
   <p>For example, suppose you have an interface like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
   <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
   <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
   public interface NamedNumber {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
       public int getNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
       public String getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
   </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
   </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
   and a {@code CompositeData} constructed like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
   <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
   <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
   CompositeData cd =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
       new {@link CompositeDataSupport}(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
           someCompositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
           new String[] {"number", "name"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
           new Object[] {<b>5</b>, "five"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
       );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
   </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
   </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
   then you can construct an object implementing {@code NamedNumber}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
   and backed by the object {@code cd} like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
   <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
   <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
   InvocationHandler handler =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
       new CompositeDataInvocationHandler(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
   NamedNumber nn = (NamedNumber)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
       Proxy.newProxyInstance(NamedNumber.class.getClassLoader(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                              new Class[] {NamedNumber.class},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                              handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
   </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
   </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 18220
diff changeset
    83
   A call to {@code nn.getNumber()} will then return <b>5</b>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
   <p>If the first letter of the property defined by a getter is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
   capital, then this handler will look first for an item in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
   {@code CompositeData} beginning with a capital, then, if that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
   not found, for an item beginning with the corresponding lowercase
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
   letter or code point.  For a getter called {@code getNumber()}, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
   handler will first look for an item called {@code Number}, then for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
   {@code number}.  If the getter is called {@code getnumber()}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
   the item must be called {@code number}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
   <p>If the method given to {@link #invoke invoke} is the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
   {@code boolean equals(Object)} inherited from {@code Object}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
   it will return true if and only if the argument is a {@code Proxy}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
   whose {@code InvocationHandler} is also a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
   CompositeDataInvocationHandler} and whose backing {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
   CompositeData} is equal (not necessarily identical) to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
   object's.  If the method given to {@code invoke} is the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
   {@code int hashCode()} inherited from {@code Object}, then it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
   return a value that is consistent with this definition of {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
   equals}: if two objects are equal according to {@code equals}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
   they will have the same {@code hashCode}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
   @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
public class CompositeDataInvocationHandler implements InvocationHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
       <p>Construct a handler backed by the given {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
       CompositeData}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
       @param compositeData the {@code CompositeData} that will supply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
       information to getters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
       @throws IllegalArgumentException if {@code compositeData}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
       is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public CompositeDataInvocationHandler(CompositeData compositeData) {
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   120
        this(compositeData, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
       <p>Construct a handler backed by the given {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
       CompositeData}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
       @param compositeData the {@code CompositeData} that will supply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
       information to getters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
       @throws IllegalArgumentException if {@code compositeData}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
       is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    CompositeDataInvocationHandler(CompositeData compositeData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                   MXBeanLookup lookup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (compositeData == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            throw new IllegalArgumentException("compositeData");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        this.compositeData = compositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        this.lookup = lookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
       Return the {@code CompositeData} that was supplied to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
       constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
       @return the {@code CompositeData} that this handler is backed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
       by.  This is never null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public CompositeData getCompositeData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        assert compositeData != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return compositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public Object invoke(Object proxy, Method method, Object[] args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        final String methodName = method.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // Handle the methods from java.lang.Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (method.getDeclaringClass() == Object.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            if (methodName.equals("toString") && args == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                return "Proxy[" + compositeData + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            else if (methodName.equals("hashCode") && args == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                return compositeData.hashCode() + 0x43444948;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            else if (methodName.equals("equals") && args.length == 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                && method.getParameterTypes()[0] == Object.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                return equals(proxy, args[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                /* Either someone is calling invoke by hand, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                   it is a non-final method from Object overriden
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                   by the generated Proxy.  At the time of writing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                   the only non-final methods in Object that are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                   handled above are finalize and clone, and these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                   are not overridden in generated proxies.  */
18220
1d724730bd2c 8007467: Better JMX type conversion
sjiang
parents: 14342
diff changeset
   172
                // this plain Method.invoke is called only if the declaring class
1d724730bd2c 8007467: Better JMX type conversion
sjiang
parents: 14342
diff changeset
   173
                // is Object and so it's safe.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                return method.invoke(this, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   178
        String propertyName = DefaultMXBeanMappingFactory.propertyName(method);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (propertyName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            throw new IllegalArgumentException("Method is not getter: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                               method.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        Object openValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (compositeData.containsKey(propertyName))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            openValue = compositeData.get(propertyName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        else {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   187
            String decap = DefaultMXBeanMappingFactory.decapitalize(propertyName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            if (compositeData.containsKey(decap))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                openValue = compositeData.get(decap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    "No CompositeData item " + propertyName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    (decap.equals(propertyName) ? "" : " or " + decap) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    " to match " + methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                throw new IllegalArgumentException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   198
        MXBeanMapping mapping =
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   199
            MXBeanMappingFactory.DEFAULT.mappingForType(method.getGenericReturnType(),
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   200
                                   MXBeanMappingFactory.DEFAULT);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 2
diff changeset
   201
        return mapping.fromOpenValue(openValue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /* This method is called when equals(Object) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * called on our proxy and hence forwarded to us.  For example, if we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * are a proxy for an interface like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * public interface GetString {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *     public String string();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * then we must compare equal to another CompositeDataInvocationHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * proxy for the same interface and where string() returns the same value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * You might think that we should also compare equal to another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * object that implements GetString directly rather than using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Proxy, provided that its string() returns the same result as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * ours, and in fact an earlier version of this class did that (by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * converting the other object into a CompositeData and comparing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * that with ours).  But in fact that doesn't make a great deal of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * sense because there's absolutely no guarantee that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * resulting equals would be reflexive (otherObject.equals(this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * might be false even if this.equals(otherObject) is true), and,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * especially, there's no way we could generate a hashCode() that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * would be equal to otherObject.hashCode() when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * this.equals(otherObject), because we don't know how
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * otherObject.hashCode() is computed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    private boolean equals(Object proxy, Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (other == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   231
        final Class<?> proxyClass = proxy.getClass();
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 715
diff changeset
   232
        final Class<?> otherClass = other.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (proxyClass != otherClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        InvocationHandler otherih = Proxy.getInvocationHandler(other);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (!(otherih instanceof CompositeDataInvocationHandler))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        CompositeDataInvocationHandler othercdih =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            (CompositeDataInvocationHandler) otherih;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return compositeData.equals(othercdih.compositeData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    private final CompositeData compositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    private final MXBeanLookup lookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}