org.omnaest.utils.proxy
Class MethodInvocationForwardingCapturer

java.lang.Object
  extended by org.omnaest.utils.proxy.MethodInvocationForwardingCapturer

public class MethodInvocationForwardingCapturer
extends Object

The MethodInvocationForwardingCapturer allows to create proxies which are put on top of existing object instances. The created proxy will then capture all method invocations and write them as xml format to a given OutputStream. The method invocation will also be forwared to the original object method.

To capture

Author:
Omnaest
See Also:
newProxyInstanceCapturing(Object, OutputStream)

Nested Class Summary
protected static class MethodInvocationForwardingCapturer.ForwardingMethodInvocationHandler
           
protected static class MethodInvocationForwardingCapturer.MethodAndArguments
          Wrapper for Method and arguments which implements MethodInvocationForwardingCapturer.MethodAndArguments.hashCode() and MethodInvocationForwardingCapturer.MethodAndArguments.equals(Object)
static class MethodInvocationForwardingCapturer.MethodInvocationAndResult
           
protected static interface MethodInvocationForwardingCapturer.MethodInvocationComparison
           
protected static class MethodInvocationForwardingCapturer.MethodOnly
           
protected static class MethodInvocationForwardingCapturer.ReplayingMethodInvocationHandler
           
 
Method Summary
static void closeCapturingOutputStream(OutputStream outputStream)
          Closes a given OutputStream which is used by a created proxy.
static ElementStream<MethodInvocationForwardingCapturer.MethodInvocationAndResult> newMethodInvocationAndResultElementStream(InputStream inputStream)
          Creates an ElementStream of MethodInvocationForwardingCapturer.MethodInvocationAndResult instances from a given InputStream which was produced by the newProxyInstanceCapturing(Object, OutputStream) before.
static Iterable<MethodInvocationForwardingCapturer.MethodInvocationAndResult> newMethodInvocationAndResultIterable(InputStream inputStream)
           
static Iterable<MethodInvocationForwardingCapturer.MethodInvocationAndResult> newMethodInvocationAndResultIterable(InputStream inputStream, Range range)
          Returns only the MethodInvocationForwardingCapturer.MethodInvocationAndResult instances within the given Range of the index positions of the order of invocation.
protected static Iterator<MethodInvocationForwardingCapturer.MethodInvocationAndResult> newMethodInvocationAndResultIterator(InputStream inputStream)
           
static
<T> T
newProxyInstanceCapturing(T object, OutputStream outputStream)
          Returns a new proxy instance which will forward all method invocations to the given object but also captures the invocations to put them into the OutputStream as xml.
static
<T> T
newProxyInstanceReplaying(Class<T> type, InputStream inputStream, boolean ignoreArgumentValues)
          Returns a new proxy instance which replays a previously recorded behavior when a method of it is invoked.
static
<T> T
newProxyInstanceReplaying(Class<T> type, InputStream inputStream, boolean ignoreArgumentValues, Range range)
          Returns a new proxy instance which replays a previously recorded behavior when a method of it is invoked.
protected static com.thoughtworks.xstream.XStream newXStream()
           
static void replayOn(InputStream inputStream, Object object, Range... ranges)
          Replays previously recorded method invocations on a real Object with the same type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newProxyInstanceCapturing

public static <T> T newProxyInstanceCapturing(T object,
                                              OutputStream outputStream)
Returns a new proxy instance which will forward all method invocations to the given object but also captures the invocations to put them into the OutputStream as xml.

Parameters:
object -
outputStream -
Returns:

closeCapturingOutputStream

public static void closeCapturingOutputStream(OutputStream outputStream)
Closes a given OutputStream which is used by a created proxy.

Parameters:
outputStream -

newProxyInstanceReplaying

public static <T> T newProxyInstanceReplaying(Class<T> type,
                                              InputStream inputStream,
                                              boolean ignoreArgumentValues)
Returns a new proxy instance which replays a previously recorded behavior when a method of it is invoked.

If argument values are ignored a recored method behavior is triggered even if the invoked method is invoked with different argument values as before. Otherwise the method replay will only occur for the same argument values given during invocation.

To record a behavior see the sibling proxy factory method newProxyInstanceCapturing(Object, OutputStream)

Parameters:
type -
inputStream -
ignoreArgumentValues -

newProxyInstanceReplaying

public static <T> T newProxyInstanceReplaying(Class<T> type,
                                              InputStream inputStream,
                                              boolean ignoreArgumentValues,
                                              Range range)
Returns a new proxy instance which replays a previously recorded behavior when a method of it is invoked.

If argument values are ignored a recored method behavior is triggered even if the invoked method is invoked with different argument values as before. Otherwise the method replay will only occur for the same argument values given during invocation.

To record a behavior see the sibling proxy factory method newProxyInstanceCapturing(Object, OutputStream)

Parameters:
type -
inputStream -
ignoreArgumentValues -
range -

replayOn

public static void replayOn(InputStream inputStream,
                            Object object,
                            Range... ranges)
Replays previously recorded method invocations on a real Object with the same type.

Optional it is possible to declare Ranges which will result in only these method invocations being repeated, where the index position is within at least one given Range.
If no Range parameters are given all method invocations are applied to the given object.

Parameters:
inputStream -
object -
ranges -

newXStream

protected static com.thoughtworks.xstream.XStream newXStream()

newMethodInvocationAndResultElementStream

public static ElementStream<MethodInvocationForwardingCapturer.MethodInvocationAndResult> newMethodInvocationAndResultElementStream(InputStream inputStream)
Creates an ElementStream of MethodInvocationForwardingCapturer.MethodInvocationAndResult instances from a given InputStream which was produced by the newProxyInstanceCapturing(Object, OutputStream) before.

Parameters:
inputStream -
Returns:

newMethodInvocationAndResultIterator

protected static Iterator<MethodInvocationForwardingCapturer.MethodInvocationAndResult> newMethodInvocationAndResultIterator(InputStream inputStream)
Parameters:
inputStream -
Returns:
See Also:
Iterator, newMethodInvocationAndResultElementStream(InputStream)

newMethodInvocationAndResultIterable

public static Iterable<MethodInvocationForwardingCapturer.MethodInvocationAndResult> newMethodInvocationAndResultIterable(InputStream inputStream)
Parameters:
inputStream -
Returns:
See Also:
newMethodInvocationAndResultElementStream(InputStream), Iterable

newMethodInvocationAndResultIterable

public static Iterable<MethodInvocationForwardingCapturer.MethodInvocationAndResult> newMethodInvocationAndResultIterable(InputStream inputStream,
                                                                                                                          Range range)
Returns only the MethodInvocationForwardingCapturer.MethodInvocationAndResult instances within the given Range of the index positions of the order of invocation.

If null is given as Range the original Iterable is returned.

Parameters:
inputStream -
range -
Returns:
See Also:
newMethodInvocationAndResultElementStream(InputStream), Range, Iterable


Copyright © 2013. All Rights Reserved.