| java.lang.Object com.sun.xml.bind.v2.runtime.Coordinator com.sun.xml.bind.v2.runtime.XMLSerializer
XMLSerializer | final public class XMLSerializer extends Coordinator (Code) | | Receives XML serialization event and writes to
XmlOutput .
This object coordinates the overall marshalling efforts across different
content-tree objects and different target formats.
The following CFG gives the proper sequence of method invocation.
MARSHALLING := ELEMENT
ELEMENT := "startElement" NSDECL* "endNamespaceDecls"
ATTRIBUTE* "endAttributes" BODY "endElement"
NSDECL := "declareNamespace"
ATTRIBUTE := "attribute"
ATTVALUES := "text"*
BODY := ( "text" | ELEMENT )*
A marshalling of one element consists of two stages. The first stage is
for marshalling attributes and collecting namespace declarations.
The second stage is for marshalling characters/child elements of that element.
Observe that multiple invocation of "text" is allowed.
Also observe that the namespace declarations are allowed only between
"startElement" and "endAttributes".
Exceptions in marshaller
IOException ,
SAXException , and
XMLStreamException are thrown from
XmlOutput . They are always considered fatal, and
therefore caught only by
MarshallerImpl .
AccessorException can be thrown when an access to a property/field
fails, and this is considered as a recoverable error, so it's caught everywhere.
author: Kohsuke Kawaguchi |
Method Summary | |
public void | addInscopeBinding(String nsUri, String prefix) This method can be called after
XMLSerializer.startDocument is called
but before the marshalling begins, to set the currently in-scope namespace
bindings. | public void | attWildcardAsAttributes(Map<QName, String> attributes, String fieldName) | public void | attWildcardAsURIs(Map<QName, String> attributes, String fieldName) | public void | attribute(String uri, String local, String value) | public void | attribute(Name name, CharSequence value) | public void | childAsRoot(Object obj) | final public void | childAsSoleContent(Object child, String fieldName) The equivalent of:
childAsURIs(child, fieldName);
endNamespaceDecls();
childAsAttributes(child, fieldName);
endAttributes();
childAsBody(child, fieldName);
This produces the given child object as the sole content of
an element. | final public void | childAsXsiType(Object child, String fieldName, JaxBeanInfo expected) This method is called when a type child object is found.
This method produces events of the following form:
NSDECL* "endNamespaceDecls" ATTRIBUTE* "endAttributes" BODY
optionally including @xsi:type if necessary.
Parameters: child - Object to be marshalled. | public void | close() | public void | endAttributes() Switches to the "marshal child texts/elements" mode. | public void | endDocument() | public void | endElement() Ends marshalling of an element. | public void | endNamespaceDecls(Object innerPeer) | public void | errorMissingId(Object obj) Called when a referenced object doesn't have an ID. | public Base64Data | getCachedBase64DataInstance() Gets the cached instance of
Base64Data . | public ValidationEventLocator | getCurrentLocation(String fieldName) | public Transformer | getIdentityTransformer() | public boolean | getInlineBinaryFlag() | public static XMLSerializer | getInstance() When called from within the realm of the marshaller, this method
returns the current
XMLSerializer in charge. | protected ValidationEventLocator | getLocation() | public NamespaceContext2 | getNamespaceContext() | public boolean | getObjectIdentityCycleDetection() | public QName | getSchemaType() | public String | getXMIMEContentType() Gets the MIME type with which the binary content shall be printed. | public boolean | handleError(Exception e) | public boolean | handleError(Exception e, Object source, String fieldName) | public boolean | handleEvent(ValidationEvent event) | public void | leafElement(Name tagName, String data, String fieldName) | public void | leafElement(Name tagName, Pcdata data, String fieldName) | public void | leafElement(Name tagName, int data, String fieldName) | public String | onID(Object owner, String value) | public String | onIDREF(Object obj) | void | reconcileID() | public void | reportError(ValidationEvent ve) | final public void | reportError(String fieldName, Throwable t) Report an error found as an exception. | public MimeType | setExpectedMimeType(MimeType expectedMimeType) This method is used by
MimeTypedTransducer to set the expected MIME type
for the encapsulated
Transducer . | public boolean | setInlineBinaryFlag(boolean value) | public void | setObjectIdentityCycleDetection(boolean val) | public void | setPrefixMapper(NamespacePrefixMapper prefixMapper) | public QName | setSchemaType(QName st) | public void | startDocument(XmlOutput out, boolean fragment, String schemaLocation, String noNsSchemaLocation) Reset this object to write to the specified output. | public void | startElement(Name tagName, Object outerPeer) | public void | startElement(String nsUri, String localName, String preferredPrefix, Object outerPeer) | public void | startElementForce(String nsUri, String localName, String forcedPrefix, Object outerPeer) Variation of
XMLSerializer.startElement(String,String,String,Object) that forces
a specific prefix. | public void | text(String text, String fieldName) Marshalls text.
This method can be called after the
XMLSerializer.endAttributes() method to marshal texts inside elements.
If the method is called more than once, those texts are considered
as separated by whitespaces. | public void | text(Pcdata text, String fieldName) The
XMLSerializer.text(String,String) method that takes
Pcdata . | public void | writeDom(E element, DomHandler<E, ?> domHandler, Object parentBean, String fieldName) | final public void | writeXsiNilTrue() |
knownUri2prefixIndexMap | final public int[] knownUri2prefixIndexMap(Code) | | |
addInscopeBinding | public void addInscopeBinding(String nsUri, String prefix)(Code) | | This method can be called after
XMLSerializer.startDocument is called
but before the marshalling begins, to set the currently in-scope namespace
bindings.
This method is useful to avoid redundant namespace declarations when
the marshalling is producing a sub-document.
|
childAsSoleContent | final public void childAsSoleContent(Object child, String fieldName) throws SAXException, IOException, XMLStreamException(Code) | | The equivalent of:
childAsURIs(child, fieldName);
endNamespaceDecls();
childAsAttributes(child, fieldName);
endAttributes();
childAsBody(child, fieldName);
This produces the given child object as the sole content of
an element.
Used to reduce the code size in the generated marshaller.
|
childAsXsiType | final public void childAsXsiType(Object child, String fieldName, JaxBeanInfo expected) throws SAXException, IOException, XMLStreamException(Code) | | This method is called when a type child object is found.
This method produces events of the following form:
NSDECL* "endNamespaceDecls" ATTRIBUTE* "endAttributes" BODY
optionally including @xsi:type if necessary.
Parameters: child - Object to be marshalled. The JaxBeanInfo forthis object must return a type name. Parameters: expected - Expected type of the object. Parameters: fieldName - property name of the parent objeect from which 'o' comes.Used as a part of the error message in case anything goes wrongwith 'o'. |
close | public void close()(Code) | | |
errorMissingId | public void errorMissingId(Object obj) throws SAXException(Code) | | Called when a referenced object doesn't have an ID.
|
getInlineBinaryFlag | public boolean getInlineBinaryFlag()(Code) | | |
getInstance | public static XMLSerializer getInstance()(Code) | | When called from within the realm of the marshaller, this method
returns the current
XMLSerializer in charge.
|
getObjectIdentityCycleDetection | public boolean getObjectIdentityCycleDetection()(Code) | | |
reportError | final public void reportError(String fieldName, Throwable t) throws SAXException(Code) | | Report an error found as an exception.
Parameters: fieldName - the name of the property being processed when an error is found. |
setInlineBinaryFlag | public boolean setInlineBinaryFlag(boolean value)(Code) | | |
setObjectIdentityCycleDetection | public void setObjectIdentityCycleDetection(boolean val)(Code) | | |
startDocument | public void startDocument(XmlOutput out, boolean fragment, String schemaLocation, String noNsSchemaLocation) throws IOException, SAXException, XMLStreamException(Code) | | Reset this object to write to the specified output.
Parameters: schemaLocation - if non-null, this value is printed on the root element as xsi:schemaLocation Parameters: noNsSchemaLocation - Similar to 'schemaLocation' but this one works for xsi:noNamespaceSchemaLocation |
text | public void text(String text, String fieldName) throws SAXException, IOException, XMLStreamException(Code) | | Marshalls text.
This method can be called after the
XMLSerializer.endAttributes() method to marshal texts inside elements.
If the method is called more than once, those texts are considered
as separated by whitespaces. For example,
c.startElement("","foo");
c.endAttributes();
c.text("abc");
c.text("def");
c.startElement("","bar");
c.endAttributes();
c.endElement();
c.text("ghi");
c.endElement();
will generate <foo>abc def<bar/>ghi</foo> .
|
writeXsiNilTrue | final public void writeXsiNilTrue() throws SAXException, IOException, XMLStreamException(Code) | | Short for the following call sequence:
getNamespaceContext().declareNamespace(WellKnownNamespace.XML_SCHEMA_INSTANCE,"xsi",true);
endNamespaceDecls();
attribute(WellKnownNamespace.XML_SCHEMA_INSTANCE,"nil","true");
endAttributes();
|
|
|