Last update: 2011-06-23

org.proteios.io
Class TagFactory

java.lang.Object
  extended by org.proteios.io.TagFactory
Direct Known Subclasses:
SchemaFactory, TandemFactory

public abstract class TagFactory
extends Object

Extend this factory when you want to read an xml file and create a set of objects out of each tag. Define newCLASS() methods for each tag you want to match returning an object of type CLASS. For each tag that you want to handel implement a done(CLASS c) method.

Author:
gregory

Field Summary
protected  javax.xml.stream.XMLStreamReader reader
           
 
Constructor Summary
TagFactory(javax.xml.stream.XMLStreamReader reader)
           
 
Method Summary
<E extends XMLTag>
E
create(E template)
          This method tries to find a method in this factory named "newCLASS" where the CLASS is the classname of the template.
<E extends XMLTag>
void
done(E tag)
          Tries to find the method done(E) and calls it with the supplied object.
protected  Double readDouble(String key)
          Convenience method to read an attribute and convert it to a Float.
protected  Float readFloat(String key)
          Convenience method to read an attribute and convert it to a Float.
protected  Integer readInt(String key)
          Convenience method to read an attribute and convert it to an Integer
protected  Integer readInteger(String key)
          The same as readInt(String)
protected  Long readLong(String key)
          Convenience method to read an attribute and convert it to a Long
protected  String readString(String key)
          Reads value of the attribute name
protected  String readText()
          Read the content of a tag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reader

protected javax.xml.stream.XMLStreamReader reader
Constructor Detail

TagFactory

public TagFactory(javax.xml.stream.XMLStreamReader reader)
Method Detail

readString

protected String readString(String key)
Reads value of the attribute name

Parameters:
key - name of the attribute
Returns:
the read value

readText

protected String readText()
Read the content of a tag

Returns:
the read value, or null if something goes wrong

readLong

protected Long readLong(String key)
Convenience method to read an attribute and convert it to a Long

Parameters:
key - name of the attribute
Returns:
a Long value
Throws:
NumberFormatException - if the value is not a valid Long

readInt

protected Integer readInt(String key)
Convenience method to read an attribute and convert it to an Integer

Parameters:
key - name of the attribute
Returns:
an Integer
Throws:
NumberFormatException - if the value is not a valid Integer

readInteger

protected Integer readInteger(String key)
The same as readInt(String)

Parameters:
key - name of the attribute
Returns:
an Integer

readFloat

protected Float readFloat(String key)
Convenience method to read an attribute and convert it to a Float.

Parameters:
key - name of the attribute
Returns:
a Float
Throws:
NumberFormatException - if the value is not a Float

readDouble

protected Double readDouble(String key)
Convenience method to read an attribute and convert it to a Float.

Parameters:
key - name of the attribute
Returns:
a Float
Throws:
NumberFormatException - if the value is not a Float

create

public <E extends XMLTag> E create(E template)
This method tries to find a method in this factory named "newCLASS" where the CLASS is the classname of the template. If no method is found an error is printed to System.err

Type Parameters:
E - a XMLTag class
Parameters:
template - class to find
Returns:
new object or null if the newCLASS method returns null or is not found

done

public <E extends XMLTag> void done(E tag)
Tries to find the method done(E) and calls it with the supplied object.

Type Parameters:
E -
Parameters:
tag - to end

Last update: 2011-06-23