com.ctc.wstx.io
Class WstxInputSource

java.lang.Object
  extended by com.ctc.wstx.io.WstxInputSource
Direct Known Subclasses:
BaseInputSource

public abstract class WstxInputSource
extends java.lang.Object

Interface that defines API actual parsers (or, "readers" in StAX lingo) can use to read input from various input sources. Needed to abstract out details of getting input from primary input files, secondary (potentially cached) referenced documents, and from parsed entities, as well as for allowing hierarchic location information for error reporting.


Field Summary
protected  WstxInputSource mParent
          Parent in input source stack
 
Constructor Summary
protected WstxInputSource(WstxInputSource parent, java.lang.String fromEntity)
           
 
Method Summary
abstract  void close()
          Method reader calls for this input source when it has encountered EOF.
abstract  void closeCompletely()
          Method reader MAY call to force full closing of the underlying input stream(s)/reader(s).
protected abstract  void doInitInputLocation(WstxInputData reader)
           
abstract  boolean fromInternalEntity()
           
 java.lang.String getEntityId()
           
protected abstract  WstxInputLocation getLocation()
          Method usually called to get a parent location for another input source.
abstract  WstxInputLocation getLocation(long total, int row, int col)
           
 WstxInputSource getParent()
           
abstract  java.lang.String getPublicId()
           
 int getScopeId()
           
abstract  java.net.URL getSource()
           
abstract  java.lang.String getSystemId()
           
 void initInputLocation(WstxInputData reader, int currScopeId)
          Method called by Reader when current input has changed to come from this input source.
 boolean isOrIsExpandedFrom(java.lang.String entityId)
          Method that checks if this input source expanded from the specified entity id, directly or by ancestor.
abstract  int readInto(WstxInputData reader)
          Method called to read at least one more char from input source, and update input data appropriately.
abstract  boolean readMore(WstxInputData reader, int minAmount)
          Method called by reader when it has to have at least specified number of consequtive input characters in its buffer, and it currently does not have.
abstract  void restoreContext(WstxInputData reader)
          Method Reader calls when this input source is resumed as the current source.
abstract  void saveContext(WstxInputData reader)
          Method Reader calls when this input source is being stored, when a nested input source gets used instead (due to entity expansion).
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mParent

protected final WstxInputSource mParent
Parent in input source stack

Constructor Detail

WstxInputSource

protected WstxInputSource(WstxInputSource parent,
                          java.lang.String fromEntity)
Method Detail

getParent

public final WstxInputSource getParent()

isOrIsExpandedFrom

public boolean isOrIsExpandedFrom(java.lang.String entityId)
Method that checks if this input source expanded from the specified entity id, directly or by ancestor.

Note that entity ids are expected to have been interned (using whatever uniqueness mechanism used), and thus can be simply identity checked.


fromInternalEntity

public abstract boolean fromInternalEntity()
Returns:
True, if this input source was directly expanded from an internal entity (general, parsed); false if not (from external entity, DTD ext. subset, main document)

getSource

public abstract java.net.URL getSource()

getPublicId

public abstract java.lang.String getPublicId()

getSystemId

public abstract java.lang.String getSystemId()

getLocation

protected abstract WstxInputLocation getLocation()
Method usually called to get a parent location for another input source. Works since at this point context (line, row, chars) information has already been saved to this object.


getLocation

public abstract WstxInputLocation getLocation(long total,
                                              int row,
                                              int col)

getEntityId

public java.lang.String getEntityId()

getScopeId

public int getScopeId()

initInputLocation

public final void initInputLocation(WstxInputData reader,
                                    int currScopeId)
Method called by Reader when current input has changed to come from this input source. Should reset/initialize input location information Reader keeps, for error messages to work ok.

Parameters:
reader - Reader whose data structures are to be used for returning data read
currScopeId -

doInitInputLocation

protected abstract void doInitInputLocation(WstxInputData reader)

readInto

public abstract int readInto(WstxInputData reader)
                      throws java.io.IOException
Method called to read at least one more char from input source, and update input data appropriately.

Returns:
Number of characters read from the input source (at least 1), if it had any input; -1 if input source has no more input.
Throws:
java.io.IOException

readMore

public abstract boolean readMore(WstxInputData reader,
                                 int minAmount)
                          throws java.io.IOException
Method called by reader when it has to have at least specified number of consequtive input characters in its buffer, and it currently does not have. If so, it asks input source to do whatever it has to do to try to get more data, if possible (including moving stuff in input buffer if necessary and possible).

Returns:
True if input source was able to provide specific number of characters or more; false if not. In latter case, source is free to return zero or more characters any way.
Throws:
java.io.IOException

saveContext

public abstract void saveContext(WstxInputData reader)
Method Reader calls when this input source is being stored, when a nested input source gets used instead (due to entity expansion). Needs to get location info from Reader and store it in this Object.


restoreContext

public abstract void restoreContext(WstxInputData reader)
Method Reader calls when this input source is resumed as the current source. Needs to update Reader's input location data used for error messages etc.


close

public abstract void close()
                    throws java.io.IOException
Method reader calls for this input source when it has encountered EOF. This may or may not close the underlying stream/reader; what happens depends on configuration

Throws:
java.io.IOException

closeCompletely

public abstract void closeCompletely()
                              throws java.io.IOException
Method reader MAY call to force full closing of the underlying input stream(s)/reader(s). No checks are done regarding configuration, but input source object is to deal gracefully with multiple calls (ie. it's not an error for reader to call this more than once).

Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object