es.uc3m.it.xbe32
Class XBE32ElementParser

java.lang.Object
  extended byes.uc3m.it.xbe32.XBE32ElementParser
All Implemented Interfaces:
XBE32ParseListener

public class XBE32ElementParser
extends Object
implements XBE32ParseListener

This XBE32ParseListener is able to process a XBE32-encoded stream and return all its XBE32 Elements as a tree.

Once the full stream is parsed the rootElements() method will return the list of the upper XBE32 Elements, that could contain themselves other XBE32 Elements, both Attrbiutes or Complex ones. If just a single XBE32 Element is parsed, use the getFirstElement() method to obtain it.

For example, 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);
 

It would create a root XBE32 Element with the same result as the following code:

   XBE32Element root, elem;
   XBE32Element attr;

   root = new XBE32Element(false, 0x0001, "service", false, false);
   listener.rootElements().add(elem);
   attr = new XBE32Element(false, 0x2102, "type", false, false, 
                           XBE32Element.STRING_VALUE_TYPE, "printer");
   root.subelements.add(attr);
   attr = new XBE32Element(false, 0x2C03, "addr", false, false, 
                           XBE32Element.OPAQUE4_VALUES_TYPE, new byte[][] {{ 0xA9, 0xFE, 0x55, 0x8B }});
   root.subelements.add(attr);
   attr = new XBE32Element(false, 0x2904, "ports", false, false, 
                           XBE32Element.INT16_VALUES_TYPE, new short[] { 515, 631 });
   root.subelements.add(attr);
   elem = new XBE32Element(false, 0x0003, "options", true, true);
   root.subelements.add(elem);
   attr = new XBE32Element(true, 0x000006, "color", false, true, 
                           XBE32Element.BOOLEAN_VALUES_TYPE, new boolean[] { false });
   elem.subelements.add(attr);
   attr = new XBE32Element(true, 0, "ppm", true, false, 
                           XBE32Element.FLOAT32_VALUES_TYPE, new float[] { 20.5 });
   elem.subelements.add(attr);
 

See Also:
XBE32Element, XBE32Parser.setListener(), XBE32Reader.setListener()

Constructor Summary
XBE32ElementParser()
          Creates a new XBE32ElementParser listener.
 
Method Summary
 void attributeElement(boolean ext, int id, String name, boolean c, boolean e, int type, Object val)
          This method is called when an Attribute Element is processed by the XBE32Parser.
 void complexElementEnd(boolean ext, int id, String name, boolean c, boolean e)
          This method is called when a Complex Element has been just processed by the XBE32Parser.
 void complexElementStart(boolean ext, int id, String name, boolean c, boolean e)
          This method is called when a Complex Element is found by the XBE32Parser.
 void endParsing(int length)
          This method is called when the XBE32Parser successfully ends parsing the full XBE32-encoded stream.
 XBE32Element getFirstElement()
          Returns the first root XBE32 Element that has been parsed.
 Vector rootElements()
          Returns the list of XBE32 Elements located at the upper-level of the XBE32-encoded stream.
 void startParsing()
          This method is called when the XBE32Parser.parse() method is called, thus the parsing process starts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XBE32ElementParser

public XBE32ElementParser()
Creates a new XBE32ElementParser listener.

Method Detail

rootElements

public Vector rootElements()
Returns the list of XBE32 Elements located at the upper-level of the XBE32-encoded stream.

Returns:
the list of upper-level XBE32 Elements. It can be empty if no XBE32 Element has been processed.
See Also:
XBE32Parser.parse()

getFirstElement

public XBE32Element getFirstElement()
Returns the first root XBE32 Element that has been parsed.

Returns:
the first root XBE32 Element that has been parsed
See Also:
XBE32Parser.parseElement()

startParsing

public void startParsing()
Description copied from interface: XBE32ParseListener
This method is called when the XBE32Parser.parse() method is called, thus the parsing process starts.

Specified by:
startParsing in interface XBE32ParseListener
See Also:
XBE32Parser.parse()

complexElementStart

public void complexElementStart(boolean ext,
                                int id,
                                String name,
                                boolean c,
                                boolean e)
                         throws XBE32ParseException
Description copied from interface: XBE32ParseListener
This method is called when a Complex Element is found by the XBE32Parser.

Specified by:
complexElementStart in interface XBE32ParseListener
Parameters:
ext - whether the Complex Element that to be parsed is an Extensible or a Compact one
id - the identifier of the Complex Element to be parsed
name - the name of the Complex Element to be parsed
c - the Continue flag of the Complex Element to be parsed
e - the Notify Error flag of the Complex Element to be parsed
Throws:
XBE32ParseException - the listener may throw this exception if any syntax error occurs while processing this event
See Also:
XBE32Parser.parse(), XBE32Parser.parseElement()

complexElementEnd

public void complexElementEnd(boolean ext,
                              int id,
                              String name,
                              boolean c,
                              boolean e)
                       throws XBE32ParseException
Description copied from interface: XBE32ParseListener
This method is called when a Complex Element has been just processed by the XBE32Parser.

Specified by:
complexElementEnd in interface XBE32ParseListener
Parameters:
ext - whether the Complex Element that has been parsed is an extensible or a compact one
id - the identifier of the Complex Element that has been parsed
name - the name of the Complex Element that has been parsed
c - the Continue flag of the Complex Element that has been parsed
e - the Notify Error flag of the Complex Element that has beee parsed
Throws:
XBE32ParseException - the listener may throw this exception if any syntax error occurs while processing this event
See Also:
XBE32Parser.parse(), XBE32Parser.parseElement()

attributeElement

public void attributeElement(boolean ext,
                             int id,
                             String name,
                             boolean c,
                             boolean e,
                             int type,
                             Object val)
                      throws XBE32ParseException
Description copied from interface: XBE32ParseListener
This method is called when an Attribute Element is processed by the XBE32Parser.

Specified by:
attributeElement in interface XBE32ParseListener
Parameters:
ext - whether the Attrbiute Element being parsed is an Extensible or a Compact one
id - the identifier of the Attribute Element being parsed
name - the name of the Attribute Element being parsed
c - the Continue flag of the Attribute Element being parsed
e - the Notify Error flag of the Attribute Element being parsed
type - the Type of the Attribute's Value being parsed
val - the Values field of the Attribute Element being parsed
Throws:
XBE32ParseException - the listener may throw this exception if any syntax error occurs while processing this event
See Also:
XBE32Element.OPAQUE_VALUE_TYPE, XBE32Element.STRING_VALUE_TYPE, XBE32Element.OPAQUE1_VALUES_TYPE, XBE32Element.INT8_VALUES_TYPE, XBE32Element.BOOLEAN_VALUES_TYPE, XBE32Element.OPAQUE2_VALUES_TYPE, XBE32Element.INT16_VALUES_TYPE, XBE32Element.OPAQUE4_VALUES_TYPE, XBE32Element.INT32_VALUES_TYPE, XBE32Element.FLOAT32_VALUES_TYPE, XBE32Element.OPAQUE8_VALUES_TYPE, XBE32Element.INT64_VALUES_TYPE, XBE32Element.FLOAT64_VALUES_TYPE, XBE32Element.OPAQUE12_VALUES_TYPE, XBE32Element.OPAQUE16_VALUES_TYPE, XBE32Parser.parse(), XBE32Parser.parseElement()

endParsing

public void endParsing(int length)
Description copied from interface: XBE32ParseListener
This method is called when the XBE32Parser successfully ends parsing the full XBE32-encoded stream.

Specified by:
endParsing in interface XBE32ParseListener
See Also:
XBE32Parser.parse()