001/*
002 * (c) 2003-2005, 2009, 2010 ThoughtWorks Ltd
003 * All rights reserved.
004 *
005 * The software in this package is published under the terms of the BSD
006 * style license a copy of which has been included with this distribution in
007 * the LICENSE.txt file.
008 * 
009 * Created on 03-May-2004
010 */
011package com.thoughtworks.proxy;
012
013import java.io.Serializable;
014
015
016/**
017 * Abstraction layer for proxy generation. Depending on this interface (rather than {@link java.lang.reflect.Proxy}
018 * directly) will allow you to use Java's standard proxy mechanism interchangeably with e.g. CGLIB.
019 *
020 * @author Aslak Hellesøy
021 * @since 0.1
022 */
023public interface ProxyFactory extends Serializable {
024
025    /**
026     * Create a new proxy instance.
027     * 
028     * @param <T> The proxy's type. 
029     * @param invoker the invocation handler.
030     * @param types   the types the proxy must emulate.
031     * @return the new proxy instance.
032     * @since 1.0
033     */
034    <T> T createProxy(Invoker invoker, Class<?>... types);
035
036    /**
037     * Test if the ProxyFactory implementation is capable of creating a proxy instance for the given type.
038     *
039     * @param type the type to create a proxy instance for.
040     * @return <code>true</code> if the type is supported.
041     * @since 0.1
042     */
043    boolean canProxy(Class<?> type);
044
045    /**
046     * Test if the given type is a proxy class.
047     *
048     * @param type the type to examine.
049     * @return <code>true</code> if the given type is a proxy class.
050     * @since 0.1
051     */
052    boolean isProxyClass(Class<?> type);
053
054    /**
055     * Retrieve the invocation handler of the proxy.
056     *
057     * @param proxy the proxy instance.
058     * @return the {@link Invoker} instance acting as invocation handler.
059     * @since 0.1
060     */
061    Invoker getInvoker(Object proxy);
062}