name.pehl.piriti.restlet.xml.client
Class PiritiXmlRepresentation<T>

java.lang.Object
  extended by org.restlet.client.representation.Variant
      extended by org.restlet.client.representation.RepresentationInfo
          extended by org.restlet.client.representation.Representation
              extended by org.restlet.client.ext.xml.DomRepresentation
                  extended by name.pehl.piriti.restlet.xml.client.PiritiXmlRepresentation<T>
Type Parameters:
T - The model type
All Implemented Interfaces:
PiritiRepresentation<T>

public class PiritiXmlRepresentation<T>
extends org.restlet.client.ext.xml.DomRepresentation
implements PiritiRepresentation<T>

Representation which uses an XmlReader for converting XML to an instance of T.

TODO Namespace support!

Version:
$Date: 2011-03-20 21:02:59 +0100 (So, 20 Mär 2011) $ $Revision: 264 $
Author:
$Author: harald.pehl $

Field Summary
 
Fields inherited from class org.restlet.client.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
PiritiXmlRepresentation(XmlReader<T> xmlReader, org.restlet.client.data.MediaType mediaType)
          Constructor for an empty document.
PiritiXmlRepresentation(XmlReader<T> xmlReader, org.restlet.client.data.MediaType mediaType, name.pehl.totoe.xml.client.Document document)
          Constructor from an existing DOM document.
PiritiXmlRepresentation(XmlReader<T> xmlReader, org.restlet.client.representation.Representation xmlRepresentation)
          Constructor.
 
Method Summary
 com.google.gwt.xml.client.Document getDocument()
          Returns always null.
 T getModel()
          Converts the XML to an instance of T using the XmlReader given as constructor argument.
 List<T> getModels()
          Converts the XML to a list of Ts using the XmlReader given as constructor argument.
 XmlReader<T> getXmlReader()
           
protected  name.pehl.totoe.xml.client.Document lazyGetDocument()
          Returns the wrapped document instance.
 
Methods inherited from class org.restlet.client.ext.xml.DomRepresentation
getReader, getStream, getText, release, setDocument
 
Methods inherited from class org.restlet.client.representation.Representation
append, exhaust, getAvailableSize, getDisposition, getExpirationDate, getRange, getSize, hasKnownSize, isAvailable, isEmpty, isTransient, setAvailable, setDisposition, setExpirationDate, setRange, setSize, setTransient
 
Methods inherited from class org.restlet.client.representation.RepresentationInfo
getModificationDate, getTag, setModificationDate, setTag
 
Methods inherited from class org.restlet.client.representation.Variant
createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PiritiXmlRepresentation

public PiritiXmlRepresentation(XmlReader<T> xmlReader,
                               org.restlet.client.data.MediaType mediaType)
Constructor for an empty document.

Parameters:
xmlReader - The XmlReader for converting the XML to an instance of T.
mediaType - The representation's media type.

PiritiXmlRepresentation

public PiritiXmlRepresentation(XmlReader<T> xmlReader,
                               org.restlet.client.data.MediaType mediaType,
                               name.pehl.totoe.xml.client.Document document)
Constructor from an existing DOM document.

Parameters:
xmlReader - The XmlReader for converting the XML to an instance of T.
mediaType - The representation's media type.
document - The source DOM document.

PiritiXmlRepresentation

public PiritiXmlRepresentation(XmlReader<T> xmlReader,
                               org.restlet.client.representation.Representation xmlRepresentation)
Constructor.

Parameters:
xmlReader - The XmlReader for converting the XML to an instance of T.
xmlRepresentation - A source XML representation to parse.
Method Detail

getXmlReader

public XmlReader<T> getXmlReader()
Returns:
the XmlReader for converting the XML to an instance of T.

getModel

public T getModel()
           throws IOException
Converts the XML to an instance of T using the XmlReader given as constructor argument. Returns null if getDocument() or XmlReader is null.

Specified by:
getModel in interface PiritiRepresentation<T>
Returns:
the converted instance of T or null if getDocument() or XmlReader is null.
Throws:
IOException

getModels

public List<T> getModels()
                  throws IOException
Converts the XML to a list of Ts using the XmlReader given as constructor argument. Returns null if getDocument() or XmlReader is null. More precisely the child elements of the documents root element are converted to instances of T.

Specified by:
getModels in interface PiritiRepresentation<T>
Returns:
the list of converted Ts or null if getDocument() or XmlReader is null.
Throws:
IOException

lazyGetDocument

protected name.pehl.totoe.xml.client.Document lazyGetDocument()
                                                       throws IOException
Returns the wrapped document instance. If no document is defined yet, it attempts to parse the XML representation eventually given at construction time. Otherwise, it returns null.

Returns:
The wrapped document instance.
Throws:
IOException

getDocument

public com.google.gwt.xml.client.Document getDocument()
                                               throws IOException
Returns always null.

Overrides:
getDocument in class org.restlet.client.ext.xml.DomRepresentation
Returns:
null
Throws:
IOException
See Also:
DomRepresentation.getDocument()


Copyright © 2012 Harald Pehl. All Rights Reserved.