|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectes.uc3m.it.xbe32.XBE32Reader
This auxiliary class is able to parse a XML file as it was a XBE32 stream.
Therefore, XBE32 Elements parsed from the XML file can be processed by a
XBE32ParseListener
.
XML Elements containig only non-empty text will be parsed as XBE32 Attributes, whereas XML Elements containing themselves other XML Elements will be parsed as XBE32 Complex Elements.
The XML tag itself is firstly considered as the XBE32 Element name, thus it is
looked at the dictionary in order to find its XBE32 numeric Id. However, the
XBE32 Id/Name could be also directly specified by means of a XML
id
attribute, overriding the tag name.
XML Elements containing a ext="true"
attribute will be parsed
as XBE32 Extensible Elements, and its Value Type, Continue and Error flags
should be specified by means of the type
, c
and
e
attributes respectively. Otherwise XML Elements will be
encoded as XBE32 Compact Elements and the Value Type, Continue and Error
flags will be obtained from their numeric XBE32 id/type.
The following sample XML DTD defines all the attributes processed by this class:
<!ELEMENT xbe32elem (xbe32elem|xbe32attr)*> <!ATTLIST xbe32elem id CDATA #REQUIRED ext (true | false) false c (true | false) false e (true | false) false type (complex) complex > <!ELEMENT xbe32attr (#PCDATA)> <!ATTLIST xbe32attr id CDATA #REQUIRED ext (true | false) false c (true | false) false e (true | false) false type (string | opaque1 | int8 | boolean | opaque2 | int16 | opaque4 | int32 | float32 | opaque8 | int64 | float64 | opaque12 | opaque16 ) #IMPLIED >
XML Attribute Elements MUST include only some non-empty text carrying their
value or values separated by commas (','
). Text values are
parsed depending on the specified/derived Value Type: Boolean values must be
true
or false. Opaque values must be encoded with
hexadecimal (0x) notation. Numeric and float values could be specified using
decimal notation. It is also possible to specify values with alternative
representations for opaque values, followed by its XBE32 primitive
hexadecimal value between brackets (e.g. <addr> 169.254.85.139
(0xA9FE558B) </addr>
).
For example, processing the following XML document (with an appropiate XBE32Dictionary
):
<service> <type> printer </type> <addr> 169.254.85.139 (0xA9FE558B) </addr> <ports> 515, 631 </ports> <options c="true" e="true"> <color ext="true" e="true" type="boolean"> false </color> <ppm ext="true" c="true" type="float32"> 20.5 </ppm> </options> </service>
It would generate the following sequence of XBE32ParseListener
events:
listener.startParsing(); listener.complexElementStart(false, 0x0001, "service", false, false); listener.attributeElement(false, 0x2102, "type", false, false, XBE32Element.STRING_VALUE_TYPE, "printer"); listener.attributeElement(false, 0x2C03, "addr", false, false, XBE32Element.OPAQUE4_VALUES_TYPE, new byte[][] {{ 0xA9, 0xFE, 0x55, 0x8B }}); listener.attributeElement(false, 0x2904, "ports", false, false, XBE32Element.INT16_VALUES_TYPE, new short[] { 515, 631 }); listener.complexElementStart(false, 0x0003, "options", true, true); listener.attributeElement(true, 0x000006, "color", false, true, XBE32Element.BOOLEAN_VALUES_TYPE, new boolean[] { false }); listener.attributeElement(true, 0, "ppm", true, false, XBE32Element.FLOAT32_VALUES_TYPE, new float[] { 20.5 }); listener.complexElementEnd(false, 0x0003, "options", true, true); listener.complexElementEnd(false, 0x0001, "service", false, false); listener.endParsing(76);
Constructor Summary | |
XBE32Reader()
Creates a new XBE32Reader to parse a XML document as a XBE32 stream. |
Method Summary | |
XBE32Dictionary |
getDictionary()
Returns the dictionary employed to translate XML Tags into XBE32 Ids |
XBE32ParseListener |
getListener()
Returns the XBE32 listener that is processing the XML parsing events. |
static void |
main(String[] args)
XBE32Reader can be executed as an standalone command-line application. |
void |
parseXMLDocument(Document doc)
Parses the specified XML Document as a XBE32 stream. |
void |
parseXMLElement(Element elem)
Parses the specified XML Element as a XBE32 stream. |
void |
setDictionary(XBE32Dictionary dict)
Sets the dictionary to be employed to translate XML Tags into XBE32 Ids |
void |
setListener(XBE32ParseListener lis)
Sets the XBE32 listener that would process XML parsing events. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public XBE32Reader()
Method Detail |
public XBE32ParseListener getListener()
public void setListener(XBE32ParseListener lis)
lis
- the new parser listenerpublic XBE32Dictionary getDictionary()
public void setDictionary(XBE32Dictionary dict)
dict
- the new dictionarypublic void parseXMLDocument(Document doc) throws SAXException
doc
- the XML DOM document to be XBE32-parsed
SAXException
public void parseXMLElement(Element elem) throws SAXException
elem
- the XML element to be XBE32-encoded
SAXException
public static void main(String[] args)
Usage: XBE32Reader <xml> <dict> [<xbe32>] <xml> : Input XML file to be XBE32lized (Use '-' to read from stdin). <dict> : Properties file with all the 'name=id' mappings. <xbe32>: Output XBE32 file
args
- Command line parameters
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |