2362N/A * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A <p>An {@link InvocationHandler} that forwards getter methods to a 0N/A {@link CompositeData}. If you have an interface that contains 0N/A only getter methods (such as {@code String getName()} or 0N/A {@code boolean isActive()}) then you can use this class in 0N/A conjunction with the {@link Proxy} class to produce an implementation 0N/A of the interface where each getter returns the value of the 0N/A corresponding item in a {@code CompositeData}.</p> 0N/A <p>For example, suppose you have an interface like this: 0N/A public interface NamedNumber { 0N/A public int getNumber(); 0N/A public String getName(); 0N/A and a {@code CompositeData} constructed like this: 0N/A new {@link CompositeDataSupport}( 0N/A new String[] {"number", "name"}, 0N/A new Object[] {<b>5</b>, "five"} 0N/A then you can construct an object implementing {@code NamedNumber} 0N/A and backed by the object {@code cd} like this: 0N/A InvocationHandler handler = 0N/A new CompositeDataInvocationHandler(cd); 0N/A NamedNumber nn = (NamedNumber) 0N/A Proxy.newProxyInstance(NamedNumber.class.getClassLoader(), 0N/A new Class[] {NamedNumber.class}, 0N/A A call to {@code nn.getNumber()} will then return <b>5</b>.</p> 0N/A <p>If the first letter of the property defined by a getter is a 0N/A capital, then this handler will look first for an item in the 0N/A {@code CompositeData} beginning with a capital, then, if that is 0N/A not found, for an item beginning with the corresponding lowercase 0N/A letter or code point. For a getter called {@code getNumber()}, the 0N/A handler will first look for an item called {@code Number}, then for 0N/A {@code number}. If the getter is called {@code getnumber()}, then 0N/A the item must be called {@code number}.</p> 0N/A <p>If the method given to {@link #invoke invoke} is the method 0N/A {@code boolean equals(Object)} inherited from {@code Object}, then 0N/A it will return true if and only if the argument is a {@code Proxy} 0N/A whose {@code InvocationHandler} is also a {@code 0N/A CompositeDataInvocationHandler} and whose backing {@code 0N/A CompositeData} is equal (not necessarily identical) to this 0N/A object's. If the method given to {@code invoke} is the method 0N/A {@code int hashCode()} inherited from {@code Object}, then it will 0N/A return a value that is consistent with this definition of {@code 0N/A equals}: if two objects are equal according to {@code equals}, then 0N/A they will have the same {@code hashCode}.</p> 0N/A <p>Construct a handler backed by the given {@code 0N/A @param compositeData the {@code CompositeData} that will supply 0N/A information to getters. 0N/A @throws IllegalArgumentException if {@code compositeData} 0N/A <p>Construct a handler backed by the given {@code 0N/A @param mbsc the {@code MBeanServerConnection} related to this 0N/A {@code CompositeData}. This is only relevant if a method in 0N/A the interface for which this is an invocation handler returns 0N/A a type that is an MXBean interface. Otherwise, it can be null. 0N/A @param compositeData the {@code CompositeData} that will supply 0N/A information to getters. 0N/A @throws IllegalArgumentException if {@code compositeData} 0N/A Return the {@code CompositeData} that was supplied to the 0N/A @return the {@code CompositeData} that this handler is backed 0N/A by. This is never null. 0N/A // Handle the methods from java.lang.Object 0N/A /* Either someone is calling invoke by hand, or 0N/A it is a non-final method from Object overriden 0N/A by the generated Proxy. At the time of writing, 0N/A the only non-final methods in Object that are not 0N/A handled above are finalize and clone, and these 0N/A are not overridden in generated proxies. */ 6287N/A // this plain Method.invoke is called only if the declaring class 6287N/A // is Object and so it's safe. 0N/A /* This method is called when equals(Object) is 0N/A * called on our proxy and hence forwarded to us. For example, if we 0N/A * are a proxy for an interface like this: 0N/A * public interface GetString { 0N/A * public String string(); 0N/A * then we must compare equal to another CompositeDataInvocationHandler 0N/A * proxy for the same interface and where string() returns the same value. 0N/A * You might think that we should also compare equal to another 0N/A * object that implements GetString directly rather than using 0N/A * Proxy, provided that its string() returns the same result as 0N/A * ours, and in fact an earlier version of this class did that (by 0N/A * converting the other object into a CompositeData and comparing 0N/A * that with ours). But in fact that doesn't make a great deal of 0N/A * sense because there's absolutely no guarantee that the 0N/A * resulting equals would be reflexive (otherObject.equals(this) 0N/A * might be false even if this.equals(otherObject) is true), and, 0N/A * especially, there's no way we could generate a hashCode() that 0N/A * would be equal to otherObject.hashCode() when 0N/A * this.equals(otherObject), because we don't know how 0N/A * otherObject.hashCode() is computed.