Last update: 2011-06-23

org.proteios.io
Class XMLTag

java.lang.Object
  extended by org.proteios.io.XMLTag
Direct Known Subclasses:
Tag, TandemFactory.ModelGroup, TandemFactory.SpectrumPathNote

public abstract class XMLTag
extends Object

Defines an xml tag that is readable using a XMLReader and TagFactory.

Author:
gregory

Field Summary
protected  XMLTag parent
           
 
Method Summary
 void addChild(XMLTag child)
          Add a child tag
 boolean allow(XMLTag... tags)
          Adds one or more xml tags that are allowed as child tags.
 Iterator<XMLTag> allowed()
           
 String asString()
           
 String attributes()
          Override this method to create an attribute string
protected  String build(Object... a)
          Simplifies building of attribute strings
 Iterator<XMLTag> children()
           
 boolean matchAttribute(javax.xml.stream.XMLStreamReader parser, String name, String value)
          Matches an attribute with the specified name and value.
abstract  boolean matchEnd(javax.xml.stream.XMLStreamReader parser, XMLTag parent)
          Implement this method to match a specific end tag.
 boolean matchEndTag(javax.xml.stream.XMLStreamReader parser, String name)
          This method returns true if the class name matches the end tagname.
abstract  boolean matchStart(javax.xml.stream.XMLStreamReader parser, XMLTag parent)
          Implement this method to match a specific tag.
 boolean matchStartTag(javax.xml.stream.XMLStreamReader parser, String name)
          This method returns true if the class name matches the start tagname.
 void setChildren(List<XMLTag> children)
          Overwrites the current list of children with a new list.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

protected XMLTag parent
Method Detail

addChild

public void addChild(XMLTag child)
Add a child tag

Parameters:
child -

allow

public boolean allow(XMLTag... tags)
Adds one or more xml tags that are allowed as child tags. Use this method to build a tree of tags that should be read.

Parameters:
tags -
Returns:
true, just as the Add method in a Collection

allowed

public Iterator<XMLTag> allowed()
Returns:
iterator of allowed tags

setChildren

public void setChildren(List<XMLTag> children)
Overwrites the current list of children with a new list.

Parameters:
children - the list of child tags to set

children

public Iterator<XMLTag> children()
Returns:
iterator of child tags, null if there are no children

matchStartTag

public boolean matchStartTag(javax.xml.stream.XMLStreamReader parser,
                             String name)
This method returns true if the class name matches the start tagname. Character casing is ignored. Eg. a class named Body that extends the XMLTag will match tags and . This method will first check if the parser is at currently at the begining of a tag.

Parameters:
parser - used to read an xml stream
name - tag name to match
Returns:
true if the tag matches, false otherwise

matchEndTag

public boolean matchEndTag(javax.xml.stream.XMLStreamReader parser,
                           String name)
This method returns true if the class name matches the end tagname. Character casing is ignored. Eg. a class named Html that extends the XMLTag will match tags and . This method will first check if the parser is at currently at the end of a tag.

Parameters:
parser - used to read an xml stream
name - tag name to match
Returns:
true if the classname matches the end tag name

matchAttribute

public boolean matchAttribute(javax.xml.stream.XMLStreamReader parser,
                              String name,
                              String value)
Matches an attribute with the specified name and value. This method will first check if the parser is at currently at the begining of a tag.

Parameters:
parser - used to read an xml stream
name - of the attribute to match
value - of the attribute to match
Returns:
true if the attribute matches, false otherwise

toString

public String toString()
Overrides:
toString in class Object
Returns:
a string representation of this tag and its children
See Also:
Object.toString()

asString

public String asString()
Returns:
a String looking like

attributes

public String attributes()
Override this method to create an attribute string

Returns:
a string looking like a=".." b=".." or null if tag has no attributes

build

protected String build(Object... a)
Simplifies building of attribute strings

Parameters:
a - list of label, value, label, value,...
Returns:
String label="value", label="value"

matchStart

public abstract boolean matchStart(javax.xml.stream.XMLStreamReader parser,
                                   XMLTag parent)
Implement this method to match a specific tag. If you only need to match the name of the tag you can extend the Tag class.

Parameters:
parser - that reads an xml stream
parent - the current parent xml tag
Returns:
true if the start tag matches, false otherwise

matchEnd

public abstract boolean matchEnd(javax.xml.stream.XMLStreamReader parser,
                                 XMLTag parent)
Implement this method to match a specific end tag. If you only use the name of a class you can extend the Tag class..

Parameters:
parser - that reads an xml stream
parent - the current parent xml tag
Returns:
true if the end tag matches, false otherwise

Last update: 2011-06-23