es.uc3m.it.xbe32
Class XBE32Reader

java.lang.Object
  extended byes.uc3m.it.xbe32.XBE32Reader

public class XBE32Reader
extends Object

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

XBE32Reader

public XBE32Reader()
Creates a new XBE32Reader to parse a XML document as a XBE32 stream.

Method Detail

getListener

public XBE32ParseListener getListener()
Returns the XBE32 listener that is processing the XML parsing events.

Returns:
the current parser listener

setListener

public void setListener(XBE32ParseListener lis)
Sets the XBE32 listener that would process XML parsing events.

Parameters:
lis - the new parser listener

getDictionary

public XBE32Dictionary getDictionary()
Returns the dictionary employed to translate XML Tags into XBE32 Ids

Returns:
the current dictionary, if any

setDictionary

public void setDictionary(XBE32Dictionary dict)
Sets the dictionary to be employed to translate XML Tags into XBE32 Ids

Parameters:
dict - the new dictionary

parseXMLDocument

public void parseXMLDocument(Document doc)
                      throws SAXException
Parses the specified XML Document as a XBE32 stream.
All the document subelements will be procesed recursively.

Parameters:
doc - the XML DOM document to be XBE32-parsed
Throws:
SAXException

parseXMLElement

public void parseXMLElement(Element elem)
                     throws SAXException
Parses the specified XML Element as a XBE32 stream.
All the node subelements will be processed recursively.

Parameters:
elem - the XML element to be XBE32-encoded
Throws:
SAXException

main

public static void main(String[] args)
XBE32Reader can be executed as an standalone command-line application.
The specified XML file will be parsed to generate a XBE32-encoded stream or file.
   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
 

Parameters:
args - Command line parameters