|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.tangosol.util.Base
com.tangosol.util.BitHelper
com.tangosol.util.ExternalizableHelper
com.tangosol.run.xml.XmlBean
public abstract class XmlBean
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.SortedMapEach 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":
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) {...}
}
The Person XML bean example above would have an XML declaration file that
resembles the following:
<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>
Consider the following code:
System.out.println(new Person(15, "John Smith").toString());
The output would be:
<person>
<person-id>15</person-id>
<full-name>John Smith</full-name>
</person>
To specify namespace information for an XML bean, add an "xmlns" element to
the bean's descriptor:
<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>
Nested Class Summary | |
---|---|
static class |
XmlBean.BeanInfo
A BeanInfo contains information about the XML bean and its properties. |
Constructor Summary | |
---|---|
protected |
XmlBean()
Construct a value object. |
Method Summary | |
---|---|
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 |
adopt(Object[] ao)
Helper to adopt a collection of XmlBean objects. |
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 |
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.BitHelper |
---|
countBits, countBits, countBits, indexOfLSB, indexOfLSB, indexOfLSB, indexOfMSB, indexOfMSB, indexOfMSB, toBitString, toBitString, toBitString |
Constructor Detail |
---|
protected XmlBean()
Method Detail |
---|
public XmlBean getParentXmlBean()
protected void setParentXmlBean(XmlBean parent)
parent
- the XmlBean that contains this XmlBeanprotected void adopt(Map map)
map
- a Map that may contain keys and/or values that are XmlBeansprotected void adopt(Collection coll)
coll
- a Collection that may contain XmlBeansprotected void adopt(Iterator iter)
iter
- an Iterator that may contain XmlBeansprotected void adopt(Object[] ao)
ao
- an array that may contain XmlBeansprotected void adopt(XmlBean child)
child
- the XmlBean that is being contained within this XmlBeanpublic boolean isMutable()
protected void setMutable(boolean fMutable)
fMutable
- true to allow this value to be modified, otherwise false
to indicate that this value is read-onlypublic XmlBean ensureMutable()
public void ensureReadOnly()
protected void checkMutable()
protected int getHashCode()
protected void setHashCode(int nHash)
nHash
- the hash codepublic XmlBean.BeanInfo getBeanInfo()
public PropertyAdapter[] getAdapters()
public boolean equals(Object o)
o
- the other value object to compare to
public int hashCode()
public String toString()
public Object clone()
public XmlElement toXml()
toXml
in interface XmlSerializable
public void fromXml(XmlElement xml)
fromXml
in interface XmlSerializable
xml
- an XmlElement that contains the serialized form of the
object
UnsupportedOperationException
IllegalStateException
IllegalArgumentException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
in
- the stream to read data from in order to restore the object
IOException
- if I/O errors occur
ClassNotFoundException
- if the class for an object being
restored cannot be found.public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
out
- the stream to write the object to
IOException
- includes any I/O exceptions that may occurpublic void readExternal(DataInput in) throws IOException
readExternal
in interface ExternalizableLite
in
- the DataInput stream to read data from in order to restore
the state of this object
IOException
- if an I/O exception occurs
NotActiveException
- if the object is not in its initial
state, and therefore cannot be deserialized intopublic void writeExternal(DataOutput out) throws IOException
writeExternal
in interface ExternalizableLite
out
- the DataOutput stream to write the state of this object to
IOException
- if an I/O exception occursprotected static void init(Class clz, String sName, String[] asProp)
clz
- the class to initializesName
- the name of the value objectasProp
- the property names that make up the value objectprotected XmlBean.BeanInfo initBeanInfo()
|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |