Home | History | Annotate | Download | only in reflect

Lines Matching defs:Proxy

56  * {@code Proxy} provides static methods for creating dynamic proxy
58 * dynamic proxy classes created by those methods.
60 * <p>To create a proxy for some interface {@code Foo}:
63 * Class&lt;?&gt; proxyClass = Proxy.getProxyClass(Foo.class.getClassLoader(), Foo.class);
69 * Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(),
74 * <p>A <i>dynamic proxy class</i> (simply referred to as a <i>proxy
79 * A <i>proxy interface</i> is such an interface that is implemented
80 * by a proxy class.
82 * A <i>proxy instance</i> is an instance of a proxy class.
84 * Each proxy instance has an associated <i>invocation handler</i>
86 * A method invocation on a proxy instance through one of its proxy
88 * invoke} method of the instance's invocation handler, passing the proxy
94 * the proxy instance.
96 * <p>A proxy class has the following properties:
99 * <li>Proxy classes are <em>public, final, and not abstract</em> if
100 * all proxy interfaces are public.</li>
102 * <li>Proxy classes are <em>non-public, final, and not abstract</em> if
103 * any of the proxy interfaces is non-public.</li>
105 * <li>The unqualified name of a proxy class is unspecified. The space
106 * of class names that begin with the string {@code "$Proxy"}
107 * should be, however, reserved for proxy classes.
109 * <li>A proxy class extends {@code java.lang.reflect.Proxy}.
111 * <li>A proxy class implements exactly the interfaces specified at its
114 * <li>If a proxy class implements a non-public interface, then it will
116 * package of a proxy class is also unspecified. Note that package
117 * sealing will not prevent a proxy class from being successfully defined
122 * <li>Since a proxy class implements all of the interfaces specified at
129 * find methods in the proxy interfaces as would be expected.
131 * <li>The {@link Proxy#isProxyClass Proxy.isProxyClass} method will
132 * return true if it is passed a proxy class-- a class returned by
133 * {@code Proxy.getProxyClass} or the class of an object returned by
134 * {@code Proxy.newProxyInstance}-- and false otherwise.
136 * <li>The {@code java.security.ProtectionDomain} of a proxy class
139 * proxy class is generated by trusted system code. This protection
143 * <li>Each proxy class has one public constructor that takes one argument,
145 * the invocation handler for a proxy instance. Rather than having to use
146 * the reflection API to access the public constructor, a proxy instance
147 * can be also be created by calling the {@link Proxy#newProxyInstance
148 * Proxy.newProxyInstance} method, which combines the actions of calling
149 * {@link Proxy#getProxyClass Proxy.getProxyClass} with invoking the
153 * <p>A proxy instance has the following properties:
156 * <li>Given a proxy instance {@code proxy} and one of the
157 * interfaces implemented by its proxy class {@code Foo}, the
160 * {@code proxy instanceof Foo}
165 * {@code (Foo) proxy}
168 * <li>Each proxy instance has an associated invocation handler, the one
170 * {@link Proxy#getInvocationHandler Proxy.getInvocationHandler} method
171 * will return the invocation handler associated with the proxy instance
174 * <li>An interface method invocation on a proxy instance will be
181 * {@code java.lang.Object} on a proxy instance will be encoded and
186 * {@code java.lang.Object}. Other public methods of a proxy
188 * overridden by a proxy class, so invocations of those methods behave
192 * <h3>Methods Duplicated in Multiple Proxy Interfaces</h3>
194 * <p>When two or more interfaces of a proxy class contain a method with
195 * the same name and parameter signature, the order of the proxy class's
197 * is invoked on a proxy instance, the {@code Method} object passed
200 * that the proxy's method was invoked through. This limitation exists
201 * because the corresponding method implementation in the generated proxy
203 * Therefore, when a duplicate method is invoked on a proxy instance,
206 * superinterface) in the proxy class's list of interfaces is passed to
210 * <p>If a proxy interface contains a method with the same name and
213 * when such a method is invoked on a proxy instance, the
217 * logically precede all of the proxy interfaces for the determination of
224 * the proxy interfaces that it can be invoked through. If the
227 * of the proxy interfaces that it can be invoked through, then an
229 * the invocation on the proxy instance. This restriction means that not
239 public class Proxy implements java.io.Serializable {
243 /** parameter types of a proxy class constructor */
248 * a cache of proxy classes
254 * the invocation handler for this proxy instance.
262 private Proxy() {
266 * Constructs a new {@code Proxy} instance from a subclass
267 * (typically, a dynamic proxy class) with the specified value
270 * @param h the invocation handler for this proxy instance
275 protected Proxy(InvocationHandler h) {
281 * Returns the {@code java.lang.Class} object for a proxy class
282 * given a class loader and an array of interfaces. The proxy class
285 * is non-public, the proxy class will be non-public. If a proxy class
287 * class loader, then the existing proxy class will be returned; otherwise,
288 * a proxy class for those interfaces will be generated dynamically
292 * passed to {@code Proxy.getProxyClass}:
311 * otherwise, it would not be possible for the proxy class to
326 * <li>The resulting proxy class must not exceed any limits imposed
334 * {@code Proxy.getProxyClass} will throw an
339 * <p>Note that the order of the specified proxy interfaces is
340 * significant: two requests for a proxy class with the same combination
342 * proxy classes.
344 * @param loader the class loader to define the proxy class
345 * @param interfaces the list of interfaces for the proxy class
347 * @return a proxy class that is defined in the specified class loader
361 * <li> for each proxy interface, {@code intf},
393 * Check permissions required to create a Proxy class.
395 * To define a proxy class, it performs the access checks as in
400 * To get a constructor and new instance of a proxy class, it performs
404 * If an interface is non-public, the proxy class must be defined by
407 * will throw IllegalAccessError when the generated proxy class is
426 * Generate a proxy class. Must call the checkProxyAccess method
435 // If the proxy class defined by the given loader implementing
437 // otherwise, it will create the proxy class via the ProxyClassFactory
442 * a key used for proxy class with 0 implemented interfaces
452 * a key used for proxy class with 1 implemented interface
479 * a key used for proxy class with 2 implemented interfaces
510 * a key used for proxy class with any number of implemented interfaces
599 * A factory function that generates, defines and returns the proxy class given
605 // prefix for all proxy class names
606 private static final String proxyClassNamePrefix = "$Proxy";
608 // next number to use for generation of unique proxy class names
646 String proxyPkg = null; // package to define proxy class in
650 * Record the package of a non-public proxy interface so that the
651 * proxy class will be defined in the same package. Verify that
652 * all non-public proxy interfaces are in the same package.
671 // if no non-public proxy interfaces, use the default package.
676 // Android-changed: Generate the proxy directly instead of calling
687 * Choose a name for the proxy class to generate.
809 * Returns an instance of a proxy class for the specified interfaces
813 * <p>{@code Proxy.newProxyInstance} throws
815 * {@code Proxy.getProxyClass} does.
817 * @param loader the class loader to define the proxy class
818 * @param interfaces the list of interfaces for the proxy class
821 * @return a proxy instance with the specified invocation handler of a
822 * proxy class that is defined by the specified class loader
836 * <li> for each proxy interface, {@code intf},
841 * <li> any of the given proxy interfaces is non-public and the
871 * Look up or generate the designated proxy class.
927 // of the proxy class
944 * generated to be a proxy class using the {@code getProxyClass}
949 * not just test if the class in question extends {@code Proxy}.
952 * @return {@code true} if the class is a proxy class and
957 return Proxy.class.isAssignableFrom(cl) && proxyClassCache.containsValue(cl);
961 * Returns the invocation handler for the specified proxy instance.
963 * @param proxy the proxy instance to return the invocation handler for
964 * @return the invocation handler for the proxy instance
966 * proxy instance
975 public static InvocationHandler getInvocationHandler(Object proxy)
979 * Verify that the object is actually a proxy instance.
981 if (!isProxyClass(proxy.getClass())) {
982 throw new IllegalArgumentException("not a proxy instance");
985 final Proxy p = (Proxy) proxy;
1003 // Android-added: Helper method invoke(Proxy, Method, Object[]) for ART native code.
1004 private static Object invoke(Proxy proxy, Method method, Object[] args) throws Throwable {
1005 InvocationHandler h = proxy.h;
1006 return h.invoke(proxy, method, args);