checkstyle/findbugs/pmd
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/proxy/trunk@1582033 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/asm4/pom.xml b/asm4/pom.xml
index cc80d21..299b6b9 100644
--- a/asm4/pom.xml
+++ b/asm4/pom.xml
@@ -57,4 +57,34 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <configuration>
+ <!--rulesets>
+ <ruleset>/org/apache/commons/proxy2/pmd.xml</ruleset>
+ </rulesets-->
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle.version}</version>
+ <configuration>
+ <configLocation>org/apache/commons/proxy2/checkstyle.xml</configLocation>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <xmlOutput>true</xmlOutput>
+ <excludeFilterFile>/org/apache/commons/proxy2/findbugs-exclude-filter.xml</excludeFilterFile>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
</project>
diff --git a/asm4/src/main/java/org/apache/commons/proxy2/asm4/ASM4ProxyFactory.java b/asm4/src/main/java/org/apache/commons/proxy2/asm4/ASM4ProxyFactory.java
index 57ed58f..dda04a0 100644
--- a/asm4/src/main/java/org/apache/commons/proxy2/asm4/ASM4ProxyFactory.java
+++ b/asm4/src/main/java/org/apache/commons/proxy2/asm4/ASM4ProxyFactory.java
@@ -22,6 +22,8 @@
import java.lang.reflect.UndeclaredThrowableException;
import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.proxy2.Interceptor;
import org.apache.commons.proxy2.Invocation;
import org.apache.commons.proxy2.Invoker;
@@ -423,8 +425,7 @@
&& method.getParameterTypes().length == 1 && Object.class.equals(method.getParameterTypes()[0]);
}
- @SuppressWarnings("serial")
- private static class ReflectionInvocation implements Invocation, Serializable
+ private static class ReflectionInvocation implements Invocation
{
private final Method method;
private final Object[] arguments;
@@ -435,7 +436,7 @@
final Object[] arguments)
{
this.method = method;
- this.arguments = (arguments == null ? ProxyUtils.EMPTY_ARGUMENTS : arguments);
+ this.arguments = ObjectUtils.defaultIfNull(ArrayUtils.clone(arguments), ProxyUtils.EMPTY_ARGUMENTS);
this.proxy = proxy;
this.target = target;
}
diff --git a/asm4/src/test/java/org/apache/commons/proxy2/asm4/TestAsm4ProxyFactory.java b/asm4/src/test/java/org/apache/commons/proxy2/asm4/TestAsm4ProxyFactory.java
index 682e948..3b1e815 100644
--- a/asm4/src/test/java/org/apache/commons/proxy2/asm4/TestAsm4ProxyFactory.java
+++ b/asm4/src/test/java/org/apache/commons/proxy2/asm4/TestAsm4ProxyFactory.java
@@ -20,7 +20,7 @@
public class TestAsm4ProxyFactory extends AbstractSubclassingProxyFactoryTestCase
{
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Constructors
+ //**********************************************************************************************************************
}
diff --git a/build-tools/src/main/resources/org/apache/commons/proxy2/checkstyle.xml b/build-tools/src/main/resources/org/apache/commons/proxy2/checkstyle.xml
index 0ed8c5b..e8f9866 100644
--- a/build-tools/src/main/resources/org/apache/commons/proxy2/checkstyle.xml
+++ b/build-tools/src/main/resources/org/apache/commons/proxy2/checkstyle.xml
@@ -22,24 +22,19 @@
<!-- commons proxy2 customization of default Checkstyle behavior -->
<module name="Checker">
- <property name="localeLanguage" value="en"/>
-
- <module name="Header">
- <property name="headerFile" value="${checkstyle.header.file}"/>
- </module>
+ <property name="localeLanguage" value="en" />
<!-- no tabs allowed in files -->
- <module name="FileTabCharacter"/>
+ <module name="FileTabCharacter" />
<module name="TreeWalker">
- <!-- Verify that EVERY source file has the appropriate license -->
<!-- check sane import statements -->
- <module name="AvoidStarImport"/>
- <module name="RedundantImport"/>
- <module name="UnusedImports"/>
+ <module name="AvoidStarImport" />
+ <module name="RedundantImport" />
+ <module name="UnusedImports" />
<module name="LineLength">
- <property name="max" value="120"/>
+ <property name="max" value="120" />
</module>
</module>
</module>
diff --git a/build-tools/src/main/resources/org/apache/commons/proxy2/findbugs-exclude-filter.xml b/build-tools/src/main/resources/org/apache/commons/proxy2/findbugs-exclude-filter.xml
new file mode 100644
index 0000000..685d104
--- /dev/null
+++ b/build-tools/src/main/resources/org/apache/commons/proxy2/findbugs-exclude-filter.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+
+<!--
+ This file contains some false positive bugs detected by findbugs. Their
+ false positive nature has been analyzed individually and they have been
+ put here to instruct findbugs it must ignore them.
+-->
+<FindBugsFilter>
+
+ <!-- Reason: invocation arguments intentionally modifiable -->
+ <Match>
+ <Class name="org.apache.commons.proxy2.javassist.JavassistInvocation" />
+ <Bug pattern="EI_EXPOSE_REP" />
+ </Match>
+
+</FindBugsFilter>
diff --git a/build-tools/src/main/resources/org/apache/commons/proxy2/license-header.txt b/build-tools/src/main/resources/org/apache/commons/proxy2/license-header.txt
deleted file mode 100644
index f974c9a..0000000
--- a/build-tools/src/main/resources/org/apache/commons/proxy2/license-header.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * 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.
- */
\ No newline at end of file
diff --git a/cglib/pom.xml b/cglib/pom.xml
index 0fa2c6e..f8c4693 100644
--- a/cglib/pom.xml
+++ b/cglib/pom.xml
@@ -55,4 +55,33 @@
</dependency>
</dependencies>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <configuration>
+ <!--rulesets>
+ <ruleset>/org/apache/commons/proxy2/pmd.xml</ruleset>
+ </rulesets-->
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle.version}</version>
+ <configuration>
+ <configLocation>org/apache/commons/proxy2/checkstyle.xml</configLocation>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <xmlOutput>true</xmlOutput>
+ <excludeFilterFile>/org/apache/commons/proxy2/findbugs-exclude-filter.xml</excludeFilterFile>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
</project>
diff --git a/cglib/src/main/java/org/apache/commons/proxy2/cglib/CglibProxyFactory.java b/cglib/src/main/java/org/apache/commons/proxy2/cglib/CglibProxyFactory.java
index 623e64b..d81fbc9 100644
--- a/cglib/src/main/java/org/apache/commons/proxy2/cglib/CglibProxyFactory.java
+++ b/cglib/src/main/java/org/apache/commons/proxy2/cglib/CglibProxyFactory.java
@@ -17,42 +17,54 @@
package org.apache.commons.proxy2.cglib;
-import net.sf.cglib.proxy.*;
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.proxy2.*;
-import org.apache.commons.proxy2.impl.AbstractSubclassingProxyFactory;
-
import java.io.Serializable;
import java.lang.reflect.Method;
+import net.sf.cglib.proxy.Callback;
+import net.sf.cglib.proxy.CallbackFilter;
+import net.sf.cglib.proxy.Dispatcher;
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.proxy2.Interceptor;
+import org.apache.commons.proxy2.Invocation;
+import org.apache.commons.proxy2.Invoker;
+import org.apache.commons.proxy2.ObjectProvider;
+import org.apache.commons.proxy2.ProxyUtils;
+import org.apache.commons.proxy2.impl.AbstractSubclassingProxyFactory;
+
/**
* Cglib-based {@link ProxyFactory} implementation.
*/
public class CglibProxyFactory extends AbstractSubclassingProxyFactory
{
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private static CallbackFilter callbackFilter = new CglibProxyFactoryCallbackFilter();
- //**********************************************************************************************************************
- // ProxyFactory Implementation
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // ProxyFactory Implementation
+ //******************************************************************************************************************
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public <T> T createDelegatorProxy(ClassLoader classLoader, ObjectProvider<?> targetProvider,
- Class<?>... proxyClasses)
+ Class<?>... proxyClasses)
{
final Enhancer enhancer = new Enhancer();
enhancer.setClassLoader(classLoader);
enhancer.setInterfaces(toInterfaces(proxyClasses));
enhancer.setSuperclass(getSuperclass(proxyClasses));
enhancer.setCallbackFilter(callbackFilter);
- enhancer.setCallbacks(new Callback[]{new ObjectProviderDispatcher(targetProvider), new EqualsHandler(), new HashCodeHandler()});
+ enhancer.setCallbacks(new Callback[] { new ObjectProviderDispatcher(targetProvider), new EqualsHandler(),
+ new HashCodeHandler() });
return (T) enhancer.create();
}
@@ -61,14 +73,15 @@
*/
@SuppressWarnings("unchecked")
public <T> T createInterceptorProxy(ClassLoader classLoader, Object target, Interceptor interceptor,
- Class<?>... proxyClasses)
+ Class<?>... proxyClasses)
{
final Enhancer enhancer = new Enhancer();
enhancer.setClassLoader(classLoader);
enhancer.setInterfaces(toInterfaces(proxyClasses));
enhancer.setSuperclass(getSuperclass(proxyClasses));
enhancer.setCallbackFilter(callbackFilter);
- enhancer.setCallbacks(new Callback[]{new InterceptorBridge(target, interceptor), new EqualsHandler(), new HashCodeHandler()});
+ enhancer.setCallbacks(new Callback[] { new InterceptorBridge(target, interceptor), new EqualsHandler(),
+ new HashCodeHandler() });
return (T) enhancer.create();
}
@@ -76,21 +89,21 @@
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
- public <T> T createInvokerProxy(ClassLoader classLoader, Invoker invoker,
- Class<?>... proxyClasses)
+ public <T> T createInvokerProxy(ClassLoader classLoader, Invoker invoker, Class<?>... proxyClasses)
{
final Enhancer enhancer = new Enhancer();
enhancer.setClassLoader(classLoader);
enhancer.setInterfaces(toInterfaces(proxyClasses));
enhancer.setSuperclass(getSuperclass(proxyClasses));
enhancer.setCallbackFilter(callbackFilter);
- enhancer.setCallbacks(new Callback[]{new InvokerBridge(invoker), new EqualsHandler(), new HashCodeHandler()});
+ enhancer.setCallbacks(
+ new Callback[] { new InvokerBridge(invoker), new EqualsHandler(), new HashCodeHandler() });
return (T) enhancer.create();
}
-//**********************************************************************************************************************
-// Inner Classes
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Inner Classes
+ //******************************************************************************************************************
private static class CglibProxyFactoryCallbackFilter implements CallbackFilter
{
@@ -133,7 +146,7 @@
}
}
- private static class InterceptorBridge implements net.sf.cglib.proxy.MethodInterceptor, Serializable
+ private static class InterceptorBridge implements MethodInterceptor, Serializable
{
/** Serialization version */
private static final long serialVersionUID = 1L;
@@ -171,11 +184,8 @@
}
}
- private static class MethodProxyInvocation implements Invocation, Serializable
+ private static class MethodProxyInvocation implements Invocation
{
- /** Serialization version */
- private static final long serialVersionUID = 1L;
-
private final Object proxy;
private final Object target;
private final Method method;
@@ -188,7 +198,7 @@
this.target = target;
this.method = method;
this.methodProxy = methodProxy;
- this.args = ArrayUtils.clone(args);
+ this.args = ObjectUtils.defaultIfNull(ArrayUtils.clone(args), ProxyUtils.EMPTY_ARGUMENTS);
}
public Method getMethod()
diff --git a/cglib/src/test/java/org/apache/commons/proxy2/cglib/CglibProxyFactoryTest.java b/cglib/src/test/java/org/apache/commons/proxy2/cglib/CglibProxyFactoryTest.java
index cb2da8d..29713c7 100644
--- a/cglib/src/test/java/org/apache/commons/proxy2/cglib/CglibProxyFactoryTest.java
+++ b/cglib/src/test/java/org/apache/commons/proxy2/cglib/CglibProxyFactoryTest.java
@@ -21,9 +21,9 @@
public class CglibProxyFactoryTest extends AbstractSubclassingProxyFactoryTestCase
{
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Constructors
+ //**********************************************************************************************************************
public CglibProxyFactoryTest()
{
diff --git a/core/pom.xml b/core/pom.xml
index 4b21370..cf19734 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -59,4 +59,33 @@
</plugins>
</build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle.version}</version>
+ <configuration>
+ <configLocation>org/apache/commons/proxy2/checkstyle.xml</configLocation>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <configuration>
+ <!--rulesets>
+ <ruleset>/org/apache/commons/proxy2/pmd.xml</ruleset>
+ </rulesets-->
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <xmlOutput>true</xmlOutput>
+ <excludeFilterFile>/org/apache/commons/proxy2/findbugs-exclude-filter.xml</excludeFilterFile>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
</project>
diff --git a/core/src/main/java/org/apache/commons/proxy2/DefaultProxyFactory.java b/core/src/main/java/org/apache/commons/proxy2/DefaultProxyFactory.java
index 0a6db83..42b6655 100644
--- a/core/src/main/java/org/apache/commons/proxy2/DefaultProxyFactory.java
+++ b/core/src/main/java/org/apache/commons/proxy2/DefaultProxyFactory.java
@@ -20,25 +20,28 @@
import java.util.ServiceLoader;
/**
- * {@link ProxyFactory} implementation that delegates to the first discovered
- * {@link ProxyFactory} service provider that {@link #canProxy(Class...)}.
- *
+ * {@link ProxyFactory} implementation that delegates to the first discovered {@link ProxyFactory} service provider that
+ * {@link #canProxy(Class...)}.
+ *
* @author Matt Benson
*/
-class DefaultProxyFactory implements ProxyFactory {
+class DefaultProxyFactory implements ProxyFactory
+{
/** Shared instance */
static final DefaultProxyFactory INSTANCE = new DefaultProxyFactory();
- private static final ServiceLoader<ProxyFactory> SERVICES = ServiceLoader
- .load(ProxyFactory.class);
+ private static final ServiceLoader<ProxyFactory> SERVICES = ServiceLoader.load(ProxyFactory.class);
/**
* {@inheritDoc}
*/
@Override
- public boolean canProxy(Class<?>... proxyClasses) {
- for (ProxyFactory proxyFactory : SERVICES) {
- if (proxyFactory.canProxy(proxyClasses)) {
+ public boolean canProxy(Class<?>... proxyClasses)
+ {
+ for (ProxyFactory proxyFactory : SERVICES)
+ {
+ if (proxyFactory.canProxy(proxyClasses))
+ {
return true;
}
}
@@ -49,11 +52,10 @@
* {@inheritDoc}
*/
@Override
- public <T> T createDelegatorProxy(ObjectProvider<?> delegateProvider,
- Class<?>... proxyClasses) {
+ public <T> T createDelegatorProxy(ObjectProvider<?> delegateProvider, Class<?>... proxyClasses)
+ {
@SuppressWarnings("unchecked")
- final T result = (T) getCapableProxyFactory(proxyClasses).createDelegatorProxy(
- delegateProvider, proxyClasses);
+ final T result = (T) getCapableProxyFactory(proxyClasses).createDelegatorProxy(delegateProvider, proxyClasses);
return result;
}
@@ -61,11 +63,12 @@
* {@inheritDoc}
*/
@Override
- public <T> T createDelegatorProxy(ClassLoader classLoader,
- ObjectProvider<?> delegateProvider, Class<?>... proxyClasses) {
+ public <T> T createDelegatorProxy(ClassLoader classLoader, ObjectProvider<?> delegateProvider,
+ Class<?>... proxyClasses)
+ {
@SuppressWarnings("unchecked")
- final T result = (T) getCapableProxyFactory(proxyClasses).createDelegatorProxy(
- classLoader, delegateProvider, proxyClasses);
+ final T result = (T) getCapableProxyFactory(proxyClasses).createDelegatorProxy(classLoader, delegateProvider,
+ proxyClasses);
return result;
}
@@ -73,11 +76,11 @@
* {@inheritDoc}
*/
@Override
- public <T> T createInterceptorProxy(Object target, Interceptor interceptor,
- Class<?>... proxyClasses) {
+ public <T> T createInterceptorProxy(Object target, Interceptor interceptor, Class<?>... proxyClasses)
+ {
@SuppressWarnings("unchecked")
- final T result = (T) getCapableProxyFactory(proxyClasses).createInterceptorProxy(
- target, interceptor, proxyClasses);
+ final T result = (T) getCapableProxyFactory(proxyClasses).createInterceptorProxy(target, interceptor,
+ proxyClasses);
return result;
}
@@ -85,11 +88,12 @@
* {@inheritDoc}
*/
@Override
- public <T> T createInterceptorProxy(ClassLoader classLoader, Object target,
- Interceptor interceptor, Class<?>... proxyClasses) {
+ public <T> T createInterceptorProxy(ClassLoader classLoader, Object target, Interceptor interceptor,
+ Class<?>... proxyClasses)
+ {
@SuppressWarnings("unchecked")
- final T result = (T) getCapableProxyFactory(proxyClasses).createInterceptorProxy(
- classLoader, target, interceptor, proxyClasses);
+ final T result = (T) getCapableProxyFactory(proxyClasses).createInterceptorProxy(classLoader, target,
+ interceptor, proxyClasses);
return result;
}
@@ -97,10 +101,10 @@
* {@inheritDoc}
*/
@Override
- public <T> T createInvokerProxy(Invoker invoker, Class<?>... proxyClasses) {
+ public <T> T createInvokerProxy(Invoker invoker, Class<?>... proxyClasses)
+ {
@SuppressWarnings("unchecked")
- final T result = (T) getCapableProxyFactory(proxyClasses).createInvokerProxy(
- invoker, proxyClasses);
+ final T result = (T) getCapableProxyFactory(proxyClasses).createInvokerProxy(invoker, proxyClasses);
return result;
}
@@ -108,21 +112,23 @@
* {@inheritDoc}
*/
@Override
- public <T> T createInvokerProxy(ClassLoader classLoader, Invoker invoker,
- Class<?>... proxyClasses) {
+ public <T> T createInvokerProxy(ClassLoader classLoader, Invoker invoker, Class<?>... proxyClasses)
+ {
@SuppressWarnings("unchecked")
- final T result = (T) getCapableProxyFactory(proxyClasses).createInvokerProxy(
- classLoader, invoker, proxyClasses);
+ final T result = (T) getCapableProxyFactory(proxyClasses)
+ .createInvokerProxy(classLoader, invoker, proxyClasses);
return result;
}
- private ProxyFactory getCapableProxyFactory(Class<?>... proxyClasses) {
- for (ProxyFactory proxyFactory : SERVICES) {
- if (proxyFactory.canProxy(proxyClasses)) {
+ private ProxyFactory getCapableProxyFactory(Class<?>... proxyClasses)
+ {
+ for (ProxyFactory proxyFactory : SERVICES)
+ {
+ if (proxyFactory.canProxy(proxyClasses))
+ {
return proxyFactory;
}
}
- throw new IllegalArgumentException("Could not proxy "
- + Arrays.toString(proxyClasses));
+ throw new IllegalArgumentException("Could not proxy " + Arrays.toString(proxyClasses));
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/Interceptor.java b/core/src/main/java/org/apache/commons/proxy2/Interceptor.java
index 5b2c668..8b660da 100644
--- a/core/src/main/java/org/apache/commons/proxy2/Interceptor.java
+++ b/core/src/main/java/org/apache/commons/proxy2/Interceptor.java
@@ -21,21 +21,22 @@
/**
* "Intercepts" a method invocation.
- *
+ *
* @author James Carman
* @since 1.0
*/
public interface Interceptor extends Serializable
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
/**
* Intercept the specified {@link Invocation}.
+ *
* @param invocation
* @return return value of the method
* @throws Throwable
*/
- Object intercept( Invocation invocation ) throws Throwable;
+ Object intercept(Invocation invocation) throws Throwable;
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/Invocation.java b/core/src/main/java/org/apache/commons/proxy2/Invocation.java
index 0c0c60b..554eb73 100644
--- a/core/src/main/java/org/apache/commons/proxy2/Invocation.java
+++ b/core/src/main/java/org/apache/commons/proxy2/Invocation.java
@@ -21,43 +21,44 @@
/**
* Method invocation for use by an {@link Interceptor}.
- *
+ *
* @author James Carman
* @since 1.0
*/
public interface Invocation
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
/**
- * Returns the arguments being passed to this method invocation. Changes in the elements of this array will be
+ * Returns the arguments being passed to this method invocation. Changes in the elements of this array will be
* propagated to the recipient of this invocation.
- *
+ *
* @return the arguments being passed to this method invocation
*/
Object[] getArguments();
/**
* Returns the method being called.
- *
+ *
* @return the method being called
*/
Method getMethod();
/**
* Returns the proxy object on which this invocation was invoked.
- *
+ *
* @return the proxy object on which this invocation was invoked
*/
Object getProxy();
/**
* Called in order to let the invocation proceed.
- *
+ *
* @return the return value of the invocation
- * @throws Throwable any exception or error that was thrown as a result of this invocation
+ * @throws Throwable
+ * any exception or error that was thrown as a result of this invocation
*/
Object proceed() throws Throwable;
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/Invoker.java b/core/src/main/java/org/apache/commons/proxy2/Invoker.java
index aa5689c..45dbf46 100644
--- a/core/src/main/java/org/apache/commons/proxy2/Invoker.java
+++ b/core/src/main/java/org/apache/commons/proxy2/Invoker.java
@@ -22,25 +22,29 @@
/**
* An invoker is responsible for handling a method invocation.
- *
+ *
* @author James Carman
* @since 1.0
*/
public interface Invoker extends Serializable
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
/**
- * "Invokes" the method. Implementation should throw a {@link org.apache.commons.proxy2.exception.InvokerException}
+ * "Invokes" the method. Implementation should throw a {@link org.apache.commons.proxy2.exception.InvokerException}
* if problems arise while trying to invoke the method.
- *
- * @param proxy the proxy2 object
- * @param method the method being invoked
- * @param arguments the arguments
+ *
+ * @param proxy
+ * the proxy2 object
+ * @param method
+ * the method being invoked
+ * @param arguments
+ * the arguments
* @return the return value
- * @throws Throwable thrown by the implementation
+ * @throws Throwable
+ * thrown by the implementation
*/
- Object invoke( Object proxy, Method method, Object[] arguments ) throws Throwable;
+ Object invoke(Object proxy, Method method, Object[] arguments) throws Throwable;
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/ObjectProvider.java b/core/src/main/java/org/apache/commons/proxy2/ObjectProvider.java
index ea3ce01..f5f46a2 100644
--- a/core/src/main/java/org/apache/commons/proxy2/ObjectProvider.java
+++ b/core/src/main/java/org/apache/commons/proxy2/ObjectProvider.java
@@ -17,23 +17,25 @@
package org.apache.commons.proxy2;
+import java.io.Serializable;
+
/**
* Provides an object to a delegating proxy.
- *
+ *
* @author James Carman
* @since 1.0
*/
-public interface ObjectProvider<T>
+public interface ObjectProvider<T> extends Serializable
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
/**
- * Returns an object. Implementing classes should throw a
+ * Returns an object. Implementing classes should throw a
* {@link org.apache.commons.proxy2.exception.ObjectProviderException} if any problems arise while
* constructing/finding the object.
- *
+ *
* @return the object on which the method should be called
*/
T getObject();
diff --git a/core/src/main/java/org/apache/commons/proxy2/ProxyFactory.java b/core/src/main/java/org/apache/commons/proxy2/ProxyFactory.java
index a3e3ea8..257f499 100644
--- a/core/src/main/java/org/apache/commons/proxy2/ProxyFactory.java
+++ b/core/src/main/java/org/apache/commons/proxy2/ProxyFactory.java
@@ -19,88 +19,104 @@
/**
* ProxyFactory interface.
+ *
* @since 2.0
*/
public interface ProxyFactory
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
/**
* Learn whether this {@link ProxyFactory} is capable of creating a proxy for the specified set of classes.
- *
- * @param proxyClasses the proxy2 classes
+ *
+ * @param proxyClasses
+ * the proxy2 classes
* @return boolean
*/
- boolean canProxy( Class<?>... proxyClasses );
+ boolean canProxy(Class<?>... proxyClasses);
/**
- * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>. The proxy will be
+ * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>. The proxy will be
* generated using the current thread's "context class loader."
- *
- * @param delegateProvider the delegate provider
- * @param proxyClasses the interfaces that the proxy should implement
+ *
+ * @param delegateProvider
+ * the delegate provider
+ * @param proxyClasses
+ * the interfaces that the proxy should implement
* @return a proxy which delegates to the object provided by the target object provider
*/
- <T> T createDelegatorProxy( ObjectProvider<?> delegateProvider, Class<?>... proxyClasses );
+ <T> T createDelegatorProxy(ObjectProvider<?> delegateProvider, Class<?>... proxyClasses);
/**
* Creates a proxy which delegates to the object provided by <code>delegateProvider</code>.
- *
- * @param classLoader the class loader to use when generating the proxy
- * @param delegateProvider the delegate provider
- * @param proxyClasses the interfaces that the proxy should implement
+ *
+ * @param classLoader
+ * the class loader to use when generating the proxy
+ * @param delegateProvider
+ * the delegate provider
+ * @param proxyClasses
+ * the interfaces that the proxy should implement
* @return a proxy which delegates to the object provided by the target <code>delegateProvider>
*/
- <T> T createDelegatorProxy( ClassLoader classLoader, ObjectProvider<?> delegateProvider,
- Class<?>... proxyClasses );
+ <T> T createDelegatorProxy(ClassLoader classLoader, ObjectProvider<?> delegateProvider, Class<?>... proxyClasses);
/**
* Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
- * <code>target</code> object. The proxy will be generated using the current thread's "context class loader."
- *
- * @param target the target object
- * @param interceptor the method interceptor
- * @param proxyClasses the interfaces that the proxy should implement
+ * <code>target</code> object. The proxy will be generated using the current thread's "context class loader."
+ *
+ * @param target
+ * the target object
+ * @param interceptor
+ * the method interceptor
+ * @param proxyClasses
+ * the interfaces that the proxy should implement
* @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
* <code>target</code> object.
*/
- <T> T createInterceptorProxy( Object target, Interceptor interceptor,
- Class<?>... proxyClasses );
+ <T> T createInterceptorProxy(Object target, Interceptor interceptor, Class<?>... proxyClasses);
/**
* Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
* <code>target</code> object.
- *
- * @param classLoader the class loader to use when generating the proxy
- * @param target the target object
- * @param interceptor the method interceptor
- * @param proxyClasses the interfaces that the proxy should implement.
+ *
+ * @param classLoader
+ * the class loader to use when generating the proxy
+ * @param target
+ * the target object
+ * @param interceptor
+ * the method interceptor
+ * @param proxyClasses
+ * the interfaces that the proxy should implement.
* @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
* <code>target</code> object.
*/
- <T> T createInterceptorProxy( ClassLoader classLoader, Object target, Interceptor interceptor,
- Class<?>... proxyClasses );
+ <T> T createInterceptorProxy(ClassLoader classLoader, Object target, Interceptor interceptor,
+ Class<?>... proxyClasses);
/**
- * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations. The proxy will be
+ * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations. The proxy will be
* generated using the current thread's "context class loader."
- *
- * @param invoker the invoker
- * @param proxyClasses the interfaces that the proxy should implement
+ *
+ * @param invoker
+ * the invoker
+ * @param proxyClasses
+ * the interfaces that the proxy should implement
* @return a proxy which uses the provided {@link Invoker} to handle all method invocations
*/
- <T> T createInvokerProxy( Invoker invoker, Class<?>... proxyClasses );
+ <T> T createInvokerProxy(Invoker invoker, Class<?>... proxyClasses);
/**
* Creates a proxy which uses the provided {@link Invoker} to handle all method invocations.
- *
- * @param classLoader the class loader to use when generating the proxy
- * @param invoker the invoker
- * @param proxyClasses the interfaces that the proxy should implement
+ *
+ * @param classLoader
+ * the class loader to use when generating the proxy
+ * @param invoker
+ * the invoker
+ * @param proxyClasses
+ * the interfaces that the proxy should implement
* @return a proxy which uses the provided {@link Invoker} to handle all method invocations
*/
- <T> T createInvokerProxy( ClassLoader classLoader, Invoker invoker,
- Class<?>... proxyClasses );
+ <T> T createInvokerProxy(ClassLoader classLoader, Invoker invoker, Class<?>... proxyClasses);
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/ProxyUtils.java b/core/src/main/java/org/apache/commons/proxy2/ProxyUtils.java
index dddab95..54eb518 100644
--- a/core/src/main/java/org/apache/commons/proxy2/ProxyUtils.java
+++ b/core/src/main/java/org/apache/commons/proxy2/ProxyUtils.java
@@ -25,24 +25,24 @@
/**
* Provides some helpful proxy utility methods.
- *
+ *
* @author James Carman
* @since 1.0
*/
public final class ProxyUtils
{
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
public static final Object[] EMPTY_ARGUMENTS = new Object[0];
public static final Class<?>[] EMPTY_ARGUMENT_TYPES = new Class[0];
private static final Map<Class<?>, Class<?>> WRAPPER_CLASS_MAP = new HashMap<Class<?>, Class<?>>();
private static final Map<Class<?>, Object> NULL_VALUE_MAP = new HashMap<Class<?>, Object>();
-//**********************************************************************************************************************
-// Static Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Static Methods
+ //******************************************************************************************************************
static
{
@@ -69,17 +69,23 @@
}
/**
- * <p>Gets an array of {@link Class} objects representing all interfaces implemented by the given class and its
- * superclasses.</p>
+ * <p>
+ * Gets an array of {@link Class} objects representing all interfaces implemented by the given class and its
+ * superclasses.
+ * </p>
* <p/>
- * <p>The order is determined by looking through each interface in turn as declared in the source file and following
+ * <p>
+ * The order is determined by looking through each interface in turn as declared in the source file and following
* its hierarchy up. Then each superclass is considered in the same way. Later duplicates are ignored, so the order
- * is maintained.</p>
+ * is maintained.
+ * </p>
* <p/>
- * <b>Note</b>: Implementation of this method was "borrowed" from
- * <a href="http://commons.apache.org/lang/">Apache Commons Lang</a> to avoid a dependency.</p>
- *
- * @param cls the class to look up, may be <code>null</code>
+ * <b>Note</b>: Implementation of this method was "borrowed" from <a href="http://commons.apache.org/lang/">Apache
+ * Commons Lang</a> to avoid a dependency.
+ * </p>
+ *
+ * @param cls
+ * the class to look up, may be <code>null</code>
* @return an array of {@link Class} objects representing all interfaces implemented by the given class and its
* superclasses or <code>null</code> if input class is null.
*/
@@ -115,10 +121,15 @@
/**
* Returns the class name as you would expect to see it in Java code.
* <p/>
- * <b>Examples:</b> <ul> <li>getJavaClassName( Object[].class ) == "Object[]"</li> <li>getJavaClassName(
- * Object[][].class ) == "Object[][]"</li> <li>getJavaClassName( Integer.TYPE ) == "int"</li> </p>
- *
- * @param clazz the class
+ * <b>Examples:</b>
+ * <ul>
+ * <li>getJavaClassName( Object[].class ) == "Object[]"</li>
+ * <li>getJavaClassName( Object[][].class ) == "Object[][]"</li>
+ * <li>getJavaClassName( Integer.TYPE ) == "int"</li>
+ * </p>
+ *
+ * @param clazz
+ * the class
* @return the class' name as you would expect to see it in Java code
*/
public static String getJavaClassName(Class<?> clazz)
@@ -132,8 +143,9 @@
/**
* Returns the wrapper class for the given primitive type.
- *
- * @param primitiveType the primitive type
+ *
+ * @param primitiveType
+ * the primitive type
* @return the wrapper class
*/
public static Class<?> getWrapperClass(Class<?> primitiveType)
@@ -143,8 +155,9 @@
/**
* Returns the proper "null value" as specified by the Java language.
- *
- * @param type the type
+ *
+ * @param type
+ * the type
* @return the null value
*/
@SuppressWarnings("unchecked")
@@ -155,38 +168,42 @@
/**
* Learn whether the specified method is/overrides {@link Object#equals(Object)}.
- * @param method to compare
+ *
+ * @param method
+ * to compare
* @return <code>true</code> for a method with signature <code>boolean equals(Object)</code>
*/
public static boolean isEqualsMethod(Method method)
{
- return "equals".equals(method.getName()) &&
- Boolean.TYPE.equals(method.getReturnType()) &&
- method.getParameterTypes().length == 1 &&
- Object.class.equals(method.getParameterTypes()[0]);
+ return "equals".equals(method.getName()) && Boolean.TYPE.equals(method.getReturnType())
+ && method.getParameterTypes().length == 1 && Object.class.equals(method.getParameterTypes()[0]);
}
/**
* Learn whether the specified method is/overrides {@link Object#hashCode()}.
- * @param method to compare
+ *
+ * @param method
+ * to compare
* @return true for a method with signature <code>int hashCode()</code>
*/
public static boolean isHashCode(Method method)
{
- return "hashCode".equals(method.getName()) &&
- Integer.TYPE.equals(method.getReturnType()) &&
- method.getParameterTypes().length == 0;
+ return "hashCode".equals(method.getName()) && Integer.TYPE.equals(method.getReturnType())
+ && method.getParameterTypes().length == 0;
}
/**
* Get a {@link ProxyFactory} that delegates to discoverable {@link ProxyFactory} service providers.
+ *
* @return {@link ProxyFactory}
*/
- public static ProxyFactory proxyFactory() {
+ public static ProxyFactory proxyFactory()
+ {
return DefaultProxyFactory.INSTANCE;
}
- private ProxyUtils() {
+ private ProxyUtils()
+ {
// Hiding constructor in utility class!
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/exception/InvokerException.java b/core/src/main/java/org/apache/commons/proxy2/exception/InvokerException.java
index a747968..5c03831 100644
--- a/core/src/main/java/org/apache/commons/proxy2/exception/InvokerException.java
+++ b/core/src/main/java/org/apache/commons/proxy2/exception/InvokerException.java
@@ -19,7 +19,7 @@
/**
* To be used by an {@link org.apache.commons.proxy2.Invoker} when they encounter an error.
- *
+ *
* @author James Carman
* @since 1.0
*/
@@ -28,9 +28,9 @@
/** Serialization version */
private static final long serialVersionUID = -1L;
- //**********************************************************************************************************************
- // Constructors
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Create a new InvokerException instance.
@@ -41,28 +41,31 @@
/**
* Create a new InvokerException instance.
+ *
* @param message
*/
- public InvokerException( String message )
+ public InvokerException(String message)
{
super(message);
}
/**
* Create a new InvokerException instance.
+ *
* @param cause
*/
- public InvokerException( Throwable cause )
+ public InvokerException(Throwable cause)
{
super(cause);
}
/**
* Create a new InvokerException instance.
+ *
* @param message
* @param cause
*/
- public InvokerException( String message, Throwable cause )
+ public InvokerException(String message, Throwable cause)
{
super(message, cause);
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/exception/ObjectProviderException.java b/core/src/main/java/org/apache/commons/proxy2/exception/ObjectProviderException.java
index 7b956ca..24f3d5c 100644
--- a/core/src/main/java/org/apache/commons/proxy2/exception/ObjectProviderException.java
+++ b/core/src/main/java/org/apache/commons/proxy2/exception/ObjectProviderException.java
@@ -20,7 +20,7 @@
/**
* {@link org.apache.commons.proxy2.ObjectProvider} implementations should throw this exception type to indicate that
* there was a problem creating/finding the object.
- *
+ *
* @author James Carman
* @since 1.0
*/
@@ -29,9 +29,9 @@
/** Serialization version */
private static final long serialVersionUID = -1L;
- //**********************************************************************************************************************
- // Constructors
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Create a new ObjectProviderException instance.
@@ -42,29 +42,55 @@
/**
* Create a new ObjectProviderException instance.
+ *
* @param message
*/
- public ObjectProviderException( String message )
+ public ObjectProviderException(String message)
{
super(message);
}
/**
+ * Create a new ObjectProviderException instance using {@link String#format(String, Object...)} for the message.
+ *
+ * @param message
+ * @param arguments
+ */
+ public ObjectProviderException(String message, Object... arguments)
+ {
+ super(String.format(message, arguments));
+ }
+
+ /**
* Create a new ObjectProviderException instance.
+ *
* @param cause
*/
- public ObjectProviderException( Throwable cause )
+ public ObjectProviderException(Throwable cause)
{
super(cause);
}
/**
* Create a new ObjectProviderException instance.
+ *
* @param message
* @param cause
*/
- public ObjectProviderException( String message, Throwable cause )
+ public ObjectProviderException(String message, Throwable cause)
{
super(message, cause);
}
+
+ /**
+ * Create a new ObjectProviderException instance using {@link String#format(String, Object...)} for the message.
+ *
+ * @param cause
+ * @param message
+ * @param arguments
+ */
+ public ObjectProviderException(Throwable cause, String message, Object... arguments)
+ {
+ super(String.format(message, arguments), cause);
+ }
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/exception/ProxyFactoryException.java b/core/src/main/java/org/apache/commons/proxy2/exception/ProxyFactoryException.java
index de673ad..b71a357 100644
--- a/core/src/main/java/org/apache/commons/proxy2/exception/ProxyFactoryException.java
+++ b/core/src/main/java/org/apache/commons/proxy2/exception/ProxyFactoryException.java
@@ -20,7 +20,7 @@
/**
* A runtime exception type to be used by {@link org.apache.commons.proxy2.ProxyFactory proxy factories} when a problem
* occurs.
- *
+ *
* @author James Carman
* @since 1.0
*/
@@ -29,9 +29,9 @@
/** Serialization version */
private static final long serialVersionUID = -1L;
- //**********************************************************************************************************************
- // Constructors
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Create a new ProxyFactoryException instance.
@@ -42,28 +42,31 @@
/**
* Create a new ProxyFactoryException instance.
+ *
* @param message
*/
- public ProxyFactoryException( String message )
+ public ProxyFactoryException(String message)
{
super(message);
}
/**
* Create a new ProxyFactoryException instance.
+ *
* @param cause
*/
- public ProxyFactoryException( Throwable cause )
+ public ProxyFactoryException(Throwable cause)
{
super(cause);
}
/**
* Create a new ProxyFactoryException instance.
+ *
* @param message
* @param cause
*/
- public ProxyFactoryException( String message, Throwable cause )
+ public ProxyFactoryException(String message, Throwable cause)
{
super(message, cause);
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/impl/AbstractProxyClassGenerator.java b/core/src/main/java/org/apache/commons/proxy2/impl/AbstractProxyClassGenerator.java
index aa777d2..31271ee 100644
--- a/core/src/main/java/org/apache/commons/proxy2/impl/AbstractProxyClassGenerator.java
+++ b/core/src/main/java/org/apache/commons/proxy2/impl/AbstractProxyClassGenerator.java
@@ -19,51 +19,57 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.util.*;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
/**
* A useful superclass for {@link ProxyClassGenerator} implementations.
- *
+ *
* @author James Carman
* @since 1.0
*/
public abstract class AbstractProxyClassGenerator implements ProxyClassGenerator
{
-//**********************************************************************************************************************
-// Static Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Static Methods
+ //******************************************************************************************************************
/**
- * Returns all methods that a proxy class must implement from the proxy interfaces. This method makes sure there
- * are no method signature clashes. For methods with the same signature (name and parameter types), the one
- * encountered first will be returned in the result. Final methods are also excluded from the result.
- *
- * @param proxyClasses the interfaces the proxy class must implement
+ * Returns all methods that a proxy class must implement from the proxy interfaces. This method makes sure there are
+ * no method signature clashes. For methods with the same signature (name and parameter types), the one encountered
+ * first will be returned in the result. Final methods are also excluded from the result.
+ *
+ * @param proxyClasses
+ * the interfaces the proxy class must implement
* @return all methods that the proxy class must implement
*/
- public static Method[] getImplementationMethods( Class<?>[] proxyClasses )
+ public static Method[] getImplementationMethods(Class<?>[] proxyClasses)
{
final Map<MethodSignature, Method> signatureMethodMap = new HashMap<MethodSignature, Method>();
final Set<MethodSignature> finalizedSignatures = new HashSet<MethodSignature>();
- for( int i = 0; i < proxyClasses.length; i++ )
+ for (int i = 0; i < proxyClasses.length; i++)
{
Class<?> proxyInterface = proxyClasses[i];
final Method[] methods = proxyInterface.getMethods();
- for( int j = 0; j < methods.length; j++ )
+ for (int j = 0; j < methods.length; j++)
{
final MethodSignature signature = new MethodSignature(methods[j]);
- if( Modifier.isFinal(methods[j].getModifiers()) )
+ if (Modifier.isFinal(methods[j].getModifiers()))
{
finalizedSignatures.add(signature);
}
- else if( !signatureMethodMap.containsKey(signature) )
+ else if (!signatureMethodMap.containsKey(signature))
{
signatureMethodMap.put(signature, methods[j]);
}
}
}
final Collection<Method> resultingMethods = signatureMethodMap.values();
- for (MethodSignature signature : finalizedSignatures) {
+ for (MethodSignature signature : finalizedSignatures)
+ {
resultingMethods.remove(signatureMethodMap.get(signature));
}
return resultingMethods.toArray(new Method[resultingMethods.size()]);
diff --git a/core/src/main/java/org/apache/commons/proxy2/impl/AbstractProxyFactory.java b/core/src/main/java/org/apache/commons/proxy2/impl/AbstractProxyFactory.java
index 253d98c..7539d9c 100644
--- a/core/src/main/java/org/apache/commons/proxy2/impl/AbstractProxyFactory.java
+++ b/core/src/main/java/org/apache/commons/proxy2/impl/AbstractProxyFactory.java
@@ -23,23 +23,23 @@
import org.apache.commons.proxy2.ProxyFactory;
/**
- * Base abstract {@link ProxyFactory} implementation, primarily providing
- * implementations of the interface methods that are typically convenience
- * constructs over the other methods.
+ * Base abstract {@link ProxyFactory} implementation, primarily providing implementations of the interface methods that
+ * are typically convenience constructs over the other methods.
*/
public abstract class AbstractProxyFactory implements ProxyFactory
{
/**
* Returns true if all <code>proxyClasses</code> are interfaces.
- *
- * @param proxyClasses the proxy classes
+ *
+ * @param proxyClasses
+ * the proxy classes
* @return true if all <code>proxyClasses</code> are interfaces
*/
- public boolean canProxy( Class<?>... proxyClasses )
+ public boolean canProxy(Class<?>... proxyClasses)
{
- for( Class<?> proxyClass : proxyClasses )
+ for (Class<?> proxyClass : proxyClasses)
{
- if( !proxyClass.isInterface() )
+ if (!proxyClass.isInterface())
{
return false;
}
@@ -48,47 +48,52 @@
}
/**
- * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>. The proxy will be
+ * Creates a proxy which delegates to the object provided by <code>delegateProvider</code>. The proxy will be
* generated using the current thread's "context class loader."
- *
- * @param delegateProvider the delegate provider
- * @param proxyClasses the interfaces that the proxy should implement
+ *
+ * @param delegateProvider
+ * the delegate provider
+ * @param proxyClasses
+ * the interfaces that the proxy should implement
* @return a proxy which delegates to the object provided by the target object provider
*/
- public <T> T createDelegatorProxy( ObjectProvider<?> delegateProvider, Class<?>... proxyClasses )
+ public <T> T createDelegatorProxy(ObjectProvider<?> delegateProvider, Class<?>... proxyClasses)
{
return createDelegatorProxy(Thread.currentThread().getContextClassLoader(), delegateProvider, proxyClasses);
}
/**
* Creates a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
- * <code>target</code> object. The proxy will be generated using the current thread's "context class loader."
- *
- * @param target the target object
- * @param interceptor the method interceptor
- * @param proxyClasses the interfaces that the proxy should implement
+ * <code>target</code> object. The proxy will be generated using the current thread's "context class loader."
+ *
+ * @param target
+ * the target object
+ * @param interceptor
+ * the method interceptor
+ * @param proxyClasses
+ * the interfaces that the proxy should implement
* @return a proxy which passes through a {@link Interceptor interceptor} before eventually reaching the
* <code>target</code> object.
*/
- public <T> T createInterceptorProxy( Object target, Interceptor interceptor,
- Class<?>... proxyClasses )
+ public <T> T createInterceptorProxy(Object target, Interceptor interceptor, Class<?>... proxyClasses)
{
return createInterceptorProxy(Thread.currentThread().getContextClassLoader(), target, interceptor,
- proxyClasses);
+ proxyClasses);
}
/**
- * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations. The proxy will be
+ * Creates a proxy which uses the provided {@link Invoker} to handle all method invocations. The proxy will be
* generated using the current thread's "context class loader."
- *
- * @param invoker the invoker
- * @param proxyClasses the interfaces that the proxy should implement
+ *
+ * @param invoker
+ * the invoker
+ * @param proxyClasses
+ * the interfaces that the proxy should implement
* @return a proxy which uses the provided {@link Invoker} to handle all method invocations
*/
- public <T> T createInvokerProxy( Invoker invoker, Class<?>... proxyClasses )
+ public <T> T createInvokerProxy(Invoker invoker, Class<?>... proxyClasses)
{
- return createInvokerProxy(Thread.currentThread().getContextClassLoader(), invoker,
- proxyClasses);
+ return createInvokerProxy(Thread.currentThread().getContextClassLoader(), invoker, proxyClasses);
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/impl/AbstractSubclassingProxyFactory.java b/core/src/main/java/org/apache/commons/proxy2/impl/AbstractSubclassingProxyFactory.java
index 46f4243..f417120 100644
--- a/core/src/main/java/org/apache/commons/proxy2/impl/AbstractSubclassingProxyFactory.java
+++ b/core/src/main/java/org/apache/commons/proxy2/impl/AbstractSubclassingProxyFactory.java
@@ -16,55 +16,57 @@
*/
package org.apache.commons.proxy2.impl;
-import org.apache.commons.proxy2.exception.ProxyFactoryException;
-
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.LinkedHashSet;
import java.util.Set;
+import org.apache.commons.proxy2.exception.ProxyFactoryException;
+
/**
- * Parent {@link AbstractProxyFactory} for implementations that permit the generation of
- * proxies with a specific inheritance hierarchy.
+ * Parent {@link AbstractProxyFactory} for implementations that permit the generation of proxies with a specific
+ * inheritance hierarchy.
*/
public abstract class AbstractSubclassingProxyFactory extends AbstractProxyFactory
{
-//**********************************************************************************************************************
-// ProxyFactory Implementation
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // ProxyFactory Implementation
+ //******************************************************************************************************************
/**
* Returns true if a suitable superclass can be found, given the desired <code>proxyClasses</code>.
- *
- * @param proxyClasses the proxy classes
+ *
+ * @param proxyClasses
+ * the proxy classes
* @return true if a suitable superclass can be found, given the desired <code>proxyClasses</code>
*/
- public boolean canProxy( Class<?>... proxyClasses )
+ public boolean canProxy(Class<?>... proxyClasses)
{
try
{
getSuperclass(proxyClasses);
return true;
}
- catch( ProxyFactoryException e )
+ catch (ProxyFactoryException e)
{
return false;
}
}
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
- private static boolean hasSuitableDefaultConstructor( Class<?> superclass )
+ private static boolean hasSuitableDefaultConstructor(Class<?> superclass)
{
final Constructor<?>[] declaredConstructors = superclass.getDeclaredConstructors();
- for( int i = 0; i < declaredConstructors.length; i++ )
+ for (int i = 0; i < declaredConstructors.length; i++)
{
Constructor<?> constructor = declaredConstructors[i];
- if( constructor.getParameterTypes().length == 0 && ( Modifier.isPublic(constructor.getModifiers()) ||
- Modifier.isProtected(constructor.getModifiers()) ) )
+ if (constructor.getParameterTypes().length == 0
+ && (Modifier.isPublic(constructor.getModifiers()) || Modifier.isProtected(constructor
+ .getModifiers())))
{
return true;
}
@@ -72,12 +74,12 @@
return false;
}
- private static Class<?>[] toNonInterfaces( Class<?>[] proxyClasses )
+ private static Class<?>[] toNonInterfaces(Class<?>[] proxyClasses)
{
final Set<Class<?>> superclasses = new LinkedHashSet<Class<?>>();
for (Class<?> proxyClass : proxyClasses)
{
- if( !proxyClass.isInterface())
+ if (!proxyClass.isInterface())
{
superclasses.add(proxyClass);
}
@@ -88,74 +90,71 @@
/**
* Returns the <code>proxyClasses</code> transformed into an array of only the interface classes.
* <p/>
- * <b>Note</b>: This class will append {@link Serializable} to the end of the list if it's
- * not found!
- *
- * @param proxyClasses the proxy classes
+ * <b>Note</b>: This class will append {@link Serializable} to the end of the list if it's not found!
+ *
+ * @param proxyClasses
+ * the proxy classes
* @return the <code>proxyClasses</code> transformed into an array of only the interface classes
*/
- protected static Class<?>[] toInterfaces( Class<?>[] proxyClasses )
+ protected static Class<?>[] toInterfaces(Class<?>[] proxyClasses)
{
final Set<Class<?>> interfaces = new LinkedHashSet<Class<?>>();
- boolean serializableFound = false;
for (Class<?> proxyClass : proxyClasses)
{
- if( proxyClass.isInterface() )
+ if (proxyClass.isInterface())
{
interfaces.add(proxyClass);
}
- serializableFound |= ( Serializable.class.equals(proxyClass) );
}
- if( !serializableFound )
- {
- interfaces.add(Serializable.class);
- }
- return ( Class[] ) interfaces.toArray(new Class[interfaces.size()]);
+ interfaces.add(Serializable.class);
+ return interfaces.toArray(new Class[interfaces.size()]);
}
/**
* Returns either {@link Object} if all of the <code>proxyClasses</code> are interfaces or the single non-interface
* class from <code>proxyClasses</code>.
- *
- * @param proxyClasses the proxy classes
+ *
+ * @param proxyClasses
+ * the proxy classes
* @return either {@link Object} if all of the <code>proxyClasses</code> are interfaces or the single non-interface
* class from <code>proxyClasses</code>
- * @throws ProxyFactoryException if multiple non-interface classes are contained in <code>proxyClasses</code> or any
- * of the non-interface classes are final
+ * @throws ProxyFactoryException
+ * if multiple non-interface classes are contained in <code>proxyClasses</code> or any of the
+ * non-interface classes are final
*/
- public static Class<?> getSuperclass( Class<?>[] proxyClasses )
+ public static Class<?> getSuperclass(Class<?>[] proxyClasses)
{
final Class<?>[] superclasses = toNonInterfaces(proxyClasses);
- switch( superclasses.length )
+ switch (superclasses.length)
{
- case 0:
- return Object.class;
- case 1:
- final Class<?> superclass = superclasses[0];
- if( Modifier.isFinal(superclass.getModifiers()) )
+ case 0:
+ return Object.class;
+ case 1:
+ final Class<?> superclass = superclasses[0];
+ if (Modifier.isFinal(superclass.getModifiers()))
+ {
+ throw new ProxyFactoryException("Proxy class cannot extend " + superclass.getName()
+ + " as it is final.");
+ }
+ if (!hasSuitableDefaultConstructor(superclass))
+ {
+ throw new ProxyFactoryException("Proxy class cannot extend " + superclass.getName()
+ + ", because it has no visible \"default\" constructor.");
+ }
+ return superclass;
+ default:
+ final StringBuilder errorMessage = new StringBuilder("Proxy class cannot extend ");
+ for (int i = 0; i < superclasses.length; i++)
+ {
+ Class<?> c = superclasses[i];
+ errorMessage.append(c.getName());
+ if (i != superclasses.length - 1)
{
- throw new ProxyFactoryException(
- "Proxy class cannot extend " + superclass.getName() + " as it is final.");
+ errorMessage.append(", ");
}
- if( !hasSuitableDefaultConstructor(superclass) )
- {
- throw new ProxyFactoryException("Proxy class cannot extend " + superclass.getName() +
- ", because it has no visible \"default\" constructor.");
- }
- return superclass;
- default:
- final StringBuilder errorMessage = new StringBuilder("Proxy class cannot extend ");
- for( int i = 0; i < superclasses.length; i++ )
- {
- Class<?> c = superclasses[i];
- errorMessage.append(c.getName());
- if( i != superclasses.length - 1 )
- {
- errorMessage.append(", ");
- }
- }
- errorMessage.append("; multiple inheritance not allowed.");
- throw new ProxyFactoryException(errorMessage.toString());
+ }
+ errorMessage.append("; multiple inheritance not allowed.");
+ throw new ProxyFactoryException(errorMessage.toString());
}
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/impl/MethodSignature.java b/core/src/main/java/org/apache/commons/proxy2/impl/MethodSignature.java
index 05cad71..17867ac 100644
--- a/core/src/main/java/org/apache/commons/proxy2/impl/MethodSignature.java
+++ b/core/src/main/java/org/apache/commons/proxy2/impl/MethodSignature.java
@@ -36,7 +36,7 @@
/**
* A class for capturing the signature of a method (its name and parameter types).
- *
+ *
* @author James Carman
* @since 1.0
*/
@@ -86,7 +86,8 @@
private static class SignaturePosition extends ParsePosition
{
- SignaturePosition() {
+ SignaturePosition()
+ {
super(0);
}
@@ -118,7 +119,8 @@
while (pos.getIndex() < internal.length())
{
final char c = internal.charAt(pos.getIndex());
- if (Character.isWhitespace(c)) {
+ if (Character.isWhitespace(c))
+ {
pos.next();
continue;
}
@@ -135,21 +137,25 @@
pos.next();
break;
}
- try {
+ try
+ {
params.add(parseType(internal, pos));
- } catch (ClassNotFoundException e) {
+ }
+ catch (ClassNotFoundException e)
+ {
throw new IllegalArgumentException(String.format("Method signature \"%s\" references unknown type",
- internal), e);
+ internal), e);
}
}
Validate.isTrue(complete, "Method signature \"%s\" is incomplete", internal);
Validate.isTrue(StringUtils.isBlank(internal.substring(pos.getIndex())),
- "Method signature \"%s\" includes unrecognized content beyond end", internal);
+ "Method signature \"%s\" includes unrecognized content beyond end", internal);
return Pair.of(name, params.toArray(ArrayUtils.EMPTY_CLASS_ARRAY));
}
- private static Class<?> parseType(String internal, SignaturePosition pos) throws ClassNotFoundException {
+ private static Class<?> parseType(String internal, SignaturePosition pos) throws ClassNotFoundException
+ {
final int here = pos.getIndex();
final char c = internal.charAt(here);
@@ -164,33 +170,33 @@
final int type = pos.getIndex();
final int semi = internal.indexOf(';', type);
Validate.isTrue(semi > 0, "Type at index %s of method signature \"%s\" not terminated by semicolon", here,
- internal);
+ internal);
final String className = internal.substring(type, semi).replace('/', '.');
Validate.notBlank(className, "Invalid classname at position %s of method signature \"%s\"", type, internal);
pos.setIndex(semi + 1);
return Class.forName(className);
default:
throw new IllegalArgumentException(String.format(
- "Unexpected character at index %s of method signature \"%s\"", here, internal));
+ "Unexpected character at index %s of method signature \"%s\"", here, internal));
}
}
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
/**
* Stored as a Java method descriptor minus return type.
*/
private final String internal;
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Create a new MethodSignature instance.
- *
+ *
* @param method
*/
public MethodSignature(Method method)
@@ -204,25 +210,25 @@
this.internal = buf.toString();
}
-//----------------------------------------------------------------------------------------------------------------------
-// Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Methods
+ //******************************************************************************************************************
/**
- * Get the corresponding {@link Method} instance
- * from the specified {@link Class}.
+ * Get the corresponding {@link Method} instance from the specified {@link Class}.
+ *
* @param type
* @return Method
*/
public Method toMethod(Class<?> type)
{
- final Pair<String,Class<?>[]> info = parse(internal);
+ final Pair<String, Class<?>[]> info = parse(internal);
return MethodUtils.getAccessibleMethod(type, info.getLeft(), info.getRight());
}
-//----------------------------------------------------------------------------------------------------------------------
-// Canonical Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Canonical Methods
+ //******************************************************************************************************************
/**
* {@inheritDoc}
diff --git a/core/src/main/java/org/apache/commons/proxy2/impl/ProxyClassCache.java b/core/src/main/java/org/apache/commons/proxy2/impl/ProxyClassCache.java
index 726a046..0ddded7 100644
--- a/core/src/main/java/org/apache/commons/proxy2/impl/ProxyClassCache.java
+++ b/core/src/main/java/org/apache/commons/proxy2/impl/ProxyClassCache.java
@@ -19,48 +19,54 @@
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
-import java.util.*;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+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.
- *
+ * 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
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private final Map<ClassLoader, Map<Set<Class<?>>, WeakReference<Class<?>>>> loaderToClassCache
- = new WeakHashMap<ClassLoader, Map<Set<Class<?>>, WeakReference<Class<?>>>>();
+ = new WeakHashMap<ClassLoader, Map<Set<Class<?>>, WeakReference<Class<?>>>>();
private final ProxyClassGenerator proxyClassGenerator;
- //**********************************************************************************************************************
- // Constructors
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Create a new ProxyClassCache instance.
+ *
* @param proxyClassGenerator
*/
- public ProxyClassCache( ProxyClassGenerator proxyClassGenerator )
+ public ProxyClassCache(ProxyClassGenerator proxyClassGenerator)
{
this.proxyClassGenerator = proxyClassGenerator;
}
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
- private Map<Set<Class<?>>, WeakReference<Class<?>>> getClassCache( ClassLoader classLoader )
+ private Map<Set<Class<?>>, WeakReference<Class<?>>> getClassCache(ClassLoader classLoader)
{
Map<Set<Class<?>>, WeakReference<Class<?>>> cache = loaderToClassCache.get(classLoader);
- if( cache == null )
+ if (cache == null)
{
cache = new HashMap<Set<Class<?>>, WeakReference<Class<?>>>();
loaderToClassCache.put(classLoader, cache);
@@ -68,7 +74,7 @@
return cache;
}
- private Set<Class<?>> toClassCacheKey( Class<?>[] proxyClasses )
+ private Set<Class<?>> toClassCacheKey(Class<?>[] proxyClasses)
{
return new HashSet<Class<?>>(Arrays.asList(proxyClasses));
}
@@ -76,29 +82,31 @@
/**
* 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
+ *
+ * @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 )
+ public synchronized Class<?> getProxyClass(ClassLoader classLoader, Class<?>[] proxyClasses)
{
final Map<Set<Class<?>>, WeakReference<Class<?>>> classCache = getClassCache(classLoader);
final Set<Class<?>> key = toClassCacheKey(proxyClasses);
Class<?> proxyClass;
Reference<Class<?>> proxyClassReference = classCache.get(key);
- if( proxyClassReference == null )
+ if (proxyClassReference == null)
{
proxyClass = proxyClassGenerator.generateProxyClass(classLoader, proxyClasses);
classCache.put(key, new WeakReference<Class<?>>(proxyClass));
}
else
{
- synchronized( proxyClassReference )
+ synchronized (proxyClassReference)
{
proxyClass = proxyClassReference.get();
- if( proxyClass == null )
+ if (proxyClass == null)
{
proxyClass = proxyClassGenerator.generateProxyClass(classLoader, proxyClasses);
classCache.put(key, new WeakReference<Class<?>>(proxyClass));
diff --git a/core/src/main/java/org/apache/commons/proxy2/impl/ProxyClassGenerator.java b/core/src/main/java/org/apache/commons/proxy2/impl/ProxyClassGenerator.java
index 531ca3f..1f989a0 100644
--- a/core/src/main/java/org/apache/commons/proxy2/impl/ProxyClassGenerator.java
+++ b/core/src/main/java/org/apache/commons/proxy2/impl/ProxyClassGenerator.java
@@ -18,26 +18,28 @@
package org.apache.commons.proxy2.impl;
/**
- * A proxy class generator generates Class instances for a given combination of interfaces
- * in a given classloader. Typically, in the context of a {@link org.apache.commons.proxy2.ProxyFactory}
- * implementation, an instance will generate proxy class instances for a specific type of proxies (interceptor,
- * invoker, etc.) and will be associated with a corresponding {@link ProxyClassCache}.
- *
+ * A proxy class generator generates Class instances for a given combination of interfaces in a given classloader.
+ * Typically, in the context of a {@link org.apache.commons.proxy2.ProxyFactory} implementation, an instance will
+ * generate proxy class instances for a specific type of proxies (interceptor, invoker, etc.) and will be associated
+ * with a corresponding {@link ProxyClassCache}.
+ *
* @author James Carman
* @since 1.0
*/
public interface ProxyClassGenerator
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
/**
* Generates a proxy class for the supplied {@link ClassLoader} and proxy classes.
- *
- * @param classLoader the classloader
- * @param proxyClasses the proxy classes
+ *
+ * @param classLoader
+ * the classloader
+ * @param proxyClasses
+ * the proxy classes
* @return the dynamically generated proxy class
*/
- Class<?> generateProxyClass( ClassLoader classLoader, Class<?>... proxyClasses );
+ Class<?> generateProxyClass(ClassLoader classLoader, Class<?>... proxyClasses);
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/interceptor/InterceptorUtils.java b/core/src/main/java/org/apache/commons/proxy2/interceptor/InterceptorUtils.java
index 7751bc1..f26bf7e 100644
--- a/core/src/main/java/org/apache/commons/proxy2/interceptor/InterceptorUtils.java
+++ b/core/src/main/java/org/apache/commons/proxy2/interceptor/InterceptorUtils.java
@@ -24,13 +24,15 @@
public final class InterceptorUtils
{
-//----------------------------------------------------------------------------------------------------------------------
-// Static Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Static Methods
+ //******************************************************************************************************************
/**
* Creates an {@link Interceptor} which always returns a constant value (for all methods).
- * @param value the constant
+ *
+ * @param value
+ * the constant
* @return an {@link Interceptor} which always returns a constant value (for all methods)
*/
public static Interceptor constant(Object value)
@@ -39,11 +41,11 @@
}
/**
- * Creates an {@link Interceptor} which returns the resulting object from an
- * object provider (for all methods).
- * @param provider the object provider
- * @return an {@link Interceptor} which returns the resulting object from an
- * object provider (for all methods)
+ * Creates an {@link Interceptor} which returns the resulting object from an object provider (for all methods).
+ *
+ * @param provider
+ * the object provider
+ * @return an {@link Interceptor} which returns the resulting object from an object provider (for all methods)
*/
public static Interceptor provider(ObjectProvider<?> provider)
{
@@ -52,7 +54,9 @@
/**
* Creates an {@link Interceptor} which throws a specific exception (for all methods).
- * @param e the exception
+ *
+ * @param e
+ * the exception
* @return an {@link Interceptor} which throws a specific exception (for all methods)
*/
public static Interceptor throwing(Exception e)
@@ -61,11 +65,11 @@
}
/**
- * Creates an {@link Interceptor} which throws the exception provided by an object
- * provider (for all methods).
- * @param provider the object provider
- * @return an {@link Interceptor} which throws the exception provided by an object
- * provider (for all methods)
+ * Creates an {@link Interceptor} which throws the exception provided by an object provider (for all methods).
+ *
+ * @param provider
+ * the object provider
+ * @return an {@link Interceptor} which throws the exception provided by an object provider (for all methods)
*/
public static Interceptor throwing(ObjectProvider<? extends Exception> provider)
{
@@ -74,7 +78,9 @@
/**
* Creates an {@link Interceptor} that delegates to the specified {@link Invoker}.
- * @param invoker delegate
+ *
+ * @param invoker
+ * delegate
* @return invoker {@link Interceptor}
*/
public static Interceptor invoking(Invoker invoker)
@@ -82,9 +88,9 @@
return new InvokerInterceptor(invoker);
}
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
private InterceptorUtils()
{
diff --git a/core/src/main/java/org/apache/commons/proxy2/interceptor/ObjectProviderInterceptor.java b/core/src/main/java/org/apache/commons/proxy2/interceptor/ObjectProviderInterceptor.java
index 250aae4..1b16bca 100644
--- a/core/src/main/java/org/apache/commons/proxy2/interceptor/ObjectProviderInterceptor.java
+++ b/core/src/main/java/org/apache/commons/proxy2/interceptor/ObjectProviderInterceptor.java
@@ -28,26 +28,26 @@
*/
public class ObjectProviderInterceptor implements Interceptor
{
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
- private final ObjectProvider<?> provider;
+ private final ObjectProvider<?> provider;
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
public ObjectProviderInterceptor(ObjectProvider<?> provider)
{
this.provider = Validate.notNull(provider, "Provider cannot be null.");
}
-//----------------------------------------------------------------------------------------------------------------------
-// Interceptor Implementation
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Interceptor Implementation
+ //******************************************************************************************************************
@Override
public Object intercept(Invocation invocation) throws Throwable
diff --git a/core/src/main/java/org/apache/commons/proxy2/interceptor/SwitchInterceptor.java b/core/src/main/java/org/apache/commons/proxy2/interceptor/SwitchInterceptor.java
index a14c654..f501c0c 100644
--- a/core/src/main/java/org/apache/commons/proxy2/interceptor/SwitchInterceptor.java
+++ b/core/src/main/java/org/apache/commons/proxy2/interceptor/SwitchInterceptor.java
@@ -17,44 +17,45 @@
package org.apache.commons.proxy2.interceptor;
+import java.io.Serializable;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.proxy2.Interceptor;
import org.apache.commons.proxy2.Invocation;
import org.apache.commons.proxy2.interceptor.matcher.InvocationMatcher;
-import java.io.Serializable;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-
/**
* A {@link SwitchInterceptor} maintains a list of
* {@link org.apache.commons.proxy2.interceptor.matcher.InvocationMatcher}/{@link Interceptor} pairs. Each invocation
- * will be checked against the registered InvocationMatchers. If one matches the current invocation, then the
+ * will be checked against the registered InvocationMatchers. If one matches the current invocation, then the
* corresponding Interceptor will be called. If no InvocationMatchers match, the
* {@link org.apache.commons.proxy2.Invocation#proceed()} method is called with no interception.
*/
public class SwitchInterceptor implements Interceptor, Serializable
{
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private static final long serialVersionUID = 1L;
- private final List<Pair<InvocationMatcher, Interceptor>> cases = new CopyOnWriteArrayList<Pair<InvocationMatcher, Interceptor>>();
+ private final List<Pair<InvocationMatcher, Interceptor>> cases
+ = new CopyOnWriteArrayList<Pair<InvocationMatcher, Interceptor>>();
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
public SwitchInterceptor()
{
}
-//----------------------------------------------------------------------------------------------------------------------
-// Interceptor Implementation
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Interceptor Implementation
+ //******************************************************************************************************************
@Override
public Object intercept(Invocation invocation) throws Throwable
@@ -69,18 +70,18 @@
return invocation.proceed();
}
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
public CaseBuilder when(InvocationMatcher matcher)
{
return new CaseBuilder(matcher);
}
-//----------------------------------------------------------------------------------------------------------------------
-// Inner Classes
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Inner Classes
+ //******************************************************************************************************************
public class CaseBuilder
{
diff --git a/core/src/main/java/org/apache/commons/proxy2/interceptor/ThrowingInterceptor.java b/core/src/main/java/org/apache/commons/proxy2/interceptor/ThrowingInterceptor.java
index 9201e29..dbfc892 100644
--- a/core/src/main/java/org/apache/commons/proxy2/interceptor/ThrowingInterceptor.java
+++ b/core/src/main/java/org/apache/commons/proxy2/interceptor/ThrowingInterceptor.java
@@ -23,26 +23,26 @@
public class ThrowingInterceptor implements Interceptor
{
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
- private final ObjectProvider<? extends Exception> provider;
+ private final ObjectProvider<? extends Exception> provider;
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
public ThrowingInterceptor(ObjectProvider<? extends Exception> provider)
{
this.provider = provider;
}
-//----------------------------------------------------------------------------------------------------------------------
-// Interceptor Implementation
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Interceptor Implementation
+ //******************************************************************************************************************
@Override
public Object intercept(Invocation invocation) throws Throwable
diff --git a/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/ArgumentMatcher.java b/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/ArgumentMatcher.java
index db3c586..fcd5a3b 100644
--- a/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/ArgumentMatcher.java
+++ b/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/ArgumentMatcher.java
@@ -19,9 +19,9 @@
public interface ArgumentMatcher<T>
{
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
boolean matches(T argument);
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/InvocationMatcher.java b/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/InvocationMatcher.java
index a439b01..38493d0 100644
--- a/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/InvocationMatcher.java
+++ b/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/InvocationMatcher.java
@@ -20,14 +20,14 @@
import org.apache.commons.proxy2.Invocation;
/**
- * An {@link InvocationMatcher} is used to conditionally match {@link Invocation} objects based on
- * some criteria such as method name, parameter values, etc.
+ * An {@link InvocationMatcher} is used to conditionally match {@link Invocation} objects based on some criteria such as
+ * method name, parameter values, etc.
*/
public interface InvocationMatcher
{
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
boolean matches(Invocation invocation);
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtils.java b/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtils.java
index bc7e295..0796b62 100644
--- a/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtils.java
+++ b/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtils.java
@@ -24,9 +24,9 @@
public final class ArgumentMatcherUtils
{
-//----------------------------------------------------------------------------------------------------------------------
-// Static Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Static Methods
+ //******************************************************************************************************************
public static <T> ArgumentMatcher<T> any()
{
@@ -88,18 +88,18 @@
return new StartsWithMatcher(Validate.notNull(prefix));
}
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
private ArgumentMatcherUtils()
{
}
-//----------------------------------------------------------------------------------------------------------------------
-// Inner Classes
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Inner Classes
+ //******************************************************************************************************************
private static final class AnyMatcher<T> implements ArgumentMatcher<T>
{
@@ -147,7 +147,7 @@
@Override
public boolean matches(String argument)
{
- return StringUtils.endsWith(argument, suffix);
+ return StringUtils.endsWith(argument, suffix);
}
}
@@ -160,6 +160,7 @@
this.value = value;
}
+ @SuppressWarnings("deprecation")
@Override
public boolean matches(T argument)
{
@@ -285,7 +286,7 @@
@Override
public boolean matches(String argument)
{
- return StringUtils.startsWith(argument, prefix);
+ return StringUtils.startsWith(argument, prefix);
}
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/invocation/DeclaredByMatcher.java b/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/invocation/DeclaredByMatcher.java
index c881b0b..ffa80bb 100644
--- a/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/invocation/DeclaredByMatcher.java
+++ b/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/invocation/DeclaredByMatcher.java
@@ -25,19 +25,20 @@
*/
public class DeclaredByMatcher implements InvocationMatcher
{
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private final boolean exactMatch;
private final Class<?> declaredByType;
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Equivalent to {@link #DeclaredByMatcher(Class, boolean)}{@code (declaredByType, false)}
+ *
* @param declaredByType
*/
public DeclaredByMatcher(Class<?> declaredByType)
@@ -51,8 +52,8 @@
* @param declaredByType
* type by which method must be declared
* @param exactMatch
- * if {@code false}, {@code declaredByType} may be a subclass of
- * the actual declaring class of the invocation method.
+ * if {@code false}, {@code declaredByType} may be a subclass of the actual declaring class of the
+ * invocation method.
*/
public DeclaredByMatcher(Class<?> declaredByType, boolean exactMatch)
{
@@ -60,16 +61,14 @@
this.exactMatch = exactMatch;
}
-//----------------------------------------------------------------------------------------------------------------------
-// InvocationMatcher Implementation
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // InvocationMatcher Implementation
+ //******************************************************************************************************************
@Override
public boolean matches(Invocation invocation)
{
final Class<?> owner = invocation.getMethod().getDeclaringClass();
- return exactMatch ?
- declaredByType.equals(owner) :
- owner.isAssignableFrom(declaredByType);
+ return exactMatch ? declaredByType.equals(owner) : owner.isAssignableFrom(declaredByType);
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/invocation/MethodNameMatcher.java b/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/invocation/MethodNameMatcher.java
index 7eaa7ef..eb80cff 100644
--- a/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/invocation/MethodNameMatcher.java
+++ b/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/invocation/MethodNameMatcher.java
@@ -26,24 +26,24 @@
*/
public class MethodNameMatcher implements InvocationMatcher
{
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private final String methodName;
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
public MethodNameMatcher(String methodName)
{
this.methodName = methodName;
}
-//----------------------------------------------------------------------------------------------------------------------
-// InvocationMatcher Implementation
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // InvocationMatcher Implementation
+ //******************************************************************************************************************
@Override
public boolean matches(Invocation invocation)
diff --git a/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/invocation/ReturnTypeMatcher.java b/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/invocation/ReturnTypeMatcher.java
index 9b7d743..32a2341 100644
--- a/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/invocation/ReturnTypeMatcher.java
+++ b/core/src/main/java/org/apache/commons/proxy2/interceptor/matcher/invocation/ReturnTypeMatcher.java
@@ -22,16 +22,16 @@
public class ReturnTypeMatcher implements InvocationMatcher
{
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private final boolean exactMatch;
private final Class<?> returnType;
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
public ReturnTypeMatcher(Class<?> returnType)
{
@@ -44,16 +44,14 @@
this.exactMatch = exactMatch;
}
-//----------------------------------------------------------------------------------------------------------------------
-// InvocationMatcher Implementation
-//----------------------------------------------------------------------------------------------------------------------
-
+ //******************************************************************************************************************
+ // InvocationMatcher Implementation
+ //******************************************************************************************************************
@Override
public boolean matches(Invocation invocation)
{
- return exactMatch ?
- returnType.equals(invocation.getMethod().getReturnType()) :
- returnType.isAssignableFrom(invocation.getMethod().getReturnType());
+ return exactMatch ? returnType.equals(invocation.getMethod().getReturnType()) : returnType
+ .isAssignableFrom(invocation.getMethod().getReturnType());
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/invoker/DelegatingInvoker.java b/core/src/main/java/org/apache/commons/proxy2/invoker/DelegatingInvoker.java
index 4607847..75125fe 100644
--- a/core/src/main/java/org/apache/commons/proxy2/invoker/DelegatingInvoker.java
+++ b/core/src/main/java/org/apache/commons/proxy2/invoker/DelegatingInvoker.java
@@ -25,8 +25,7 @@
import org.apache.commons.proxy2.ObjectProvider;
/**
- * Delegates a method invocation to the object provided by an
- * {@link ObjectProvider}.
+ * Delegates a method invocation to the object provided by an {@link ObjectProvider}.
*
* @param <T>
*/
diff --git a/core/src/main/java/org/apache/commons/proxy2/invoker/DuckTypingInvoker.java b/core/src/main/java/org/apache/commons/proxy2/invoker/DuckTypingInvoker.java
index 0e6a11d..fdb48d9 100644
--- a/core/src/main/java/org/apache/commons/proxy2/invoker/DuckTypingInvoker.java
+++ b/core/src/main/java/org/apache/commons/proxy2/invoker/DuckTypingInvoker.java
@@ -17,19 +17,20 @@
package org.apache.commons.proxy2.invoker;
+import java.lang.reflect.Method;
+
import org.apache.commons.proxy2.Invoker;
import org.apache.commons.proxy2.ObjectProvider;
-import java.lang.reflect.Method;
-
/**
* An invoker which supports <a href="http://en.wikipedia.org/wiki/Duck_typing">"duck typing"</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.
+ * 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!
* {
@@ -48,6 +49,7 @@
* DuckTypingInvoker invoker = new DuckTypingInvoker(targetProvider);
* Duck duck = ( Duck )proxyFactory.createInvokerProxy( invoker, new Class[] { Duck.class } );
* </pre>
+ *
* </p>
*/
public class DuckTypingInvoker implements Invoker
@@ -55,50 +57,51 @@
/** Serialization version */
private static final long serialVersionUID = 1L;
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private final ObjectProvider<?> targetProvider;
- //**********************************************************************************************************************
- // Constructors
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Create a new DuckTypingInvoker instance.
+ *
* @param targetProvider
*/
- public DuckTypingInvoker( final ObjectProvider<?> targetProvider )
+ public DuckTypingInvoker(final ObjectProvider<?> targetProvider)
{
this.targetProvider = targetProvider;
}
- //**********************************************************************************************************************
- // Invoker Implementation
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Invoker Implementation
+ //******************************************************************************************************************
/**
* {@inheritDoc}
*/
- public Object invoke( final Object proxy, final Method method, final Object[] arguments ) throws Throwable
+ 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()) )
+ if (method.getReturnType().isAssignableFrom(targetMethod.getReturnType()))
{
return targetMethod.invoke(target, arguments);
}
- throw new UnsupportedOperationException(
- "Target type " + targetClass.getName() + " method has incompatible return type.");
+ throw new UnsupportedOperationException("Target type " + targetClass.getName()
+ + " method has incompatible return type.");
}
- catch( NoSuchMethodException e )
+ catch (NoSuchMethodException e)
{
- throw new UnsupportedOperationException(
- "Target type " + targetClass.getName() + " does not have a method matching " + method + ".", e);
+ throw new UnsupportedOperationException("Target type " + targetClass.getName()
+ + " does not have a method matching " + method + ".", e);
}
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/invoker/InvocationHandlerAdapter.java b/core/src/main/java/org/apache/commons/proxy2/invoker/InvocationHandlerAdapter.java
index 71714ba..02b0bd1 100644
--- a/core/src/main/java/org/apache/commons/proxy2/invoker/InvocationHandlerAdapter.java
+++ b/core/src/main/java/org/apache/commons/proxy2/invoker/InvocationHandlerAdapter.java
@@ -17,15 +17,14 @@
package org.apache.commons.proxy2.invoker;
-import org.apache.commons.proxy2.Invoker;
-
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import org.apache.commons.proxy2.Invoker;
+
/**
- * An adapter class to adapt the JDK's {@link InvocationHandler} interface to Commons Proxy's
- * {@link Invoker} interface.
- *
+ * An adapter class to adapt the JDK's {@link InvocationHandler} interface to Commons Proxy's {@link Invoker} interface.
+ *
* @author James Carman
* @since 1.0
*/
@@ -34,33 +33,34 @@
/** Serialization version */
private static final long serialVersionUID = 1L;
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private final InvocationHandler invocationHandler;
- //**********************************************************************************************************************
- // Constructors
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Create a new InvocationHandlerAdapter instance.
+ *
* @param invocationHandler
*/
- public InvocationHandlerAdapter( InvocationHandler invocationHandler )
+ public InvocationHandlerAdapter(InvocationHandler invocationHandler)
{
this.invocationHandler = invocationHandler;
}
- //**********************************************************************************************************************
- // Invoker Implementation
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Invoker Implementation
+ //******************************************************************************************************************
/**
* {@inheritDoc}
*/
- public Object invoke( Object proxy, Method method, Object[] arguments ) throws Throwable
+ public Object invoke(Object proxy, Method method, Object[] arguments) throws Throwable
{
return invocationHandler.invoke(proxy, method, arguments);
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/invoker/NullInvoker.java b/core/src/main/java/org/apache/commons/proxy2/invoker/NullInvoker.java
index 1bcc33e..a5e19bf 100644
--- a/core/src/main/java/org/apache/commons/proxy2/invoker/NullInvoker.java
+++ b/core/src/main/java/org/apache/commons/proxy2/invoker/NullInvoker.java
@@ -17,16 +17,16 @@
package org.apache.commons.proxy2.invoker;
-import org.apache.commons.proxy2.Invoker;
-import org.apache.commons.proxy2.ProxyUtils;
-
import java.io.Serializable;
import java.lang.reflect.Method;
+import org.apache.commons.proxy2.Invoker;
+import org.apache.commons.proxy2.ProxyUtils;
+
/**
- * 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.
- *
+ * 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
*/
@@ -40,14 +40,14 @@
*/
public static final NullInvoker INSTANCE = new NullInvoker();
- //**********************************************************************************************************************
- // Invoker Implementation
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Invoker Implementation
+ //******************************************************************************************************************
/**
* {@inheritDoc}
*/
- public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
final Class<?> returnType = method.getReturnType();
return ProxyUtils.nullValue(returnType);
diff --git a/core/src/main/java/org/apache/commons/proxy2/invoker/RecordedInvocation.java b/core/src/main/java/org/apache/commons/proxy2/invoker/RecordedInvocation.java
index ada8299..4144a7e 100644
--- a/core/src/main/java/org/apache/commons/proxy2/invoker/RecordedInvocation.java
+++ b/core/src/main/java/org/apache/commons/proxy2/invoker/RecordedInvocation.java
@@ -17,32 +17,32 @@
package org.apache.commons.proxy2.invoker;
+import java.lang.reflect.Method;
+
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.proxy2.ProxyUtils;
-import java.lang.reflect.Method;
-
/**
* Detached representation of a method invocation.
- *
+ *
* @author James Carman
*/
public class RecordedInvocation
{
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private final Method invokedMethod;
private final Object[] arguments;
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Create a new RecordedInvocation instance.
- *
+ *
* @param invokedMethod
* @param arguments
*/
@@ -52,13 +52,13 @@
this.arguments = ArrayUtils.nullToEmpty(ArrayUtils.clone(arguments));
}
-//----------------------------------------------------------------------------------------------------------------------
-// Getter/Setter Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Getter/Setter Methods
+ //******************************************************************************************************************
/**
* Get the invokedMethod.
- *
+ *
* @return Method
*/
public Method getInvokedMethod()
@@ -66,9 +66,9 @@
return invokedMethod;
}
-//----------------------------------------------------------------------------------------------------------------------
-// Canonical Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Canonical Methods
+ //******************************************************************************************************************
/**
* {@inheritDoc}
@@ -94,13 +94,13 @@
return buffer.toString();
}
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
/**
* Add a string representation of <code>input</code> to <code>buffer</code>.
- *
+ *
* @param buffer
* @param input
*/
@@ -119,30 +119,27 @@
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++)
{
- 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)
{
- 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(", ");
}
- 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("}");
}
/**
* Get the arguments.
- *
+ *
* @return Object[]
*/
public Object[] getArguments()
diff --git a/core/src/main/java/org/apache/commons/proxy2/invoker/recorder/InvocationRecorder.java b/core/src/main/java/org/apache/commons/proxy2/invoker/recorder/InvocationRecorder.java
index 20149d2..f170db0 100644
--- a/core/src/main/java/org/apache/commons/proxy2/invoker/recorder/InvocationRecorder.java
+++ b/core/src/main/java/org/apache/commons/proxy2/invoker/recorder/InvocationRecorder.java
@@ -17,19 +17,20 @@
package org.apache.commons.proxy2.invoker.recorder;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.LinkedList;
+import java.util.List;
+
import org.apache.commons.lang3.reflect.TypeUtils;
import org.apache.commons.proxy2.Invoker;
import org.apache.commons.proxy2.ProxyFactory;
import org.apache.commons.proxy2.ProxyUtils;
import org.apache.commons.proxy2.invoker.RecordedInvocation;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.LinkedList;
-import java.util.List;
-
/**
* An {@link InvocationRecorder} records method invocations against its generated proxies.
+ *
* @author James Carman
*/
public class InvocationRecorder
@@ -39,15 +40,17 @@
/**
* Create a new InvocationRecorder instance.
+ *
* @param proxyFactory
*/
- public InvocationRecorder( ProxyFactory proxyFactory )
+ public InvocationRecorder(ProxyFactory proxyFactory)
{
this.proxyFactory = proxyFactory;
}
/**
- * Get the invocations that have been recorded up to this point. The list is "live" and should not be modified.
+ * Get the invocations that have been recorded up to this point. The list is "live" and should not be modified.
+ *
* @return {@link List} of {@link RecordedInvocation}
*/
public List<RecordedInvocation> getRecordedInvocations()
@@ -57,25 +60,27 @@
/**
* Generate a recording proxy for the specified class.
+ *
* @param <T>
* @param type
* @return the generated proxy
*/
- public <T> T proxy( Class<T> type )
+ public <T> T proxy(Class<T> type)
{
return proxy(type, type);
}
/**
* Generate a recording proxy for the specified class, qualified as <code>genericType</code>.
+ *
* @param <T>
* @param genericType
* @param type
* @return the generated proxy
*/
- public <T> T proxy( Type genericType, Class<T> type )
+ public <T> T proxy(Type genericType, Class<T> type)
{
- if( proxyFactory.canProxy(type) )
+ if (proxyFactory.canProxy(type))
{
@SuppressWarnings("unchecked")
final T result = (T) proxyFactory.createInvokerProxy(new InvocationRecorderInvoker(genericType), type);
@@ -91,7 +96,7 @@
private final Type targetType;
- private InvocationRecorderInvoker( Type targetType )
+ private InvocationRecorderInvoker(Type targetType)
{
this.targetType = targetType;
}
@@ -99,7 +104,7 @@
/**
* {@inheritDoc}
*/
- public Object invoke( Object o, Method method, Object[] args ) throws Throwable
+ public Object invoke(Object o, Method method, Object[] args) throws Throwable
{
recordedInvocations.add(new RecordedInvocation(method, args));
final Class<?> returnType = TypeUtils.getRawType(method.getGenericReturnType(), targetType);
diff --git a/core/src/main/java/org/apache/commons/proxy2/provider/BeanProvider.java b/core/src/main/java/org/apache/commons/proxy2/provider/BeanProvider.java
index 68b0d4c..4cc0912 100644
--- a/core/src/main/java/org/apache/commons/proxy2/provider/BeanProvider.java
+++ b/core/src/main/java/org/apache/commons/proxy2/provider/BeanProvider.java
@@ -17,15 +17,15 @@
package org.apache.commons.proxy2.provider;
+import java.io.Serializable;
+
import org.apache.commons.lang3.Validate;
import org.apache.commons.proxy2.ObjectProvider;
import org.apache.commons.proxy2.exception.ObjectProviderException;
-import java.io.Serializable;
-
/**
* Uses <code>Class.newInstance()</code> to instantiate an object.
- *
+ *
* @author James Carman
* @since 1.0
*/
@@ -34,30 +34,31 @@
/** Serialization version */
private static final long serialVersionUID = 1L;
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private final Class<? extends T> beanClass;
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Constructs a provider which instantiates objects of the specified bean class.
- *
- * @param beanClass the bean class
+ *
+ * @param beanClass
+ * the bean class
*/
- public BeanProvider( Class<? extends T> beanClass )
+ public BeanProvider(Class<? extends T> beanClass)
{
Validate.notNull(beanClass, "Bean class cannot be null.");
this.beanClass = beanClass;
}
-//**********************************************************************************************************************
-// ObjectProvider Implementation
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // ObjectProvider Implementation
+ //******************************************************************************************************************
/**
* {@inheritDoc}
@@ -68,14 +69,13 @@
{
return beanClass.newInstance();
}
- catch( InstantiationException e )
+ catch (InstantiationException e)
{
- throw new ObjectProviderException("Class " + beanClass.getName() + " is not concrete.", e);
+ throw new ObjectProviderException(e, "%s is not concrete.", beanClass);
}
- catch( IllegalAccessException e )
+ catch (IllegalAccessException e)
{
- throw new ObjectProviderException("Constructor for class " + beanClass.getName() + " is not accessible.",
- e);
+ throw new ObjectProviderException(e, "Constructor for %s is not accessible.", beanClass);
}
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/provider/CloningProvider.java b/core/src/main/java/org/apache/commons/proxy2/provider/CloningProvider.java
index 2b494c4..f82e127 100644
--- a/core/src/main/java/org/apache/commons/proxy2/provider/CloningProvider.java
+++ b/core/src/main/java/org/apache/commons/proxy2/provider/CloningProvider.java
@@ -17,17 +17,17 @@
package org.apache.commons.proxy2.provider;
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.apache.commons.proxy2.ObjectProvider;
import org.apache.commons.proxy2.exception.ObjectProviderException;
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-
/**
* Merely calls <code>clone()</code> (reflectively) on the given {@link Cloneable} object.
- *
+ *
* @author James Carman
* @since 1.0
*/
@@ -38,35 +38,33 @@
*/
private static final long serialVersionUID = 1L;
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private final T cloneable;
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
- * Constructs a provider which returns clone copies of the specified {@link Cloneable}
- * object.
- *
- * @param cloneable the object to clone
+ * Constructs a provider which returns clone copies of the specified {@link Cloneable} object.
+ *
+ * @param cloneable
+ * the object to clone
*/
public CloningProvider(T cloneable)
{
Validate.notNull(cloneable, "Cloneable object cannot be null.");
- Validate.isTrue(
- MethodUtils.getAccessibleMethod(cloneable.getClass(), "clone") != null,
- String.format("Class %s does not override clone() method as public.",
- cloneable.getClass().getName()));
+ Validate.isTrue(MethodUtils.getAccessibleMethod(cloneable.getClass(), "clone") != null,
+ String.format("Class %s does not override clone() method as public.", cloneable.getClass().getName()));
this.cloneable = cloneable;
}
- //**********************************************************************************************************************
+ //******************************************************************************************************************
// ObjectProvider Implementation
- //**********************************************************************************************************************
+ //******************************************************************************************************************
/**
* {@inheritDoc}
@@ -80,24 +78,20 @@
}
catch (IllegalAccessException e)
{
- throw new ObjectProviderException(
- "Class " + cloneable.getClass().getName() + " does not have a public clone() method.", 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);
+ throw new ObjectProviderException("Attempt to clone object of type " + cloneable.getClass().getName()
+ + " threw an exception.", e);
}
catch (NoSuchMethodException e)
{
- throw new ObjectProviderException(
- String.format("Class %s does not have a clone() method (should never happen).", cloneable.getClass().getName()), e);
+ throw new ObjectProviderException(String.format(
+ "Class %s does not have a clone() method (should never happen).", cloneable.getClass().getName()),
+ e);
}
}
-//**********************************************************************************************************************
-// Getter/Setter Methods
-//**********************************************************************************************************************
-
-
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/provider/ConstantProvider.java b/core/src/main/java/org/apache/commons/proxy2/provider/ConstantProvider.java
index 55ca010..1f3c789 100644
--- a/core/src/main/java/org/apache/commons/proxy2/provider/ConstantProvider.java
+++ b/core/src/main/java/org/apache/commons/proxy2/provider/ConstantProvider.java
@@ -17,13 +17,13 @@
package org.apache.commons.proxy2.provider;
-import org.apache.commons.proxy2.ObjectProvider;
-
import java.io.Serializable;
+import org.apache.commons.proxy2.ObjectProvider;
+
/**
* Always returns the same object.
- *
+ *
* @author James Carman
* @since 1.0
*/
@@ -32,28 +32,29 @@
/** Serialization version */
private static final long serialVersionUID = 1L;
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private final T constant;
- //**********************************************************************************************************************
- // Constructors
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Create a new ConstantProvider instance.
+ *
* @param constant
*/
- public ConstantProvider( T constant )
+ public ConstantProvider(T constant)
{
this.constant = constant;
}
- //**********************************************************************************************************************
- // ObjectProvider Implementation
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // ObjectProvider Implementation
+ //******************************************************************************************************************
/**
* {@inheritDoc}
@@ -62,4 +63,4 @@
{
return constant;
}
-}
+}
diff --git a/core/src/main/java/org/apache/commons/proxy2/provider/NullProvider.java b/core/src/main/java/org/apache/commons/proxy2/provider/NullProvider.java
index 8aca99b..1feae94 100644
--- a/core/src/main/java/org/apache/commons/proxy2/provider/NullProvider.java
+++ b/core/src/main/java/org/apache/commons/proxy2/provider/NullProvider.java
@@ -19,7 +19,7 @@
/**
* Always returns null.
- *
+ *
* @author James Carman
* @since 1.0
*/
@@ -28,9 +28,9 @@
/** Serialization version */
private static final long serialVersionUID = 1L;
- //**********************************************************************************************************************
- // Constructors
- //**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Create a new NullProvider instance.
diff --git a/core/src/main/java/org/apache/commons/proxy2/provider/ObjectProviderUtils.java b/core/src/main/java/org/apache/commons/proxy2/provider/ObjectProviderUtils.java
index 8b8204e..aca8d86 100644
--- a/core/src/main/java/org/apache/commons/proxy2/provider/ObjectProviderUtils.java
+++ b/core/src/main/java/org/apache/commons/proxy2/provider/ObjectProviderUtils.java
@@ -21,9 +21,9 @@
public final class ObjectProviderUtils
{
-//----------------------------------------------------------------------------------------------------------------------
-// Static Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Static Methods
+ //******************************************************************************************************************
public static <T> ObjectProvider<T> bean(Class<T> beanClass)
{
@@ -50,12 +50,11 @@
return new SingletonProvider<T>(inner);
}
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
private ObjectProviderUtils()
{
-
}
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/provider/ProviderDecorator.java b/core/src/main/java/org/apache/commons/proxy2/provider/ProviderDecorator.java
index ded2907..c6447f9 100644
--- a/core/src/main/java/org/apache/commons/proxy2/provider/ProviderDecorator.java
+++ b/core/src/main/java/org/apache/commons/proxy2/provider/ProviderDecorator.java
@@ -20,31 +20,31 @@
import org.apache.commons.proxy2.ObjectProvider;
/**
- * Returns the result of the inner {@link ObjectProvider provider}. Subclasses can override the {@link #getObject()}
+ * 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
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
/**
* The wrapped {@link ObjectProvider}.
*/
private ObjectProvider<? extends T> inner;
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Create a new ProviderDecorator instance.
- *
+ *
* @param inner
*/
public ProviderDecorator(ObjectProvider<? extends T> inner)
@@ -52,9 +52,9 @@
this.inner = inner;
}
-//----------------------------------------------------------------------------------------------------------------------
-// ObjectProvider Implementation
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // ObjectProvider Implementation
+ //******************************************************************************************************************
/**
* {@inheritDoc}
@@ -64,9 +64,9 @@
return inner.getObject();
}
-//----------------------------------------------------------------------------------------------------------------------
-// Getter/Setter Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Getter/Setter Methods
+ //******************************************************************************************************************
protected ObjectProvider<? extends T> getInner()
{
diff --git a/core/src/main/java/org/apache/commons/proxy2/provider/SingletonProvider.java b/core/src/main/java/org/apache/commons/proxy2/provider/SingletonProvider.java
index ceda06a..38dd5a3 100644
--- a/core/src/main/java/org/apache/commons/proxy2/provider/SingletonProvider.java
+++ b/core/src/main/java/org/apache/commons/proxy2/provider/SingletonProvider.java
@@ -22,25 +22,25 @@
/**
* 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
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private T instance;
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
/**
* Create a new SingletonProvider instance.
- *
+ *
* @param inner
*/
public SingletonProvider(ObjectProvider<? extends T> inner)
@@ -48,9 +48,9 @@
super(inner);
}
-//**********************************************************************************************************************
-// ObjectProvider Implementation
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // ObjectProvider Implementation
+ //******************************************************************************************************************
/**
* {@inheritDoc}
diff --git a/core/src/main/java/org/apache/commons/proxy2/serialization/ReadResolve.java b/core/src/main/java/org/apache/commons/proxy2/serialization/ReadResolve.java
index eb18e99..1fb41ac 100755
--- a/core/src/main/java/org/apache/commons/proxy2/serialization/ReadResolve.java
+++ b/core/src/main/java/org/apache/commons/proxy2/serialization/ReadResolve.java
@@ -27,6 +27,7 @@
{
/**
* Get the deserialized version of this {@link Serializable}.
+ *
* @return Object
*/
Object readResolve();
diff --git a/core/src/main/java/org/apache/commons/proxy2/serialization/WriteReplace.java b/core/src/main/java/org/apache/commons/proxy2/serialization/WriteReplace.java
index b05cae6..7b62d5e 100755
--- a/core/src/main/java/org/apache/commons/proxy2/serialization/WriteReplace.java
+++ b/core/src/main/java/org/apache/commons/proxy2/serialization/WriteReplace.java
@@ -27,6 +27,7 @@
{
/**
* Get the serialized version of this object.
+ *
* @return Object
*/
Object writeReplace();
diff --git a/core/src/main/java/org/apache/commons/proxy2/serialization/package-info.java b/core/src/main/java/org/apache/commons/proxy2/serialization/package-info.java
index d67eaff..03f70e1 100755
--- a/core/src/main/java/org/apache/commons/proxy2/serialization/package-info.java
+++ b/core/src/main/java/org/apache/commons/proxy2/serialization/package-info.java
@@ -34,4 +34,5 @@
* equivalent proxy object, which probably implies some form of {@code static} access.
*/
package org.apache.commons.proxy2.serialization;
-import java.io.Serializable;
+
+
diff --git a/core/src/main/java/org/apache/commons/proxy2/stub/AnnotationBuilder.java b/core/src/main/java/org/apache/commons/proxy2/stub/AnnotationBuilder.java
index 48dafd8..58ae177 100644
--- a/core/src/main/java/org/apache/commons/proxy2/stub/AnnotationBuilder.java
+++ b/core/src/main/java/org/apache/commons/proxy2/stub/AnnotationBuilder.java
@@ -25,6 +25,8 @@
import java.util.Map;
import org.apache.commons.lang3.AnnotationUtils;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.reflect.TypeUtils;
import org.apache.commons.proxy2.Interceptor;
@@ -79,11 +81,8 @@
}
- private static class ReflectionInvocation implements Invocation, Serializable
+ private static class ReflectionInvocation implements Invocation
{
- /** Serialization version */
- private static final long serialVersionUID = 1L;
-
private final Method method;
private final Object[] arguments;
private final Object target;
@@ -91,7 +90,7 @@
public ReflectionInvocation(Object target, Method method, Object[] arguments)
{
this.method = method;
- this.arguments = (arguments == null ? ProxyUtils.EMPTY_ARGUMENTS : arguments);
+ this.arguments = ObjectUtils.defaultIfNull(ArrayUtils.clone(arguments), ProxyUtils.EMPTY_ARGUMENTS);
this.target = target;
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/stub/AnnotationInvoker.java b/core/src/main/java/org/apache/commons/proxy2/stub/AnnotationInvoker.java
index 6e0b0e6..9743b4d 100644
--- a/core/src/main/java/org/apache/commons/proxy2/stub/AnnotationInvoker.java
+++ b/core/src/main/java/org/apache/commons/proxy2/stub/AnnotationInvoker.java
@@ -29,10 +29,11 @@
public static final AnnotationInvoker INSTANCE = new AnnotationInvoker();
@Override
- public Object invoke(Object proxy, Method method, Object[] arguments) throws Throwable {
+ public Object invoke(Object proxy, Method method, Object[] arguments) throws Throwable
+ {
final Object result = method.getDefaultValue();
- return result == null && method.getReturnType().isPrimitive() ? ProxyUtils
- .nullValue(method.getReturnType()) : result;
+ return result == null && method.getReturnType().isPrimitive() ? ProxyUtils.nullValue(method.getReturnType())
+ : result;
}
-
+
}
\ No newline at end of file
diff --git a/core/src/main/java/org/apache/commons/proxy2/stub/AnnotationTrainer.java b/core/src/main/java/org/apache/commons/proxy2/stub/AnnotationTrainer.java
index a808deb..2c3a0ff 100644
--- a/core/src/main/java/org/apache/commons/proxy2/stub/AnnotationTrainer.java
+++ b/core/src/main/java/org/apache/commons/proxy2/stub/AnnotationTrainer.java
@@ -21,11 +21,13 @@
public abstract class AnnotationTrainer<A extends Annotation> extends BaseAnnotationTrainer<AnnotationTrainer<A>, A>
{
- protected AnnotationTrainer() {
+ protected AnnotationTrainer()
+ {
super();
}
- protected AnnotationTrainer(Class<A> traineeType) {
+ protected AnnotationTrainer(Class<A> traineeType)
+ {
super(traineeType);
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/stub/BaseTrainer.java b/core/src/main/java/org/apache/commons/proxy2/stub/BaseTrainer.java
index 8c386da..aedfa24 100644
--- a/core/src/main/java/org/apache/commons/proxy2/stub/BaseTrainer.java
+++ b/core/src/main/java/org/apache/commons/proxy2/stub/BaseTrainer.java
@@ -32,19 +32,18 @@
public abstract class BaseTrainer<S extends BaseTrainer<S, T>, T>
{
- // ----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
// Fields
- // ----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
public final Class<T> traineeType;
- // ----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
// Constructors
- // ----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
/**
- * Create a new {@link BaseTrainer} instance. This constructor should only
- * be called by classes that explicitly assign the T parameter in the class
- * definition. This should include basically any runtime-usable class.
+ * Create a new {@link BaseTrainer} instance. This constructor should only be called by classes that explicitly
+ * assign the T parameter in the class definition. This should include basically any runtime-usable class.
*/
protected BaseTrainer()
{
@@ -67,15 +66,15 @@
this.traineeType = resolvedVariable;
}
- // ----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
// Abstract Methods
- // ----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
protected abstract void train(T trainee);
- // ----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
// Other Methods
- // ----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
protected <R> R any(Class<R> type)
{
@@ -176,9 +175,9 @@
return (S) this;
}
- // ----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
// Inner Classes
- // ----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
protected abstract class BaseWhen<R>
{
@@ -285,9 +284,8 @@
}
/**
- * Intermediate result of a when(Class) call. Provided because it is such a
- * common case to have a mismatch between a declared Class<?> return type
- * and the bound parameter of a class literal.
+ * Intermediate result of a when(Class) call. Provided because it is such a common case to have a mismatch between a
+ * declared Class<?> return type and the bound parameter of a class literal.
*/
protected class WhenClass extends BaseWhen<Class<?>>
{
diff --git a/core/src/main/java/org/apache/commons/proxy2/stub/StubBuilder.java b/core/src/main/java/org/apache/commons/proxy2/stub/StubBuilder.java
index 8b3b261..0f25571 100644
--- a/core/src/main/java/org/apache/commons/proxy2/stub/StubBuilder.java
+++ b/core/src/main/java/org/apache/commons/proxy2/stub/StubBuilder.java
@@ -33,18 +33,18 @@
public class StubBuilder<T> implements Builder<T>
{
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private final ProxyFactory proxyFactory;
private final T target;
private final SwitchInterceptor switchInterceptor = new SwitchInterceptor();
private final Set<Class<?>> proxyTypes = new HashSet<Class<?>>();
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
public StubBuilder(ProxyFactory proxyFactory, Class<T> type)
{
@@ -57,7 +57,7 @@
this.target = proxyFactory.createInvokerProxy(invoker, type);
this.proxyTypes.add(Validate.notNull(type));
}
-
+
public StubBuilder(ProxyFactory proxyFactory, Class<T> type, ObjectProvider<? extends T> provider)
{
this.proxyFactory = proxyFactory;
@@ -72,9 +72,9 @@
this.proxyTypes.add(Validate.notNull(type));
}
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
public T build()
{
diff --git a/core/src/main/java/org/apache/commons/proxy2/stub/StubInterceptorBuilder.java b/core/src/main/java/org/apache/commons/proxy2/stub/StubInterceptorBuilder.java
index dff59f9..6e8cbab 100644
--- a/core/src/main/java/org/apache/commons/proxy2/stub/StubInterceptorBuilder.java
+++ b/core/src/main/java/org/apache/commons/proxy2/stub/StubInterceptorBuilder.java
@@ -23,25 +23,25 @@
public class StubInterceptorBuilder
{
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private final ProxyFactory proxyFactory;
private final SwitchInterceptor interceptor = new SwitchInterceptor();
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
public StubInterceptorBuilder(ProxyFactory proxyFactory)
{
this.proxyFactory = proxyFactory;
}
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
public Interceptor build()
{
diff --git a/core/src/main/java/org/apache/commons/proxy2/stub/Trainer.java b/core/src/main/java/org/apache/commons/proxy2/stub/Trainer.java
index d0962bc..34fd22e 100644
--- a/core/src/main/java/org/apache/commons/proxy2/stub/Trainer.java
+++ b/core/src/main/java/org/apache/commons/proxy2/stub/Trainer.java
@@ -17,13 +17,16 @@
package org.apache.commons.proxy2.stub;
-public abstract class Trainer<T> extends BaseTrainer<Trainer<T>, T> {
+public abstract class Trainer<T> extends BaseTrainer<Trainer<T>, T>
+{
- protected Trainer() {
+ protected Trainer()
+ {
super();
}
- protected Trainer(Class<T> traineeType) {
+ protected Trainer(Class<T> traineeType)
+ {
super(traineeType);
}
diff --git a/core/src/main/java/org/apache/commons/proxy2/stub/TrainingContext.java b/core/src/main/java/org/apache/commons/proxy2/stub/TrainingContext.java
index e737de3..328f1a0 100644
--- a/core/src/main/java/org/apache/commons/proxy2/stub/TrainingContext.java
+++ b/core/src/main/java/org/apache/commons/proxy2/stub/TrainingContext.java
@@ -16,23 +16,31 @@
*/
package org.apache.commons.proxy2.stub;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.UUID;
+
import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.proxy2.*;
+import org.apache.commons.proxy2.Interceptor;
+import org.apache.commons.proxy2.Invocation;
+import org.apache.commons.proxy2.Invoker;
+import org.apache.commons.proxy2.ProxyFactory;
+import org.apache.commons.proxy2.ProxyUtils;
import org.apache.commons.proxy2.interceptor.SwitchInterceptor;
import org.apache.commons.proxy2.interceptor.matcher.ArgumentMatcher;
import org.apache.commons.proxy2.interceptor.matcher.InvocationMatcher;
import org.apache.commons.proxy2.invoker.NullInvoker;
import org.apache.commons.proxy2.invoker.RecordedInvocation;
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
-import java.util.*;
-
class TrainingContext
{
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private static final ThreadLocal<TrainingContext> TRAINING_CONTEXT = new ThreadLocal<TrainingContext>();
@@ -42,9 +50,9 @@
private final TrainingContext resume;
-//----------------------------------------------------------------------------------------------------------------------
-// Static Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Static Methods
+ //******************************************************************************************************************
static TrainingContext current()
{
@@ -58,9 +66,9 @@
return context;
}
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
private TrainingContext(ProxyFactory proxyFactory)
{
@@ -68,9 +76,9 @@
this.resume = current();
}
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Other Methods
+ //******************************************************************************************************************
void part()
{
@@ -100,12 +108,10 @@
<T> T pop(Invoker invoker)
{
final TrainingContextFrame<?> frame = frameDeque.pop();
- return proxyFactory.createInterceptorProxy(
- proxyFactory.createInvokerProxy(invoker, frame.type),
- frame.stubInterceptor,
- frame.type);
+ return proxyFactory.createInterceptorProxy(proxyFactory.createInvokerProxy(invoker, frame.type),
+ frame.stubInterceptor, frame.type);
}
-
+
<T> T push(Class<T> type)
{
return push(type, new SwitchInterceptor());
@@ -129,9 +135,9 @@
peek().then(interceptor);
}
-//----------------------------------------------------------------------------------------------------------------------
-// Inner Classes
-//----------------------------------------------------------------------------------------------------------------------
+ //******************************************************************************************************************
+ // Inner Classes
+ //******************************************************************************************************************
private static final class ExactArgumentsMatcher implements InvocationMatcher
{
@@ -145,8 +151,8 @@
@Override
public boolean matches(Invocation invocation)
{
- return invocation.getMethod().equals(recordedInvocation.getInvokedMethod()) &&
- Arrays.deepEquals(invocation.getArguments(), recordedInvocation.getArguments());
+ return invocation.getMethod().equals(recordedInvocation.getInvokedMethod())
+ && Arrays.deepEquals(invocation.getArguments(), recordedInvocation.getArguments());
}
}
@@ -164,8 +170,8 @@
@Override
public boolean matches(Invocation invocation)
{
- return invocation.getMethod().equals(recordedInvocation.getInvokedMethod()) &&
- allArgumentsMatch(invocation.getArguments());
+ return invocation.getMethod().equals(recordedInvocation.getInvokedMethod())
+ && allArgumentsMatch(invocation.getArguments());
}
private boolean allArgumentsMatch(Object[] arguments)
@@ -219,7 +225,8 @@
void methodInvoked(Method method, Object[] arguments)
{
- final ArgumentMatcher<?>[] matchersArray = argumentMatchers.toArray(new ArgumentMatcher[argumentMatchers.size()]);
+ final ArgumentMatcher<?>[] matchersArray = argumentMatchers.toArray(new ArgumentMatcher[argumentMatchers
+ .size()]);
argumentMatchers.clear();
final RecordedInvocation invocation = new RecordedInvocation(method, arguments);
if (ArrayUtils.isEmpty(matchersArray))
diff --git a/core/src/test/java/org/apache/commons/proxy2/AbstractProxyFactoryTestCase.java b/core/src/test/java/org/apache/commons/proxy2/AbstractProxyFactoryTestCase.java
index 9a65855..2ecda05 100644
--- a/core/src/test/java/org/apache/commons/proxy2/AbstractProxyFactoryTestCase.java
+++ b/core/src/test/java/org/apache/commons/proxy2/AbstractProxyFactoryTestCase.java
@@ -17,18 +17,34 @@
package org.apache.commons.proxy2;
-import org.apache.commons.proxy2.provider.BeanProvider;
-import org.apache.commons.proxy2.provider.ConstantProvider;
-import org.apache.commons.proxy2.provider.SingletonProvider;
-import org.apache.commons.proxy2.util.*;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Method;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ServiceLoader;
+import java.util.SortedSet;
+import java.util.TreeSet;
-import static org.junit.Assert.*;
+import org.apache.commons.proxy2.provider.BeanProvider;
+import org.apache.commons.proxy2.provider.ConstantProvider;
+import org.apache.commons.proxy2.provider.SingletonProvider;
+import org.apache.commons.proxy2.util.AbstractTestCase;
+import org.apache.commons.proxy2.util.DuplicateEcho;
+import org.apache.commons.proxy2.util.Echo;
+import org.apache.commons.proxy2.util.EchoImpl;
+import org.apache.commons.proxy2.util.SuffixInterceptor;
+import org.junit.Test;
/**
* @author James Carman
@@ -37,17 +53,17 @@
@SuppressWarnings("serial")
public abstract class AbstractProxyFactoryTestCase extends AbstractTestCase
{
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Fields
+ //**********************************************************************************************************************
- private static final Class<?>[] ECHO_ONLY = new Class[]{Echo.class};
+ private static final Class<?>[] ECHO_ONLY = new Class[] { Echo.class };
protected final ProxyFactory factory;
- private static final Class<?>[] COMPARABLE_ONLY = new Class[]{Comparable.class};
+ private static final Class<?>[] COMPARABLE_ONLY = new Class[] { Comparable.class };
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Constructors
+ //**********************************************************************************************************************
protected AbstractProxyFactoryTestCase()
{
@@ -64,9 +80,9 @@
}
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Other Methods
+ //**********************************************************************************************************************
private ObjectProvider<Echo> createSingletonEcho()
{
@@ -98,10 +114,8 @@
public void testInterceptorEquals()
{
final Date date = new Date();
- final Comparable<?> proxy1 = factory.createInterceptorProxy(date,
- new NoOpMethodInterceptor(), COMPARABLE_ONLY);
- final Comparable<?> proxy2 = factory.createInterceptorProxy(date,
- new NoOpMethodInterceptor(), COMPARABLE_ONLY);
+ final Comparable<?> proxy1 = factory.createInterceptorProxy(date, new NoOpMethodInterceptor(), COMPARABLE_ONLY);
+ final Comparable<?> proxy2 = factory.createInterceptorProxy(date, new NoOpMethodInterceptor(), COMPARABLE_ONLY);
assertEquals(proxy1, proxy1);
assertFalse(proxy1.equals(proxy2));
assertFalse(proxy2.equals(proxy1));
@@ -121,10 +135,8 @@
public void testDelegatorEquals() throws Exception
{
final Date date = new Date();
- final Comparable<?> proxy1 = factory.createDelegatorProxy(new ConstantProvider<Date>(date),
- COMPARABLE_ONLY);
- final Comparable<?> proxy2 = factory.createDelegatorProxy(new ConstantProvider<Date>(date),
- COMPARABLE_ONLY);
+ final Comparable<?> proxy1 = factory.createDelegatorProxy(new ConstantProvider<Date>(date), COMPARABLE_ONLY);
+ final Comparable<?> proxy2 = factory.createDelegatorProxy(new ConstantProvider<Date>(date), COMPARABLE_ONLY);
assertEquals(proxy1, proxy1);
assertFalse(proxy1.equals(proxy2));
assertFalse(proxy2.equals(proxy1));
@@ -183,9 +195,10 @@
public void testDelegatingProxyInterfaceOrder()
{
final Echo echo = factory.createDelegatorProxy(createSingletonEcho(), Echo.class, DuplicateEcho.class);
- final List<Class<?>> expected = new LinkedList<Class<?>>(Arrays.<Class<?>>asList(Echo.class, DuplicateEcho.class));
+ final List<Class<?>> expected = new LinkedList<Class<?>>(Arrays.<Class<?>> asList(Echo.class,
+ DuplicateEcho.class));
final List<Class<?>> actual = new LinkedList<Class<?>>(Arrays.asList(echo.getClass().getInterfaces()));
- actual.retainAll(expected); // Doesn't alter order!
+ actual.retainAll(expected); // Doesn't alter order!
assertEquals(expected, actual);
}
@@ -229,7 +242,8 @@
@Test
public void testInterfaceHierarchies()
{
- final SortedSet<String> set = factory.createDelegatorProxy(new ConstantProvider<SortedSet<String>>(new TreeSet<String>()), SortedSet.class);
+ final SortedSet<String> set = factory.createDelegatorProxy(new ConstantProvider<SortedSet<String>>(
+ new TreeSet<String>()), SortedSet.class);
set.add("Hello");
}
@@ -337,9 +351,9 @@
proxy.echo();
}
-//**********************************************************************************************************************
-// Inner Classes
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Inner Classes
+ //**********************************************************************************************************************
private static class ChangeArgumentInterceptor implements Interceptor
{
diff --git a/core/src/test/java/org/apache/commons/proxy2/AbstractSubclassingProxyFactoryTestCase.java b/core/src/test/java/org/apache/commons/proxy2/AbstractSubclassingProxyFactoryTestCase.java
index 7146ae5..17254ff 100644
--- a/core/src/test/java/org/apache/commons/proxy2/AbstractSubclassingProxyFactoryTestCase.java
+++ b/core/src/test/java/org/apache/commons/proxy2/AbstractSubclassingProxyFactoryTestCase.java
@@ -17,6 +17,12 @@
package org.apache.commons.proxy2;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Date;
+
import org.apache.commons.proxy2.exception.ProxyFactoryException;
import org.apache.commons.proxy2.invoker.NullInvoker;
import org.apache.commons.proxy2.provider.ConstantProvider;
@@ -25,10 +31,6 @@
import org.apache.commons.proxy2.util.EchoImpl;
import org.junit.Test;
-import java.util.Date;
-
-import static org.junit.Assert.*;
-
/**
* @author James Carman
* @since 1.0
@@ -36,27 +38,27 @@
@SuppressWarnings("serial")
public abstract class AbstractSubclassingProxyFactoryTestCase extends AbstractProxyFactoryTestCase
{
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Fields
+ //----------------------------------------------------------------------------------------------------------------------
- private static final Class<?>[] DATE_ONLY = new Class[]{Date.class};
+ private static final Class<?>[] DATE_ONLY = new Class[] { Date.class };
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Other Methods
+ //----------------------------------------------------------------------------------------------------------------------
@Test
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}));
+ 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 }));
}
@Test
@@ -64,9 +66,9 @@
{
final EqualsEcho echo = new EqualsEcho("text");
final Echo proxy1 = factory.createDelegatorProxy(new ConstantProvider<Echo>(echo),
- new Class[]{EqualsEcho.class});
+ new Class[] { EqualsEcho.class });
final Echo proxy2 = factory.createDelegatorProxy(new ConstantProvider<Echo>(echo),
- new Class[]{EqualsEcho.class});
+ new Class[] { EqualsEcho.class });
assertEquals(proxy1, proxy1);
assertFalse(proxy1.equals(proxy2));
assertFalse(proxy2.equals(proxy1));
@@ -75,15 +77,15 @@
@Test(expected = ProxyFactoryException.class)
public void testDelegatorWithMultipleSuperclasses()
{
- factory.createDelegatorProxy(new ConstantProvider<EchoImpl>(new EchoImpl()),
- new Class[]{EchoImpl.class, String.class});
+ factory.createDelegatorProxy(new ConstantProvider<EchoImpl>(new EchoImpl()), new Class[] { EchoImpl.class,
+ String.class });
}
@Test
public void testDelegatorWithSuperclass()
{
- final Echo echo = factory
- .createDelegatorProxy(new ConstantProvider<EchoImpl>(new EchoImpl()), new Class[]{Echo.class, EchoImpl.class});
+ final Echo echo = factory.createDelegatorProxy(new ConstantProvider<EchoImpl>(new EchoImpl()), new Class[] {
+ Echo.class, EchoImpl.class });
assertTrue(echo instanceof EchoImpl);
}
@@ -91,10 +93,10 @@
public void testInterceptorEquals()
{
final EqualsEcho echo = new EqualsEcho("text");
- final Echo proxy1 = factory.createInterceptorProxy(echo,
- new NoOpMethodInterceptor(), new Class[]{EqualsEcho.class});
- final Echo proxy2 = factory.createInterceptorProxy(echo,
- new NoOpMethodInterceptor(), new Class[]{EqualsEcho.class});
+ final Echo proxy1 = factory.createInterceptorProxy(echo, new NoOpMethodInterceptor(),
+ new Class[] { EqualsEcho.class });
+ final Echo proxy2 = factory.createInterceptorProxy(echo, new NoOpMethodInterceptor(),
+ new Class[] { EqualsEcho.class });
assertEquals(proxy1, proxy1);
assertFalse(proxy1.equals(proxy2));
assertFalse(proxy2.equals(proxy1));
@@ -103,23 +105,22 @@
@Test(expected = ProxyFactoryException.class)
public void testInterceptorWithMultipleSuperclasses()
{
- factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(),
- new Class[]{EchoImpl.class, String.class});
+ factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), new Class[] { EchoImpl.class,
+ String.class });
}
@Test
public void testInterceptorWithSuperclass()
{
- final Echo echo = factory
- .createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), new Class[]{Echo.class, EchoImpl.class});
+ final Echo echo = factory.createInterceptorProxy(new EchoImpl(), new NoOpMethodInterceptor(), new Class[] {
+ Echo.class, EchoImpl.class });
assertTrue(echo instanceof EchoImpl);
}
@Test(expected = ProxyFactoryException.class)
public void testInvocationHandlerWithMultipleSuperclasses()
{
- factory.createInvokerProxy(new NullInvoker(),
- new Class[]{EchoImpl.class, String.class});
+ factory.createInvokerProxy(new NullInvoker(), new Class[] { EchoImpl.class, String.class });
}
@Test
@@ -135,15 +136,14 @@
@Test
public void testInvokerWithSuperclass()
{
- final Echo echo = factory
- .createInvokerProxy(new NullInvoker(), new Class[]{Echo.class, EchoImpl.class});
+ final Echo echo = factory.createInvokerProxy(new NullInvoker(), new Class[] { Echo.class, EchoImpl.class });
assertTrue(echo instanceof EchoImpl);
}
@Test
public void testProxiesWithClashingFinalMethodInSuperclass()
{
- final Class<?>[] proxyClasses = new Class[]{Echo.class, FinalMethodEcho.class};
+ final Class<?>[] proxyClasses = new Class[] { Echo.class, FinalMethodEcho.class };
Echo proxy = factory.createDelegatorProxy(new ConstantProvider<EchoImpl>(new EchoImpl()), proxyClasses);
assertEquals("final", proxy.echoBack("echo"));
@@ -157,14 +157,15 @@
@Test
public void testWithAbstractSuperclass()
{
- final Echo echo = factory.createDelegatorProxy(new ConstantProvider<EchoImpl>(new EchoImpl()), new Class[]{AbstractEcho.class});
+ final Echo echo = factory.createDelegatorProxy(new ConstantProvider<EchoImpl>(new EchoImpl()),
+ new Class[] { AbstractEcho.class });
assertEquals("hello", echo.echoBack("hello"));
assertEquals("helloworld", echo.echoBack("hello", "world"));
}
-//----------------------------------------------------------------------------------------------------------------------
-// Inner Classes
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Inner Classes
+ //----------------------------------------------------------------------------------------------------------------------
public static class EqualsEcho extends EchoImpl
{
diff --git a/core/src/test/java/org/apache/commons/proxy2/ProxyUtilsTest.java b/core/src/test/java/org/apache/commons/proxy2/ProxyUtilsTest.java
index e2f25f1..bd77730 100644
--- a/core/src/test/java/org/apache/commons/proxy2/ProxyUtilsTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/ProxyUtilsTest.java
@@ -17,6 +17,13 @@
package org.apache.commons.proxy2;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Properties;
+
import org.apache.commons.proxy2.util.AbstractTestCase;
import org.apache.commons.proxy2.util.DuplicateEcho;
import org.apache.commons.proxy2.util.Echo;
@@ -25,24 +32,17 @@
import org.junit.Before;
import org.junit.Test;
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Properties;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
public class ProxyUtilsTest extends AbstractTestCase
{
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Fields
+ //**********************************************************************************************************************
private Properties prevProperties;
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Other Methods
+ //**********************************************************************************************************************
@Before
public void setUp() throws Exception
@@ -61,17 +61,17 @@
public void testNullValue()
{
assertNullValue(null, String.class);
- assertNullValue(( char ) 0, Character.TYPE);
+ assertNullValue((char) 0, Character.TYPE);
assertNullValue(0, Integer.TYPE);
- assertNullValue(( long ) 0, Long.TYPE);
- assertNullValue(( short ) 0, Short.TYPE);
- assertNullValue(( double ) 0, Double.TYPE);
- assertNullValue(( float ) 0, Float.TYPE);
+ assertNullValue((long) 0, Long.TYPE);
+ assertNullValue((short) 0, Short.TYPE);
+ assertNullValue((double) 0, Double.TYPE);
+ assertNullValue((float) 0, Float.TYPE);
assertNullValue(false, Boolean.TYPE);
- assertNullValue(( byte ) 0, Byte.TYPE);
+ assertNullValue((byte) 0, Byte.TYPE);
}
- private void assertNullValue( Object expected, Class<?> type )
+ private void assertNullValue(Object expected, Class<?> type)
{
assertEquals(expected, ProxyUtils.nullValue(type));
}
@@ -80,8 +80,8 @@
public void testGetAllInterfaces()
{
assertNull(ProxyUtils.getAllInterfaces(null));
- assertEquals(Arrays.asList(new Class[] {DuplicateEcho.class, Serializable.class, Echo.class}),
- Arrays.asList(ProxyUtils.getAllInterfaces(EchoImpl.class)));
+ assertEquals(Arrays.asList(new Class[] { DuplicateEcho.class, Serializable.class, Echo.class }),
+ Arrays.asList(ProxyUtils.getAllInterfaces(EchoImpl.class)));
}
@Test
diff --git a/core/src/test/java/org/apache/commons/proxy2/exception/AbstractExceptionClassTestCase.java b/core/src/test/java/org/apache/commons/proxy2/exception/AbstractExceptionClassTestCase.java
index f065412..968ece5 100644
--- a/core/src/test/java/org/apache/commons/proxy2/exception/AbstractExceptionClassTestCase.java
+++ b/core/src/test/java/org/apache/commons/proxy2/exception/AbstractExceptionClassTestCase.java
@@ -17,9 +17,11 @@
package org.apache.commons.proxy2.exception;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
import org.apache.commons.proxy2.util.AbstractTestCase;
import org.junit.Test;
-import static org.junit.Assert.*;
/**
* @author James Carman
@@ -27,30 +29,31 @@
*/
public abstract class AbstractExceptionClassTestCase extends AbstractTestCase
{
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Fields
+ //**********************************************************************************************************************
private final Class<?> exceptionClass;
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Constructors
+ //**********************************************************************************************************************
- public AbstractExceptionClassTestCase( Class<?> exceptionClass )
+ public AbstractExceptionClassTestCase(Class<?> exceptionClass)
{
this.exceptionClass = exceptionClass;
}
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Other Methods
+ //**********************************************************************************************************************
@Test
public void testCauseOnlyConstructor() throws Exception
{
final Exception cause = new Exception();
- Exception e = ( Exception ) exceptionClass.getConstructor(new Class[] {Throwable.class}).newInstance(new Object[] {cause});
+ Exception e = (Exception) exceptionClass.getConstructor(new Class[] { Throwable.class }).newInstance(
+ new Object[] { cause });
assertEquals(cause.toString(), e.getMessage());
assertEquals(cause, e.getCause());
}
@@ -60,7 +63,8 @@
{
final Exception cause = new Exception();
final String message = "message";
- Exception e = ( Exception ) exceptionClass.getConstructor(new Class[] {String.class, Throwable.class}).newInstance(new Object[] {message, cause});
+ Exception e = (Exception) exceptionClass.getConstructor(new Class[] { String.class, Throwable.class })
+ .newInstance(new Object[] { message, cause });
assertEquals(message, e.getMessage());
assertEquals(cause, e.getCause());
}
@@ -69,7 +73,8 @@
public void testMessageOnlyConstructor() throws Exception
{
final String message = "message";
- Exception e = ( Exception ) exceptionClass.getConstructor(new Class[] {String.class}).newInstance(new Object[] {message});
+ Exception e = (Exception) exceptionClass.getConstructor(new Class[] { String.class }).newInstance(
+ new Object[] { message });
assertEquals(message, e.getMessage());
assertNull(e.getCause());
}
@@ -77,7 +82,7 @@
@Test
public void testNoArgConstructor() throws Exception
{
- Exception e = ( Exception ) exceptionClass.getConstructor(new Class[] {}).newInstance(new Object[] {});
+ Exception e = (Exception) exceptionClass.getConstructor(new Class[] {}).newInstance(new Object[] {});
assertNull(e.getMessage());
assertNull(e.getCause());
}
diff --git a/core/src/test/java/org/apache/commons/proxy2/exception/DelegateProviderExceptionTest.java b/core/src/test/java/org/apache/commons/proxy2/exception/DelegateProviderExceptionTest.java
index d1c41ac..6db0a19 100644
--- a/core/src/test/java/org/apache/commons/proxy2/exception/DelegateProviderExceptionTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/exception/DelegateProviderExceptionTest.java
@@ -19,9 +19,9 @@
public class DelegateProviderExceptionTest extends AbstractExceptionClassTestCase
{
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Constructors
+ //**********************************************************************************************************************
public DelegateProviderExceptionTest()
{
diff --git a/core/src/test/java/org/apache/commons/proxy2/exception/InvocationHandlerExceptionTest.java b/core/src/test/java/org/apache/commons/proxy2/exception/InvocationHandlerExceptionTest.java
index 1534b29..597f74a 100644
--- a/core/src/test/java/org/apache/commons/proxy2/exception/InvocationHandlerExceptionTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/exception/InvocationHandlerExceptionTest.java
@@ -19,9 +19,9 @@
public class InvocationHandlerExceptionTest extends AbstractExceptionClassTestCase
{
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Constructors
+ //**********************************************************************************************************************
public InvocationHandlerExceptionTest()
{
diff --git a/core/src/test/java/org/apache/commons/proxy2/exception/ProxyFactoryExceptionTest.java b/core/src/test/java/org/apache/commons/proxy2/exception/ProxyFactoryExceptionTest.java
index 2f56286..c25e539 100644
--- a/core/src/test/java/org/apache/commons/proxy2/exception/ProxyFactoryExceptionTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/exception/ProxyFactoryExceptionTest.java
@@ -23,9 +23,9 @@
*/
public class ProxyFactoryExceptionTest extends AbstractExceptionClassTestCase
{
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Constructors
+ //**********************************************************************************************************************
public ProxyFactoryExceptionTest()
{
diff --git a/core/src/test/java/org/apache/commons/proxy2/impl/MethodSignatureTest.java b/core/src/test/java/org/apache/commons/proxy2/impl/MethodSignatureTest.java
index a4471ee..af2c8ac 100644
--- a/core/src/test/java/org/apache/commons/proxy2/impl/MethodSignatureTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/impl/MethodSignatureTest.java
@@ -17,6 +17,11 @@
package org.apache.commons.proxy2.impl;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.lang.reflect.Method;
import org.apache.commons.lang3.SerializationUtils;
@@ -27,13 +32,11 @@
import org.apache.commons.proxy2.util.EchoImpl;
import org.junit.Test;
-import static org.junit.Assert.*;
-
public class MethodSignatureTest extends AbstractTestCase
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Other Methods
+ //**********************************************************************************************************************
@Test
public void testEquals() throws Exception
@@ -58,13 +61,18 @@
public void testToString() throws Exception
{
assertEquals("echo()", new MethodSignature(Echo.class.getMethod("echo")).toString());
- assertEquals("echoBack(Ljava/lang/String;)", new MethodSignature(Echo.class.getMethod("echoBack", String.class)).toString());
- assertEquals("echoBack([Ljava/lang/String;)", new MethodSignature(Echo.class.getMethod("echoBack", String[].class)).toString());
- assertEquals("echoBack([[Ljava/lang/String;)", new MethodSignature(Echo.class.getMethod("echoBack", String[][].class)).toString());
- assertEquals("echoBack([[[Ljava/lang/String;)", new MethodSignature(Echo.class.getMethod("echoBack", String[][][].class)).toString());
+ assertEquals("echoBack(Ljava/lang/String;)",
+ new MethodSignature(Echo.class.getMethod("echoBack", String.class)).toString());
+ assertEquals("echoBack([Ljava/lang/String;)",
+ new MethodSignature(Echo.class.getMethod("echoBack", String[].class)).toString());
+ assertEquals("echoBack([[Ljava/lang/String;)",
+ new MethodSignature(Echo.class.getMethod("echoBack", String[][].class)).toString());
+ assertEquals("echoBack([[[Ljava/lang/String;)",
+ new MethodSignature(Echo.class.getMethod("echoBack", String[][][].class)).toString());
assertEquals("echoBack(I)", new MethodSignature(Echo.class.getMethod("echoBack", int.class)).toString());
assertEquals("echoBack(Z)", new MethodSignature(Echo.class.getMethod("echoBack", boolean.class)).toString());
- assertEquals("echoBack(Ljava/lang/String;Ljava/lang/String;)", new MethodSignature(Echo.class.getMethod("echoBack", String.class, String.class)).toString());
+ assertEquals("echoBack(Ljava/lang/String;Ljava/lang/String;)",
+ new MethodSignature(Echo.class.getMethod("echoBack", String.class, String.class)).toString());
assertEquals("illegalArgument()", new MethodSignature(Echo.class.getMethod("illegalArgument")).toString());
assertEquals("ioException()", new MethodSignature(Echo.class.getMethod("ioException")).toString());
}
diff --git a/core/src/test/java/org/apache/commons/proxy2/interceptor/InterceptorUtilsTest.java b/core/src/test/java/org/apache/commons/proxy2/interceptor/InterceptorUtilsTest.java
index fda9dfb..2f848df 100644
--- a/core/src/test/java/org/apache/commons/proxy2/interceptor/InterceptorUtilsTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/interceptor/InterceptorUtilsTest.java
@@ -17,6 +17,8 @@
package org.apache.commons.proxy2.interceptor;
+import static org.junit.Assert.assertEquals;
+
import org.apache.commons.proxy2.Interceptor;
import org.apache.commons.proxy2.Invocation;
import org.apache.commons.proxy2.provider.ObjectProviderUtils;
@@ -24,8 +26,6 @@
import org.apache.commons.proxy2.util.Echo;
import org.junit.Test;
-import static org.junit.Assert.*;
-
public class InterceptorUtilsTest extends AbstractTestCase
{
@Test
@@ -55,7 +55,8 @@
@Test(expected = RuntimeException.class)
public void testThrowingProvidedException() throws Throwable
{
- Interceptor interceptor = InterceptorUtils.throwing(ObjectProviderUtils.constant(new RuntimeException("Oops!")));
+ Interceptor interceptor = InterceptorUtils
+ .throwing(ObjectProviderUtils.constant(new RuntimeException("Oops!")));
Invocation invocation = mockInvocation(Echo.class, "echoBack", String.class).withArguments("World!").build();
interceptor.intercept(invocation);
}
diff --git a/core/src/test/java/org/apache/commons/proxy2/interceptor/ObjectProviderInterceptorTest.java b/core/src/test/java/org/apache/commons/proxy2/interceptor/ObjectProviderInterceptorTest.java
index 09de5e7..69b4467 100644
--- a/core/src/test/java/org/apache/commons/proxy2/interceptor/ObjectProviderInterceptorTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/interceptor/ObjectProviderInterceptorTest.java
@@ -17,17 +17,17 @@
package org.apache.commons.proxy2.interceptor;
+import static org.junit.Assert.assertEquals;
+
import org.apache.commons.proxy2.provider.ObjectProviderUtils;
import org.apache.commons.proxy2.util.AbstractTestCase;
import org.junit.Test;
-import static org.junit.Assert.*;
-
public class ObjectProviderInterceptorTest extends AbstractTestCase
{
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Other Methods
+ //----------------------------------------------------------------------------------------------------------------------
@Test
public void testIntercept() throws Throwable
diff --git a/core/src/test/java/org/apache/commons/proxy2/interceptor/SwitchInterceptorTest.java b/core/src/test/java/org/apache/commons/proxy2/interceptor/SwitchInterceptorTest.java
index ef418a6..bfa6b67 100644
--- a/core/src/test/java/org/apache/commons/proxy2/interceptor/SwitchInterceptorTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/interceptor/SwitchInterceptorTest.java
@@ -31,9 +31,9 @@
public class SwitchInterceptorTest extends AbstractTestCase
{
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Other Methods
+ //----------------------------------------------------------------------------------------------------------------------
@Test
public void testWithMultipleAdvices() throws Throwable
@@ -58,7 +58,8 @@
@Test
public void testWithSingleAdviceWhichDoesNotMatch() throws Throwable
{
- SwitchInterceptor interceptor = new SwitchInterceptor().when(new MethodNameMatcher("echoBackZZZZ")).then(constant("bar"));
+ SwitchInterceptor interceptor = new SwitchInterceptor().when(new MethodNameMatcher("echoBackZZZZ")).then(
+ constant("bar"));
Method method = Echo.class.getMethod("echoBack", String.class);
Invocation invocation = new MockInvocation(method, "foo", "foo");
assertEquals("foo", interceptor.intercept(invocation));
@@ -67,7 +68,8 @@
@Test
public void testWithSingleAdviceWhichMatches() throws Throwable
{
- SwitchInterceptor interceptor = new SwitchInterceptor().when(new MethodNameMatcher("echoBack")).then(constant("bar"));
+ SwitchInterceptor interceptor = new SwitchInterceptor().when(new MethodNameMatcher("echoBack")).then(
+ constant("bar"));
Method method = Echo.class.getMethod("echoBack", String.class);
Invocation invocation = new MockInvocation(method, "foo", "foo");
assertEquals("bar", interceptor.intercept(invocation));
diff --git a/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/DeclaredByMatcherTest.java b/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/DeclaredByMatcherTest.java
index 7f1853b..1c6fd50 100644
--- a/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/DeclaredByMatcherTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/DeclaredByMatcherTest.java
@@ -32,9 +32,9 @@
public class DeclaredByMatcherTest extends AbstractTestCase
{
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Other Methods
+ //----------------------------------------------------------------------------------------------------------------------
@Test
public void testExactMatchNonMatching() throws Throwable
diff --git a/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/MethodNameMatcherTest.java b/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/MethodNameMatcherTest.java
index e23ce0a..563913e 100644
--- a/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/MethodNameMatcherTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/MethodNameMatcherTest.java
@@ -17,28 +17,29 @@
package org.apache.commons.proxy2.interceptor.matcher;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Method;
+
import org.apache.commons.proxy2.interceptor.matcher.invocation.MethodNameMatcher;
import org.apache.commons.proxy2.util.AbstractTestCase;
import org.apache.commons.proxy2.util.Echo;
import org.apache.commons.proxy2.util.MockInvocation;
import org.junit.Test;
-import java.lang.reflect.Method;
-
-import static org.junit.Assert.*;
-
public class MethodNameMatcherTest extends AbstractTestCase
{
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Other Methods
+ //----------------------------------------------------------------------------------------------------------------------
@Test
public void testWithMatchingMethod() throws Exception
{
MethodNameMatcher matcher = new MethodNameMatcher("echo");
final Method method = Echo.class.getMethod("echo");
- assertTrue(matcher.matches(new MockInvocation(method,null)));
+ assertTrue(matcher.matches(new MockInvocation(method, null)));
}
@Test
diff --git a/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/ReturnTypeMatcherTest.java b/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/ReturnTypeMatcherTest.java
index 8c50ba5..09cff9b 100644
--- a/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/ReturnTypeMatcherTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/ReturnTypeMatcherTest.java
@@ -17,6 +17,12 @@
package org.apache.commons.proxy2.interceptor.matcher;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
import org.apache.commons.proxy2.Invocation;
import org.apache.commons.proxy2.interceptor.matcher.invocation.ReturnTypeMatcher;
import org.apache.commons.proxy2.util.AbstractTestCase;
@@ -24,16 +30,11 @@
import org.apache.commons.proxy2.util.MockInvocation;
import org.junit.Test;
-import java.io.Serializable;
-import java.lang.reflect.Method;
-
-import static org.junit.Assert.*;
-
public class ReturnTypeMatcherTest extends AbstractTestCase
{
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Other Methods
+ //----------------------------------------------------------------------------------------------------------------------
@Test
public void testExactMatchNonMatching() throws Throwable
diff --git a/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtilsTest.java b/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtilsTest.java
index b261b3a..9928fe5 100644
--- a/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtilsTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/interceptor/matcher/argument/ArgumentMatcherUtilsTest.java
@@ -17,17 +17,18 @@
package org.apache.commons.proxy2.interceptor.matcher.argument;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.apache.commons.proxy2.interceptor.matcher.ArgumentMatcher;
import org.junit.Test;
-import static org.junit.Assert.*;
-
public class ArgumentMatcherUtilsTest
{
@Test
public void testAny() throws Exception
{
- ArgumentMatcher<Object> matcher =ArgumentMatcherUtils.any();
+ ArgumentMatcher<Object> matcher = ArgumentMatcherUtils.any();
assertTrue(matcher.matches(null));
assertTrue(matcher.matches("Hello!"));
assertTrue(matcher.matches(12345));
diff --git a/core/src/test/java/org/apache/commons/proxy2/provider/BeanProviderTest.java b/core/src/test/java/org/apache/commons/proxy2/provider/BeanProviderTest.java
index 415c895..7a1d864 100644
--- a/core/src/test/java/org/apache/commons/proxy2/provider/BeanProviderTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/provider/BeanProviderTest.java
@@ -23,9 +23,9 @@
public class BeanProviderTest extends AbstractTestCase
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Other Methods
+ //**********************************************************************************************************************
@Test(expected = ObjectProviderException.class)
public void testAbstractBeanClass()
@@ -53,9 +53,9 @@
p.getObject();
}
-//**********************************************************************************************************************
-// Inner Classes
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Inner Classes
+ //**********************************************************************************************************************
public static class MyBean
{
diff --git a/core/src/test/java/org/apache/commons/proxy2/provider/CloningProviderTest.java b/core/src/test/java/org/apache/commons/proxy2/provider/CloningProviderTest.java
index c332f49..8607188 100644
--- a/core/src/test/java/org/apache/commons/proxy2/provider/CloningProviderTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/provider/CloningProviderTest.java
@@ -17,19 +17,21 @@
package org.apache.commons.proxy2.provider;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.fail;
+
+import java.util.Date;
+
import org.apache.commons.proxy2.exception.ObjectProviderException;
import org.apache.commons.proxy2.util.AbstractTestCase;
import org.junit.Test;
-import java.util.Date;
-
-import static org.junit.Assert.*;
-
public class CloningProviderTest extends AbstractTestCase
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Other Methods
+ //**********************************************************************************************************************
@Test
public void testSerialization()
@@ -54,7 +56,8 @@
@Test
public void testWithExceptionThrown()
{
- final CloningProvider<ExceptionCloneable> provider = new CloningProvider<ExceptionCloneable>(new ExceptionCloneable());
+ final CloningProvider<ExceptionCloneable> provider = new CloningProvider<ExceptionCloneable>(
+ new ExceptionCloneable());
try
{
provider.getObject();
@@ -74,13 +77,14 @@
@Test(expected = IllegalArgumentException.class)
public void testWithProtectedCloneMethod()
{
- final CloningProvider<ProtectedCloneable> provider = new CloningProvider<ProtectedCloneable>(new ProtectedCloneable());
+ final CloningProvider<ProtectedCloneable> provider = new CloningProvider<ProtectedCloneable>(
+ new ProtectedCloneable());
provider.getObject();
}
-//**********************************************************************************************************************
-// Inner Classes
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Inner Classes
+ //**********************************************************************************************************************
public static class ExceptionCloneable implements Cloneable
{
diff --git a/core/src/test/java/org/apache/commons/proxy2/provider/ConstantProviderTest.java b/core/src/test/java/org/apache/commons/proxy2/provider/ConstantProviderTest.java
index 6c756e7..243d589 100644
--- a/core/src/test/java/org/apache/commons/proxy2/provider/ConstantProviderTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/provider/ConstantProviderTest.java
@@ -17,19 +17,19 @@
package org.apache.commons.proxy2.provider;
+import static org.junit.Assert.assertSame;
+
import org.apache.commons.proxy2.util.AbstractTestCase;
import org.junit.Test;
-import static org.junit.Assert.*;
-
/**
* @since 1.0
*/
public class ConstantProviderTest extends AbstractTestCase
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Other Methods
+ //**********************************************************************************************************************
@Test
public void testGetObject() throws Exception
diff --git a/core/src/test/java/org/apache/commons/proxy2/provider/CountingProvider.java b/core/src/test/java/org/apache/commons/proxy2/provider/CountingProvider.java
index 18d46a2..4f00912 100644
--- a/core/src/test/java/org/apache/commons/proxy2/provider/CountingProvider.java
+++ b/core/src/test/java/org/apache/commons/proxy2/provider/CountingProvider.java
@@ -25,25 +25,24 @@
*/
public class CountingProvider<T> extends ProviderDecorator<T>
{
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Fields
+ //**********************************************************************************************************************
private int count = 0;
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Constructors
+ //**********************************************************************************************************************
- public CountingProvider( ObjectProvider<? extends T> inner )
+ public CountingProvider(ObjectProvider<? extends T> inner)
{
super(inner);
}
-//**********************************************************************************************************************
-// ObjectProvider Implementation
-//**********************************************************************************************************************
-
+ //**********************************************************************************************************************
+ // ObjectProvider Implementation
+ //**********************************************************************************************************************
public synchronized T getObject()
{
@@ -51,9 +50,9 @@
return super.getObject();
}
-//**********************************************************************************************************************
-// Getter/Setter Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Getter/Setter Methods
+ //**********************************************************************************************************************
public synchronized int getCount()
{
diff --git a/core/src/test/java/org/apache/commons/proxy2/provider/NullProviderTest.java b/core/src/test/java/org/apache/commons/proxy2/provider/NullProviderTest.java
index fbf8b04..7414381 100644
--- a/core/src/test/java/org/apache/commons/proxy2/provider/NullProviderTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/provider/NullProviderTest.java
@@ -17,20 +17,20 @@
package org.apache.commons.proxy2.provider;
+import static org.junit.Assert.assertNull;
+
import org.apache.commons.proxy2.util.AbstractTestCase;
import org.junit.Test;
-import static org.junit.Assert.*;
-
/**
* @author James Carman
* @since 1.0
*/
public class NullProviderTest extends AbstractTestCase
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Other Methods
+ //**********************************************************************************************************************
@Test
public void testGetObject()
diff --git a/core/src/test/java/org/apache/commons/proxy2/provider/ObjectProviderUtilsTest.java b/core/src/test/java/org/apache/commons/proxy2/provider/ObjectProviderUtilsTest.java
index 89ce98a..4a87810 100644
--- a/core/src/test/java/org/apache/commons/proxy2/provider/ObjectProviderUtilsTest.java
+++ b/core/src/test/java/org/apache/commons/proxy2/provider/ObjectProviderUtilsTest.java
@@ -17,13 +17,13 @@
package org.apache.commons.proxy2.provider;
-import org.apache.commons.proxy2.util.AbstractTestCase;
-import org.apache.commons.proxy2.util.EchoImpl;
-import org.junit.Test;
+import static org.junit.Assert.assertTrue;
import java.util.Date;
-import static org.junit.Assert.*;
+import org.apache.commons.proxy2.util.AbstractTestCase;
+import org.apache.commons.proxy2.util.EchoImpl;
+import org.junit.Test;
public class ObjectProviderUtilsTest extends AbstractTestCase
{
diff --git a/core/src/test/java/org/apache/commons/proxy2/util/AbstractEcho.java b/core/src/test/java/org/apache/commons/proxy2/util/AbstractEcho.java
index fe8bc51..c32140b 100644
--- a/core/src/test/java/org/apache/commons/proxy2/util/AbstractEcho.java
+++ b/core/src/test/java/org/apache/commons/proxy2/util/AbstractEcho.java
@@ -26,11 +26,11 @@
@SuppressWarnings("serial")
public abstract class AbstractEcho implements Echo, Serializable
{
-//**********************************************************************************************************************
-// Echo Implementation
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Echo Implementation
+ //**********************************************************************************************************************
- public String echoBack( String message )
+ public String echoBack(String message)
{
return message;
}
diff --git a/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java b/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java
index da5c228..a5d1b80 100644
--- a/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java
+++ b/core/src/test/java/org/apache/commons/proxy2/util/AbstractTestCase.java
@@ -16,31 +16,31 @@
*/
package org.apache.commons.proxy2.util;
+import static org.junit.Assert.assertTrue;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.Builder;
import org.apache.commons.proxy2.Invocation;
import org.apache.commons.proxy2.ProxyUtils;
-import java.io.Serializable;
-import java.lang.reflect.Method;
-
-import static org.junit.Assert.*;
-
/**
* @author James Carman
* @since 2.0
*/
public abstract class AbstractTestCase
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Other Methods
+ //**********************************************************************************************************************
- protected void assertSerializable( Object o )
+ protected void assertSerializable(Object o)
{
assertTrue(o instanceof Serializable);
- SerializationUtils.clone(( Serializable ) o);
+ SerializationUtils.clone((Serializable) o);
}
protected MockInvocationBuilder mockInvocation(Class<?> type, String name, Class<?>... argumentTypes)
diff --git a/core/src/test/java/org/apache/commons/proxy2/util/DuplicateEcho.java b/core/src/test/java/org/apache/commons/proxy2/util/DuplicateEcho.java
index cc64d97..8c94811 100644
--- a/core/src/test/java/org/apache/commons/proxy2/util/DuplicateEcho.java
+++ b/core/src/test/java/org/apache/commons/proxy2/util/DuplicateEcho.java
@@ -23,9 +23,9 @@
*/
public interface DuplicateEcho
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Other Methods
+ //**********************************************************************************************************************
- public String echoBack( String message );
+ public String echoBack(String message);
}
diff --git a/core/src/test/java/org/apache/commons/proxy2/util/Echo.java b/core/src/test/java/org/apache/commons/proxy2/util/Echo.java
index af04e06..3908825 100644
--- a/core/src/test/java/org/apache/commons/proxy2/util/Echo.java
+++ b/core/src/test/java/org/apache/commons/proxy2/util/Echo.java
@@ -25,25 +25,25 @@
*/
public interface Echo
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Other Methods
+ //**********************************************************************************************************************
public void echo();
- public String echoBack( String message );
+ public String echoBack(String message);
- public String echoBack( String[] messages );
+ public String echoBack(String[] messages);
- public String echoBack( String[][] messages );
+ public String echoBack(String[][] messages);
- public String echoBack( String[][][] messages );
+ public String echoBack(String[][][] messages);
- public int echoBack( int i );
+ public int echoBack(int i);
- public boolean echoBack( boolean b );
+ public boolean echoBack(boolean b);
- public String echoBack( String message1, String message2 );
+ public String echoBack(String message1, String message2);
public void illegalArgument();
diff --git a/core/src/test/java/org/apache/commons/proxy2/util/EchoImpl.java b/core/src/test/java/org/apache/commons/proxy2/util/EchoImpl.java
index 66169d5..a496948 100644
--- a/core/src/test/java/org/apache/commons/proxy2/util/EchoImpl.java
+++ b/core/src/test/java/org/apache/commons/proxy2/util/EchoImpl.java
@@ -26,30 +26,29 @@
*/
public class EchoImpl extends AbstractEcho implements DuplicateEcho, Serializable
{
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Fields
+ //**********************************************************************************************************************
private static final long serialVersionUID = -4844873352607521103L;
-//**********************************************************************************************************************
-// Echo Implementation
-//**********************************************************************************************************************
-
+ //**********************************************************************************************************************
+ // Echo Implementation
+ //**********************************************************************************************************************
public void echo()
{
}
- public boolean echoBack( boolean b )
+ public boolean echoBack(boolean b)
{
return b;
}
- public String echoBack( String[] messages )
+ public String echoBack(String[] messages)
{
final StringBuilder sb = new StringBuilder();
- for( int i = 0; i < messages.length; i++ )
+ for (int i = 0; i < messages.length; i++)
{
String message = messages[i];
sb.append(message);
@@ -57,32 +56,32 @@
return sb.toString();
}
- public String echoBack( String[][] messages )
+ public String echoBack(String[][] messages)
{
final StringBuilder sb = new StringBuilder();
- for( int i = 0; i < messages.length; i++ )
+ for (int i = 0; i < messages.length; i++)
{
sb.append(echoBack(messages[i]));
}
return sb.toString();
}
- public String echoBack( String[][][] messages )
+ public String echoBack(String[][][] messages)
{
final StringBuilder sb = new StringBuilder();
- for( int i = 0; i < messages.length; i++ )
+ for (int i = 0; i < messages.length; i++)
{
sb.append(echoBack(messages[i]));
}
return sb.toString();
}
- public int echoBack( int i )
+ public int echoBack(int i)
{
return i;
}
- public String echoBack( String message1, String message2 )
+ public String echoBack(String message1, String message2)
{
return message1 + message2;
}
diff --git a/core/src/test/java/org/apache/commons/proxy2/util/MockInvocation.java b/core/src/test/java/org/apache/commons/proxy2/util/MockInvocation.java
index 0ba7c45..ce4ce94 100644
--- a/core/src/test/java/org/apache/commons/proxy2/util/MockInvocation.java
+++ b/core/src/test/java/org/apache/commons/proxy2/util/MockInvocation.java
@@ -16,35 +16,37 @@
*/
package org.apache.commons.proxy2.util;
-import org.apache.commons.proxy2.Invocation;
-
import java.lang.reflect.Method;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.proxy2.Invocation;
+import org.apache.commons.proxy2.ProxyUtils;
+
public class MockInvocation implements Invocation
{
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Fields
+ //----------------------------------------------------------------------------------------------------------------------
private final Method method;
private final Object[] arguments;
private final Object returnValue;
-//----------------------------------------------------------------------------------------------------------------------
-// Constructors
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Constructors
+ //----------------------------------------------------------------------------------------------------------------------
public MockInvocation(Method method, Object returnValue, Object... arguments)
{
this.returnValue = returnValue;
- this.arguments = arguments;
+ this.arguments = ObjectUtils.defaultIfNull(ArrayUtils.clone(arguments), ProxyUtils.EMPTY_ARGUMENTS);
this.method = method;
}
-//----------------------------------------------------------------------------------------------------------------------
-// Invocation Implementation
-//----------------------------------------------------------------------------------------------------------------------
-
+ //----------------------------------------------------------------------------------------------------------------------
+ // Invocation Implementation
+ //----------------------------------------------------------------------------------------------------------------------
@Override
public Object[] getArguments()
diff --git a/core/src/test/java/org/apache/commons/proxy2/util/QuoteService.java b/core/src/test/java/org/apache/commons/proxy2/util/QuoteService.java
index bd8d841..3abcd91 100644
--- a/core/src/test/java/org/apache/commons/proxy2/util/QuoteService.java
+++ b/core/src/test/java/org/apache/commons/proxy2/util/QuoteService.java
@@ -26,9 +26,9 @@
*/
public interface QuoteService extends Remote
{
-//**********************************************************************************************************************
-// Other Methods
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Other Methods
+ //**********************************************************************************************************************
- public float getQuote( String symbol ) throws RemoteException;
+ public float getQuote(String symbol) throws RemoteException;
}
diff --git a/core/src/test/java/org/apache/commons/proxy2/util/SuffixInterceptor.java b/core/src/test/java/org/apache/commons/proxy2/util/SuffixInterceptor.java
index 466925e..afe39db 100644
--- a/core/src/test/java/org/apache/commons/proxy2/util/SuffixInterceptor.java
+++ b/core/src/test/java/org/apache/commons/proxy2/util/SuffixInterceptor.java
@@ -27,33 +27,32 @@
@SuppressWarnings("serial")
public class SuffixInterceptor implements Interceptor
{
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Fields
+ //**********************************************************************************************************************
private final String suffix;
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Constructors
+ //**********************************************************************************************************************
- public SuffixInterceptor( String suffix )
+ public SuffixInterceptor(String suffix)
{
this.suffix = suffix;
}
-//**********************************************************************************************************************
-// Interceptor Implementation
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Interceptor Implementation
+ //**********************************************************************************************************************
-
- public Object intercept( Invocation methodInvocation ) throws Throwable
+ public Object intercept(Invocation methodInvocation) throws Throwable
{
- Object result = methodInvocation.proceed();
- if (result instanceof String)
- {
- result = ((String) result) + suffix;
- }
- return result;
+ Object result = methodInvocation.proceed();
+ if (result instanceof String)
+ {
+ result = ((String) result) + suffix;
+ }
+ return result;
}
}
diff --git a/core/src/test/resources/log4j.properties b/core/src/test/resources/log4j.properties
index 1a98c66..12c40cb 100644
--- a/core/src/test/resources/log4j.properties
+++ b/core/src/test/resources/log4j.properties
@@ -1,4 +1,3 @@
-#
# 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.
diff --git a/javassist/pom.xml b/javassist/pom.xml
index bfb013c..19b3b19 100644
--- a/javassist/pom.xml
+++ b/javassist/pom.xml
@@ -53,4 +53,34 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <configuration>
+ <!--rulesets>
+ <ruleset>/org/apache/commons/proxy2/pmd.xml</ruleset>
+ </rulesets-->
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle.version}</version>
+ <configuration>
+ <configLocation>org/apache/commons/proxy2/checkstyle.xml</configLocation>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <xmlOutput>true</xmlOutput>
+ <excludeFilterFile>/org/apache/commons/proxy2/findbugs-exclude-filter.xml</excludeFilterFile>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
</project>
diff --git a/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistInvocation.java b/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistInvocation.java
index 0bf9a30..39e08a0 100644
--- a/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistInvocation.java
+++ b/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistInvocation.java
@@ -17,35 +17,38 @@
package org.apache.commons.proxy2.javassist;
-import javassist.CannotCompileException;
-import javassist.CtClass;
-import javassist.CtConstructor;
-import javassist.CtMethod;
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.proxy2.Invocation;
-import org.apache.commons.proxy2.ProxyUtils;
-
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
+import javassist.CannotCompileException;
+import javassist.CtClass;
+import javassist.CtConstructor;
+import javassist.CtMethod;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.proxy2.Invocation;
+import org.apache.commons.proxy2.ProxyUtils;
+
/**
- * A <a href="http://www.jboss.org/products/javassist">Javassist</a>-based {@link Invocation} implementation. This
- * class actually serves as the superclass for all <a href="http://www.jboss.org/products/javassist">Javassist</a>-based
- * method invocations. Subclasses are dynamically created to deal with specific interface methods (they're hard-wired).
- *
+ * A <a href="http://www.jboss.org/products/javassist">Javassist</a>-based {@link Invocation} implementation. This class
+ * actually serves as the superclass for all <a href="http://www.jboss.org/products/javassist">Javassist</a>-based
+ * method invocations. Subclasses are dynamically created to deal with specific interface methods (they're hard-wired).
+ *
* @author James Carman
* @since 1.0
*/
public abstract class JavassistInvocation implements Invocation
{
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
- private static WeakHashMap<ClassLoader, Map<String, WeakReference<Class<?>>>> loaderToClassCache = new WeakHashMap<ClassLoader, Map<String,WeakReference<Class<?>>>>();
+ private static WeakHashMap<ClassLoader, Map<String, WeakReference<Class<?>>>> loaderToClassCache
+ = new WeakHashMap<ClassLoader, Map<String, WeakReference<Class<?>>>>();
/** The proxy object */
private final Object proxy;
@@ -59,44 +62,40 @@
/** The method arguments */
private final Object[] arguments;
-//**********************************************************************************************************************
-// Static Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Static Methods
+ //******************************************************************************************************************
- private static String createCastExpression( Class<?> type, String objectToCast )
+ private static String createCastExpression(Class<?> type, String objectToCast)
{
- if( !type.isPrimitive() )
+ if (!type.isPrimitive())
{
return "( " + ProxyUtils.getJavaClassName(type) + " )" + objectToCast;
}
else
{
- return "( ( " + ProxyUtils.getWrapperClass(type).getName() + " )" + objectToCast + " )." +
- type.getName() + "Value()";
+ return "( ( " + ProxyUtils.getWrapperClass(type).getName() + " )" + objectToCast + " )." + type.getName()
+ + "Value()";
}
}
- private static Class<?> createInvocationClass( ClassLoader classLoader, Method interfaceMethod )
+ private static Class<?> createInvocationClass(ClassLoader classLoader, Method interfaceMethod)
throws CannotCompileException
{
- Class<?> invocationClass;
- final CtClass ctClass = JavassistUtils.createClass(
- getSimpleName(interfaceMethod.getDeclaringClass()) + "_" + interfaceMethod.getName() +
- "_invocation",
- JavassistInvocation.class);
- final CtConstructor constructor = new CtConstructor(
- JavassistUtils.resolve(new Class[] { Object.class, Object.class, Method.class, Object[].class }),
- ctClass);
+ final CtClass ctClass = JavassistUtils.createClass(getSimpleName(interfaceMethod.getDeclaringClass()) + "_"
+ + interfaceMethod.getName() + "_invocation", JavassistInvocation.class);
+ final CtConstructor constructor = new CtConstructor(JavassistUtils.resolve(new Class[] { Object.class,
+ Object.class, Method.class, Object[].class }), ctClass);
constructor.setBody("{\n\tsuper($$);\n}");
ctClass.addConstructor(constructor);
final CtMethod proceedMethod = new CtMethod(JavassistUtils.resolve(Object.class), "proceed",
JavassistUtils.resolve(new Class[0]), ctClass);
final Class<?>[] argumentTypes = interfaceMethod.getParameterTypes();
final StringBuilder proceedBody = new StringBuilder("{\n");
- if( !Void.TYPE.equals(interfaceMethod.getReturnType()) )
+ if (!Void.TYPE.equals(interfaceMethod.getReturnType()))
{
proceedBody.append("\treturn ");
- if( interfaceMethod.getReturnType().isPrimitive() )
+ if (interfaceMethod.getReturnType().isPrimitive())
{
proceedBody.append("new ");
proceedBody.append(ProxyUtils.getWrapperClass(interfaceMethod.getReturnType()).getName());
@@ -112,16 +111,16 @@
proceedBody.append(" )getTarget() ).");
proceedBody.append(interfaceMethod.getName());
proceedBody.append("(");
- for( int i = 0; i < argumentTypes.length; ++i )
+ for (int i = 0; i < argumentTypes.length; ++i)
{
final Class<?> argumentType = argumentTypes[i];
proceedBody.append(createCastExpression(argumentType, "getArguments()[" + i + "]"));
- if( i != argumentTypes.length - 1 )
+ if (i != argumentTypes.length - 1)
{
proceedBody.append(", ");
}
}
- if( !Void.TYPE.equals(interfaceMethod.getReturnType()) && interfaceMethod.getReturnType().isPrimitive() )
+ if (!Void.TYPE.equals(interfaceMethod.getReturnType()) && interfaceMethod.getReturnType().isPrimitive())
{
proceedBody.append(") );\n");
}
@@ -129,7 +128,7 @@
{
proceedBody.append(");\n");
}
- if( Void.TYPE.equals(interfaceMethod.getReturnType()) )
+ if (Void.TYPE.equals(interfaceMethod.getReturnType()))
{
proceedBody.append("\treturn null;\n");
}
@@ -137,14 +136,16 @@
final String body = proceedBody.toString();
proceedMethod.setBody(body);
ctClass.addMethod(proceedMethod);
- invocationClass = ctClass.toClass(classLoader);
+
+ @SuppressWarnings("deprecation")
+ final Class<?> invocationClass = ctClass.toClass(classLoader);
return invocationClass;
}
- private static Map<String, WeakReference<Class<?>>> getClassCache( ClassLoader classLoader )
+ private static Map<String, WeakReference<Class<?>>> getClassCache(ClassLoader classLoader)
{
Map<String, WeakReference<Class<?>>> cache = loaderToClassCache.get(classLoader);
- if( cache == null )
+ if (cache == null)
{
cache = new HashMap<String, WeakReference<Class<?>>>();
loaderToClassCache.put(classLoader, cache);
@@ -154,31 +155,33 @@
/**
* Returns a method invocation class specifically coded to invoke the supplied interface method.
- *
- * @param classLoader the classloader to use
- * @param interfaceMethod the interface method
+ *
+ * @param classLoader
+ * the classloader to use
+ * @param interfaceMethod
+ * the interface method
* @return a method invocation class specifically coded to invoke the supplied interface method
- * @throws CannotCompileException if a compilation error occurs
+ * @throws CannotCompileException
+ * if a compilation error occurs
*/
- static synchronized Class<?> getMethodInvocationClass( ClassLoader classLoader,
- Method interfaceMethod )
+ static synchronized Class<?> getMethodInvocationClass(ClassLoader classLoader, Method interfaceMethod)
throws CannotCompileException
{
final Map<String, WeakReference<Class<?>>> classCache = getClassCache(classLoader);
final String key = toClassCacheKey(interfaceMethod);
final WeakReference<Class<?>> invocationClassRef = classCache.get(key);
Class<?> invocationClass;
- if( invocationClassRef == null )
+ if (invocationClassRef == null)
{
invocationClass = createInvocationClass(classLoader, interfaceMethod);
classCache.put(key, new WeakReference<Class<?>>(invocationClass));
}
else
{
- synchronized( invocationClassRef )
+ synchronized (invocationClassRef)
{
invocationClass = invocationClassRef.get();
- if( invocationClass == null )
+ if (invocationClass == null)
{
invocationClass = createInvocationClass(classLoader, interfaceMethod);
classCache.put(key, new WeakReference<Class<?>>(invocationClass));
@@ -188,33 +191,33 @@
return invocationClass;
}
- private static String getSimpleName( Class<?> c )
+ private static String getSimpleName(Class<?> c)
{
final String name = c.getName();
final int ndx = name.lastIndexOf('.');
return ndx == -1 ? name : name.substring(ndx + 1);
}
- private static String toClassCacheKey( Method method )
+ private static String toClassCacheKey(Method method)
{
return String.valueOf(method);
}
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Constructors
+ //******************************************************************************************************************
- protected JavassistInvocation( Object proxy, Object target, Method method, Object[] arguments )
+ protected JavassistInvocation(Object proxy, Object target, Method method, Object[] arguments)
{
this.proxy = proxy;
this.target = target;
this.method = method;
- this.arguments = ArrayUtils.clone(arguments);
+ this.arguments = ObjectUtils.defaultIfNull(ArrayUtils.clone(arguments), ProxyUtils.EMPTY_ARGUMENTS);
}
-//**********************************************************************************************************************
-// Invocation Implementation
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Invocation Implementation
+ //******************************************************************************************************************
protected final Object getTarget()
{
return target;
diff --git a/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistProxyFactory.java b/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistProxyFactory.java
index 4ba823e..ac15c4c 100644
--- a/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistProxyFactory.java
+++ b/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistProxyFactory.java
@@ -17,10 +17,13 @@
package org.apache.commons.proxy2.javassist;
+import java.lang.reflect.Method;
+
import javassist.CannotCompileException;
import javassist.CtClass;
import javassist.CtConstructor;
import javassist.CtMethod;
+
import org.apache.commons.proxy2.Interceptor;
import org.apache.commons.proxy2.Invoker;
import org.apache.commons.proxy2.ObjectProvider;
@@ -30,13 +33,11 @@
import org.apache.commons.proxy2.impl.AbstractSubclassingProxyFactory;
import org.apache.commons.proxy2.impl.ProxyClassCache;
-import java.lang.reflect.Method;
-
public class JavassistProxyFactory extends AbstractSubclassingProxyFactory
{
- //**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
private static final String GET_METHOD_METHOD_NAME = "_javassistGetMethod";
@@ -44,39 +45,38 @@
new DelegatingProxyClassGenerator());
private static final ProxyClassCache INTERCEPTOR_PROXY_CACHE = new ProxyClassCache(
new InterceptorProxyClassGenerator());
- private static final ProxyClassCache INVOKER_PROXY_CACHE = new ProxyClassCache(
- new InvokerProxyClassGenerator());
+ private static final ProxyClassCache INVOKER_PROXY_CACHE = new ProxyClassCache(new InvokerProxyClassGenerator());
-//**********************************************************************************************************************
-// Static Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Static Methods
+ //******************************************************************************************************************
private static void addGetMethodMethod(CtClass proxyClass) throws CannotCompileException
{
final CtMethod method = new CtMethod(JavassistUtils.resolve(Method.class), GET_METHOD_METHOD_NAME,
- JavassistUtils.resolve(new Class[]{String.class, String.class, Class[].class}), proxyClass);
- final String body = "try { return Class.forName($1).getMethod($2, $3); } catch( Exception e ) " +
- "{ throw new RuntimeException(\"Unable to look up method.\", e); }";
+ JavassistUtils.resolve(new Class[] { String.class, String.class, Class[].class }), proxyClass);
+ final String body = "try { return Class.forName($1).getMethod($2, $3); } catch( Exception e ) "
+ + "{ throw new RuntimeException(\"Unable to look up method.\", e); }";
method.setBody(body);
proxyClass.addMethod(method);
}
- //**********************************************************************************************************************
+ //******************************************************************************************************************
// ProxyFactory Implementation
- //**********************************************************************************************************************
+ //******************************************************************************************************************
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public <T> T createDelegatorProxy(ClassLoader classLoader, ObjectProvider<?> targetProvider,
- Class<?>... proxyClasses)
+ Class<?>... proxyClasses)
{
try
{
- final Class<? extends T> clazz = (Class<? extends T>) DELEGATING_PROXY_CACHE.getProxyClass(classLoader, proxyClasses);
- return clazz.getConstructor(ObjectProvider.class)
- .newInstance(targetProvider);
+ final Class<? extends T> clazz = (Class<? extends T>) DELEGATING_PROXY_CACHE.getProxyClass(classLoader,
+ proxyClasses);
+ return clazz.getConstructor(ObjectProvider.class).newInstance(targetProvider);
}
catch (Exception e)
{
@@ -89,13 +89,13 @@
*/
@SuppressWarnings("unchecked")
public <T> T createInterceptorProxy(ClassLoader classLoader, Object target, Interceptor interceptor,
- Class<?>... proxyClasses)
+ Class<?>... proxyClasses)
{
try
{
- final Class<? extends T> clazz = (Class<? extends T>) INTERCEPTOR_PROXY_CACHE.getProxyClass(classLoader, proxyClasses);
- return clazz.getConstructor(Object.class, Interceptor.class)
- .newInstance(target, interceptor);
+ final Class<? extends T> clazz = (Class<? extends T>) INTERCEPTOR_PROXY_CACHE.getProxyClass(classLoader,
+ proxyClasses);
+ return clazz.getConstructor(Object.class, Interceptor.class).newInstance(target, interceptor);
}
catch (Exception e)
{
@@ -107,14 +107,13 @@
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
- public <T> T createInvokerProxy(ClassLoader classLoader, Invoker invoker,
- Class<?>... proxyClasses)
+ public <T> T createInvokerProxy(ClassLoader classLoader, Invoker invoker, Class<?>... proxyClasses)
{
try
{
- final Class<? extends T> clazz = (Class<? extends T>) INVOKER_PROXY_CACHE.getProxyClass(classLoader, proxyClasses);
- return clazz.getConstructor(Invoker.class)
- .newInstance(invoker);
+ final Class<? extends T> clazz = (Class<? extends T>) INVOKER_PROXY_CACHE.getProxyClass(classLoader,
+ proxyClasses);
+ return clazz.getConstructor(Invoker.class).newInstance(invoker);
}
catch (Exception e)
{
@@ -122,9 +121,9 @@
}
}
-//**********************************************************************************************************************
-// Inner Classes
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Inner Classes
+ //******************************************************************************************************************
private static class DelegatingProxyClassGenerator extends AbstractProxyClassGenerator
{
@@ -135,8 +134,7 @@
final CtClass proxyClass = JavassistUtils.createClass(getSuperclass(proxyClasses));
JavassistUtils.addField(ObjectProvider.class, "provider", proxyClass);
final CtConstructor proxyConstructor = new CtConstructor(
- JavassistUtils.resolve(new Class[]{ObjectProvider.class}),
- proxyClass);
+ JavassistUtils.resolve(new Class[] { ObjectProvider.class }), proxyClass);
proxyConstructor.setBody("{ this.provider = $1; }");
proxyClass.addConstructor(proxyConstructor);
JavassistUtils.addInterfaces(proxyClass, toInterfaces(proxyClasses));
@@ -149,17 +147,14 @@
{
final Method method = methods[i];
final CtMethod ctMethod = new CtMethod(JavassistUtils.resolve(method.getReturnType()),
- method.getName(),
- JavassistUtils.resolve(method.getParameterTypes()),
- proxyClass);
- final String body = "{ return ( $r ) ( ( " + method.getDeclaringClass().getName() +
- " )provider.getObject() )." +
- method.getName() + "($$); }";
+ method.getName(), JavassistUtils.resolve(method.getParameterTypes()), proxyClass);
+ final String body = "{ return ( $r ) ( ( " + method.getDeclaringClass().getName()
+ + " )provider.getObject() )." + method.getName() + "($$); }";
ctMethod.setBody(body);
proxyClass.addMethod(ctMethod);
}
}
- return proxyClass.toClass(classLoader);
+ return proxyClass.toClass(classLoader, null);
}
catch (CannotCompileException e)
{
@@ -182,34 +177,30 @@
addGetMethodMethod(proxyClass);
addHashCodeMethod(proxyClass);
addEqualsMethod(proxyClass);
- final CtConstructor proxyConstructor = new CtConstructor(
- JavassistUtils.resolve(
- new Class[]{Object.class, Interceptor.class}),
- proxyClass);
- proxyConstructor
- .setBody(
- "{\n\tthis.target = $1;\n\tthis.interceptor = $2; }");
+ final CtConstructor proxyConstructor = new CtConstructor(JavassistUtils.resolve(new Class[] {
+ Object.class, Interceptor.class }), proxyClass);
+ proxyConstructor.setBody("{\n\tthis.target = $1;\n\tthis.interceptor = $2; }");
proxyClass.addConstructor(proxyConstructor);
for (int i = 0; i < methods.length; ++i)
{
if (!ProxyUtils.isEqualsMethod(methods[i]) && !ProxyUtils.isHashCode(methods[i]))
{
final CtMethod method = new CtMethod(JavassistUtils.resolve(methods[i].getReturnType()),
- methods[i].getName(),
- JavassistUtils.resolve(methods[i].getParameterTypes()),
+ methods[i].getName(), JavassistUtils.resolve(methods[i].getParameterTypes()),
proxyClass);
- final Class<?> invocationClass = JavassistInvocation
- .getMethodInvocationClass(classLoader, methods[i]);
+ final Class<?> invocationClass = JavassistInvocation.getMethodInvocationClass(classLoader,
+ methods[i]);
- final String body = "{\n\t return ( $r ) interceptor.intercept( new " + invocationClass.getName() +
- "( this, target, " + GET_METHOD_METHOD_NAME + "(\"" + methods[i].getDeclaringClass().getName() +
- "\", \"" + methods[i].getName() + "\", $sig), $args ) );\n }";
+ final String body = "{\n\t return ( $r ) interceptor.intercept( new "
+ + invocationClass.getName() + "( this, target, " + GET_METHOD_METHOD_NAME + "(\""
+ + methods[i].getDeclaringClass().getName() + "\", \"" + methods[i].getName()
+ + "\", $sig), $args ) );\n }";
method.setBody(body);
proxyClass.addMethod(method);
}
}
- return proxyClass.toClass(classLoader);
+ return proxyClass.toClass(classLoader, null);
}
catch (CannotCompileException e)
{
@@ -217,24 +208,21 @@
}
}
-
}
- private static void addEqualsMethod(CtClass proxyClass)
- throws CannotCompileException
+ private static void addEqualsMethod(CtClass proxyClass) throws CannotCompileException
{
final CtMethod equalsMethod = new CtMethod(JavassistUtils.resolve(Boolean.TYPE), "equals",
- JavassistUtils.resolve(new Class[]{Object.class}), proxyClass);
+ JavassistUtils.resolve(new Class[] { Object.class }), proxyClass);
final String body = "{\n\treturn this == $1;\n}";
equalsMethod.setBody(body);
proxyClass.addMethod(equalsMethod);
}
- private static void addHashCodeMethod(CtClass proxyClass)
- throws CannotCompileException
+ private static void addHashCodeMethod(CtClass proxyClass) throws CannotCompileException
{
- final CtMethod hashCodeMethod = new CtMethod(JavassistUtils.resolve(Integer.TYPE), "hashCode",
- new CtClass[0], proxyClass);
+ final CtMethod hashCodeMethod = new CtMethod(JavassistUtils.resolve(Integer.TYPE), "hashCode", new CtClass[0],
+ proxyClass);
hashCodeMethod.setBody("{\n\treturn System.identityHashCode(this);\n}");
proxyClass.addMethod(hashCodeMethod);
}
@@ -250,11 +238,8 @@
JavassistUtils.addInterfaces(proxyClass, toInterfaces(proxyClasses));
JavassistUtils.addField(Invoker.class, "invoker", proxyClass);
final CtConstructor proxyConstructor = new CtConstructor(
- JavassistUtils.resolve(
- new Class[]{Invoker.class}),
- proxyClass);
- proxyConstructor
- .setBody("{\n\tthis.invoker = $1; }");
+ JavassistUtils.resolve(new Class[] { Invoker.class }), proxyClass);
+ proxyConstructor.setBody("{\n\tthis.invoker = $1; }");
proxyClass.addConstructor(proxyConstructor);
addGetMethodMethod(proxyClass);
addHashCodeMethod(proxyClass);
@@ -264,17 +249,16 @@
if (!ProxyUtils.isEqualsMethod(methods[i]) && !ProxyUtils.isHashCode(methods[i]))
{
final CtMethod method = new CtMethod(JavassistUtils.resolve(methods[i].getReturnType()),
- methods[i].getName(),
- JavassistUtils.resolve(methods[i].getParameterTypes()),
+ methods[i].getName(), JavassistUtils.resolve(methods[i].getParameterTypes()),
proxyClass);
- final String body = "{\n\t return ( $r ) invoker.invoke( this, " + GET_METHOD_METHOD_NAME + "(\"" +
- methods[i].getDeclaringClass().getName() +
- "\", \"" + methods[i].getName() + "\", $sig), $args );\n }";
+ final String body = "{\n\t return ( $r ) invoker.invoke( this, " + GET_METHOD_METHOD_NAME
+ + "(\"" + methods[i].getDeclaringClass().getName() + "\", \"" + methods[i].getName()
+ + "\", $sig), $args );\n }";
method.setBody(body);
proxyClass.addMethod(method);
}
}
- return proxyClass.toClass(classLoader);
+ return proxyClass.toClass(classLoader, null);
}
catch (CannotCompileException e)
{
diff --git a/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistUtils.java b/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistUtils.java
index 78dc74e..a270fc0 100644
--- a/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistUtils.java
+++ b/javassist/src/main/java/org/apache/commons/proxy2/javassist/JavassistUtils.java
@@ -17,34 +17,40 @@
package org.apache.commons.proxy2.javassist;
-import javassist.*;
-import org.apache.commons.proxy2.ProxyUtils;
-import org.apache.commons.proxy2.exception.ObjectProviderException;
-
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtField;
+import javassist.LoaderClassPath;
+import javassist.NotFoundException;
+
+import org.apache.commons.proxy2.ProxyUtils;
+import org.apache.commons.proxy2.exception.ObjectProviderException;
+
/**
- * Some utility methods for dealing with Javassist. This class is not part of the public API!
- *
+ * Some utility methods for dealing with Javassist. This class is not part of the public API!
+ *
* @author James Carman
* @since 1.0
*/
final class JavassistUtils
{
-//**********************************************************************************************************************
-// Fields
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Fields
+ //******************************************************************************************************************
public static final String DEFAULT_BASE_NAME = "JavassistUtilsGenerated";
private static final AtomicInteger CLASS_NUMBER = new AtomicInteger(0);
private static final ClassPool CLASS_POOL = new ClassPool();
private static final Set<ClassLoader> CLASS_LOADERS = new HashSet<ClassLoader>();
-//**********************************************************************************************************************
-// Static Methods
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Static Methods
+ //******************************************************************************************************************
static
{
@@ -53,13 +59,17 @@
/**
* Adds a field to a class.
- *
- * @param fieldType the field's type
- * @param fieldName the field name
- * @param enclosingClass the class receiving the new field
- * @throws CannotCompileException if a compilation problem occurs
+ *
+ * @param fieldType
+ * the field's type
+ * @param fieldName
+ * the field name
+ * @param enclosingClass
+ * the class receiving the new field
+ * @throws CannotCompileException
+ * if a compilation problem occurs
*/
- public static void addField( Class<?> fieldType, String fieldName, CtClass enclosingClass )
+ public static void addField(Class<?> fieldType, String fieldName, CtClass enclosingClass)
throws CannotCompileException
{
enclosingClass.addField(new CtField(resolve(fieldType), fieldName, enclosingClass));
@@ -67,13 +77,15 @@
/**
* Adds interfaces to a {@link CtClass}
- *
- * @param ctClass the {@link CtClass}
- * @param proxyClasses the interfaces
+ *
+ * @param ctClass
+ * the {@link CtClass}
+ * @param proxyClasses
+ * the interfaces
*/
- public static void addInterfaces( CtClass ctClass, Class<?>[] proxyClasses )
+ public static void addInterfaces(CtClass ctClass, Class<?>[] proxyClasses)
{
- for( int i = 0; i < proxyClasses.length; i++ )
+ for (int i = 0; i < proxyClasses.length; i++)
{
Class<?> proxyInterface = proxyClasses[i];
ctClass.addInterface(resolve(proxyInterface));
@@ -82,72 +94,78 @@
/**
* Creates a new {@link CtClass} derived from the Java {@link Class} using the default base name.
- *
- * @param superclass the superclass
+ *
+ * @param superclass
+ * the superclass
* @return the new derived {@link CtClass}
*/
- public static CtClass createClass( Class<?> superclass )
+ public static CtClass createClass(Class<?> superclass)
{
return createClass(DEFAULT_BASE_NAME, superclass);
}
/**
* Creates a new {@link CtClass} derived from the Java {@link Class} using the supplied base name.
- *
- * @param baseName the base name
- * @param superclass the superclass
+ *
+ * @param baseName
+ * the base name
+ * @param superclass
+ * the superclass
* @return the new derived {@link CtClass}
*/
- public static synchronized CtClass createClass( String baseName, Class<?> superclass )
+ public static synchronized CtClass createClass(String baseName, Class<?> superclass)
{
return CLASS_POOL.makeClass(baseName + "_" + CLASS_NUMBER.incrementAndGet(), resolve(superclass));
}
/**
* Finds the {@link CtClass} corresponding to the Java {@link Class} passed in.
- *
- * @param clazz the Java {@link Class}
+ *
+ * @param clazz
+ * the Java {@link Class}
* @return the {@link CtClass}
*/
- public static CtClass resolve( Class<?> clazz )
+ public static CtClass resolve(Class<?> clazz)
{
- synchronized(CLASS_LOADERS)
+ synchronized (CLASS_LOADERS)
{
try
{
final ClassLoader loader = clazz.getClassLoader();
- if( loader != null && !CLASS_LOADERS.contains(loader) )
+ if (loader != null && !CLASS_LOADERS.contains(loader))
{
CLASS_LOADERS.add(loader);
CLASS_POOL.appendClassPath(new LoaderClassPath(loader));
}
return CLASS_POOL.get(ProxyUtils.getJavaClassName(clazz));
}
- catch( NotFoundException e )
+ catch (NotFoundException e)
{
- throw new ObjectProviderException(
- "Unable to find class " + clazz.getName() + " in default Javassist class pool.", e);
+ throw new ObjectProviderException("Unable to find class " + clazz.getName()
+ + " in default Javassist class pool.", e);
}
}
}
/**
* Resolves an array of Java {@link Class}es to an array of their corresponding {@link CtClass}es.
- *
- * @param classes the Java {@link Class}es
+ *
+ * @param classes
+ * the Java {@link Class}es
* @return the corresponding {@link CtClass}es
*/
- public static CtClass[] resolve( Class<?>[] classes )
+ public static CtClass[] resolve(Class<?>[] classes)
{
final CtClass[] ctClasses = new CtClass[classes.length];
- for( int i = 0; i < ctClasses.length; ++i )
+ for (int i = 0; i < ctClasses.length; ++i)
{
ctClasses[i] = resolve(classes[i]);
}
return ctClasses;
}
- private JavassistUtils() {
+ private JavassistUtils()
+ {
// Hiding constructor in utility class!
}
}
diff --git a/javassist/src/test/java/org/apache/commons/proxy2/javassist/JavassistProxyFactoryTest.java b/javassist/src/test/java/org/apache/commons/proxy2/javassist/JavassistProxyFactoryTest.java
index ac53c6b..839af29 100644
--- a/javassist/src/test/java/org/apache/commons/proxy2/javassist/JavassistProxyFactoryTest.java
+++ b/javassist/src/test/java/org/apache/commons/proxy2/javassist/JavassistProxyFactoryTest.java
@@ -20,7 +20,7 @@
public class JavassistProxyFactoryTest extends AbstractSubclassingProxyFactoryTestCase
{
-//**********************************************************************************************************************
-// Constructors
-//**********************************************************************************************************************
+ //**********************************************************************************************************************
+ // Constructors
+ //**********************************************************************************************************************
}
diff --git a/jdk/pom.xml b/jdk/pom.xml
index 28715b7..6087dce 100644
--- a/jdk/pom.xml
+++ b/jdk/pom.xml
@@ -49,4 +49,34 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <configuration>
+ <!--rulesets>
+ <ruleset>/org/apache/commons/proxy2/pmd.xml</ruleset>
+ </rulesets-->
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle.version}</version>
+ <configuration>
+ <configLocation>org/apache/commons/proxy2/checkstyle.xml</configLocation>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <xmlOutput>true</xmlOutput>
+ <excludeFilterFile>/org/apache/commons/proxy2/findbugs-exclude-filter.xml</excludeFilterFile>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
</project>
diff --git a/jdk/src/main/java/org/apache/commons/proxy2/jdk/JdkProxyFactory.java b/jdk/src/main/java/org/apache/commons/proxy2/jdk/JdkProxyFactory.java
index cc4ff4e..fa1187f 100644
--- a/jdk/src/main/java/org/apache/commons/proxy2/jdk/JdkProxyFactory.java
+++ b/jdk/src/main/java/org/apache/commons/proxy2/jdk/JdkProxyFactory.java
@@ -17,90 +17,104 @@
package org.apache.commons.proxy2.jdk;
-import org.apache.commons.proxy2.*;
-import org.apache.commons.proxy2.impl.AbstractProxyFactory;
-
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.proxy2.Interceptor;
+import org.apache.commons.proxy2.Invocation;
+import org.apache.commons.proxy2.Invoker;
+import org.apache.commons.proxy2.ObjectProvider;
+import org.apache.commons.proxy2.ProxyUtils;
+import org.apache.commons.proxy2.impl.AbstractProxyFactory;
+
/**
* {@link ProxyFactory} implementation that uses {@link java.lang.reflect.Proxy} proxies.
*/
public class JdkProxyFactory extends AbstractProxyFactory
{
-//**********************************************************************************************************************
-// ProxyFactory Implementation
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // ProxyFactory Implementation
+ //******************************************************************************************************************
/**
* Creates a proxy2 which delegates to the object provided by <code>delegateProvider</code>.
- *
- * @param classLoader the class loader to use when generating the proxy2
- * @param delegateProvider the delegate provider
- * @param proxyClasses the interfaces that the proxy2 should implement
+ *
+ * @param classLoader
+ * the class loader to use when generating the proxy2
+ * @param delegateProvider
+ * the delegate provider
+ * @param proxyClasses
+ * the interfaces that the proxy2 should implement
* @return a proxy2 which delegates to the object provided by the target <code>delegateProvider>
*/
@SuppressWarnings("unchecked")
- public <T> T createDelegatorProxy( ClassLoader classLoader, ObjectProvider<?> delegateProvider,
- Class<?>... proxyClasses )
+ public <T> T createDelegatorProxy(ClassLoader classLoader, ObjectProvider<?> delegateProvider,
+ Class<?>... proxyClasses)
{
- return (T) Proxy.newProxyInstance(classLoader, proxyClasses,
- new DelegatorInvocationHandler(delegateProvider));
+ return (T) Proxy.newProxyInstance(classLoader, proxyClasses, new DelegatorInvocationHandler(delegateProvider));
}
/**
* Creates a proxy2 which passes through a {@link Interceptor interceptor} before eventually reaching the
* <code>target</code> object.
- *
- * @param classLoader the class loader to use when generating the proxy2
- * @param target the target object
- * @param interceptor the method interceptor
- * @param proxyClasses the interfaces that the proxy2 should implement.
+ *
+ * @param classLoader
+ * the class loader to use when generating the proxy2
+ * @param target
+ * the target object
+ * @param interceptor
+ * the method interceptor
+ * @param proxyClasses
+ * the interfaces that the proxy2 should implement.
* @return a proxy2 which passes through a {@link Interceptor interceptor} before eventually reaching the
* <code>target</code> object.
*/
@SuppressWarnings("unchecked")
- public <T> T createInterceptorProxy( ClassLoader classLoader, Object target, Interceptor interceptor,
- Class<?>... proxyClasses )
+ public <T> T createInterceptorProxy(ClassLoader classLoader, Object target, Interceptor interceptor,
+ Class<?>... proxyClasses)
{
- return (T) Proxy
- .newProxyInstance(classLoader, proxyClasses, new InterceptorInvocationHandler(target, interceptor));
+ return (T) Proxy.newProxyInstance(classLoader, proxyClasses, new InterceptorInvocationHandler(target,
+ interceptor));
}
/**
* Creates a proxy2 which uses the provided {@link Invoker} to handle all method invocations.
- *
- * @param classLoader the class loader to use when generating the proxy2
- * @param invoker the invoker
- * @param proxyClasses the interfaces that the proxy2 should implement
+ *
+ * @param classLoader
+ * the class loader to use when generating the proxy2
+ * @param invoker
+ * the invoker
+ * @param proxyClasses
+ * the interfaces that the proxy2 should implement
* @return a proxy2 which uses the provided {@link Invoker} to handle all method invocations
*/
@SuppressWarnings("unchecked")
- public <T> T createInvokerProxy( ClassLoader classLoader, Invoker invoker,
- Class<?>... proxyClasses )
+ public <T> T createInvokerProxy(ClassLoader classLoader, Invoker invoker, Class<?>... proxyClasses)
{
return (T) Proxy.newProxyInstance(classLoader, proxyClasses, new InvokerInvocationHandler(invoker));
}
-//**********************************************************************************************************************
-// Inner Classes
-//**********************************************************************************************************************
+ //******************************************************************************************************************
+ // Inner Classes
+ //******************************************************************************************************************
private abstract static class AbstractInvocationHandler implements InvocationHandler, Serializable
{
/** Serialization version */
private static final long serialVersionUID = 1L;
- public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
- if( ProxyUtils.isHashCode(method) )
+ if (ProxyUtils.isHashCode(method))
{
return System.identityHashCode(proxy);
}
- else if( ProxyUtils.isEqualsMethod(method) )
+ else if (ProxyUtils.isEqualsMethod(method))
{
return proxy == args[0];
}
@@ -110,7 +124,7 @@
}
}
- protected abstract Object invokeImpl( Object proxy, Method method, Object[] args ) throws Throwable;
+ protected abstract Object invokeImpl(Object proxy, Method method, Object[] args) throws Throwable;
}
private static class DelegatorInvocationHandler extends AbstractInvocationHandler
@@ -120,18 +134,18 @@
private final ObjectProvider<?> delegateProvider;
- protected DelegatorInvocationHandler( ObjectProvider<?> delegateProvider )
+ protected DelegatorInvocationHandler(ObjectProvider<?> delegateProvider)
{
this.delegateProvider = delegateProvider;
}
- public Object invokeImpl( Object proxy, Method method, Object[] args ) throws Throwable
+ public Object invokeImpl(Object proxy, Method method, Object[] args) throws Throwable
{
try
{
return method.invoke(delegateProvider.getObject(), args);
}
- catch( InvocationTargetException e )
+ catch (InvocationTargetException e)
{
throw e.getTargetException();
}
@@ -146,13 +160,13 @@
private final Object target;
private final Interceptor methodInterceptor;
- public InterceptorInvocationHandler( Object target, Interceptor methodInterceptor )
+ public InterceptorInvocationHandler(Object target, Interceptor methodInterceptor)
{
this.target = target;
this.methodInterceptor = methodInterceptor;
}
- public Object invokeImpl( Object proxy, Method method, Object[] args ) throws Throwable
+ public Object invokeImpl(Object proxy, Method method, Object[] args) throws Throwable
{
final ReflectionInvocation invocation = new ReflectionInvocation(proxy, target, method, args);
return methodInterceptor.intercept(invocation);
@@ -166,33 +180,30 @@
private final Invoker invoker;
- public InvokerInvocationHandler( Invoker invoker )
+ public InvokerInvocationHandler(Invoker invoker)
{
this.invoker = invoker;
}
- public Object invokeImpl( Object proxy, Method method, Object[] args ) throws Throwable
+ public Object invokeImpl(Object proxy, Method method, Object[] args) throws Throwable
{
return invoker.invoke(proxy, method, args);
}
}
- private static class ReflectionInvocation implements Invocation, Serializable
+ private static class ReflectionInvocation implements Invocation
{
- /** Serialization version */
- private static final long serialVersionUID = 1L;
-
private final Object proxy;
private final Object target;
private final Method method;
private final Object[] arguments;
- public ReflectionInvocation( Object proxy, Object target, Method method, Object[] arguments )
+ public ReflectionInvocation(Object proxy, Object target, Method method, Object[] arguments)
{
this.proxy = proxy;
this.target = target;
this.method = method;
- this.arguments = ( arguments == null ? ProxyUtils.EMPTY_ARGUMENTS : arguments );
+ this.arguments = ObjectUtils.defaultIfNull(ArrayUtils.clone(arguments), ProxyUtils.EMPTY_ARGUMENTS);
}
public Object[] getArguments()
@@ -216,7 +227,7 @@
{
return method.invoke(target, arguments);
}
- catch( InvocationTargetException e )
+ catch (InvocationTargetException e)
{
throw e.getTargetException();
}
diff --git a/pom.xml b/pom.xml
index ee86228..4e73e98 100644
--- a/pom.xml
+++ b/pom.xml
@@ -249,7 +249,7 @@
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
- <version>3.18.1.GA</version>
+ <version>3.18.1-GA</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
@@ -281,6 +281,11 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle.version}</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
@@ -418,7 +423,7 @@
</dependencies>
<configuration>
<configLocation>org/apache/commons/proxy2/checkstyle.xml</configLocation>
- <headerLocation>org/apache/commons/proxy2/license-header.txt</headerLocation>
+ <includes>**/*.java</includes>
</configuration>
</plugin>
<!-- Unfortunately the much simpler
@@ -493,7 +498,7 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>commons-weaver-build-tools</artifactId>
+ <artifactId>commons-proxy2-build-tools</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
@@ -592,12 +597,12 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>commons-weaver-build-tools</artifactId>
+ <artifactId>commons-proxy2-build-tools</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<configuration>
- <!--excludeFilterFile>/org/apache/commons/proxy2/findbugs-exclude-filter.xml</excludeFilterFile-->
+ <excludeFilterFile>/org/apache/commons/proxy2/findbugs-exclude-filter.xml</excludeFilterFile>
</configuration>
</plugin>
</plugins>
@@ -607,14 +612,6 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <configuration>
- <configLocation>org/apache/commons/proxy2/checkstyle.xml</configLocation>
- <headerLocation>org/apache/commons/proxy2/license-header.txt</headerLocation>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
diff --git a/src/site/site.xml b/src/site/site.xml
index f732b03..bbca988 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -21,7 +21,7 @@
<bannerRight>
<name>Commons Proxy</name>
<src>images/logo.png</src>
- <href>http://commons.apache.org/proxy/</href>
+ <href>/index.html</href>
</bannerRight>
<body>
<menu name="Commons Proxy">
diff --git a/test/pom.xml b/test/pom.xml
index d0fa3c3..9d30bfb 100644
--- a/test/pom.xml
+++ b/test/pom.xml
@@ -92,4 +92,17 @@
</plugin>
</plugins>
</build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle.version}</version>
+ <configuration>
+ <configLocation>org/apache/commons/proxy2/checkstyle.xml</configLocation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
</project>
diff --git a/test/src/test/java/org/apache/commons/proxy2/DefaultProxyFactoryTest.java b/test/src/test/java/org/apache/commons/proxy2/DefaultProxyFactoryTest.java
index a5657e0..ef8dfbb 100644
--- a/test/src/test/java/org/apache/commons/proxy2/DefaultProxyFactoryTest.java
+++ b/test/src/test/java/org/apache/commons/proxy2/DefaultProxyFactoryTest.java
@@ -17,52 +17,56 @@
package org.apache.commons.proxy2;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Proxy;
+
import org.apache.commons.proxy2.invoker.NullInvoker;
import org.junit.Before;
import org.junit.Test;
-import java.lang.reflect.Proxy;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
/**
* Test the default ProxyFactory provided by {@link ProxyUtils}.
*/
-public class DefaultProxyFactoryTest {
+public class DefaultProxyFactoryTest
+{
private ProxyFactory proxyFactory;
@Before
- public void setUp() {
+ public void setUp()
+ {
proxyFactory = ProxyUtils.proxyFactory();
}
@Test
- public void testBasic() {
- Foo foo = proxyFactory.createInvokerProxy(NullInvoker.INSTANCE,
- Foo.class);
+ public void testBasic()
+ {
+ Foo foo = proxyFactory.createInvokerProxy(NullInvoker.INSTANCE, Foo.class);
assertNotNull(foo);
assertTrue(foo instanceof Proxy);
}
@Test
- public void testSubclassing() {
- Bar bar = proxyFactory.createInvokerProxy(NullInvoker.INSTANCE,
- Bar.class);
+ public void testSubclassing()
+ {
+ Bar bar = proxyFactory.createInvokerProxy(NullInvoker.INSTANCE, Bar.class);
assertNotNull(bar);
}
@Test
- public void testCombined() {
- Bar bar = proxyFactory.createInvokerProxy(NullInvoker.INSTANCE,
- Bar.class, Foo.class);
+ public void testCombined()
+ {
+ Bar bar = proxyFactory.createInvokerProxy(NullInvoker.INSTANCE, Bar.class, Foo.class);
assertNotNull(bar);
assertTrue(bar instanceof Foo);
}
- public interface Foo {
+ public interface Foo
+ {
}
- public static class Bar {
+ public static class Bar
+ {
}
}
diff --git a/test/src/test/java/org/apache/commons/proxy2/serialization/SerializationProxyTest.java b/test/src/test/java/org/apache/commons/proxy2/serialization/SerializationProxyTest.java
index 1956e7c..b6481c0 100755
--- a/test/src/test/java/org/apache/commons/proxy2/serialization/SerializationProxyTest.java
+++ b/test/src/test/java/org/apache/commons/proxy2/serialization/SerializationProxyTest.java
@@ -16,7 +16,8 @@
*/
package org.apache.commons.proxy2.serialization;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.Serializable;
@@ -58,24 +59,24 @@
private static SwitchInterceptor implementProvider(String value)
{
return new SwitchInterceptor().when(new DeclaredByMatcher(Provider.class)).then(
- InterceptorUtils.constant(new NonSerializableStringWrapper(value)));
+ InterceptorUtils.constant(new NonSerializableStringWrapper(value)));
}
private static Provider serializableProvider(final String value)
{
return PROXY_FACTORY.get().createInterceptorProxy(
- null,
- implementProvider(value).when(new DeclaredByMatcher(WriteReplace.class)).then(
- InterceptorUtils.constant(new ReadResolve()
- {
- private static final long serialVersionUID = 1L;
+ null,
+ implementProvider(value).when(new DeclaredByMatcher(WriteReplace.class)).then(
+ InterceptorUtils.constant(new ReadResolve()
+ {
+ private static final long serialVersionUID = 1L;
- @Override
- public Object readResolve()
- {
- return serializableProvider(value);
- }
- })), Provider.class, WriteReplace.class);
+ @Override
+ public Object readResolve()
+ {
+ return serializableProvider(value);
+ }
+ })), Provider.class, WriteReplace.class);
}
@Before
@@ -93,15 +94,16 @@
@Test(expected = SerializationException.class)
public void testNaive()
{
- final Provider proxy =
- proxyFactory.createInterceptorProxy(null, implementProvider("foo"), Provider.class, Serializable.class);
+ final Provider proxy = proxyFactory.createInterceptorProxy(null, implementProvider("foo"), Provider.class,
+ Serializable.class);
assertEquals("foo", proxy.getObject().getValue());
assertTrue(Serializable.class.isInstance(proxy));
SerializationUtils.roundtrip((Serializable) proxy);
}
@Test
- public void testSerializationProxy() {
+ public void testSerializationProxy()
+ {
final Provider proxy = serializableProvider("foo");
assertEquals("foo", proxy.getObject().getValue());
assertTrue(Serializable.class.isInstance(proxy));
diff --git a/test/src/test/java/org/apache/commons/proxy2/stub/AbstractProxyFactoryAgnosticTest.java b/test/src/test/java/org/apache/commons/proxy2/stub/AbstractProxyFactoryAgnosticTest.java
index b34e9ba..713a835 100755
--- a/test/src/test/java/org/apache/commons/proxy2/stub/AbstractProxyFactoryAgnosticTest.java
+++ b/test/src/test/java/org/apache/commons/proxy2/stub/AbstractProxyFactoryAgnosticTest.java
@@ -33,10 +33,12 @@
* Conveniently defines the setup for a unit test class that runs with all known {@link ProxyFactory} implementations.
*/
@RunWith(Parameterized.class)
-public abstract class AbstractProxyFactoryAgnosticTest {
+public abstract class AbstractProxyFactoryAgnosticTest
+{
@Parameters(name = "{0}")
- public static List<Object[]> createParameters() {
+ public static List<Object[]> createParameters()
+ {
final List<Object[]> result = new ArrayList<Object[]>();
result.add(new Object[] { new JdkProxyFactory() });
result.add(new Object[] { new CglibProxyFactory() });
diff --git a/test/src/test/java/org/apache/commons/proxy2/stub/AbstractStubTestCase.java b/test/src/test/java/org/apache/commons/proxy2/stub/AbstractStubTestCase.java
index 85bf1e4..e8187a8 100644
--- a/test/src/test/java/org/apache/commons/proxy2/stub/AbstractStubTestCase.java
+++ b/test/src/test/java/org/apache/commons/proxy2/stub/AbstractStubTestCase.java
@@ -125,8 +125,7 @@
{
when(trainee.one("Whatever")).thenReturn("One");
}
- })
- .build();
+ }).build();
}
});
diff --git a/test/src/test/java/org/apache/commons/proxy2/stub/RetentionWrapper.java b/test/src/test/java/org/apache/commons/proxy2/stub/RetentionWrapper.java
index 2976eba..6301cdc 100644
--- a/test/src/test/java/org/apache/commons/proxy2/stub/RetentionWrapper.java
+++ b/test/src/test/java/org/apache/commons/proxy2/stub/RetentionWrapper.java
@@ -26,9 +26,9 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface RetentionWrapper
{
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Other Methods
+ //----------------------------------------------------------------------------------------------------------------------
Retention value();
}
diff --git a/test/src/test/java/org/apache/commons/proxy2/stub/StubBuilderTest.java b/test/src/test/java/org/apache/commons/proxy2/stub/StubBuilderTest.java
index d81ec2d..bb64de6 100644
--- a/test/src/test/java/org/apache/commons/proxy2/stub/StubBuilderTest.java
+++ b/test/src/test/java/org/apache/commons/proxy2/stub/StubBuilderTest.java
@@ -33,10 +33,9 @@
public class StubBuilderTest extends AbstractStubTestCase
{
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
-
+ //----------------------------------------------------------------------------------------------------------------------
+ // Other Methods
+ //----------------------------------------------------------------------------------------------------------------------
@Override
protected StubInterface createProxy(Trainer<StubInterface> trainer)
@@ -47,7 +46,8 @@
@Test
public void testWithConcreteTarget()
{
- StubBuilder<StubInterface> builder = new StubBuilder<StubInterface>(proxyFactory, StubInterface.class, new SimpleStub());
+ StubBuilder<StubInterface> builder = new StubBuilder<StubInterface>(proxyFactory, StubInterface.class,
+ new SimpleStub());
builder.train(new Trainer<StubInterface>()
{
@Override
@@ -87,7 +87,8 @@
@Test
public void testWithObjectProviderTarget()
{
- StubBuilder<StubInterface> builder = new StubBuilder<StubInterface>(proxyFactory, StubInterface.class, new BeanProvider<StubInterface>(SimpleStub.class));
+ StubBuilder<StubInterface> builder = new StubBuilder<StubInterface>(proxyFactory, StubInterface.class,
+ new BeanProvider<StubInterface>(SimpleStub.class));
builder.train(new Trainer<StubInterface>()
{
@Override
@@ -101,7 +102,8 @@
}
@Test
- public void testAdditionalInterfaces() {
+ public void testAdditionalInterfaces()
+ {
StubBuilder<StubInterface> builder = new StubBuilder<StubInterface>(proxyFactory, StubInterface.class,
ObjectProviderUtils.constant(new SimpleStub()));
builder.train(new Trainer<Iterable<String>>()
@@ -127,9 +129,9 @@
assertTrue(stub instanceof Marker);
}
-//----------------------------------------------------------------------------------------------------------------------
-// Inner Classes
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Inner Classes
+ //----------------------------------------------------------------------------------------------------------------------
private static class SimpleStub implements StubInterface
{
@@ -154,55 +156,55 @@
@Override
public byte[] byteArray()
{
- return new byte[]{1, 2, 3};
+ return new byte[] { 1, 2, 3 };
}
@Override
public char[] charArray()
{
- return new char[]{'1', '2', '3'};
+ return new char[] { '1', '2', '3' };
}
@Override
public short[] shortArray()
{
- return new short[]{1, 2, 3};
+ return new short[] { 1, 2, 3 };
}
@Override
public int[] intArray()
{
- return new int[]{1, 2, 3};
+ return new int[] { 1, 2, 3 };
}
@Override
public long[] longArray()
{
- return new long[]{1, 2, 3};
+ return new long[] { 1, 2, 3 };
}
@Override
public float[] floatArray()
{
- return new float[]{1.0f, 2.0f, 3.0f};
+ return new float[] { 1.0f, 2.0f, 3.0f };
}
@Override
public double[] doubleArray()
{
- return new double[]{1.0, 2.0, 3.0};
+ return new double[] { 1.0, 2.0, 3.0 };
}
@Override
public boolean[] booleanArray()
{
- return new boolean[]{true, false, true};
+ return new boolean[] { true, false, true };
}
@Override
public String[] stringArray()
{
- return new String[]{"One", "Two", "Three"};
+ return new String[] { "One", "Two", "Three" };
}
@Override
diff --git a/test/src/test/java/org/apache/commons/proxy2/stub/StubInterceptorBuilderTest.java b/test/src/test/java/org/apache/commons/proxy2/stub/StubInterceptorBuilderTest.java
index 401fa32..72cba7c 100644
--- a/test/src/test/java/org/apache/commons/proxy2/stub/StubInterceptorBuilderTest.java
+++ b/test/src/test/java/org/apache/commons/proxy2/stub/StubInterceptorBuilderTest.java
@@ -30,15 +30,15 @@
public class StubInterceptorBuilderTest extends AbstractStubTestCase
{
-//----------------------------------------------------------------------------------------------------------------------
-// Fields
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Fields
+ //----------------------------------------------------------------------------------------------------------------------
private StubInterceptorBuilder builder;
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Other Methods
+ //----------------------------------------------------------------------------------------------------------------------
@Before
public void initialize()
@@ -51,8 +51,7 @@
{
Interceptor interceptor = builder.train(trainer).build();
return proxyFactory.createInterceptorProxy(
- proxyFactory.createInvokerProxy(NullInvoker.INSTANCE, StubInterface.class),
- interceptor,
+ proxyFactory.createInvokerProxy(NullInvoker.INSTANCE, StubInterface.class), interceptor,
StubInterface.class);
}
@@ -75,7 +74,8 @@
});
}
}).build();
- RetentionWrapper wrapper = proxyFactory.createInterceptorProxy(proxyFactory.createInvokerProxy(NullInvoker.INSTANCE), interceptor, RetentionWrapper.class);
+ RetentionWrapper wrapper = proxyFactory.createInterceptorProxy(
+ proxyFactory.createInvokerProxy(NullInvoker.INSTANCE), interceptor, RetentionWrapper.class);
assertNotNull(wrapper.value());
assertEquals(RetentionPolicy.RUNTIME, wrapper.value().value());
}
@@ -91,7 +91,8 @@
when(trainee.value()).thenReturn(RetentionPolicy.RUNTIME);
}
}).build();
- Retention wrapper = proxyFactory.createInterceptorProxy(proxyFactory.createInvokerProxy(NullInvoker.INSTANCE), interceptor, Retention.class);
+ Retention wrapper = proxyFactory.createInterceptorProxy(proxyFactory.createInvokerProxy(NullInvoker.INSTANCE),
+ interceptor, Retention.class);
assertEquals(RetentionPolicy.RUNTIME, wrapper.value());
}
diff --git a/test/src/test/java/org/apache/commons/proxy2/stub/StubInterface.java b/test/src/test/java/org/apache/commons/proxy2/stub/StubInterface.java
index 1812f6b..094d477 100644
--- a/test/src/test/java/org/apache/commons/proxy2/stub/StubInterface.java
+++ b/test/src/test/java/org/apache/commons/proxy2/stub/StubInterface.java
@@ -19,22 +19,32 @@
public interface StubInterface
{
-//----------------------------------------------------------------------------------------------------------------------
-// Other Methods
-//----------------------------------------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------------------------------------
+ // Other Methods
+ //----------------------------------------------------------------------------------------------------------------------
String one(String value);
+
String three(String arg1, String arg2);
+
String two(String value);
byte[] byteArray();
+
char[] charArray();
+
short[] shortArray();
+
int[] intArray();
+
long[] longArray();
+
float[] floatArray();
+
double[] doubleArray();
+
boolean[] booleanArray();
+
String[] stringArray();
String arrayParameter(String... strings);
@@ -42,5 +52,6 @@
void voidMethod(String arg);
StubInterface stub();
+
StubInterface[] stubs();
}