org.argouml.persistence
Class XmlInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byjava.io.BufferedInputStream
              extended byorg.argouml.persistence.XmlInputStream

public class XmlInputStream
extends BufferedInputStream

A BufferInputStream that is aware of XML structure. It can searches for the first occurence of a named tag and reads only the data (inclusively) from that tag to the matching end tag or it can search for the first occurence of a named tag and read on the child tags. The tag is not expected to be an empty tag.


Field Summary
private  Map attributes
           
private  byte[] buffer
           
private  boolean childOnly
           
private  StringBuffer currentTag
           
private  boolean endStream
           
private  String endTagName
           
private  long eventSpacing
          The number of bytes to be read between each progress event.
private  int instanceCount
           
private  int instanceRequired
           
private  boolean inTag
           
private  long length
          The expected stream length
private  EventListenerList listenerList
           
private static Logger LOG
           
private  long readCount
          The number of characters read so far
private  String tagName
           
private  boolean xmlStarted
           
 
Fields inherited from class java.io.BufferedInputStream
buf, count, marklimit, markpos, pos
 
Fields inherited from class java.io.FilterInputStream
in
 
Fields inherited from class java.io.InputStream
 
Constructor Summary
XmlInputStream(InputStream in, String theTag, long theLength, long theEventSpacing)
          Construct a new XmlInputStream
 
Method Summary
 void addProgressListener(ProgressListener listener)
           
 void close()
          The close method is overridden to prevent some class out of our control from closing the stream (such as a SAX parser).
private  void fireProgressEvent()
           
private  boolean isLastTag(int ch)
          Determines if the character is the last character of the last tag of interest.
private  boolean isNameTerminator(char ch)
           
 int read()
           
 int read(byte[] b, int off, int len)
           
private  Map readAttributes()
          Having read the inputstream up until the tag name.
 void realClose()
          Really close the input
private  int realRead()
           
 void removeProgressListener(ProgressListener listener)
           
 void reopen(String theTag)
          Reopen a stream that has already reached the end of an XML fragment.
 void reopen(String theTag, Map attribs, boolean child)
          Reopen a stream that has already reached the end of an XML fragment.
private  void skipToTag()
          Keep on reading an input stream until a specific sequence of characters has ben read.
private  int superRead()
           
 
Methods inherited from class java.io.BufferedInputStream
available, mark, markSupported, reset, skip
 
Methods inherited from class java.io.FilterInputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlStarted

private boolean xmlStarted

inTag

private boolean inTag

currentTag

private StringBuffer currentTag

endStream

private boolean endStream

tagName

private String tagName

endTagName

private String endTagName

attributes

private Map attributes

childOnly

private boolean childOnly

instanceRequired

private int instanceRequired

instanceCount

private int instanceCount

buffer

private byte[] buffer

listenerList

private EventListenerList listenerList

eventSpacing

private long eventSpacing
The number of bytes to be read between each progress event.


readCount

private long readCount
The number of characters read so far


length

private long length
The expected stream length


LOG

private static final Logger LOG
Constructor Detail

XmlInputStream

public XmlInputStream(InputStream in,
                      String theTag,
                      long theLength,
                      long theEventSpacing)
Construct a new XmlInputStream

Parameters:
in - the input stream to wrap.
theTag - the tag name from which to start reading
theLength - the expected length of the input stream
theEventSpacing - the number of characers to read before firing a progress event.
Method Detail

reopen

public void reopen(String theTag,
                   Map attribs,
                   boolean child)
Reopen a stream that has already reached the end of an XML fragment.

Parameters:
theTag - the tag name
attribs - the attributes
child - child only

reopen

public void reopen(String theTag)
Reopen a stream that has already reached the end of an XML fragment.

Parameters:
theTag - the tag name

read

public int read()
         throws IOException
Throws:
IOException
See Also:
InputStream.read()

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Throws:
IOException
See Also:
InputStream.read(byte[], int, int)

isLastTag

private boolean isLastTag(int ch)
Determines if the character is the last character of the last tag of interest. Every character read after the first tag of interest should be passed through this method in order.

Parameters:
ch - the character to test.
Returns:
true if this is the end of the last tag.

skipToTag

private void skipToTag()
                throws IOException
Keep on reading an input stream until a specific sequence of characters has ben read. This method assumes there is at least one match.

Throws:
IOException

isNameTerminator

private boolean isNameTerminator(char ch)

readAttributes

private Map readAttributes()
                    throws IOException
Having read the inputstream up until the tag name. This method continues to read the contents of the tag to retrieve any attribute names and values.

Returns:
a map of name value pairs.
Throws:
IOException

close

public void close()
           throws IOException
The close method is overridden to prevent some class out of our control from closing the stream (such as a SAX parser). Use realClose() to finally close the stream for real.

Throws:
IOException - to satisfy ancestor but will never happen.

realClose

public void realClose()
               throws IOException
Really close the input

Throws:
IOException - if an I/O error occurs.

realRead

private int realRead()
              throws IOException
Throws:
IOException

superRead

private int superRead()
               throws IOException
Throws:
IOException

fireProgressEvent

private void fireProgressEvent()

addProgressListener

public void addProgressListener(ProgressListener listener)
Parameters:
listener - the progress listener

removeProgressListener

public void removeProgressListener(ProgressListener listener)
Parameters:
listener - the progress listener


ArgoUML © 1996-2004 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook