as well as an attribute value String encoding, i.e just the "..." part
from the complete encoding.
This implies that the XML encoding cannot recursively contain other XML tags,
which limits basic values to simple values like ints, longs, floats, doubles,
Strings, tuples of fixed length etc.
XMLBasicValue is a "base" class for implementing such classes.
It suffices to (re)implement the following methods:
public StringBufer appendAttributeString(StringBuilder buf) and
public void decodeAttribute(String attrName, String valCode).
The appendAttributeString method must append a string to buf, and return the latter;
The appended string must have the form: attr1="value1" attr2="value2" ....
The decodeAttribute method is called while the XMLStructure is being reconstructed
from XML code. A call of the form decodeAttribute(attr-i, value-i) will be made,
for each attribute found in the XML encoding. The implementation of decodeAttribute
should be able to reconstruct the XMLStructure object from these calls.
- Author:
- Job Zwiers
|
Method Summary |
StringBuilder |
appendAttribute(StringBuilder buf,
String attrName,
Object attrValue)
|
StringBuilder |
appendAttribute(StringBuilder buf,
String attrName,
String attrValue)
|
StringBuilder |
appendAttributeString(StringBuilder buf)
Appends a String to buf that encodes the attributes for the XML encoding. |
protected void |
appendSpace(int nsp)
|
StringBuilder |
appendXML(StringBuilder buf)
appends the value of this XMLBasicValue to buf. |
StringBuilder |
appendXML(StringBuilder buf,
int tab)
appends the value of this XMLBasicValue to buf. |
StringBuilder |
appendXML(StringBuilder buf,
XMLFormatting fmt)
appends the value of this XMLBasicValue to buf. |
private void |
clearBuffer(int len)
|
private void |
decode()
|
void |
decodeAttribute(String attrName,
String attrValue)
|
void |
decodeAttribute(String attrName,
String attrValue,
XMLTokenizer tokenizer)
decodes the value from an attribute value String
MUST BE OVERWRITTEN BY IMPLEMENTATIONS. |
protected String |
getAttributeName()
parse attribute name part, consisting of a chracter sequence. |
protected String |
getAttributeValue()
parse attribute value part of form: = "value" or: = 'value'
and returns the value as a String. |
String |
getXMLTag()
Returns the XML tag that is used to encode this XMLBasicValue
The default returns null |
private boolean |
isNameChar()
|
private int |
nextChar()
|
XMLStructure |
readXML(Reader in)
reconstructs this XMLBasicValue object by reading and parsing XML encoded data
Data is read until a '<' character is read or until end-of-data is reached. |
XMLStructure |
readXML(String s)
reconstructs this XMLBasicValue object by parsing an XML encoded String s
This method can throw an (unchecked) RuntimeException in case of incorrectly
formatted XML. |
XMLStructure |
readXML(XMLTokenizer tokenizer)
reconstructs this XMLBasicValue using a XMLTokenizer. |
private void |
skipSpaceChars()
|
String |
toAttributeString()
returns a String that encodes the attributes for the XML encoding. |
String |
toXMLString()
yields an XML encoded String of this XMLIzable object. |
String |
toXMLString(int tab)
yields an XML encoded String of this XMLIzable object. |
String |
toXMLString(XMLFormatting fmt)
yields an XML encoded String of this XMLIzable object. |
T |
unwrap()
The default implementation of unwrap simply return this. |
void |
writeXML(PrintWriter out)
writes the value of this XMLBasicValue to out,
with no indentation. |
void |
writeXML(PrintWriter out,
int tab)
writes the value of this XMLBasicValue to out,
using "tab" as a hint for indentation. |
void |
writeXML(PrintWriter out,
XMLFormatting fmt)
writes the value of this XMLBasicValue to out,
using "tab" as a hint for indentation. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
encoding
private String encoding
buffer
private StringBuilder buffer
ciPos
private int ciPos
ci
private int ci
bufLen
private int bufLen
curtab
private int curtab
BUFFERSIZE
public static final int BUFFERSIZE
- See Also:
- Constant Field Values
EOS
private static final int EOS
- See Also:
- Constant Field Values
XMLBasicValue
public XMLBasicValue()
getXMLTag
public String getXMLTag()
- Returns the XML tag that is used to encode this XMLBasicValue
The default returns null
- Specified by:
getXMLTag in interface XMLStructure
unwrap
public T unwrap()
- The default implementation of unwrap simply return this.
(Should be overwritten by XMLBasicValues that are "wrappers"
for non-XMLStructure Java Objects)
- Specified by:
unwrap in interface XMLWrapper<T>
clearBuffer
private void clearBuffer(int len)
appendSpace
protected void appendSpace(int nsp)
decode
private void decode()
readXML
public XMLStructure readXML(Reader in)
throws IOException
- reconstructs this XMLBasicValue object by reading and parsing XML encoded data
Data is read until a '<' character is read or until end-of-data is reached.
This method can throw IOExceptions.
- Specified by:
readXML in interface XMLStructure
- Throws:
IOException
readXML
public XMLStructure readXML(String s)
- reconstructs this XMLBasicValue object by parsing an XML encoded String s
This method can throw an (unchecked) RuntimeException in case of incorrectly
formatted XML.
- Specified by:
readXML in interface XMLStructure
readXML
public XMLStructure readXML(XMLTokenizer tokenizer)
- reconstructs this XMLBasicValue using a XMLTokenizer.
This method can throw an (unchecked) RuntimeException in case of incorrectly
formatted XML.
- Specified by:
readXML in interface XMLStructure
writeXML
public void writeXML(PrintWriter out)
- writes the value of this XMLBasicValue to out,
with no indentation.
relies on the String as delivered by toXMLString()
- Specified by:
writeXML in interface XMLStructure
writeXML
public void writeXML(PrintWriter out,
int tab)
- writes the value of this XMLBasicValue to out,
using "tab" as a hint for indentation.
relies on the String as delivered by toXMLString(tab)
- Specified by:
writeXML in interface XMLStructure
writeXML
public void writeXML(PrintWriter out,
XMLFormatting fmt)
- writes the value of this XMLBasicValue to out,
using "tab" as a hint for indentation.
relies on the String as delivered by toXMLString(tab)
- Specified by:
writeXML in interface XMLStructure
appendXML
public StringBuilder appendXML(StringBuilder buf)
- appends the value of this XMLBasicValue to buf.
relies on the String as delivered by toXMLString(0)
- Specified by:
appendXML in interface XMLStructure
appendXML
public StringBuilder appendXML(StringBuilder buf,
int tab)
- appends the value of this XMLBasicValue to buf.
relies on the String as delivered by toXMLString(tab)
- Specified by:
appendXML in interface XMLStructure
appendXML
public StringBuilder appendXML(StringBuilder buf,
XMLFormatting fmt)
- appends the value of this XMLBasicValue to buf.
relies on the String as delivered by toXMLString(tab)
- Specified by:
appendXML in interface XMLStructure
toXMLString
public String toXMLString()
- yields an XML encoded String of this XMLIzable object.
The readXML() methods are able to reconstruct this object from
the String delivered by toXMLString().
- Specified by:
toXMLString in interface XMLStructure
toXMLString
public String toXMLString(int tab)
- yields an XML encoded String of this XMLIzable object.
The readXML() methods are able to reconstruct this object from
the String delivered by toXMLString().
- Specified by:
toXMLString in interface XMLStructure
toXMLString
public String toXMLString(XMLFormatting fmt)
- yields an XML encoded String of this XMLIzable object.
The readXML() methods are able to reconstruct this object from
the String delivered by toXMLString().
- Specified by:
toXMLString in interface XMLStructure
toAttributeString
public String toAttributeString()
- returns a String that encodes the attributes for the XML encoding.
Relies on String appended by appendAttributeString()
appendAttributeString
public StringBuilder appendAttributeString(StringBuilder buf)
- Appends a String to buf that encodes the attributes for the XML encoding.
and that encodes this basic value.
MUST BE OVERWRITTEN BY IMPLEMENTATIONS. (The default implementation appends nothing).
appendAttribute
public StringBuilder appendAttribute(StringBuilder buf,
String attrName,
String attrValue)
appendAttribute
public StringBuilder appendAttribute(StringBuilder buf,
String attrName,
Object attrValue)
decodeAttribute
public void decodeAttribute(String attrName,
String attrValue,
XMLTokenizer tokenizer)
- decodes the value from an attribute value String
MUST BE OVERWRITTEN BY IMPLEMENTATIONS.
decodeAttribute
public void decodeAttribute(String attrName,
String attrValue)
getAttributeValue
protected final String getAttributeValue()
- parse attribute value part of form: = "value" or: = 'value'
and returns the value as a String.
The value string is not "parsed" in the sense of XML parsed character data,
i.e. XML entities like < or ' are not expanded.
If necessary, this should be done at a later stage, while decoding the attribute value.
getAttributeName
protected final String getAttributeName()
- parse attribute name part, consisting of a chracter sequence.
and returns the value as a String.
skipSpaceChars
private void skipSpaceChars()
isNameChar
private boolean isNameChar()
nextChar
private int nextChar()