net.sf.fikin.pojostate.format
Class PropertiesStateFormat

java.lang.Object
  extended by java.text.Format
      extended by net.sf.fikin.pojostate.StateFormat
          extended by net.sf.fikin.pojostate.format.PropertiesStateFormat
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
XmlStateFormat

public class PropertiesStateFormat
extends StateFormat

Format a State object in properties-like fashion.

Output format is like:

 UI name=UI value
 #UI description
 ...
 

It recognizes most stream and writer interfaces, @see #format(Object, Object), created on Jul 6, 2005

Since:
Version:
$Revision: 1.3 $
Author:
fiykov
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.Format
java.text.Format.Field
 
Constructor Summary
PropertiesStateFormat()
           
 
Method Summary
 void format(java.lang.Object obj, java.lang.Object out)
          It does recognize following output object types: java.io.BufferedOutputStream java.io.BufferedWriter java.io.OutputStream java.io.Writer java.io.PrintStream java.io.PrintWriter
For all other types raises an exception.
 java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
          Format the object to a string and append it to toAppendTo.
 void format(State state, java.io.PrintWriter out)
          Print the State object to string.
 java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
          a dummy implementation as typically this is a not supported method
 void printFooter(State state, java.io.PrintWriter out)
          empty, part of the prototype format(State, PrintWriter) algorithm.
 void printHeader(State state, java.io.PrintWriter out)
          empty, part of the prototype format(State, PrintWriter) algorithm.
 void printProperty(Property property, java.io.PrintWriter out)
          Prints the Property object in properties-like fashion: UI name=UI value #UI description
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiesStateFormat

public PropertiesStateFormat()
Method Detail

format

public java.lang.StringBuffer format(java.lang.Object obj,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition pos)
Format the object to a string and append it to toAppendTo.

The execution fails to

formatState state, new StringWriter()

Specified by:
format in class java.text.Format
Parameters:
obj -
toAppendTo -
pos -
Returns:
appended toAppendTo

format

public void format(java.lang.Object obj,
                   java.lang.Object out)
            throws java.lang.IllegalArgumentException,
                   java.io.IOException
It does recognize following output object types:
 java.io.BufferedOutputStream
 java.io.BufferedWriter
 java.io.OutputStream
 java.io.Writer
 java.io.PrintStream
 java.io.PrintWriter
 

For all other types raises an exception.

For all but java.io.PrintWriter it provides with dynamic object decoration in the way of new PrintWriter( (XXX)out ) and delegates the formating to format(State, PrintWriter).

Output stream is not closed!
The caller is expected to take care of this.

Specified by:
format in class StateFormat
Parameters:
obj - The object to format
out - The object to print the text to directly.
Throws:
java.lang.IllegalArgumentException - if the Format cannot format the given object or out object type is not any of the aforementioned.
java.io.IOException - in case when writting to output object failed

format

public void format(State state,
                   java.io.PrintWriter out)
            throws java.io.IOException
Print the State object to string.

This is a prototype method which does call in order printHeader(), iterate over all printProperty() and then calls printFooter().

Output stream is not closed!

Parameters:
state -
out -
Throws:
java.io.IOException

printHeader

public void printHeader(State state,
                        java.io.PrintWriter out)
                 throws java.io.IOException
empty, part of the prototype format(State, PrintWriter) algorithm.

Parameters:
state -
out -
Throws:
java.io.IOException

printFooter

public void printFooter(State state,
                        java.io.PrintWriter out)
                 throws java.io.IOException
empty, part of the prototype format(State, PrintWriter) algorithm.

Parameters:
state -
out -
Throws:
java.io.IOException

printProperty

public void printProperty(Property property,
                          java.io.PrintWriter out)
                   throws java.io.IOException
Prints the Property object in properties-like fashion:
 UI name=UI value
 #UI description
 

Parameters:
property -
out -
Throws:
java.io.IOException

parseObject

public java.lang.Object parseObject(java.lang.String source,
                                    java.text.ParsePosition pos)
a dummy implementation as typically this is a not supported method

Specified by:
parseObject in class java.text.Format


Copyright © 2005 Nikolay Fiykov. All Rights Reserved.