001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.proxy2; 019 020/** 021 * ProxyFactory interface. 022 * 023 * @since 2.0 024 */ 025public interface ProxyFactory 026{ 027 //****************************************************************************************************************** 028 // Other Methods 029 //****************************************************************************************************************** 030 031 /** 032 * Learn whether this {@link ProxyFactory} is capable of creating a proxy for the specified set of classes. 033 * 034 * @param proxyClasses 035 * the proxy2 classes 036 * @return boolean 037 */ 038 boolean canProxy(Class<?>... proxyClasses); 039 040 /** 041 * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>. The proxy will be 042 * generated using the current thread's "context class loader." 043 * 044 * @param delegateProvider 045 * the delegate provider 046 * @param proxyClasses 047 * the interfaces that the proxy should implement 048 * @return a proxy which delegates to the object provided by the target object provider 049 */ 050 <T> T createDelegatorProxy(ObjectProvider<?> delegateProvider, Class<?>... proxyClasses); 051 052 /** 053 * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>. 054 * 055 * @param classLoader 056 * the class loader to use when generating the proxy 057 * @param delegateProvider 058 * the delegate provider 059 * @param proxyClasses 060 * the interfaces that the proxy should implement 061 * @return a proxy which delegates to the object provided by the target <code>delegateProvider> 062 */ 063 <T> T createDelegatorProxy(ClassLoader classLoader, ObjectProvider<?> delegateProvider, Class<?>... proxyClasses); 064 065 /** 066 * Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the 067 * <code>target</code> object. The proxy will be generated using the current thread's "context class loader." 068 * 069 * @param target 070 * the target object 071 * @param interceptor 072 * the method interceptor 073 * @param proxyClasses 074 * the interfaces that the proxy should implement 075 * @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the 076 * <code>target</code> object. 077 */ 078 <T> T createInterceptorProxy(Object target, Interceptor interceptor, Class<?>... proxyClasses); 079 080 /** 081 * Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the 082 * <code>target</code> object. 083 * 084 * @param classLoader 085 * the class loader to use when generating the proxy 086 * @param target 087 * the target object 088 * @param interceptor 089 * the method interceptor 090 * @param proxyClasses 091 * the interfaces that the proxy should implement. 092 * @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the 093 * <code>target</code> object. 094 */ 095 <T> T createInterceptorProxy(ClassLoader classLoader, Object target, Interceptor interceptor, 096 Class<?>... proxyClasses); 097 098 /** 099 * 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}