T
- type of the object being wrappedU
- type of the resulting wrapper (must be extending T
)public class MutableWrapper<T,U extends T> extends Object
For a given object (normally a POJO) this utility generates a wrapper (via Java Dynamic Proxies or CGLIB) which initially has the state identical to the one of the source due to the default method call delegation. However, the wrapper can be deliberately modified without a fear of affecting the source object thanks to the wrappers internal state which automatically absorbs all the changes coming through setter calls or some such.
Besides merely acting as a wrapper, the proxy object is also supplied with an implementation of the MutableWrapper.Mutable
interface, which simplifies
dynamic mutator implementations.
Mutator
Modifier and Type | Class and Description |
---|---|
static class |
MutableWrapper.BeanPropertyMethodInvoker
Deprecated.
since 6.1. Use
ByteBuddyMutableWrapperHelper instead. |
static interface |
MutableWrapper.Mutable<T>
Generic interface which allows to set the arbitrary object properties via
MutableWrapper.Mutable.setProperty(String, Object) . |
static interface |
MutableWrapper.ProxyWithBeanPropertyMethodInvoker
Deprecated.
since 6.1. Use
ByteBuddyMutableWrapperHelper instead. |
Modifier and Type | Field and Description |
---|---|
protected static Method |
getInvoker |
protected static Method |
getObject |
protected static Method |
setProperty |
Modifier and Type | Method and Description |
---|---|
static <U> MutableWrapper.Mutable<U> |
asMutable(U instance)
Merely attempts to cast an instance to
MutableWrapper.Mutable . |
static <U> U |
wrap(U source)
Does the same as
wrapAs(Object, Class) but uses a provided instance's type
as a default target type. |
static <T,U extends T> |
wrapAs(T source,
Class<U> type)
Takes an arbitrary source object
T and produces a proxied wrapper of type U which may extend T . |
protected static Method setProperty
protected static Method getObject
protected static Method getInvoker
public static <T,U extends T> U wrapAs(T source, Class<U> type)
T
and produces a proxied wrapper of type U
which may extend T
.
Once the source object is wrapped via this API - all the sub-objects retrieved via getters will get automatically (and recursively) wrapped as well.
Returned instance's state can be modified without a risk of affecting the source
instance's state.
Modification can be done via setters (should T
have any) or via MutableWrapper.Mutable
interface which
the returned wrapper implements.
public static <U> U wrap(U source)
wrapAs(Object, Class)
but uses a provided instance's type
as a default target type.public static <U> MutableWrapper.Mutable<U> asMutable(U instance)
MutableWrapper.Mutable
.IllegalArgumentException
- if instance
does not implement MutableWrapper.Mutable
(i.e. if instance has not been wrapped with MutableWrapper
previously).Copyright © 2003–2019 Magnolia International Ltd.. All rights reserved.