|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--y.io.gml.ItemParser
This class can be used as a base class for parsers, that want to
parse items. It will intercept events which are delivered by the
GMLTOkenizer, store topscopelevel attributes in a Map. It can be provided
with child Itemparser instances, that will be automatically be invoked
for subsections. Implementers basically need to overwrite three
methods in order to get a working parser.
ItemParser.begin()
will be automatically called when the parsers
enters the scope level. Subclasses, that overwrite this method should
should make a super call, since the internal attribute map will be
cleared there.
ItemParser.childFinished(y.io.gml.ItemParser)
will be called as soon as the parser leaves
the scope of a child ItemParser, after the child's ItemParser.end()
method
has been called.
ItemParser.end()
will be called as soon as the current scope will be left.
Instances can than process the attributes and the results of the child
parsers to produce a suitable item.
Field Summary | |
protected Map |
attributes
the attribute map, used to store key value pairs which belong to the toplevel only |
protected Map |
childMap
the map of section names to child ItemParser instances |
protected ItemParser |
delegate
the currently active child |
protected int |
level
the relative scope depth of the parser, i.e. 0 if we are on the current toplevel, and positive if in a subsection |
Constructor Summary | |
ItemParser()
constructs a new ItemParser with no children. |
Method Summary | |
void |
addAttribute(String key,
Object value)
Puts the key value pair into the local attribute map |
void |
addChild(String scopeName,
ItemParser child)
add a child ItemParser, to which events will be delegated if the parser comes across a section with the specified scope name. |
void |
attribute(String key,
Number value)
Note: subclass implementers should make a super call, if they want to overwrite this method. |
void |
attribute(String key,
String value)
Note: subclass implementers should make a super call, if they want to overwrite this method. |
void |
begin()
this method will be called as soon as the parser enters the scope. |
void |
beginScope(String scopeName)
Note: subclass implementers should make a super call, if they want to overwrite this method. |
void |
childFinished(ItemParser p)
this method will be called, as soon as the a child ItemParser finished and returned from its end() method. |
void |
end()
this method will be called as soon as the parser leaves the scope. |
void |
endScope(String endScope)
Note: subclass implementers should make a super call, if they want to overwrite this method. |
Map |
getAttributes()
Getter for property attributes. |
boolean |
getBoolean(String key)
Convenience method, which returns true if and only if there is
an integer attribute valued >0 in the table for the key. |
double |
getDouble(String key)
Convenience method, which returns a double if there is an numeric attribute in the table for the key, or 0.0d |
double |
getDouble(String key,
double defaultValue)
Convenience method, which returns a double if there is an numeric attribute in the table for the key, or the default value |
int |
getInt(String key)
Convenience method, which returns a double if there is an numeric attribute in the table for the key, or 0 |
int |
getInt(String key,
int defaultValue)
Convenience method, which returns an int if there is an numeric attribute in the table for the key, or the default value |
Object |
getItem()
Returns the "product" of this scope. |
int |
getLevel()
Getter for property level. |
String |
getString(String key)
Returns a String representation of the value in the map for key. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int level
protected Map childMap
protected Map attributes
protected ItemParser delegate
Constructor Detail |
public ItemParser()
Method Detail |
public void addChild(String scopeName, ItemParser child)
scopeName
- the name of the sub sectionchild
- the responsibler ItemParserpublic void beginScope(String scopeName)
beginScope
in interface GMLTokenizer.Callback
scopeName
- the name of the scopepublic void endScope(String endScope)
endScope
in interface GMLTokenizer.Callback
endScope
- the name of the scope which was leftpublic void attribute(String key, String value)
attribute
in interface GMLTokenizer.Callback
key
- the key of the attribute value pairvalue
- the string valuepublic void attribute(String key, Number value)
attribute
in interface GMLTokenizer.Callback
key
- the key of the attribute value pairvalue
- the numeric valuepublic void addAttribute(String key, Object value)
key
- the keyvalue
- the valuepublic boolean getBoolean(String key)
true
if and only if there is
an integer attribute valued >0 in the table for the key.
key
- the key
true
, iff map.get(key)!= null and the value is an
positive Integerpublic String getString(String key)
key
- the key
null
public double getDouble(String key)
0.0d
key
- the key
0.0d
public double getDouble(String key, double defaultValue)
key
- the keydefaultValue
- a default value
public int getInt(String key)
0
key
- the key
0
public int getInt(String key, int defaultValue)
key
- the keydefaultValue
- the default value
public void begin()
public void end()
public Object getItem()
ItemParser.end()
has been called. The latter should construct
the resulting item from the collected data and this item
should be returned by this method. By default, this method
return the map of the attributes.
Map
public void childFinished(ItemParser p)
p
- the child ItemParser, which just finishedpublic int getLevel()
public Map getAttributes()
|
© Copyright 2000-2003, yWorks GmbH. All rights reserved. 2003 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |