org.basex.io.serial
Class Serializer

java.lang.Object
  extended by org.basex.io.serial.Serializer
Direct Known Subclasses:
BuilderSerializer, OutputSerializer, SAXSerializer

public abstract class Serializer
extends java.lang.Object

This is an interface for serializing XQuery values.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Field Summary
protected  byte[] elem
          Current tag.
protected  boolean indent
          Indentation flag.
protected  int level
          Current level.
static SerializerProp PROPS
          Default serialization parameters.
protected  TokenList tags
          Stack with opened tag names.
protected  boolean undecl
          Undeclare prefixes.
 
Constructor Summary
Serializer()
           
 
Method Summary
protected abstract  void atomic(Item item)
          Serializes an atomic value.
protected abstract  void attribute(byte[] name, byte[] value)
          Serializes an attribute.
 void close()
          Closes the serializer.
protected  void closeDoc()
          Closes a document.
protected  void closeElement()
          Closes an element.
protected  void closeResult()
          Closes a result.
protected abstract  void finishClose()
          Closes an element.
protected abstract  void finishComment(byte[] value)
          Serializes a comment.
 boolean finished()
          Tests if the serialization was interrupted.
protected abstract  void finishEmpty()
          Closes an empty element.
protected abstract  void finishOpen()
          Finishes an opening element node.
protected abstract  void finishPi(byte[] name, byte[] value)
          Serializes a processing instruction.
protected abstract  void finishText(byte[] value)
          Serializes a text.
protected  void finishText(byte[] value, FTPos ftp)
          Serializes a text.
static XMLSerializer get(java.io.OutputStream os)
          Returns an XML serializer.
static Serializer get(java.io.OutputStream os, SerializerProp props)
          Returns a specific serializer.
protected  void namespace(byte[] pref, byte[] uri)
          Serializes a namespace if it has not been serialized by an ancestor yet.
protected  byte[] nsUri(byte[] pref)
          Gets the namespace URI currently bound by the given prefix.
protected  void openDoc(byte[] name)
          Opens a document.
protected  void openResult()
          Starts a result.
 void reset()
          Resets the serializer (indentation, etc).
 void serialize(Item item)
          Serializes the specified item, which may be a node or an atomic value.
protected  void startElement(byte[] name)
          Opens an element.
protected abstract  void startOpen(byte[] name)
          Starts an element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPS

public static final SerializerProp PROPS
Default serialization parameters.


tags

protected final TokenList tags
Stack with opened tag names.


level

protected int level
Current level.


elem

protected byte[] elem
Current tag.


undecl

protected boolean undecl
Undeclare prefixes.


indent

protected boolean indent
Indentation flag.

Constructor Detail

Serializer

public Serializer()
Method Detail

get

public static XMLSerializer get(java.io.OutputStream os)
                         throws java.io.IOException
Returns an XML serializer.

Parameters:
os - output stream reference
Returns:
serializer
Throws:
java.io.IOException - I/O exception

get

public static Serializer get(java.io.OutputStream os,
                             SerializerProp props)
                      throws java.io.IOException
Returns a specific serializer.

Parameters:
os - output stream reference
props - serialization properties (can be null)
Returns:
serializer
Throws:
java.io.IOException - I/O exception

serialize

public final void serialize(Item item)
                     throws java.io.IOException
Serializes the specified item, which may be a node or an atomic value.

Parameters:
item - item to be serialized
Throws:
java.io.IOException - I/O exception

close

public void close()
           throws java.io.IOException
Closes the serializer.

Throws:
java.io.IOException - I/O exception

finished

public boolean finished()
Tests if the serialization was interrupted.

Returns:
result of check

reset

public void reset()
Resets the serializer (indentation, etc).


startElement

protected final void startElement(byte[] name)
                           throws java.io.IOException
Opens an element.

Parameters:
name - element name
Throws:
java.io.IOException - I/O exception

closeElement

protected final void closeElement()
                           throws java.io.IOException
Closes an element.

Throws:
java.io.IOException - I/O exception

finishText

protected void finishText(byte[] value,
                          FTPos ftp)
                   throws java.io.IOException
Serializes a text.

Parameters:
value - value
ftp - full-text positions, used for visualization highlighting
Throws:
java.io.IOException - I/O exception

nsUri

protected final byte[] nsUri(byte[] pref)
Gets the namespace URI currently bound by the given prefix.

Parameters:
pref - namespace prefix
Returns:
URI if found, null otherwise

namespace

protected void namespace(byte[] pref,
                         byte[] uri)
                  throws java.io.IOException
Serializes a namespace if it has not been serialized by an ancestor yet.

Parameters:
pref - prefix
uri - URI
Throws:
java.io.IOException - I/O exception

openResult

protected void openResult()
                   throws java.io.IOException
Starts a result.

Throws:
java.io.IOException - I/O exception

closeResult

protected void closeResult()
                    throws java.io.IOException
Closes a result.

Throws:
java.io.IOException - I/O exception

openDoc

protected void openDoc(byte[] name)
                throws java.io.IOException
Opens a document.

Parameters:
name - name
Throws:
java.io.IOException - I/O exception

closeDoc

protected void closeDoc()
                 throws java.io.IOException
Closes a document.

Throws:
java.io.IOException - I/O exception

attribute

protected abstract void attribute(byte[] name,
                                  byte[] value)
                           throws java.io.IOException
Serializes an attribute.

Parameters:
name - name
value - value
Throws:
java.io.IOException - I/O exception

startOpen

protected abstract void startOpen(byte[] name)
                           throws java.io.IOException
Starts an element.

Parameters:
name - tag name
Throws:
java.io.IOException - I/O exception

finishOpen

protected abstract void finishOpen()
                            throws java.io.IOException
Finishes an opening element node.

Throws:
java.io.IOException - I/O exception

finishEmpty

protected abstract void finishEmpty()
                             throws java.io.IOException
Closes an empty element.

Throws:
java.io.IOException - I/O exception

finishClose

protected abstract void finishClose()
                             throws java.io.IOException
Closes an element.

Throws:
java.io.IOException - I/O exception

finishText

protected abstract void finishText(byte[] value)
                            throws java.io.IOException
Serializes a text.

Parameters:
value - value
Throws:
java.io.IOException - I/O exception

finishComment

protected abstract void finishComment(byte[] value)
                               throws java.io.IOException
Serializes a comment.

Parameters:
value - value
Throws:
java.io.IOException - I/O exception

finishPi

protected abstract void finishPi(byte[] name,
                                 byte[] value)
                          throws java.io.IOException
Serializes a processing instruction.

Parameters:
name - name
value - value
Throws:
java.io.IOException - I/O exception

atomic

protected abstract void atomic(Item item)
                        throws java.io.IOException
Serializes an atomic value.

Parameters:
item - item
Throws:
java.io.IOException - I/O exception