|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.dautelle.xml.ObjectWriter
This class takes a Representable
object and formats it to
a stream as XML. Objects written using this facility may be read using
the Constructor
class.
Namespaces are supported (including default namespace).
For example, the following code creates an ObjectWriter
using a default namespace for all classes within the package
com.dautelle
, excepts for the com.dautelle.math
classes which will be using the math
prefix.
ObjectWriter objectWriter = new ObjectWriter(); objectWriter.setNamespace("", "com.dautelle"); // Default namespace. objectWriter.setNamespace("math", "com.dautelle.math"); ... objectWriter.write(matrix, outputStream); // UTF-8 encoding. objectWriter.write(matrix, writer); // Writer encoding.
The more discriminative namespace is used during serialization. If an
object being serialized has no matching namespace (including the default
namespace for which the default value ""
matches all
possible classes), then a local namespace is automatically created
(with the prefix pkg
).
Constructor Summary | |
ObjectWriter()
Creates a default writer. |
Method Summary | |
void |
setIndent(java.lang.String indent)
Sets the indentation String (default two-spaces). |
void |
setNamespace(java.lang.String prefix,
java.lang.String packageName)
Maps a namespace to a Java package. |
void |
setProlog(boolean isProlog)
Indicates if the XML prolog has to be written (default true ). |
void |
write(Representable r,
java.io.File file)
Writes the specified Representable to the specified
file in XML format. |
void |
write(Representable r,
java.io.OutputStream out)
Writes the specified Representable to the given output
stream in XML format. |
void |
write(Representable r,
java.io.Writer writer)
Writes the specified Representable to the given writer
in XML format. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ObjectWriter()
Method Detail |
public void setNamespace(java.lang.String prefix, java.lang.String packageName)
setNamespace("math", "com.dautelle.math")
associates the
namespace prefix math
with the namespace name
java:com.dautelle.math
. Any class within the package
com.dautelle.math
now uses the math
prefix
(e.g. <math:Complex real='0' imaginary='1'\>).
Any previous association of the specified prefix or package is removed.
prefix
- the namespace prefix or ""
to set the default
namespace.packageName
- of the package associated to the specified prefix.
java.lang.IllegalArgumentException
- if the prefix "pkg"
if
used (reserved for local namespace declarations).public void setIndent(java.lang.String indent)
String
(default two-spaces).
indent
- the indent String
, usually some number of
spaces.public void setProlog(boolean isProlog)
true
).
isProlog
- true
if the XML prolog has to be written;
false
otherwise.public void write(Representable r, java.io.File file) throws java.io.IOException
Representable
to the specified
file in XML format. The characters are written using UTF-8 encoding.
r
- the Representable
object to format.file
- the file to write to.
java.io.IOException
- if there's any problem writing.public void write(Representable r, java.io.OutputStream out) throws java.io.IOException
Representable
to the given output
stream in XML format. The characters are written using UTF-8 encoding.
r
- the Representable
object to format.out
- the output stream to write to.
java.io.IOException
- if there's any problem writing.public void write(Representable r, java.io.Writer writer) throws java.io.IOException
Representable
to the given writer
in XML format.
Note: The encoding specified in the prolog is "UTF-16"
except for java.io.OutputStreamWriter
instances for
which the actual stream encoding is used.
r
- the Representable
object to format.writer
- the writer to write to.
java.io.IOException
- if there's any problem writing.
|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |