public abstract class DualWrapper<R,M> extends BaseWrapper<R> implements Externalizable
It is essential to note that the wrapper always maintains this
invariant: the raw and marshalled forms represent the same object
at all times. A consequence of this invariant is that the wrapper
should not be considered an alternate storage container for objects
server-side: if an object cannot be converted to its marshalled
form (e.g. Java serialization fails for SerWrapper), then
the wrapper will refuse to store that object and will set both the
raw and marshalled forms to null. The wrapper will still get
created and remote these null values to the client, but, on the
server-side, the wrapper will not have retained the raw form.
The M type parameter should implement Serializable, and subclasses of this class need to have a public
empty constructor if this wrapper (or its subclasses) is to be used
for Java Serialization. The former constraint is not enforced by
the class because, if this wrapper is only used for JAXB
marshalling, M need not implement Serializable
(and the empty constructor's visibility can be more limited).
| Modifier | Constructor and Description |
|---|---|
protected |
DualWrapper()
Creates a new wrapper.
|
|
DualWrapper(R raw)
Creates a new wrapper with the given value, in its raw form.
|
| Modifier and Type | Method and Description |
|---|---|
M |
getMarshalled()
Returns the receiver's data, in its marshalled form.
|
R |
getRaw()
Returns the receiver's data, in its raw form.
|
void |
readExternal(ObjectInput in) |
void |
setMarshalled(M marshalled)
Sets the receiver's data to the given value, in its marshalled
form.
|
protected void |
setMarshalledOnly(M marshalled)
Sets the receiver's data to the given value, in its marshalled
form.
|
void |
setRaw(R raw)
Sets the receiver's data to the given value, in its raw
form.
|
protected void |
setRawOnly(R raw)
Sets the receiver's data to the given value, in its raw
form.
|
protected abstract void |
toMarshalled()
Sets the marshalled form of the receiver's value so that it
corresponds to its raw form.
|
protected abstract void |
toRaw()
Sets the raw form of the receiver's value so that it
corresponds to its marshalled form.
|
void |
writeExternal(ObjectOutput out) |
public DualWrapper(R raw)
raw - The value in raw form, which may be null.protected DualWrapper()
public void writeExternal(ObjectOutput out) throws IOException
writeExternal in interface ExternalizableIOExceptionpublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal in interface ExternalizableIOExceptionClassNotFoundExceptionprotected void setRawOnly(R raw)
raw - The value in raw form, which may be null.public void setRaw(R raw)
raw - The value in raw form, which may be null. If the
given value is invalid, it will be replaced by null.public R getRaw()
protected void setMarshalledOnly(M marshalled)
marshalled - The value in marshalled form, which may be
null.public void setMarshalled(M marshalled)
marshalled - The value in marshalled form, which may be
null. If the given value is invalid, it will be replaced by
null.public M getMarshalled()
protected abstract void toRaw()
setRawOnly(Object) and
setMarshalledOnly(Object) should be used in
setting either form, to prevent infinite recursion. The raw
form is null if and only if the marshalled one is null; the
caller of this method will enforce this invariant, so the
subclass implementation can set just the raw form to null.protected abstract void toMarshalled()
setRawOnly(Object) and
setMarshalledOnly(Object) should be used in setting
either form, to prevent infinite recursion. The raw form is
null if and only if the marshalled one is null; the caller of
this method will enforce this invariant, so the subclass
implementation can set just the marshalled form to null.Copyright © 2015. All Rights Reserved.