com.google.gdata.wireformats.input
Class AbstractParser<T>

java.lang.Object
  extended by com.google.gdata.wireformats.input.AbstractParser<T>
All Implemented Interfaces:
InputParser<T>
Direct Known Subclasses:
CharacterParser, MediaMultipartParser, MediaParser

public abstract class AbstractParser<T>
extends java.lang.Object
implements InputParser<T>

The AbstractParser class is an abstract base class that can be used in the creation of new InputParser implementations. It provides the basic storage and getters for the alternate representation and result type and utility code for constructing new result type implementation instances.


Field Summary
protected  AltFormat altFormat
           
protected  java.lang.Class<? extends T> resultType
           
 
Constructor Summary
protected AbstractParser(AltFormat altFormat, java.lang.Class<? extends T> resultType)
          Constructs a new AbstractParser instance for the specified representation and result type.
 
Method Summary
protected  T createResult()
          Creates a new result object instance using the result type passed to the constructor.
protected
<R extends T>
R
createResult(java.lang.Class<R> resultImplClass)
          Creates a new result object instance using the provided result implementation class.
 AltFormat getAltFormat()
          Returns the alternate representation format that is expected as input to the parser.
 java.lang.Class<? extends T> getResultType()
          Returns the target type that is populated by the parser from the input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.google.gdata.wireformats.input.InputParser
parse
 

Field Detail

altFormat

protected final AltFormat altFormat

resultType

protected final java.lang.Class<? extends T> resultType
Constructor Detail

AbstractParser

protected AbstractParser(AltFormat altFormat,
                         java.lang.Class<? extends T> resultType)
Constructs a new AbstractParser instance for the specified representation and result type.

Parameters:
altFormat - parsed alternate representation
resultType - type of result
Method Detail

getAltFormat

public AltFormat getAltFormat()
Description copied from interface: InputParser
Returns the alternate representation format that is expected as input to the parser.

Specified by:
getAltFormat in interface InputParser<T>

getResultType

public java.lang.Class<? extends T> getResultType()
Description copied from interface: InputParser
Returns the target type that is populated by the parser from the input stream.

Specified by:
getResultType in interface InputParser<T>

createResult

protected T createResult()
                  throws ContentCreationException
Creates a new result object instance using the result type passed to the constructor. This form can be used by subclasses where the result type is a concrete implementation class.

Returns:
result instance
Throws:
ContentCreationException

createResult

protected <R extends T> R createResult(java.lang.Class<R> resultImplClass)
                            throws ContentCreationException
Creates a new result object instance using the provided result implementation class. This form can be used by subclasses where the result type is an interface or where results may be an implementation class that is a subclass of the result type.

Type Parameters:
R - type of the created result
Parameters:
resultImplClass - Result implementation class. The type must implement the result type of the parser and provide a null argument constructor.
Returns:
result instance
Throws:
ContentCreationException - if unable to create result object