|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbiz.c24.io.api.presentation.CDOStreamWriter
public class CDOStreamWriter
The XMLStreamWriter implementation for an Complex Data Object.
Provides construction of aComplex Data Object
based on
StAX events. It does not perform any other validation checking on input
beside that specified by model binding rules. I.e. its behaviuor is controlled
by the JSR-173
specification as well as by the data model for an expected
Complex Data Object
. That model
is specified by the element
provided during
instantiation. On finish
the result
will be represented as constructed
Complex Data Object
. Before the
finish
the result is undefined and can't be used.
If used with Java 1.5 or 1.4, then please ensure that the JSR-173 API library
added to your classpath (jsr173_api.jar).
Note. Internal parts of this built up on the "Thread Local pattern".
So, between the {#writeStartDocument start document} and
end document
it should not be used by any other threads
.
The typical usage scenarion is following:
That will produce theElement element = ... CDOStreamWriter writer = new CDOStreamWriter(element); writer.writeStartDocument(); // write root element <test> writer.writeStartElement("test"); writer.writeDefaultNamespace("http://www.c24.biz/IO/StAXSupport"); // write nested element <a> writer.writeStartElement("a"); // within attribute att=&qout;value&qout; writer.writeAttribute("att", "value"); // and textual content 'data' writer.writeCharacters("data") // write closing tag for an element <a> writer.writeEndElement(); ... // other stuff that should be written ... // write closing tag for a root element <test> writer.writeEndElement(); writer.writeEndDocument(); // optional writer.flush() // getting the expected CDO ComplexDataObject cdo = writer.getResult();
Complex
Data Object
having following XML representation:
Constructor Summary | |
---|---|
CDOStreamWriter(Element element)
Constructor with expected object model. |
Method Summary | |
---|---|
void |
close()
Closes this writer and free any resources associated with it. |
void |
flush()
Writes any cached data to the underlying output mechanism. |
NamespaceContext |
getNamespaceContext()
Returns the current namespace context. |
String |
getPrefix(String uri)
Gets the prefix the namespece URI is bound to. |
Object |
getProperty(String name)
Get the value of a feature/property from the underlying implementation. |
ComplexDataObject |
getResult()
Returns the result of writing. |
void |
setDefaultNamespace(String uri)
Binds a URI to the default namespace. |
void |
setNamespaceContext(NamespaceContext context)
Sets the current namespace context for prefix and namespace URI bindings. |
void |
setPrefix(String prefix,
String uri)
Sets the prefix the namespace URI is bound to. |
void |
writeAttribute(String name,
String value)
Writes an attribute with local name only. |
void |
writeAttribute(String uri,
String name,
String value)
Writes an attribute without prefix into current context. |
void |
writeAttribute(String prefix,
String uri,
String name,
String value)
Writes an attribute into current context. |
void |
writeCData(String data)
Writes a CDATA section. |
void |
writeCharacters(char[] text,
int start,
int len)
Write characters to the current context. |
void |
writeCharacters(String text)
Write text to the current context. |
void |
writeComment(String data)
Writes a comment with the data enclosed. |
void |
writeDefaultNamespace(String uri)
Writes the default namespace. |
void |
writeDTD(String dtd)
Write a DTD section. |
void |
writeEmptyElement(String name)
Writes an empty element tag with local name only. |
void |
writeEmptyElement(String uri,
String name)
Writes an empty element tag without prefix. |
void |
writeEmptyElement(String prefix,
String name,
String uri)
Writes an empty element tag. |
void |
writeEndDocument()
Closes any start tags and writes corresponding end tags. |
void |
writeEndElement()
Writes an end tag. |
void |
writeEntityRef(String name)
Writes an entity reference. |
void |
writeNamespace(String prefix,
String uri)
Writes a namespace. |
void |
writeProcessingInstruction(String target)
Writes a processing instruction without data. |
void |
writeProcessingInstruction(String target,
String data)
Writes a processing instruction. |
void |
writeStartDocument()
Write the default XML Declaration. |
void |
writeStartDocument(String version)
Write the XML Declaration with specified version. |
void |
writeStartDocument(String encoding,
String version)
Write the XML Declaration with specified version and encoding. |
void |
writeStartElement(String name)
Writes a start tag with local name only. |
void |
writeStartElement(String uri,
String name)
Writes a start tag without prefix. |
void |
writeStartElement(String prefix,
String name,
String uri)
Writes a start tag. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CDOStreamWriter(Element element)
CDO
writer
with specified element model
which describes the expected Complex Data Object
.
The provided element may be null. This means that
result
has not a model and consequently may contain
an any contents (i.e. an analog of XML's
element
- the element instance that described the expected
Complex Data Object, may be null.Method Detail |
---|
public void writeStartDocument() throws javax.xml.stream.XMLStreamException
writeStartDocument
in interface javax.xml.stream.XMLStreamWriter
javax.xml.stream.XMLStreamException
- if process failed.public void writeStartDocument(String version) throws javax.xml.stream.XMLStreamException
default XML
Declaration writing
.
writeStartDocument
in interface javax.xml.stream.XMLStreamWriter
version
- version of the xml document.
javax.xml.stream.XMLStreamException
writeStartDocument()
public void writeStartDocument(String encoding, String version) throws javax.xml.stream.XMLStreamException
default XML
Declaration writing
.
writeStartDocument
in interface javax.xml.stream.XMLStreamWriter
encoding
- encoding of the xml declarationversion
- version of the xml document
javax.xml.stream.XMLStreamException
writeStartDocument(String)
public void writeProcessingInstruction(String target, String data) throws javax.xml.stream.XMLStreamException
writeProcessingInstruction
in interface javax.xml.stream.XMLStreamWriter
target
- the target of the processing instruction, may not be
null.data
- the data contained in the processing instruction.
javax.xml.stream.XMLStreamException
- if process failed.
IllegalArgumentException
- if provided target or
data is null.public void writeProcessingInstruction(String target) throws javax.xml.stream.XMLStreamException
writeProcessingInstruction
in interface javax.xml.stream.XMLStreamWriter
target
- the target of the processing instruction, may not be
null.
javax.xml.stream.XMLStreamException
- if process failed.
IllegalArgumentException
- if provided target or
data is null.public void writeComment(String data) throws javax.xml.stream.XMLStreamException
writeComment
in interface javax.xml.stream.XMLStreamWriter
data
- the data contained in the comment, may be null.
javax.xml.stream.XMLStreamException
public void writeStartElement(String prefix, String name, String uri) throws javax.xml.stream.XMLStreamException
writes end tag
will cause
the closing current context.
writeStartElement
in interface javax.xml.stream.XMLStreamWriter
name
- local name of the tag, may not be null.prefix
- the prefix of the tag, may not be null.uri
- the namespace URI to bind the prefix to, may not be
null.
javax.xml.stream.XMLStreamException
- if process failed.
IllegalArgumentException
- if any arguments is null.public void writeStartElement(String uri, String name) throws javax.xml.stream.XMLStreamException
writeStartElement(String, String, String)
with empty (means
default) prefix.
writeStartElement
in interface javax.xml.stream.XMLStreamWriter
uri
- the namespace URI of the prefix to use, may not be
null.name
- local name of the tag, may not be null.
javax.xml.stream.XMLStreamException
- if the namespace URI has not
been bound to a prefix.
IllegalArgumentException
- if any arguments is null.public void writeStartElement(String name) throws javax.xml.stream.XMLStreamException
writeStartElement(String, String)
with empty namespace URI.
writeStartElement
in interface javax.xml.stream.XMLStreamWriter
name
- local name of the tag, may not be null.
javax.xml.stream.XMLStreamException
- if process failed.
IllegalArgumentException
- if name is null.public void writeEmptyElement(String prefix, String name, String uri) throws javax.xml.stream.XMLStreamException
writeStartElement(String, String, String)
and
writeEndElement()
.
writeEmptyElement
in interface javax.xml.stream.XMLStreamWriter
prefix
- the prefix of the tag, may not be null.name
- local name of the tag, may not be null.uri
- the namespace URI to bind the tag to, may not be
null.
javax.xml.stream.XMLStreamException
- if process failed.
IllegalArgumentException
- if any arguments is null.public void writeEmptyElement(String uri, String name) throws javax.xml.stream.XMLStreamException
writeEmptyElement(String, String, String)
with empty prefix.
writeEmptyElement
in interface javax.xml.stream.XMLStreamWriter
uri
- the namespace URI to bind the tag to, may not be
null.name
- local name of the tag, may not be null.
javax.xml.stream.XMLStreamException
- if the namespace URI has not
been bound to a prefix.writeEmptyElement(String, String, String)
public void writeEmptyElement(String name) throws javax.xml.stream.XMLStreamException
writeEmptyElement(String, String)
with empty namespace URI.
writeEmptyElement
in interface javax.xml.stream.XMLStreamWriter
name
- local name of the tag, may not be null.
javax.xml.stream.XMLStreamException
- if the namespace URI has not
been bound to a prefix.writeEmptyElement(String, String)
public void writeEndElement() throws javax.xml.stream.XMLStreamException
start tag writer
.
writeEndElement
in interface javax.xml.stream.XMLStreamWriter
javax.xml.stream.XMLStreamException
- if process failed.public void writeEndDocument() throws javax.xml.stream.XMLStreamException
writeEndDocument
in interface javax.xml.stream.XMLStreamWriter
javax.xml.stream.XMLStreamException
- if process failed.public void close() throws javax.xml.stream.XMLStreamException
close
in interface javax.xml.stream.XMLStreamWriter
javax.xml.stream.XMLStreamException
- never happend, preserves the stream writer
contract.public void flush() throws javax.xml.stream.XMLStreamException
flush
in interface javax.xml.stream.XMLStreamWriter
javax.xml.stream.XMLStreamException
- if process failed.public void writeAttribute(String prefix, String uri, String name, String value) throws javax.xml.stream.XMLStreamException
writeAttribute
in interface javax.xml.stream.XMLStreamWriter
prefix
- the prefix for this attributeuri
- the namespace URI of the prefix for this attribute.name
- the local name of the attribute.value
- the value of the attribute.
IllegalStateException
- if the current state does not allow
attribute writing.
javax.xml.stream.XMLStreamException
- if the namespace URI has not
been bound to a prefix.public void writeAttribute(String uri, String name, String value) throws javax.xml.stream.XMLStreamException
writeAttribute(String, String, String, String)
with an empty
prefix.
writeAttribute
in interface javax.xml.stream.XMLStreamWriter
uri
- the namespace URI of the prefix for this attribute.name
- the local name of the attribute.value
- the value of the attribute.
IllegalStateException
- if the current state does not allow
attribute writing.
javax.xml.stream.XMLStreamException
- if the namespace URI has not
been bound to a prefix.public void writeAttribute(String name, String value) throws javax.xml.stream.XMLStreamException
writeAttribute(String, String, String)
with an empty namespace
URI.
writeAttribute
in interface javax.xml.stream.XMLStreamWriter
name
- the local name of the attributevalue
- the value of the attribute
IllegalStateException
- if the current state does not allow
attribute writing.
javax.xml.stream.XMLStreamException
- if the namespace URI has not
been bound to a prefix.public void writeDTD(String dtd) throws javax.xml.stream.XMLStreamException
writeDTD
in interface javax.xml.stream.XMLStreamWriter
dtd
- the DTD to be written.
javax.xml.stream.XMLStreamException
- if proces failed.public void writeEntityRef(String name) throws javax.xml.stream.XMLStreamException
writeEntityRef
in interface javax.xml.stream.XMLStreamWriter
name
- the name of the entity.
javax.xml.stream.XMLStreamException
- if process failed.public void writeCharacters(String text) throws javax.xml.stream.XMLStreamException
writeCharacters
in interface javax.xml.stream.XMLStreamWriter
text
- the value to write.
javax.xml.stream.XMLStreamException
- if process failed.public void writeCharacters(char[] text, int start, int len) throws javax.xml.stream.XMLStreamException
writeCharacters
in interface javax.xml.stream.XMLStreamWriter
text
- the characters to write.start
- the starting position in the characters.len
- the number of characters to write.
javax.xml.stream.XMLStreamException
- if process failed.public void writeCData(String data) throws javax.xml.stream.XMLStreamException
writeCData
in interface javax.xml.stream.XMLStreamWriter
data
- the data contained in the CDATA section, may not be
null
javax.xml.stream.XMLStreamException
- if process failed.public String getPrefix(String uri) throws javax.xml.stream.XMLStreamException
getPrefix
in interface javax.xml.stream.XMLStreamWriter
javax.xml.stream.XMLStreamException
- if process failed.public void setPrefix(String prefix, String uri) throws javax.xml.stream.XMLStreamException
writeNamespace(String, String)
.
setPrefix
in interface javax.xml.stream.XMLStreamWriter
prefix
- the prefix to bind to the namespace URI, may not be
null.uri
- the namespace URI to bind to the prefix, may be null.
javax.xml.stream.XMLStreamException
- if process failed.public void writeNamespace(String prefix, String uri) throws javax.xml.stream.XMLStreamException
Complex Data Object
. If the
prefix argument to this method is the empty string,
"xmlns"
or null
this method will delegate call to the
writeDefaultNamespace
.
writeNamespace
in interface javax.xml.stream.XMLStreamWriter
prefix
- the prefix to bind this namespace to.uri
- the URI to bind the prefix to.
IllegalStateException
- if the current state does not allow
namespace writing.
javax.xml.stream.XMLStreamException
- if process failed.public void writeDefaultNamespace(String uri) throws javax.xml.stream.XMLStreamException
Complex Data Object
.
In fact, delegates the call to the
writeNamespace(String, String)
with an empty prefix.
writeDefaultNamespace
in interface javax.xml.stream.XMLStreamWriter
uri
- the namespace URI to bind the default namespace to.
IllegalStateException
- if the current state does not allow
namespace writing.
javax.xml.stream.XMLStreamException
- if process failed.public void setDefaultNamespace(String uri) throws javax.xml.stream.XMLStreamException
writeDefaultNamespace(String)
.
setDefaultNamespace
in interface javax.xml.stream.XMLStreamWriter
uri
- the uri to bind to the default namespace, may be
null.
javax.xml.stream.XMLStreamException
- if process failed.public void setNamespaceContext(NamespaceContext context) throws javax.xml.stream.XMLStreamException
setPrefix(String, String)
and
setDefaultNamespace(String)
will bind namespaces using the
context passed to the method as the root context for resolving
namespaces. This method may only be called once at the start of the
document. It does not cause the namespaces to be declared.
If a namespace URI to prefix mapping is found in the namespace context it
is treated as declared and the prefix may be used by the writer.
setNamespaceContext
in interface javax.xml.stream.XMLStreamWriter
context
- the namespace context to use for this writer, may not
be null.
javax.xml.stream.XMLStreamException
- if process failed.public NamespaceContext getNamespaceContext()
getNamespaceContext
in interface javax.xml.stream.XMLStreamWriter
setNamespaceContext(javax.xml.namespace.NamespaceContext)
public Object getProperty(String name) throws IllegalArgumentException
getProperty
in interface javax.xml.stream.XMLStreamWriter
name
- The name of the property, may not be null.
IllegalArgumentException
- if the property is not supported.
NullPointerException
- if the name is null.public ComplexDataObject getResult()
Complex Data Object
that was built during writer using.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |