|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectes.uc3m.it.xbe32.XBE32Printer
This auxiliary XBE32ParseListerner class prints the XBE32 Elements being
parsed as XML tags.
The Elements are printed in the specified PrintStream
(or in System.out
by default).
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 print the following XML fragment if processed by a XBE32Printer
:
<service> <type> printer </type> <addr> 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 allows a second XBE32ParseListener
to be registered. Thus it
is able to process the XBE32 parsing events once the XBE32 Elements are
printed into the specified output stream.
This class may be extended, for example to print opaque values with a better representation than its plain hexadecimal value.
XBE32Parser.setListener()
,
XBE32Element
Constructor Summary | |
XBE32Printer()
Creates a new XBE32Printer to print XBE32 parse events as XML tags |
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. |
protected String |
getCloseTag(String name,
boolean attr)
Returns the XML close tag for the specified XBE32 Element |
protected String |
getIndent()
Returns the leading whitespace characters according to the current indent level. |
XBE32ParseListener |
getListener()
Returns the registered XBE32ParseListener, if any |
String |
getOpenTag(boolean ext,
int id,
String name,
boolean c,
boolean e,
int type)
Returns the XML open tag for the specified XBE32 Element. |
PrintStream |
getPrintStream()
Returns the PrintStream where XBE32 Elements are printed at as XML tags |
static void |
main(String[] args)
XBE32Printer can be executed as an standalone command-line application. |
void |
printElement(XBE32Element elem)
Prints the specified XBE32 Element with XML tags. |
void |
setListener(XBE32ParseListener lis)
Sets the XBE32ParseListener that receives XBE32 parsing events |
void |
setPrintStream(PrintStream out)
Sets the PrintStream to write XBE32 Elementss at as XML tags |
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 |
public XBE32Printer()
Method Detail |
public PrintStream getPrintStream()
public void setPrintStream(PrintStream out) throws IllegalArgumentException
out
- the PrintStream to use
IllegalArgumentException
- if out is null
public XBE32ParseListener getListener()
public void setListener(XBE32ParseListener lis)
lis
- the XBE32ParseListener to registerpublic void printElement(XBE32Element elem)
elem
- the XBE32 Element to be printed.public void startParsing()
XBE32ParseListener
XBE32Parser.parse()
method is
called, thus the parsing process starts.
startParsing
in interface XBE32ParseListener
XBE32Parser.parse()
public void complexElementStart(boolean ext, int id, String name, boolean c, boolean e) throws XBE32ParseException
XBE32ParseListener
XBE32Parser
.
complexElementStart
in interface XBE32ParseListener
ext
- whether the Complex Element that to be parsed is an Extensible
or a Compact oneid
- the identifier of the Complex Element to be parsedname
- the name of the Complex Element to be parsedc
- the Continue flag of the Complex Element to be parsede
- the Notify Error flag of the Complex Element to be parsed
XBE32ParseException
- the listener may throw this exception if any
syntax error occurs while processing this eventXBE32Parser.parse()
,
XBE32Parser.parseElement()
public void complexElementEnd(boolean ext, int id, String name, boolean c, boolean e) throws XBE32ParseException
XBE32ParseListener
XBE32Parser
.
complexElementEnd
in interface XBE32ParseListener
ext
- whether the Complex Element that has been parsed is an extensible
or a compact oneid
- the identifier of the Complex Element that has been parsedname
- the name of the Complex Element that has been parsedc
- the Continue flag of the Complex Element that has been parsede
- the Notify Error flag of the Complex Element that has beee
parsed
XBE32ParseException
- the listener may throw this exception if any
syntax error occurs while processing this eventXBE32Parser.parse()
,
XBE32Parser.parseElement()
public void attributeElement(boolean ext, int id, String name, boolean c, boolean e, int type, Object val) throws XBE32ParseException
XBE32ParseListener
XBE32Parser
.
attributeElement
in interface XBE32ParseListener
ext
- whether the Attrbiute Element being parsed is an Extensible or
a Compact oneid
- the identifier of the Attribute Element being parsedname
- the name of the Attribute Element being parsedc
- the Continue flag of the Attribute Element being parsede
- the Notify Error flag of the Attribute Element being parsedtype
- the Type of the Attribute's Value being parsedval
- the Values field of the Attribute Element being parsed
XBE32ParseException
- the listener may throw this exception if any
syntax error occurs while processing this eventXBE32Element.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()
public void endParsing(int length)
XBE32ParseListener
XBE32Parser
successfully ends
parsing the full XBE32-encoded stream.
endParsing
in interface XBE32ParseListener
XBE32Parser.parse()
protected String getIndent()
public String getOpenTag(boolean ext, int id, String name, boolean c, boolean e, int type)
ext
- whether the Element is an Extensible or a Compact oneid
- the identifier of the Elementname
- the name of the Elementc
- the Continue flag of the Elemente
- the Notify Error flag of the Elementtype
- the Type of the Element
protected String getCloseTag(String name, boolean attr)
name
- the Element nameattr
- whether the specified Element is an Attribute or a Complex
one
public static void main(String[] args)
Usage: XBE32Printer <xbe32> [<dict>] <xbe32> : XBE32 encoded file to be XMLized (Use '-' to read from stdin). <dict> : Properties file with all the 'name=id' mappings.
args
- Command line parameters
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |