Class DualWrapper<R,M>
- java.lang.Object
-
- org.marketcetera.util.ws.wrappers.BaseWrapper<R>
-
- org.marketcetera.util.ws.wrappers.DualWrapper<R,M>
-
- All Implemented Interfaces:
Externalizable,Serializable
- Direct Known Subclasses:
DateWrapper,LocaleWrapper,SerWrapper
public abstract class DualWrapper<R,M> extends BaseWrapper<R> implements Externalizable
A dual-form wrapper for marshalling a data value via JAXB or regular Java serialization. One of the two forms is a raw one, namely the standard class used to represent that value in Java; the other is a type that can be marshalled via JAXB or Java serialization. The raw form is null if and only if the marshalled one is null.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
Mtype parameter should implementSerializable, 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,Mneed not implementSerializable(and the empty constructor's visibility can be more limited).- Since:
- 1.0.0
- Version:
- $Id: DualWrapper.java 16154 2012-07-14 16:34:05Z colin $
- Author:
- tlerios@marketcetera.com
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private MmMarshalledprivate static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description protectedDualWrapper()Creates a new wrapper.DualWrapper(R raw)Creates a new wrapper with the given value, in its raw form.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description MgetMarshalled()Returns the receiver's data, in its marshalled form.RgetRaw()Returns the receiver's data, in its raw form.voidreadExternal(ObjectInput in)voidsetMarshalled(M marshalled)Sets the receiver's data to the given value, in its marshalled form.protected voidsetMarshalledOnly(M marshalled)Sets the receiver's data to the given value, in its marshalled form.voidsetRaw(R raw)Sets the receiver's data to the given value, in its raw form.protected voidsetRawOnly(R raw)Sets the receiver's data to the given value, in its raw form.protected abstract voidtoMarshalled()Sets the marshalled form of the receiver's value so that it corresponds to its raw form.protected abstract voidtoRaw()Sets the raw form of the receiver's value so that it corresponds to its marshalled form.voidwriteExternal(ObjectOutput out)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
mMarshalled
private M mMarshalled
-
-
Constructor Detail
-
DualWrapper
public DualWrapper(R raw)
Creates a new wrapper with the given value, in its raw form. It also sets the internal marshalled form to match.- Parameters:
raw- The value in raw form, which may be null.
-
DualWrapper
protected DualWrapper()
Creates a new wrapper. This empty constructor is intended for use by JAXB and Java serialization.
-
-
Method Detail
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
setRawOnly
protected void setRawOnly(R raw)
Sets the receiver's data to the given value, in its raw form. It does not set the internal marshalled form to match.- Parameters:
raw- The value in raw form, which may be null.
-
setRaw
public void setRaw(R raw)
Sets the receiver's data to the given value, in its raw form. It also sets the internal marshalled form to match.- Parameters:
raw- The value in raw form, which may be null. If the given value is invalid, it will be replaced by null.
-
getRaw
public R getRaw()
Returns the receiver's data, in its raw form.- Returns:
- The data, which may be null.
-
setMarshalledOnly
protected void setMarshalledOnly(M marshalled)
Sets the receiver's data to the given value, in its marshalled form. It does not set the internal raw form to match.- Parameters:
marshalled- The value in marshalled form, which may be null.
-
setMarshalled
public void setMarshalled(M marshalled)
Sets the receiver's data to the given value, in its marshalled form. It also sets the internal raw form to match.- Parameters:
marshalled- The value in marshalled form, which may be null. If the given value is invalid, it will be replaced by null.
-
getMarshalled
public M getMarshalled()
Returns the receiver's data, in its marshalled form.- Returns:
- The data, which may be null.
-
toRaw
protected abstract void toRaw()
Sets the raw form of the receiver's value so that it corresponds to its marshalled form. The subclass implementation can assume that the latter form is non-null. The subclass may modify both the former and latter forms (for example, if the latter form is invalid). OnlysetRawOnly(Object)andsetMarshalledOnly(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.
-
toMarshalled
protected abstract void toMarshalled()
Sets the marshalled form of the receiver's value so that it corresponds to its raw form. The subclass implementation can assume that the latter form is non-null. The subclass may modify both the former and latter forms (for example, if the latter form is invalid). OnlysetRawOnly(Object)andsetMarshalledOnly(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.
-
-