org.ujac.util.xml
Class BaseObjectSerializer

java.lang.Object
  extended by org.ujac.util.xml.BaseObjectSerializer
Direct Known Subclasses:
DynamicObjectSerializer, TableSerializer

public abstract class BaseObjectSerializer
extends Object

Name: BaseObjectSerializer
Description: A base class for classes which read/write objects from/to XML documents.

Author:
lauerc

Nested Class Summary
 class BaseObjectSerializer.ObjectHandler
          Name: ObjectHandler
Description: Description of the class.
 class BaseObjectSerializer.StackElement
          Name: StackElement
Description: A class holding stack elements.
 
Field Summary
protected  BaseObjectSerializer parentSerializer
          The parent serializer.
 
Constructor Summary
BaseObjectSerializer()
          Constructs a BaseObjectSerializer instance with no specific attributes.
BaseObjectSerializer(String encoding)
          Constructs a BaseObjectSerializer instance with specific attributes.
 
Method Summary
 void closeOpenTag(PrintWriter writer, boolean bodyLess, boolean newLine)
          Closes an open tag to the given writer.
 void delegateHandler(BaseObjectSerializer delegate)
          Delegates the XML parsing to the given serializer.
abstract  void endElement(BaseObjectSerializer.StackElement localElement, String content, BaseObjectSerializer.StackElement parentElement, Object root)
          Ends the given local element.
 String getEncoding()
          Getter method for the the property encoding.
 int getRootLevel()
          Getter method for the the property rootLevel.
 Object getRootObject()
          Gets the parsed root object.
 void indent(PrintWriter writer, int level)
          Writes the defined indention to the given print writer.
protected  boolean parseBooleanValue(String string, boolean defaultValue)
          Parses the given boolean value.
protected  int parseIntValue(String string, int defaultValue)
          Parses an integer value from the given String.
 Object read(InputSource src)
          Parses an instance from the given input source.
 Object read(InputStream is)
          Parses an object from the given input stream.
 Object read(Reader reader)
          Parses an object from the given reader.
 void setEncoding(String encoding)
          Setter method for the the property encoding.
 void setRootLevel(int rootLevel)
          Setter method for the the property rootLevel.
abstract  void startElement(BaseObjectSerializer.StackElement localElement, BaseObjectSerializer.StackElement parentElement, Object root)
          Starts the given local element.
 void startNewLine(PrintWriter writer)
          Starts a new line.
 void write(OutputStream os, Object obj)
          Writes an object to the given output stream.
 void write(PrintWriter writer, Object obj)
          Writes an object to the given print writer.
 void write(Writer writer, Object obj)
          Writes an object to the given writer.
 void writeAttribute(PrintWriter writer, String name, boolean value)
          Writes a XML attribute to the given writer.
 void writeAttribute(PrintWriter writer, String name, int value)
          Writes a XML attribute to the given writer.
 void writeAttribute(PrintWriter writer, String name, String value)
          Writes a XML attribute to the given writer.
 void writeCloseTag(PrintWriter writer, String name, boolean newLine)
          Writes a close tag to the given writer.
 void writeOpenTag(PrintWriter writer, String name, boolean leaveOpen, boolean newLine)
          Writes an open tag to the given writer.
 void writeTag(PrintWriter writer, String name, Object value, boolean isCData)
          Writes a XML tag to the given writer.
 void writeTagBody(PrintWriter writer, Object value, boolean cData)
          Writes a tag body.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parentSerializer

protected BaseObjectSerializer parentSerializer
The parent serializer.

Constructor Detail

BaseObjectSerializer

public BaseObjectSerializer()
Constructs a BaseObjectSerializer instance with no specific attributes.


BaseObjectSerializer

public BaseObjectSerializer(String encoding)
Constructs a BaseObjectSerializer instance with specific attributes.

Parameters:
encoding - The encoding to use.
Method Detail

getRootObject

public Object getRootObject()
Gets the parsed root object.

Returns:
The parsed root object.

getRootLevel

public int getRootLevel()
Getter method for the the property rootLevel.

Returns:
The current value of property rootLevel.

setRootLevel

public void setRootLevel(int rootLevel)
Setter method for the the property rootLevel.

Parameters:
rootLevel - The value to set for the property rootLevel.

read

public Object read(InputStream is)
            throws SAXException,
                   IOException
Parses an object from the given input stream.

Parameters:
is - The stream to read the object from.
Returns:
The parsed WebForm.
Throws:
SAXException - In case the parsing failed.
IOException - In case an I/O failure occurred or the parsing failed.

read

public Object read(Reader reader)
            throws SAXException,
                   IOException
Parses an object from the given reader.

Parameters:
reader - The reader to read the object from.
Returns:
The parsed object.
Throws:
SAXException - In case the parsing failed.
IOException - In case an I/O failure occurred or the parsing failed.

read

public Object read(InputSource src)
            throws SAXException,
                   IOException
Parses an instance from the given input source.

Parameters:
src - The input source to read the WebForm from.
Returns:
The parsed WebForm.
Throws:
SAXException - In case the parsing failed.
IOException - In case an I/O failure occurred.

write

public void write(OutputStream os,
                  Object obj)
           throws IOException
Writes an object to the given output stream.

Parameters:
os - The stream to write the object to.
obj - The instance to write.
Throws:
IOException - In case an I/O failure occurred.

write

public void write(Writer writer,
                  Object obj)
           throws IOException
Writes an object to the given writer.

Parameters:
writer - The writer to write the WebForm to.
obj - The instance to write.
Throws:
IOException - In case an I/O failure occurred.

write

public void write(PrintWriter writer,
                  Object obj)
           throws IOException
Writes an object to the given print writer.

Parameters:
writer - The writer to write the WebForm to.
obj - The instance to write.
Throws:
IOException - In case an I/O failure occurred.

writeTagBody

public void writeTagBody(PrintWriter writer,
                         Object value,
                         boolean cData)
Writes a tag body.

Parameters:
writer - The writer to write to.
value - The value to write.
cData - Tells whether or not wrap value into CDATA.

writeAttribute

public void writeAttribute(PrintWriter writer,
                           String name,
                           String value)
Writes a XML attribute to the given writer. In case the given value is null, the output of the attribute is skipped.

Parameters:
writer - The writer to write to.
name - The name of the attribute to write.
value - The attribute's value.

writeAttribute

public void writeAttribute(PrintWriter writer,
                           String name,
                           boolean value)
Writes a XML attribute to the given writer. In case the given value is null, the output of the attribute is skipped.

Parameters:
writer - The writer to write to.
name - The name of the attribute to write.
value - The attribute's value.

writeAttribute

public void writeAttribute(PrintWriter writer,
                           String name,
                           int value)
Writes a XML attribute to the given writer. In case the given value is null, the output of the attribute is skipped.

Parameters:
writer - The writer to write to.
name - The name of the attribute to write.
value - The attribute's value.

indent

public void indent(PrintWriter writer,
                   int level)
Writes the defined indention to the given print writer.

Parameters:
writer - The writer to write the WebForm to.
level - The indention level.

startNewLine

public void startNewLine(PrintWriter writer)
Starts a new line.

Parameters:
writer - The writer to write the WebForm to.

writeOpenTag

public void writeOpenTag(PrintWriter writer,
                         String name,
                         boolean leaveOpen,
                         boolean newLine)
Writes an open tag to the given writer.

Parameters:
writer - The writer to write to.
name - The name of the tag to open.
leaveOpen - Tells to leave the tag open.
newLine - Tells to start a new line after the tag.

closeOpenTag

public void closeOpenTag(PrintWriter writer,
                         boolean bodyLess,
                         boolean newLine)
Closes an open tag to the given writer.

Parameters:
writer - The writer to write to.
bodyLess - Tells whether or not to close a bodyless tag.
newLine - Tells to start a new line after the tag.

writeCloseTag

public void writeCloseTag(PrintWriter writer,
                          String name,
                          boolean newLine)
Writes a close tag to the given writer.

Parameters:
writer - The writer to write to.
name - The name of the tag to open.
newLine - Tells to start a new line after the tag.

writeTag

public void writeTag(PrintWriter writer,
                     String name,
                     Object value,
                     boolean isCData)
Writes a XML tag to the given writer. In case the given value is null, the tag output is skipped.

Parameters:
writer - The writer to write to.
name - The name of the tag to write.
value - The attribute's value.
isCData - Tells whether or not the body should be written as CDATA.

getEncoding

public String getEncoding()
Getter method for the the property encoding.

Returns:
The current value of property encoding.

setEncoding

public void setEncoding(String encoding)
Setter method for the the property encoding.

Parameters:
encoding - The value to set for the property encoding.

delegateHandler

public void delegateHandler(BaseObjectSerializer delegate)
                     throws SAXException
Delegates the XML parsing to the given serializer.

Parameters:
delegate - The serializer to delegat the job to.
Throws:
SAXException - In case the parsing failed.

startElement

public abstract void startElement(BaseObjectSerializer.StackElement localElement,
                                  BaseObjectSerializer.StackElement parentElement,
                                  Object root)
                           throws SAXException
Starts the given local element.

Parameters:
localElement - The element to process.
parentElement - The parent element if present, else null.
root - The root object of the data structure.
Throws:
SAXException - In case the parsing failed.

endElement

public abstract void endElement(BaseObjectSerializer.StackElement localElement,
                                String content,
                                BaseObjectSerializer.StackElement parentElement,
                                Object root)
                         throws SAXException
Ends the given local element.

Parameters:
localElement - The element to process.
content - The content of the local element.
parentElement - The parent element if present, else null.
root - The root object of the data structure.
Throws:
SAXException - In case the parsing failed.

parseIntValue

protected int parseIntValue(String string,
                            int defaultValue)
Parses an integer value from the given String.

Parameters:
string - The String to parse.
defaultValue - The default value.
Returns:
The parsed data type.

parseBooleanValue

protected boolean parseBooleanValue(String string,
                                    boolean defaultValue)
Parses the given boolean value.

Parameters:
string - The String to parse.
defaultValue - The default value.
Returns:
The parsed boolean value.


Copyright © 2003-2004 UJAC.org. All Rights Reserved.