Package com.tangosol.run.xml
Class XmlBean
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.tangosol.util.BitHelper
-
- com.tangosol.util.ExternalizableHelper
-
- com.tangosol.run.xml.XmlBean
-
- All Implemented Interfaces:
ExternalizableLite
,XmlSerializable
,Externalizable
,Serializable
,Cloneable
public abstract class XmlBean extends ExternalizableHelper implements Cloneable, Externalizable, ExternalizableLite, XmlSerializable
This is a base class for building XmlSerializable value objects.The following property types are supported using standard property adapters:
1) XmlValue types: TYPE_BOOLEAN - boolean, java.lang.Boolean TYPE_INT - byte, char, short, int, java.lang.Byte, java.lang.Character, java.lang.Short, java.lang.Integer TYPE_LONG - long, java.lang.Long TYPE_DOUBLE - float, double, java.lang.Float, java.lang.Double TYPE_DECIMAL - java.math.BigDecimal, java.math.BigInteger TYPE_STRING - java.lang.String TYPE_BINARY - com.tangosol.util.Binary, byte[] TYPE_DATE - java.sql.Date TYPE_TIME - java.sql.Time TYPE_DATETIME - java.sql.Timestamp, java.util.Date 2) Objects implementing XmlSerializable (including XmlBean subclasses) 3) Objects implementing Serializable 4) Collections of any of the above: Java arrays java.util.Collection java.util.Set java.util.List java.util.Map java.util.SortedSet java.util.SortedMap
Each XmlBean must have a corresponding XML declaration file that provides the necessary information to parse XML into the XML bean and to format the XML bean into XML. The declaration file should be located in the same package (directory) as the class itself.For example, here is an XmlBean subclass with an int property "Id" and a String property "Name":
The Person XML bean example above would have an XML declaration file that resembles the following:public class Person extends XmlBean { public Person(int nId, String sName) {...} public int getId() {...} public void setId(int nId) {...} public String getName() {...} public void setName(String sName) {...} }
Consider the following code:<xml-bean> <name>person</name> <property> <name>Id</name> <xml-name>person-id</xml-name> </property> <property> <name>Name</name> <xml-name>full-name</xml-name> </property> </xml-bean>
The output would be:System.out.println(new Person(15, "John Smith").toString());
To specify namespace information for an XML bean, add an "xmlns" element to the bean's descriptor:<person> <person-id>15</person-id> <full-name>John Smith</full-name> </person>
<xml-bean> <name>person</name> <xmlns> <uri>the-schema-URI-goes-here</uri> <prefix>the-default-namespace-prefix-goes-here</prefix> <xmlns> <property> ... </property> </xml-bean>
- Version:
- 1.2
- Author:
- cp 2000.11.10, gg 2002.05.17 anonymous element and XML Namespaces support, cp 2003.03.27 ExternalizableLite support
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XmlBean.BeanInfo
A BeanInfo contains information about the XML bean and its properties.-
Nested classes/interfaces inherited from class com.tangosol.util.ExternalizableHelper
ExternalizableHelper.DecoratedMultiBufferReadBuffer, ExternalizableHelper.DefaultObjectStreamFactory, ExternalizableHelper.FormatAwareCompressor, ExternalizableHelper.IntDecoratedObject, ExternalizableHelper.Shielded, ExternalizableHelper.ShieldedDataOutputStream, ExternalizableHelper.ShieldedInputStream, ExternalizableHelper.ShieldedObjectOutputStream, ExternalizableHelper.ShieldedOutputStream, ExternalizableHelper.SimpleXmlBeanClassCache, ExternalizableHelper.Stats, ExternalizableHelper.XmlBeanClassCache
-
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
-
Field Summary
-
Fields inherited from class com.tangosol.util.ExternalizableHelper
BINARY_SIZE, CHUNK_SIZE, CHUNK_THRESHOLD, CONVERTER_FROM_BINARY, CONVERTER_STRIP_INTDECO, CONVERTER_TO_BINARY, DECO_APP_1, DECO_APP_2, DECO_APP_3, DECO_BACKUP, DECO_CUSTOM, DECO_EXPIRY, DECO_ID_MAX, DECO_ID_MIN, DECO_JCACHE, DECO_JCACHE_SYNTHETIC, DECO_MEMCACHED, DECO_PUSHREP, DECO_QUEUE_METADATA, DECO_RSVD_1, DECO_STORE, DECO_TX, DECO_VALUE, DECO_WLS, EMPTY_BINARY_ARRAY, FMT_B_ARRAY, FMT_BIN_DECO, FMT_BIN_EXT_DECO, FMT_BINARY, FMT_BOOLEAN, FMT_BYTE, FMT_DECIMAL, FMT_DOUBLE, FMT_EXT, FMT_FLOAT, FMT_IDO, FMT_INT, FMT_INTEGER, FMT_LONG, FMT_NONE, FMT_NULL, FMT_OBJ_EXT, FMT_OBJ_SER, FMT_OPT, FMT_OPT_DOUBLE, FMT_OPT_INT, FMT_OPT_LONG, FMT_SHORT, FMT_STRING, FMT_UNKNOWN, FMT_XML_BEAN, FMT_XML_SER, FORCE_RESOLVING_STREAMS, LAMBDA_SERIALIZATION, MAX_DECO_HEADER_BYTES, PACKED_INT_SIZE, PACKED_LONG_SIZE, PROPERTY_CONFIG, s_streamfactory, TRINT_DOMAIN_SPAN, TRINT_MAX_VALUE, TRINT_MAX_VARIANCE, USE_POF_STREAMS, USE_XMLBEAN_CLASS_CACHE, XMLBEAN_CLASS_CACHE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
XmlBean()
Construct a value object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
adopt(XmlBean child)
When an XmlBean adds a contained XmlBean, it should invoke this method to relate the contained XmlBean with this XmlBean.protected void
adopt(Object[] ao)
Helper to adopt a collection of XmlBean objects.protected void
adopt(Collection coll)
Helper to adopt a Collection of XmlBean objects.protected void
adopt(Iterator iter)
Helper to adopt a collection of XmlBean objects.protected void
adopt(Map map)
Helper to adopt a Map of XmlBean objects.protected void
checkMutable()
Verify that this XmlBean is mutable.Object
clone()
Clone the value object.XmlBean
ensureMutable()
Make sure that this XML bean is mutable.void
ensureReadOnly()
Make sure that this value is read-only (immutable).boolean
equals(Object o)
Determine if this value object is equal to the passed value object.void
fromXml(XmlElement xml)
Deserialize the object from an XmlElement.PropertyAdapter[]
getAdapters()
Obtain the PropertyAdapter objects for this XmlBean.XmlBean.BeanInfo
getBeanInfo()
Obtain the BeanInfo for this XmlBean object, or create and configure a BeanInfo if one does not exist.protected int
getHashCode()
Get the cached hash code.XmlBean
getParentXmlBean()
Obtain the XmlBean that contains this XmlBean.int
hashCode()
Determine a hash code for this value object.protected static void
init(Class clz, String sName, String[] asProp)
For backwards compatibility only - loads reflection info.protected XmlBean.BeanInfo
initBeanInfo()
Initialize the Object, loading the XML Bean design information if necessary.boolean
isMutable()
Determine if this value can be modified.void
readExternal(DataInput in)
Restore the contents of this object by loading the object's state from the passed DataInput object.void
readExternal(ObjectInput in)
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.protected void
setHashCode(int nHash)
Set the cached hash code.protected void
setMutable(boolean fMutable)
Specify whether this value can be modified or not.protected void
setParentXmlBean(XmlBean parent)
Specify the XmlBean that contains this XmlBean.String
toString()
To assist in debugging, provide a clear indication of the key's state.XmlElement
toXml()
Serialize the object into an XmlElement.void
writeExternal(DataOutput out)
Save the contents of this object by storing the object's state into the passed DataOutput object.void
writeExternal(ObjectOutput out)
The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.-
Methods inherited from class com.tangosol.util.ExternalizableHelper
asBinary, calculatePackedLength, calculatePackedLength, checkObjectInputFilter, checkObjectInputFilter, checkObjectInputFilter, convertUTF, decodeExpiry, decorate, decorate, decorate, decorate, decorate, decorateBinary, encodeExpiry, ensureSerializer, extractIntDecoration, fromBinary, fromBinary, fromBinary, fromBinary, fromBinary, fromBinary, fromByteArray, fromByteArray, getClass, getConfigSerialFilter, getConfigSerialFilterFactory, getDecoration, getDecoration, getDecorations, getDeltaCompressor, getInputStream, getNewObjectInput, getObjectInput, getObjectInputFilter, getObjectOutput, getObjectStreamFactory, getOutputStream, getShieldedOutputStream, getStreamFormat, getUndecorated, getUndecorated, isDecorated, isDecorated, isIntDecorated, isIntDecorated, isPatchCompatible, isPatchCompatible, isResolving, isSerializable, isSerializerCompatible, isVersionCompatible, isVersionCompatible, isVersionCompatible, isVersionCompatible, isVersionCompatible, isVersionCompatible, loadClass, loadResource, main, makeTrint, readBigDecimal, readBigInteger, readBooleanArray, readBooleanArray, readByteArray, readCharArray, readCharArray, readCollection, readDate, readDoubleArray, readDoubleArray, readExternalizableLite, readExternalizableLite, readFloatArray, readFloatArray, readInt, readInt, readIntArray, readIntArray, readIntArray2d, readLargeBooleanArray, readLargeByteArray, readLargeCharArray, readLargeDoubleArray, readLargeFloatArray, readLargeIntArray, readLargeLongArray, readLargeObjectArray, readLargeStringArray, readLong, readLong, readLongArray, readLongArray, readMap, readMap, readObject, readObject, readObjectArray, readObjectArray, readSafeUTF, readSafeUTF, readSerializable, readSerializable, readStringArray, readStringArray, readTime, readTimestamp, readTrint, readUnsignedTrint, readUTF, readXmlBean, readXmlSerializable, readXmlSerializable, realize, removeIntDecoration, removeIntDecoration, replace, reportIncompatibleSerializers, setObjectStreamFactory, toBinary, toBinary, toBinary, toByteArray, toByteArray, toByteArray, toLiteBinary, toLong, undecorate, undecorate, validateBufferSize, validateLoadArray, validateLoadClass, writeBigDecimal, writeBigInteger, writeBooleanArray, writeByteArray, writeCollection, writeDate, writeDoubleArray, writeExternalizableLite, writeFloatArray, writeInt, writeInt, writeIntArray2d, writeLong, writeLong, writeMap, writeObject, writeSafeUTF, writeSafeUTF, writeSerializable, writeStringArray, writeTime, writeTimestamp, writeTrint, writeTrint, writeUTF, writeXmlBean, writeXmlSerializable
-
Methods inherited from class com.tangosol.util.BitHelper
countBits, countBits, countBits, indexOfLSB, indexOfLSB, indexOfLSB, indexOfMSB, indexOfMSB, indexOfMSB, rotateLeft, rotateLeft, rotateLeft, rotateRight, rotateRight, rotateRight, toBitString, toBitString, toBitString, toBytes, toBytes, toBytes, toBytes, toInt, toInt, toLong
-
Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
-
-
-
Method Detail
-
getParentXmlBean
public XmlBean getParentXmlBean()
Obtain the XmlBean that contains this XmlBean.- Returns:
- the containing XmlBean, or null if there is none
-
setParentXmlBean
protected void setParentXmlBean(XmlBean parent)
Specify the XmlBean that contains this XmlBean.- Parameters:
parent
- the XmlBean that contains this XmlBean
-
adopt
protected void adopt(Map map)
Helper to adopt a Map of XmlBean objects.- Parameters:
map
- a Map that may contain keys and/or values that are XmlBeans
-
adopt
protected void adopt(Collection coll)
Helper to adopt a Collection of XmlBean objects.- Parameters:
coll
- a Collection that may contain XmlBeans
-
adopt
protected void adopt(Iterator iter)
Helper to adopt a collection of XmlBean objects.- Parameters:
iter
- an Iterator that may contain XmlBeans
-
adopt
protected void adopt(Object[] ao)
Helper to adopt a collection of XmlBean objects.- Parameters:
ao
- an array that may contain XmlBeans
-
adopt
protected void adopt(XmlBean child)
When an XmlBean adds a contained XmlBean, it should invoke this method to relate the contained XmlBean with this XmlBean.- Parameters:
child
- the XmlBean that is being contained within this XmlBean
-
isMutable
public boolean isMutable()
Determine if this value can be modified. If the value can not be modified, all mutating methods are required to throw an UnsupportedOperationException.- Returns:
- true if this value can be modified, otherwise false to indicate that this value is read-only
-
setMutable
protected void setMutable(boolean fMutable)
Specify whether this value can be modified or not.- Parameters:
fMutable
- true to allow this value to be modified, otherwise false to indicate that this value is read-only
-
ensureMutable
public XmlBean ensureMutable()
Make sure that this XML bean is mutable.- Returns:
- this XmlBean if it is mutable, otherwise a mutable copy of this XmlBean
-
ensureReadOnly
public void ensureReadOnly()
Make sure that this value is read-only (immutable).
-
checkMutable
protected void checkMutable()
Verify that this XmlBean is mutable. This method is designed to be called by all mutator methods of an XmlBean to ensure that the bean fulfills the contract provided by the Mutable property.
-
getHashCode
protected int getHashCode()
Get the cached hash code. Value objects whose hash code is supposed to change must override the hashCode implementation.- Returns:
- the cached hash code
-
setHashCode
protected void setHashCode(int nHash)
Set the cached hash code. Value objects whose hash code is supposed to change must override the hashCode implementation.- Parameters:
nHash
- the hash code
-
getBeanInfo
public XmlBean.BeanInfo getBeanInfo()
Obtain the BeanInfo for this XmlBean object, or create and configure a BeanInfo if one does not exist.- Returns:
- the BeanInfo that describes this XmlBean
-
getAdapters
public PropertyAdapter[] getAdapters()
Obtain the PropertyAdapter objects for this XmlBean.- Returns:
- the PropertyAdapter objects that handle the properties of this XmlBean
-
equals
public boolean equals(Object o)
Determine if this value object is equal to the passed value object.
-
hashCode
public int hashCode()
Determine a hash code for this value object. For value objects with multiple properties, the hash code is calculated from the xor of the hash codes for each property.
-
toString
public String toString()
To assist in debugging, provide a clear indication of the key's state.
-
clone
public Object clone()
Clone the value object.
-
toXml
public XmlElement toXml()
Serialize the object into an XmlElement.- Specified by:
toXml
in interfaceXmlSerializable
- Returns:
- an XmlElement that contains the serialized form of the object
-
fromXml
public void fromXml(XmlElement xml)
Deserialize the object from an XmlElement. This method can throw one of several RuntimeExceptions.- Specified by:
fromXml
in interfaceXmlSerializable
- Parameters:
xml
- an XmlElement that contains the serialized form of the object- Throws:
UnsupportedOperationException
- if the operation is not supportedIllegalStateException
- if this is not an appropriate stateIllegalArgumentException
- if there is an illegal argument
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.- Specified by:
readExternal
in interfaceExternalizable
- Parameters:
in
- the stream to read data from in order to restore the object- Throws:
IOException
- if I/O errors occurClassNotFoundException
- if the class for an object being restored cannot be found.
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.- Specified by:
writeExternal
in interfaceExternalizable
- Parameters:
out
- the stream to write the object to- Throws:
IOException
- includes any I/O exceptions that may occur
-
readExternal
public void readExternal(DataInput in) throws IOException
Restore the contents of this object by loading the object's state from the passed DataInput object.- Specified by:
readExternal
in interfaceExternalizableLite
- Parameters:
in
- the DataInput stream to read data from in order to restore the state of this object- Throws:
IOException
- if an I/O exception occursNotActiveException
- if the object is not in its initial state, and therefore cannot be deserialized into
-
writeExternal
public void writeExternal(DataOutput out) throws IOException
Save the contents of this object by storing the object's state into the passed DataOutput object.- Specified by:
writeExternal
in interfaceExternalizableLite
- Parameters:
out
- the DataOutput stream to write the state of this object to- Throws:
IOException
- if an I/O exception occurs
-
init
protected static void init(Class clz, String sName, String[] asProp)
For backwards compatibility only - loads reflection info. This method is intended to be called by the static initializer of each concrete sub-class.- Parameters:
clz
- the class to initializesName
- the name of the value objectasProp
- the property names that make up the value object
-
initBeanInfo
protected XmlBean.BeanInfo initBeanInfo()
Initialize the Object, loading the XML Bean design information if necessary.- Returns:
- a BeanInfo object
-
-