commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r964636 [2/3] - in /commons/proper/proxy/branches/version-2.0-work: ./ cglib/ cglib/src/ cglib/src/main/ cglib/src/main/java/ cglib/src/main/java/org/ cglib/src/main/java/org/apache/ cglib/src/main/java/org/apache/commons/ cglib/src/main/ja...
Date Thu, 15 Jul 2010 23:10:46 GMT
Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassCache.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.impl;
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ * A cache for storing implementation classes for proxies based on a specific type of {@link ProxyClassGenerator}.  A
+ * proxy class cache ensures that there is only one class for every
+ * {@link ProxyClassGenerator}/{@link ClassLoader}/proxy class array combination.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class ProxyClassCache
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+    private final Map loaderToClassCache = new WeakHashMap();
+    private final ProxyClassGenerator proxyClassGenerator;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    public ProxyClassCache( ProxyClassGenerator proxyClassGenerator )
+    {
+        this.proxyClassGenerator = proxyClassGenerator;
+    }
+
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+    private Map getClassCache( ClassLoader classLoader )
+    {
+        Map cache = ( Map ) loaderToClassCache.get(classLoader);
+        if( cache == null )
+        {
+            cache = new HashMap();
+            loaderToClassCache.put(classLoader, cache);
+        }
+        return cache;
+    }
+
+    private String toClassCacheKey( Class[] proxyClasses )
+    {
+        final StringBuffer sb = new StringBuffer();
+        for( int i = 0; i < proxyClasses.length; i++ )
+        {
+            Class proxyInterface = proxyClasses[i];
+            sb.append(proxyInterface.getName());
+            if( i != proxyClasses.length - 1 )
+            {
+                sb.append(",");
+            }
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Returns the proxy class generated by the {@link ProxyClassGenerator} using the specified {@link ClassLoader} and
+     * array of proxy classes.
+     *
+     * @param classLoader  the classloader
+     * @param proxyClasses the proxy classes
+     * @return the proxy class generated by the {@link ProxyClassGenerator} using the specified {@link ClassLoader} and
+     *         array of proxy classes
+     */
+    public synchronized Class getProxyClass( ClassLoader classLoader, Class[] proxyClasses )
+    {
+        final Map classCache = getClassCache(classLoader);
+        final String key = toClassCacheKey(proxyClasses);
+        Class proxyClass;
+        WeakReference proxyClassReference = ( WeakReference ) classCache.get(key);
+        if( proxyClassReference == null )
+        {
+            proxyClass = proxyClassGenerator.generateProxyClass(classLoader, proxyClasses);
+            classCache.put(key, new WeakReference(proxyClass));
+        }
+        else
+        {
+            synchronized( proxyClassReference )
+            {
+                proxyClass = ( Class ) proxyClassReference.get();
+                if( proxyClass == null )
+                {
+                    proxyClass = proxyClassGenerator.generateProxyClass(classLoader, proxyClasses);
+                    classCache.put(key, new WeakReference(proxyClass));
+                }
+            }
+        }
+        return proxyClass;
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/impl/ProxyClassGenerator.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.impl;
+
+/**
+ * A proxy class generator generates specific type of proxies (interceptor, invoker, etc.).
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public interface ProxyClassGenerator
+{
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+    /**
+     * Generates a proxy class for the supplied {@link ClassLoader} and proxy classes.
+     *
+     * @param classLoader  the classloader
+     * @param proxyClasses the proxy classes
+     * @return the dynamically generated proxy class
+     */
+    public Class generateProxyClass( ClassLoader classLoader, Class[] proxyClasses );
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/DuckTypingInvoker.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.invoker;
+
+import org.apache.commons.proxy.Invoker;
+import org.apache.commons.proxy.ObjectProvider;
+
+import java.lang.reflect.Method;
+
+/**
+ * An invoker which supports <a href="http://en.wikipedia.org/wiki/Duck_typing">&quot;duck typing&quot;</a>, meaning
+ * that it finds a matching method on the object returned from the target provider and invokes it.  This class is
+ * useful for adapting an existing class to an interface it does not implement.
+ * <p>
+ * <b>Example:</b>
+ * </p>
+ * <p>
+ * <pre>
+ * public class LegacyDuck // Does not implement interface!
+ * {
+ *   public void quack()
+ *   {
+ *     // Quacking logic...
+ *   }
+ * }
+ * <p/>
+ * public interface Duck
+ * {
+ *   public void quack();
+ * }
+ * <p/>
+ * ObjectProvider targetProvider = new ConstantProvider(new LegacyDuck()); // Always returns a "legacy" duck
+ * DuckTypingInvoker invoker = new DuckTypingInvoker(targetProvider);
+ * Duck duck = ( Duck )proxyFactory.createInvokerProxy( invoker, new Class[] { Duck.class } );
+ * </pre>
+ * </p>
+ */
+public class DuckTypingInvoker implements Invoker
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+    private final ObjectProvider targetProvider;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    public DuckTypingInvoker( final ObjectProvider targetProvider )
+    {
+        this.targetProvider = targetProvider;
+    }
+
+//**********************************************************************************************************************
+// Invoker Implementation
+//**********************************************************************************************************************
+
+    public Object invoke( final Object proxy, final Method method, final Object[] arguments ) throws Throwable
+    {
+        final Object target = targetProvider.getObject();
+        final Class targetClass = target.getClass();
+        try
+        {
+            final Method targetMethod = targetClass.getMethod(method.getName(), method.getParameterTypes());
+            if( method.getReturnType().isAssignableFrom(targetMethod.getReturnType()) )
+            {
+                return targetMethod.invoke(target, arguments);
+            }
+            throw new UnsupportedOperationException(
+                    "Target type " + targetClass.getName() + " method has incompatible return type.");
+        }
+        catch( NoSuchMethodException e )
+        {
+            throw new UnsupportedOperationException(
+                    "Target type " + targetClass.getName() + " does not have a method matching " + method + ".");
+        }
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/InvocationHandlerAdapter.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.invoker;
+
+import org.apache.commons.proxy.Invoker;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+/**
+ * An adapter class to adapt the JDK's {@link InvocationHandler} interface to Commons Proxy's
+ * {@link Invoker} interface.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class InvocationHandlerAdapter implements Invoker
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+    private final InvocationHandler invocationHandler;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    public InvocationHandlerAdapter( InvocationHandler invocationHandler )
+    {
+        this.invocationHandler = invocationHandler;
+    }
+
+//**********************************************************************************************************************
+// Invoker Implementation
+//**********************************************************************************************************************
+
+
+    public Object invoke( Object proxy, Method method, Object[] arguments ) throws Throwable
+    {
+        return invocationHandler.invoke(proxy, method, arguments);
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/NullInvoker.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.invoker;
+
+import org.apache.commons.proxy.Invoker;
+import org.apache.commons.proxy.ProxyUtils;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
+/**
+ * An {@link Invoker} implementation which merely returns null for all method invocations.  This class is
+ * useful for scenarios where the "null object" design pattern is needed.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class NullInvoker implements Invoker, Serializable
+{
+//**********************************************************************************************************************
+// Invoker Implementation
+//**********************************************************************************************************************
+
+    public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable
+    {
+        final Class returnType = method.getReturnType();
+        return ProxyUtils.nullValue(returnType);
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/XmlRpcInvoker.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.invoker;
+
+import org.apache.commons.proxy.Invoker;
+import org.apache.commons.proxy.exception.InvokerException;
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.XmlRpcHandler;
+
+import java.lang.reflect.Method;
+import java.util.Vector;
+
+/**
+ * Uses <a href="http://ws.apache.org/xmlrpc/">Apache XML-RPC</a> to invoke methods on an XML-RPC service.
+ * <p/>
+ * <p>
+ * <b>Dependencies</b>:
+ * <ul>
+ * <li>Apache XML-RPC version 2.0 or greater</li>
+ * </ul>
+ * </p>
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class XmlRpcInvoker implements Invoker
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+    private final XmlRpcHandler handler;
+    private final String handlerName;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    public XmlRpcInvoker( XmlRpcHandler handler, String handlerName )
+    {
+        this.handler = handler;
+        this.handlerName = handlerName;
+    }
+
+//**********************************************************************************************************************
+// Invoker Implementation
+//**********************************************************************************************************************
+
+
+    public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable
+    {
+        final Object returnValue = handler.execute(handlerName + "." + method.getName(), toArgumentVector(args));
+        if( returnValue instanceof XmlRpcException )
+        {
+            throw new InvokerException("Unable to execute XML-RPC call.", ( XmlRpcException ) returnValue);
+        }
+        return returnValue;
+    }
+
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+    private Vector toArgumentVector( Object[] args )
+    {
+        final Vector v = new Vector();
+        for( int i = 0; i < args.length; i++ )
+        {
+            Object arg = args[i];
+            v.addElement(arg);
+        }
+        return v;
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/InvocationRecorder.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.invoker.recorder;
+
+import org.apache.commons.proxy.Invoker;
+import org.apache.commons.proxy.ProxyFactory;
+import org.apache.commons.proxy.ProxyUtils;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * @auothor James Carman
+ */
+public class InvocationRecorder
+{
+    private final ProxyFactory proxyFactory;
+    private List<RecordedInvocation> recordedInvocations = new LinkedList<RecordedInvocation>();
+
+    public InvocationRecorder( ProxyFactory proxyFactory )
+    {
+        this.proxyFactory = proxyFactory;
+    }
+
+    public List<RecordedInvocation> getRecordedInvocations()
+    {
+        return recordedInvocations;
+    }
+
+    public <T> T proxy( Class<T> type )
+    {
+        return proxy(type, type);
+    }
+
+    public <T> T proxy( Type genericType, Class<T> type )
+    {
+        if( proxyFactory.canProxy(type) )
+        {
+            return proxyFactory.createInvokerProxy(new InvocationRecorderInvoker(genericType), type);
+        }
+        return ProxyUtils.nullValue(type);
+    }
+
+    private class InvocationRecorderInvoker implements Invoker
+    {
+        private final Type targetType;
+
+        private InvocationRecorderInvoker( Type targetType )
+        {
+            this.targetType = targetType;
+        }
+
+        @SuppressWarnings("unchecked")
+        public Object invoke( Object o, Method method, Object[] args ) throws Throwable
+        {
+            recordedInvocations.add(new RecordedInvocation(method, args));
+            final Class returnType = getReturnType(targetType, method);
+            return proxy(method.getGenericReturnType(), returnType);
+        }
+    }
+
+    public void reset()
+    {
+        recordedInvocations.clear();
+    }
+
+    public static Class getReturnType( Type enclosingType, Method method ) throws Exception
+    {
+        Type returnType = method.getGenericReturnType();
+        if( returnType instanceof Class )
+        {
+            return ( Class ) returnType;
+        }
+        else if( returnType instanceof TypeVariable )
+        {
+            return resolveVariable(enclosingType, ( TypeVariable ) returnType);
+        }
+        else if( returnType instanceof ParameterizedType )
+        {
+            return ( Class ) ( ( ParameterizedType ) returnType ).getRawType();
+        }
+        return null;
+    }
+
+    public static Class resolveVariable( Type enclosingType, TypeVariable typeVar ) throws Exception
+    {
+        if( enclosingType instanceof ParameterizedType )
+        {
+            ParameterizedType pt = ( ParameterizedType ) enclosingType;
+            final Class rawType = ( Class ) pt.getRawType();
+            TypeVariable[] typeParameters = rawType.getTypeParameters();
+            for( int i = 0; i < typeParameters.length; i++ )
+            {
+                TypeVariable typeParameter = typeParameters[i];
+                if( typeParameter == typeVar )
+                {
+                    return ( Class ) pt.getActualTypeArguments()[i];
+                }
+            }
+        }
+        else if( enclosingType instanceof Class )
+        {
+            return resolveVariable(( ( Class ) enclosingType ).getGenericSuperclass(), typeVar);
+        }
+        return null;
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/invoker/recorder/RecordedInvocation.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.invoker.recorder;
+
+import org.apache.commons.proxy.ProxyUtils;
+
+import java.lang.reflect.Method;
+
+/**
+ * @auothor James Carman
+ */
+public class RecordedInvocation
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+    private final Method invokedMethod;
+    private final Object[] arguments;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    public RecordedInvocation( Method invokedMethod, Object[] arguments )
+    {
+        this.invokedMethod = invokedMethod;
+        this.arguments = arguments;
+    }
+
+//**********************************************************************************************************************
+// Canonical Methods
+//**********************************************************************************************************************
+
+    public Method getInvokedMethod()
+    {
+        return invokedMethod;
+    }
+
+    public Object[] getArguments()
+    {
+        return arguments;
+    }
+
+    public String toString()
+    {
+        StringBuffer buffer = new StringBuffer();
+        buffer.append(invokedMethod.getDeclaringClass().getName());
+        buffer.append(".");
+        buffer.append(invokedMethod.getName());
+        buffer.append("(");
+        int count = arguments.length;
+        for( int i = 0; i < count; i++ )
+        {
+            Object arg = arguments[i];
+            if( i > 0 )
+            {
+                buffer.append(", ");
+            }
+            convert(buffer, arg);
+        }
+        buffer.append(")");
+        return buffer.toString();
+    }
+
+    protected void convert( StringBuffer buffer, Object input )
+    {
+        if( input == null )
+        {
+            buffer.append("<null>");
+            return;
+        }
+
+        // Primitive types, and non-object arrays
+        // use toString().
+        if( !( input instanceof Object[] ) )
+        {
+            buffer.append(input.toString());
+            return;
+        }
+        else
+        {
+            buffer.append("(");
+            buffer.append(ProxyUtils.getJavaClassName(input.getClass()));
+            buffer.append("){");
+            Object[] array = ( Object[] ) input;
+            int count = array.length;
+            for( int i = 0; i < count; i++ )
+            {
+                if( i > 0 )
+                {
+                    buffer.append(", ");
+                }
+                // We use convert() again, because it could be a multi-dimensional array
+                // where each element must be converted.
+                convert(buffer, array[i]);
+            }
+            buffer.append("}");
+        }
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/BeanProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/BeanProvider.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/BeanProvider.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/BeanProvider.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.provider;
+
+import org.apache.commons.proxy.ObjectProvider;
+import org.apache.commons.proxy.exception.ObjectProviderException;
+
+import java.io.Serializable;
+
+/**
+ * Uses <code>Class.newInstance()</code> to instantiate an object.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class BeanProvider<T> implements ObjectProvider<T>, Serializable
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+    private Class<T> beanClass;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    public BeanProvider()
+    {
+    }
+
+    /**
+     * Constructs a provider which instantiates objects of the specified bean class.
+     *
+     * @param beanClass the bean class
+     */
+    public BeanProvider( Class<T> beanClass )
+    {
+        this.beanClass = beanClass;
+    }
+
+//**********************************************************************************************************************
+// ObjectProvider Implementation
+//**********************************************************************************************************************
+
+    public T getObject()
+    {
+        try
+        {
+            if( beanClass == null )
+            {
+                throw new ObjectProviderException("No bean class provided.");
+            }
+            return beanClass.newInstance();
+        }
+        catch( InstantiationException e )
+        {
+            throw new ObjectProviderException("Class " + beanClass.getName() + " is not concrete.", e);
+        }
+        catch( IllegalAccessException e )
+        {
+            throw new ObjectProviderException("Constructor for class " + beanClass.getName() + " is not accessible.",
+                    e);
+        }
+    }
+
+//**********************************************************************************************************************
+// Getter/Setter Methods
+//**********************************************************************************************************************
+
+    public void setBeanClass( Class<T> beanClass )
+    {
+        this.beanClass = beanClass;
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/CloningProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/CloningProvider.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/CloningProvider.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/CloningProvider.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.provider;
+
+import org.apache.commons.proxy.ObjectProvider;
+import org.apache.commons.proxy.ProxyUtils;
+import org.apache.commons.proxy.exception.ObjectProviderException;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Merely calls <code>clone()</code> (reflectively) on the given {@link Cloneable} object.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class CloningProvider<T extends Cloneable> implements ObjectProvider<T>, Serializable
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+    private final T cloneable;
+    private Method cloneMethod;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    /**
+     * Constructs a provider which returns clone copies of the specified {@link Cloneable}
+     * object.
+     *
+     * @param cloneable the object to clone
+     */
+    public CloningProvider( T cloneable )
+    {
+        this.cloneable = cloneable;
+    }
+
+//**********************************************************************************************************************
+// ObjectProvider Implementation
+//**********************************************************************************************************************
+
+    @SuppressWarnings("unchecked")
+    public T getObject()
+    {
+        try
+        {
+            return (T)getCloneMethod().invoke(cloneable, ProxyUtils.EMPTY_ARGUMENTS);
+        }
+        catch( IllegalAccessException e )
+        {
+            throw new ObjectProviderException(
+                    "Class " + cloneable.getClass().getName() + " does not have a public clone() method.", e);
+        }
+        catch( InvocationTargetException e )
+        {
+            throw new ObjectProviderException(
+                    "Attempt to clone object of type " + cloneable.getClass().getName() + " threw an exception.", e);
+        }
+    }
+
+//**********************************************************************************************************************
+// Getter/Setter Methods
+//**********************************************************************************************************************
+
+    private synchronized Method getCloneMethod()
+    {
+        if( cloneMethod == null )
+        {
+            try
+            {
+                cloneMethod = cloneable.getClass().getMethod("clone", ProxyUtils.EMPTY_ARGUMENT_TYPES);
+            }
+            catch( NoSuchMethodException e )
+            {
+                throw new ObjectProviderException(
+                        "Class " + cloneable.getClass().getName() + " does not have a public clone() method.");
+            }
+        }
+        return cloneMethod;
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/ConstantProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/ConstantProvider.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/ConstantProvider.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/ConstantProvider.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.provider;
+
+import org.apache.commons.proxy.ObjectProvider;
+
+import java.io.Serializable;
+
+/**
+ * Always returns the same object.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class ConstantProvider<T> implements ObjectProvider<T>, Serializable
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+    private final T constant;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    public ConstantProvider( T constant )
+    {
+        this.constant = constant;
+    }
+
+//**********************************************************************************************************************
+// ObjectProvider Implementation
+//**********************************************************************************************************************
+
+    public T getObject()
+    {
+        return constant;
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/NullProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/NullProvider.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/NullProvider.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/NullProvider.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.provider;
+
+/**
+ * Always returns null.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class NullProvider<T> extends ConstantProvider<T>
+{
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    public NullProvider()
+    {
+        super(null);
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/ProviderDecorator.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/ProviderDecorator.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/ProviderDecorator.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/ProviderDecorator.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.provider;
+
+import org.apache.commons.proxy.ObjectProvider;
+
+/**
+ * Returns the result of the inner {@link ObjectProvider provider}.  Subclasses can override the {@link #getObject()}
+ * method and decorate what comes back from the inner provider in some way (by {@link SingletonProvider caching it} for
+ * example).
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class ProviderDecorator<T> implements ObjectProvider<T>
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+    protected ObjectProvider<T> inner;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    public ProviderDecorator( ObjectProvider<T> inner )
+    {
+        this.inner = inner;
+    }
+
+//**********************************************************************************************************************
+// ObjectProvider Implementation
+//**********************************************************************************************************************
+
+    public T getObject()
+    {
+        return inner.getObject();
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/SingletonProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/SingletonProvider.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/SingletonProvider.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/main/java/org/apache/commons/proxy/provider/SingletonProvider.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.provider;
+
+import org.apache.commons.proxy.ObjectProvider;
+
+/**
+ * Wraps another object provider, making sure to only call it once, returning the value returned from the wrapped
+ * provider on all subsequent invocations.
+ *
+ * @author James Carman
+ * @since 1.0
+ */
+public class SingletonProvider<T> extends ProviderDecorator<T>
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+    private T instance;
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    public SingletonProvider( ObjectProvider<T> inner )
+    {
+        super(inner);
+    }
+
+//**********************************************************************************************************************
+// ObjectProvider Implementation
+//**********************************************************************************************************************
+
+    public T getObject()
+    {
+        synchronized( this )
+        {
+            if( instance == null )
+            {
+                instance = super.getObject();
+                inner = null; // Garbage collection
+            }
+        }
+        return instance;
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/AbstractProxyFactoryTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/AbstractProxyFactoryTestCase.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/AbstractProxyFactoryTestCase.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/AbstractProxyFactoryTestCase.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,392 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy;
+
+import org.apache.commons.proxy.provider.BeanProvider;
+import org.apache.commons.proxy.provider.ConstantProvider;
+import org.apache.commons.proxy.provider.SingletonProvider;
+import org.apache.commons.proxy.util.AbstractTestCase;
+import org.apache.commons.proxy.util.DuplicateEcho;
+import org.apache.commons.proxy.util.Echo;
+import org.apache.commons.proxy.util.EchoImpl;
+import org.apache.commons.proxy.util.SuffixInterceptor;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * @author James Carman
+ * @since 1.0
+ */
+public abstract class AbstractProxyFactoryTestCase extends AbstractTestCase
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+    private static final Class[] ECHO_ONLY = new Class[]{Echo.class};
+    protected final ProxyFactory factory;
+    private static final Class[] COMPARABLE_ONLY = new Class[] { Comparable.class };
+
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    protected AbstractProxyFactoryTestCase(ProxyFactory factory)
+    {
+        this.factory = factory;
+    }
+
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+    private ObjectProvider createSingletonEcho()
+    {
+        return new SingletonProvider(new BeanProvider(EchoImpl.class));
+    }
+
+    public void testInterceptorHashCode()
+    {
+        final Echo proxy = (Echo) factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), ECHO_ONLY);
+        assertEquals(proxy.hashCode(), System.identityHashCode(proxy));
+    }
+
+    public void testInvokerHashCode() throws Exception
+    {
+        final Echo proxy = (Echo) factory.createInvokerProxy(new InvokerTester(), ECHO_ONLY);
+        assertEquals(proxy.hashCode(), System.identityHashCode(proxy));
+    }
+
+    public void testDelegatorHashCode() throws Exception
+    {
+        final Echo proxy = factory.createDelegatorProxy(new ConstantProvider<Echo>(new EchoImpl()), Echo.class);
+        assertEquals(proxy.hashCode(), System.identityHashCode(proxy));
+    }
+
+
+    public void testInterceptorEquals()
+    {
+        final Date date = new Date();
+        final Comparable proxy1 = (Comparable) factory.createInterceptorProxy(date,
+                new NoOpMethodInterceptor(), COMPARABLE_ONLY);
+        final Comparable proxy2 = (Comparable) factory.createInterceptorProxy(date,
+                new NoOpMethodInterceptor(), COMPARABLE_ONLY);
+        assertEquals(proxy1, proxy1);
+        assertFalse(proxy1.equals(proxy2));
+        assertFalse(proxy2.equals(proxy1));
+    }
+
+    public void testInvokerEquals() throws Exception
+    {
+        final Comparable proxy1 = (Comparable) factory.createInvokerProxy(new InvokerTester(), COMPARABLE_ONLY);
+        final Comparable proxy2 = (Comparable) factory.createInvokerProxy(new InvokerTester(), COMPARABLE_ONLY);
+        assertEquals(proxy1, proxy1);
+        assertFalse(proxy1.equals(proxy2));
+        assertFalse(proxy2.equals(proxy1));
+    }
+
+    public void testDelegatorEquals() throws Exception
+    {
+        final Date date = new Date();
+        final Comparable proxy1 = (Comparable) factory.createDelegatorProxy(new ConstantProvider<Date>(date),
+                COMPARABLE_ONLY);
+        final Comparable proxy2 = (Comparable) factory.createDelegatorProxy(new ConstantProvider<Date>(date),
+                COMPARABLE_ONLY);
+        assertEquals(proxy1, proxy1);
+        assertFalse(proxy1.equals(proxy2));
+        assertFalse(proxy2.equals(proxy1));
+    }
+
+    public void testBooleanInterceptorParameter()
+    {
+        final Echo echo = (Echo) factory.createInterceptorProxy(new EchoImpl(), new InterceptorTester(), ECHO_ONLY);
+        assertFalse(echo.echoBack(false));
+        assertTrue(echo.echoBack(true));
+    }
+
+    public void testCanProxy()
+    {
+        assertTrue(factory.canProxy(Echo.class));
+        assertFalse(factory.canProxy(EchoImpl.class));
+    }
+
+    public void testChangingArguments()
+    {
+        final Echo proxy = (Echo) factory.createInterceptorProxy(new EchoImpl(), new ChangeArgumentInterceptor(), ECHO_ONLY);
+        assertEquals("something different", proxy.echoBack("whatever"));
+    }
+
+    public void testCreateDelegatingProxy()
+    {
+        final Echo echo = (Echo) factory.createDelegatorProxy(createSingletonEcho(), ECHO_ONLY);
+        echo.echo();
+        assertEquals("message", echo.echoBack("message"));
+        assertEquals("ab", echo.echoBack("a", "b"));
+    }
+
+    public void testCreateInterceptorProxy()
+    {
+        final Echo target = (Echo) factory.createDelegatorProxy(createSingletonEcho(), ECHO_ONLY);
+        final Echo proxy = (Echo) factory.createInterceptorProxy(target, new SuffixInterceptor(" suffix"), ECHO_ONLY);
+        proxy.echo();
+        assertEquals("message suffix", proxy.echoBack("message"));
+    }
+
+    public void testDelegatingProxyClassCaching() throws Exception
+    {
+        final Echo proxy1 = factory.createDelegatorProxy(new ConstantProvider<Echo>(new EchoImpl()), Echo.class);
+        final Echo proxy2 = factory.createDelegatorProxy(new ConstantProvider<Echo>(new EchoImpl()), Echo.class);
+        assertNotSame(proxy1, proxy2);
+        assertSame(proxy1.getClass(), proxy2.getClass());
+    }
+
+    public void testDelegatingProxyInterfaceOrder()
+    {
+        final Echo echo = (Echo) factory.createDelegatorProxy(createSingletonEcho(), Echo.class, DuplicateEcho.class);
+        final List<Class> expected = new LinkedList<Class>(Arrays.asList(Echo.class, DuplicateEcho.class));
+        final List<Class> actual = new LinkedList<Class>(Arrays.asList(echo.getClass().getInterfaces()));
+        actual.retainAll(expected);  // Doesn't alter order!
+        assertEquals(expected, actual);
+    }
+
+    public void testDelegatingProxySerializable() throws Exception
+    {
+        final Echo proxy = factory.createDelegatorProxy(new ConstantProvider<Echo>(new EchoImpl()), Echo.class);
+        assertSerializable(proxy);
+    }
+
+    public void testInterceptingProxyClassCaching() throws Exception
+    {
+        final Echo proxy1 = (Echo) factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), ECHO_ONLY);
+        final Echo proxy2 = (Echo) factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), ECHO_ONLY);
+        assertNotSame(proxy1, proxy2);
+        assertSame(proxy1.getClass(), proxy2.getClass());
+    }
+
+    public void testInterceptingProxySerializable() throws Exception
+    {
+        final Echo proxy = (Echo) factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), ECHO_ONLY);
+        assertSerializable(proxy);
+    }
+
+    public void testInterceptorProxyWithCheckedException() throws Exception
+    {
+        final Echo proxy = (Echo) factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), ECHO_ONLY);
+        try
+        {
+            proxy.ioException();
+            fail();
+        }
+        catch (IOException e)
+        {
+        }
+    }
+
+    public void testInterceptorProxyWithUncheckedException() throws Exception
+    {
+        final Echo proxy = (Echo) factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), ECHO_ONLY);
+        try
+        {
+            proxy.illegalArgument();
+            fail();
+        }
+        catch (IllegalArgumentException e)
+        {
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testInterfaceHierarchies()
+    {
+        final SortedSet set = factory.createDelegatorProxy(new ConstantProvider<SortedSet>(new TreeSet()), SortedSet.class);
+        set.add("Hello");
+    }
+
+    public void testInvokerProxy() throws Exception
+    {
+        final InvokerTester tester = new InvokerTester();
+        final Echo echo = (Echo) factory.createInvokerProxy(tester, ECHO_ONLY);
+        echo.echoBack("hello");
+        assertEquals(Echo.class.getMethod("echoBack", String.class), tester.method);
+        assertSame(echo, tester.proxy);
+        assertNotNull(tester.args);
+        assertEquals(1, tester.args.length);
+        assertEquals("hello", tester.args[0]);
+    }
+
+    public void testInvokerProxyClassCaching() throws Exception
+    {
+        final Echo proxy1 = (Echo) factory.createInvokerProxy(new InvokerTester(), ECHO_ONLY);
+        final Echo proxy2 = (Echo) factory.createInvokerProxy(new InvokerTester(), ECHO_ONLY);
+        assertNotSame(proxy1, proxy2);
+        assertSame(proxy1.getClass(), proxy2.getClass());
+    }
+
+    public void testInvokerProxySerializable() throws Exception
+    {
+        final Echo proxy = (Echo) factory.createInvokerProxy(new InvokerTester(), ECHO_ONLY);
+        assertSerializable(proxy);
+    }
+
+    public void testMethodInvocationClassCaching() throws Exception
+    {
+        final InterceptorTester tester = new InterceptorTester();
+        final EchoImpl target = new EchoImpl();
+        final Echo proxy1 = (Echo) factory.createInterceptorProxy(target, tester, ECHO_ONLY);
+        final Echo proxy2 = (Echo) factory.createInterceptorProxy(target, tester, Echo.class, DuplicateEcho.class);
+        proxy1.echoBack("hello1");
+        final Class invocationClass1 = tester.invocationClass;
+        proxy2.echoBack("hello2");
+        assertSame(invocationClass1, tester.invocationClass);
+    }
+
+    public void testMethodInvocationDuplicateMethods() throws Exception
+    {
+        final InterceptorTester tester = new InterceptorTester();
+        final EchoImpl target = new EchoImpl();
+        final Echo proxy = (Echo) factory.createInterceptorProxy(target, tester, Echo.class, DuplicateEcho.class);
+        proxy.echoBack("hello");
+        assertEquals(Echo.class.getMethod("echoBack", String.class), tester.method);
+    }
+
+    public void testMethodInvocationImplementation() throws Exception
+    {
+        final InterceptorTester tester = new InterceptorTester();
+        final EchoImpl target = new EchoImpl();
+        final Echo proxy = (Echo) factory.createInterceptorProxy(target, tester, ECHO_ONLY);
+        proxy.echo();
+        assertNotNull(tester.arguments);
+        assertEquals(0, tester.arguments.length);
+        assertEquals(Echo.class.getMethod("echo"), tester.method);
+        assertEquals(target, tester.proxy);
+        proxy.echoBack("Hello");
+        assertNotNull(tester.arguments);
+        assertEquals(1, tester.arguments.length);
+        assertEquals("Hello", tester.arguments[0]);
+        assertEquals(Echo.class.getMethod("echoBack", String.class), tester.method);
+        proxy.echoBack("Hello", "World");
+        assertNotNull(tester.arguments);
+        assertEquals(2, tester.arguments.length);
+        assertEquals("Hello", tester.arguments[0]);
+        assertEquals("World", tester.arguments[1]);
+        assertEquals(Echo.class.getMethod("echoBack", String.class, String.class), tester.method);
+    }
+
+    public void testPrimitiveParameter()
+    {
+        final Echo echo = (Echo) factory.createDelegatorProxy(createSingletonEcho(), ECHO_ONLY);
+        assertEquals(1, echo.echoBack(1));
+    }
+
+    public void testProxyWithCheckedException() throws Exception
+    {
+        final Echo proxy = factory.createDelegatorProxy(new ConstantProvider<Echo>(new EchoImpl()), Echo.class);
+        try
+        {
+            proxy.ioException();
+            fail();
+        }
+        catch (IOException e)
+        {
+        }
+    }
+
+    public void testProxyWithUncheckedException() throws Exception
+    {
+        final Echo proxy = factory.createDelegatorProxy(new ConstantProvider<Echo>(new EchoImpl()), Echo.class);
+        try
+        {
+            proxy.illegalArgument();
+            fail();
+        }
+        catch (IllegalArgumentException e)
+        {
+        }
+    }
+
+    public void testWithNonAccessibleTargetType()
+    {
+        final Echo proxy = (Echo) factory.createInterceptorProxy(new PrivateEcho(), new NoOpMethodInterceptor(), ECHO_ONLY);
+        proxy.echo();
+    }
+
+//**********************************************************************************************************************
+// Inner Classes
+//**********************************************************************************************************************
+
+    private static class ChangeArgumentInterceptor implements Interceptor
+    {
+        public Object intercept(Invocation methodInvocation) throws Throwable
+        {
+            methodInvocation.getArguments()[0] = "something different";
+            return methodInvocation.proceed();
+        }
+    }
+
+    protected static class InterceptorTester implements Interceptor
+    {
+        private Object[] arguments;
+        private Method method;
+        private Object proxy;
+        private Class invocationClass;
+
+        public Object intercept(Invocation methodInvocation) throws Throwable
+        {
+            arguments = methodInvocation.getArguments();
+            method = methodInvocation.getMethod();
+            proxy = methodInvocation.getProxy();
+            invocationClass = methodInvocation.getClass();
+            return methodInvocation.proceed();
+        }
+    }
+
+    protected static class InvokerTester implements Invoker
+    {
+        private Object method;
+        private Object[] args;
+        private Object proxy;
+
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+        {
+            this.proxy = proxy;
+            this.method = method;
+            this.args = args;
+            return null;
+        }
+    }
+
+    protected static class NoOpMethodInterceptor implements Interceptor, Serializable
+    {
+        public Object intercept(Invocation methodInvocation) throws Throwable
+        {
+            return methodInvocation.proceed();
+        }
+    }
+
+    private static class PrivateEcho extends EchoImpl
+    {
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/AbstractSubclassingProxyFactoryTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/AbstractSubclassingProxyFactoryTestCase.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/AbstractSubclassingProxyFactoryTestCase.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/AbstractSubclassingProxyFactoryTestCase.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy;
+
+import org.apache.commons.proxy.exception.ProxyFactoryException;
+import org.apache.commons.proxy.invoker.NullInvoker;
+import org.apache.commons.proxy.provider.ConstantProvider;
+import org.apache.commons.proxy.util.AbstractEcho;
+import org.apache.commons.proxy.util.Echo;
+import org.apache.commons.proxy.util.EchoImpl;
+
+import java.util.Date;
+
+/**
+ * @author James Carman
+ * @since 1.0
+ */
+public abstract class AbstractSubclassingProxyFactoryTestCase extends AbstractProxyFactoryTestCase
+{
+    private static final Class[] DATE_ONLY = new Class[]{Date.class};
+//**********************************************************************************************************************
+// Constructors
+//**********************************************************************************************************************
+
+    protected AbstractSubclassingProxyFactoryTestCase(ProxyFactory factory)
+    {
+        super(factory);
+    }
+
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+    public void testCanProxy()
+    {
+        assertTrue(factory.canProxy(new Class[]{Echo.class}));
+        assertTrue(factory.canProxy(new Class[]{EchoImpl.class}));
+        assertFalse(factory.canProxy(new Class[]{FinalEcho.class}));
+        assertTrue(factory.canProxy(new Class[]{FinalMethodEcho.class, Echo.class}));
+        assertFalse(factory.canProxy(new Class[]{NoDefaultConstructorEcho.class}));
+        assertTrue(factory.canProxy(new Class[]{ProtectedConstructorEcho.class}));
+        assertFalse(factory.canProxy(new Class[]{InvisibleEcho.class}));
+        assertFalse(factory.canProxy(new Class[]{Echo.class, EchoImpl.class, String.class}));
+    }
+
+    public void testDelegatorWithMultipleSuperclasses()
+    {
+        try
+        {
+            factory.createDelegatorProxy(new ConstantProvider(new EchoImpl()),
+                    new Class[]{EchoImpl.class, String.class});
+            fail();
+        }
+        catch (ProxyFactoryException e)
+        {
+        }
+    }
+
+    public void testDelegatorWithSuperclass()
+    {
+        final Echo echo = (Echo) factory
+                .createDelegatorProxy(new ConstantProvider(new EchoImpl()), new Class[]{Echo.class, EchoImpl.class});
+        assertTrue(echo instanceof EchoImpl);
+    }
+
+    public void testInterceptorWithMultipleSuperclasses()
+    {
+        try
+        {
+            factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(),
+                    new Class[]{EchoImpl.class, String.class});
+            fail();
+        }
+        catch (ProxyFactoryException e)
+        {
+        }
+    }
+
+    public void testInterceptorWithSuperclass()
+    {
+        final Echo echo = (Echo) factory
+                .createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), new Class[]{Echo.class, EchoImpl.class});
+        assertTrue(echo instanceof EchoImpl);
+    }
+
+    public void testInvocationHandlerWithMultipleSuperclasses()
+    {
+        try
+        {
+            factory.createInvokerProxy(new NullInvoker(),
+                    new Class[]{EchoImpl.class, String.class});
+            fail();
+        }
+        catch (ProxyFactoryException e)
+        {
+        }
+    }
+
+    public void testInvokerWithSuperclass()
+    {
+        final Echo echo = (Echo) factory
+                .createInvokerProxy(new NullInvoker(), new Class[]{Echo.class, EchoImpl.class});
+        assertTrue(echo instanceof EchoImpl);
+    }
+
+    public void testProxiesWithClashingFinalMethodInSuperclass()
+    {
+        final Class[] proxyClasses = new Class[]{Echo.class, FinalMethodEcho.class};
+        Echo proxy = (Echo) factory.createDelegatorProxy(new ConstantProvider(new EchoImpl()), proxyClasses);
+        assertEquals("final", proxy.echoBack("echo"));
+
+        proxy = (Echo) factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), proxyClasses);
+        assertEquals("final", proxy.echoBack("echo"));
+
+        proxy = (Echo) factory.createInvokerProxy(new NullInvoker(), proxyClasses);
+        assertEquals("final", proxy.echoBack("echo"));
+    }
+
+    public void testWithAbstractSuperclass()
+    {
+        final Echo echo = (Echo) factory.createDelegatorProxy(new ConstantProvider(new EchoImpl()), new Class[]{AbstractEcho.class});
+        assertEquals("hello", echo.echoBack("hello"));
+        assertEquals("helloworld", echo.echoBack("hello", "world"));
+    }
+
+    public void testInterceptorEquals()
+    {
+        final EqualsEcho echo = new EqualsEcho("text");
+        final Echo proxy1 = (Echo) factory.createInterceptorProxy(echo,
+                new NoOpMethodInterceptor(), new Class[] { EqualsEcho.class } );
+        final Echo proxy2 = (Echo) factory.createInterceptorProxy(echo,
+                new NoOpMethodInterceptor(), new Class[] { EqualsEcho.class } );
+        assertEquals(proxy1, proxy1);
+        assertFalse(proxy1.equals(proxy2));
+        assertFalse(proxy2.equals(proxy1));
+    }
+
+    public void testInvokerEquals() throws Exception
+    {
+        final Date proxy1 = (Date) factory.createInvokerProxy(new InvokerTester(), DATE_ONLY);
+        final Date proxy2 = (Date) factory.createInvokerProxy(new InvokerTester(), DATE_ONLY);
+        assertEquals(proxy1, proxy1);
+        assertFalse(proxy1.equals(proxy2));
+        assertFalse(proxy2.equals(proxy1));
+    }
+
+    public void testDelegatorEquals() throws Exception
+    {
+        final EqualsEcho echo = new EqualsEcho("text");
+        final Echo proxy1 = (Echo) factory.createDelegatorProxy(new ConstantProvider(echo),
+                new Class[] { EqualsEcho.class });
+        final Echo proxy2 = (Echo) factory.createDelegatorProxy(new ConstantProvider(echo),
+                new Class[] { EqualsEcho.class });
+        assertEquals(proxy1, proxy1);
+        assertFalse(proxy1.equals(proxy2));
+        assertFalse(proxy2.equals(proxy1));
+    }
+
+//**********************************************************************************************************************
+// Inner Classes
+//**********************************************************************************************************************
+
+    public static final class FinalEcho extends EchoImpl
+    {
+    }
+
+    public static class FinalMethodEcho extends EchoImpl
+    {
+        public final String echoBack(String message)
+        {
+            return "final";
+        }
+    }
+
+    public static class EqualsEcho extends EchoImpl
+    {
+        private final String text;
+
+        public EqualsEcho()
+        {
+            this("testing");
+        }
+
+        public EqualsEcho(String text)
+        {
+            this.text = text;
+        }
+    }
+
+    private static class InvisibleEcho extends EchoImpl
+    {
+    }
+
+    public static class NoDefaultConstructorEcho extends EchoImpl
+    {
+        public NoDefaultConstructorEcho(String param)
+        {
+        }
+    }
+
+    public static class ProtectedConstructorEcho extends EchoImpl
+    {
+        protected ProtectedConstructorEcho()
+        {
+        }
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractEcho.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractEcho.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractEcho.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractEcho.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.util;
+
+import java.io.Serializable;
+
+/**
+ * @author James Carman
+ * @since 1.0
+ */
+public abstract class AbstractEcho implements Echo, Serializable
+{
+//**********************************************************************************************************************
+// Echo Implementation
+//**********************************************************************************************************************
+
+    public String echoBack( String message )
+    {
+        return message;
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/AbstractTestCase.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,23 @@
+package org.apache.commons.proxy.util;
+
+import junit.framework.TestCase;
+import org.apache.commons.lang.SerializationUtils;
+
+import java.io.Serializable;
+
+/**
+ * @auothor James Carman
+ * @since 1.1
+ */
+public abstract class AbstractTestCase extends TestCase
+{
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+    protected void assertSerializable( Object o )
+    {
+        assertTrue(o instanceof Serializable);
+        SerializationUtils.clone(( Serializable ) o);
+    }
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/DuplicateEcho.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/DuplicateEcho.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/DuplicateEcho.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/DuplicateEcho.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.util;
+
+/**
+ * @author James Carman
+ * @since 1.0
+ */
+public interface DuplicateEcho
+{
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+    public String echoBack( String message );
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/Echo.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/Echo.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/Echo.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/Echo.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.util;
+
+import java.io.IOException;
+
+/**
+ * @author James Carman
+ * @since 1.0
+ */
+public interface Echo
+{
+//**********************************************************************************************************************
+// Other Methods
+//**********************************************************************************************************************
+
+    public void echo();
+
+    public String echoBack( String message );
+
+    public String echoBack( String[] messages );
+
+    public int echoBack( int i );
+
+    public boolean echoBack( boolean b );
+
+    public String echoBack( String message1, String message2 );
+
+    public void illegalArgument();
+
+    public void ioException() throws IOException;
+}

Added: commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/EchoImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/EchoImpl.java?rev=964636&view=auto
==============================================================================
--- commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/EchoImpl.java (added)
+++ commons/proper/proxy/branches/version-2.0-work/core/src/test/java/org/apache/commons/proxy/util/EchoImpl.java Thu Jul 15 23:10:43 2010
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.proxy.util;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+/**
+ * @author James Carman
+ * @since 1.0
+ */
+public class EchoImpl extends AbstractEcho implements DuplicateEcho, Serializable
+{
+//**********************************************************************************************************************
+// Fields
+//**********************************************************************************************************************
+
+    private static final long serialVersionUID = -4844873352607521103L;
+
+//**********************************************************************************************************************
+// Echo Implementation
+//**********************************************************************************************************************
+
+
+    public void echo()
+    {
+    }
+
+    public boolean echoBack( boolean b )
+    {
+        return b;
+    }
+
+    public String echoBack( String[] messages )
+    {
+        final StringBuffer sb = new StringBuffer();
+        for( int i = 0; i < messages.length; i++ )
+        {
+            String message = messages[i];
+            sb.append(message);
+        }
+        return sb.toString();
+    }
+
+    public int echoBack( int i )
+    {
+        return i;
+    }
+
+    public String echoBack( String message1, String message2 )
+    {
+        return message1 + message2;
+    }
+
+    public void illegalArgument()
+    {
+        throw new IllegalArgumentException("dummy message");
+    }
+
+    public void ioException() throws IOException
+    {
+        throw new IOException("dummy message");
+    }
+}



Mime
View raw message