1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.commons.proxy2;
19
20 /**
21 * ProxyFactory interface.
22 *
23 * @since 2.0
24 */
25 public interface ProxyFactory
26 {
27 //******************************************************************************************************************
28 // Other Methods
29 //******************************************************************************************************************
30
31 /**
32 * Learn whether this {@link ProxyFactory} is capable of creating a proxy for the specified set of classes.
33 *
34 * @param proxyClasses
35 * the proxy2 classes
36 * @return boolean
37 */
38 boolean canProxy(Class<?>... proxyClasses);
39
40 /**
41 * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>. The proxy will be
42 * generated using the current thread's "context class loader."
43 *
44 * @param delegateProvider
45 * the delegate provider
46 * @param proxyClasses
47 * the interfaces that the proxy should implement
48 * @return a proxy which delegates to the object provided by the target object provider
49 */
50 <T> T createDelegatorProxy(ObjectProvider<?> delegateProvider, Class<?>... proxyClasses);
51
52 /**
53 * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>.
54 *
55 * @param classLoader
56 * the class loader to use when generating the proxy
57 * @param delegateProvider
58 * the delegate provider
59 * @param proxyClasses
60 * the interfaces that the proxy should implement
61 * @return a proxy which delegates to the object provided by the target <code>delegateProvider>
62 */
63 <T> T createDelegatorProxy(ClassLoader classLoader, ObjectProvider<?> delegateProvider, Class<?>... proxyClasses);
64
65 /**
66 * Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
67 * <code>target</code> object. The proxy will be generated using the current thread's "context class loader."
68 *
69 * @param target
70 * the target object
71 * @param interceptor
72 * the method interceptor
73 * @param proxyClasses
74 * the interfaces that the proxy should implement
75 * @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
76 * <code>target</code> object.
77 */
78 <T> T createInterceptorProxy(Object target, Interceptor interceptor, Class<?>... proxyClasses);
79
80 /**
81 * Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
82 * <code>target</code> object.
83 *
84 * @param classLoader
85 * the class loader to use when generating the proxy
86 * @param target
87 * the target object
88 * @param interceptor
89 * the method interceptor
90 * @param proxyClasses
91 * the interfaces that the proxy should implement.
92 * @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
93 * <code>target</code> object.
94 */
95 <T> T createInterceptorProxy(ClassLoader classLoader, Object target, Interceptor interceptor,
96 Class<?>... proxyClasses);
97
98 /**
99 * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations. The proxy will be
100 * generated using the current thread's "context class loader."
101 *
102 * @param invoker
103 * the invoker
104 * @param proxyClasses
105 * the interfaces that the proxy should implement
106 * @return a proxy which uses the provided {@link Invoker} to handle all method invocations
107 */
108 <T> T createInvokerProxy(Invoker invoker, Class<?>... proxyClasses);
109
110 /**
111 * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations.
112 *
113 * @param classLoader
114 * the class loader to use when generating the proxy
115 * @param invoker
116 * the invoker
117 * @param proxyClasses
118 * the interfaces that the proxy should implement
119 * @return a proxy which uses the provided {@link Invoker} to handle all method invocations
120 */
121 <T> T createInvokerProxy(ClassLoader classLoader, Invoker invoker, Class<?>... proxyClasses);
122 }