Manage a serialization, including keeping track of namespace mappings
and element stacks.
attributeQName2String
public String attributeQName2String(QName qName)
Convert attribute QName to a string of the form
:
There are slightly different rules for attributes:
- There is no default namespace
- any attribute in a namespace must have a prefix
- prefixed qname representation for serialization.
endElement
public void endElement()
throws IOException
Writes the end element tag for the open element.
getCurrentMessage
public Message getCurrentMessage()
Return the current message
getCurrentXMLType
public QName getCurrentXMLType()
Get the currently prefered xmlType
getDoMultiRefs
public boolean getDoMultiRefs()
Are we doing multirefs?
getEncoding
public String getEncoding()
get the encoding for the serialization
getEncodingStyle
public String getEncodingStyle()
Returns this context's encoding style. If we've got a message
context then we'll get the style from that; otherwise we'll
return a default.
getItemQName
public QName getItemQName()
getItemType
public QName getItemType()
getMessageContext
public MessageContext getMessageContext()
Get the MessageContext we're operating with
getPrefixForURI
public String getPrefixForURI(String uri)
Get a prefix for a namespace URI. This method will ALWAYS
return a valid prefix - if the given URI is already mapped in this
serialization, we return the previous prefix. If it is not mapped,
we will add a new mapping and return a generated prefix of the form
"ns".
uri
- is the namespace uri
getPrefixForURI
public String getPrefixForURI(String uri,
String defaultPrefix)
Get a prefix for the given namespace URI. If one has already been
defined in this serialization, use that. Otherwise, map the passed
default prefix to the URI, and return that. If a null default prefix
is passed, use one of the form "ns"
getPrefixForURI
public String getPrefixForURI(String uri,
String defaultPrefix,
boolean attribute)
Get a prefix for the given namespace URI. If one has already been
defined in this serialization, use that. Otherwise, map the passed
default prefix to the URI, and return that. If a null default prefix
is passed, use one of the form "ns"
getPretty
public boolean getPretty()
Get whether the serialization should be pretty printed.
getQNameForClass
public QName getQNameForClass(Class cls)
Get the QName associated with the specified class.
cls
- Class of an object requiring serialization.
- appropriate QName associated with the class.
getSerializerForJavaType
public final Serializer getSerializerForJavaType(Class javaType)
Convenience method to get the Serializer for a specific
java type
javaType
- is Class for a type to serialize
getTypeMapping
public TypeMapping getTypeMapping()
Get the TypeMapping we're using.
getTypeMappingRegistry
public TypeMappingRegistry getTypeMappingRegistry()
Get the TypeMappingRegistry we're using.
getValueAsString
public String getValueAsString(Object value,
QName xmlType)
throws IOException
isEncoded
public boolean isEncoded()
Returns whether this context should be encoded or not.
isPrimitive
public boolean isPrimitive(Object value)
Indicates whether the object should be interpretted as a primitive
for the purposes of multi-ref processing. A primitive value
is serialized directly instead of using id/href pairs. Thus
primitive serialization/deserialization is slightly faster.
outputMultiRefs
public void outputMultiRefs()
throws IOException
The serialize method uses hrefs to reference all non-primitive
values. These values are stored and serialized by calling
outputMultiRefs after the serialize method completes.
qName2String
public String qName2String(QName qName)
qName2String
public String qName2String(QName qName,
boolean writeNS)
Convert QName to a string of the form
:
- prefixed qname representation for serialization.
registerPrefixForURI
public void registerPrefixForURI(String prefix,
String uri)
Register prefix for the indicated uri
prefix
- uri
- is the namespace uri
serialize
public void serialize(QName elemQName,
Attributes attributes,
Object value)
throws IOException
Serialize the indicated value as an element with the name
indicated by elemQName.
The attributes are additional attribute to be serialized on the element.
The value is the object being serialized. (It may be serialized
directly or serialized as an mult-ref'd item)
The value is an Object, which may be a wrapped primitive, the
javaType is the actual unwrapped object type.
xsi:type is set by using the javaType to
find an appopriate xmlType from the TypeMappingRegistry.
Null values and the xsi:type flag will be sent or not depending
on previous configuration of this SerializationContext.
elemQName
- is the QName of the elementattributes
- are additional attributesvalue
- is the object to serialize
serialize
public void serialize(QName elemQName,
Attributes attributes,
Object value,
QName xmlType)
throws IOException
Serialize the indicated value as an element with the name
indicated by elemQName.
The attributes are additional attribute to be serialized on the element.
The value is the object being serialized. (It may be serialized
directly or serialized as an mult-ref'd item)
The value is an Object, which may be a wrapped primitive, the
javaType is the actual unwrapped object type.
The xmlType is the QName of the type that is used to set
xsi:type. If not specified, xsi:type is set by using the javaType to
find an appopriate xmlType from the TypeMappingRegistry.
Null values and the xsi:type flag will be sent or not depending
on previous configuration of this SerializationContext.
elemQName
- is the QName of the elementattributes
- are additional attributesvalue
- is the object to serialize
serialize
public void serialize(QName elemQName,
Attributes attributes,
Object value,
QName xmlType,
Boolean sendNull,
Boolean sendType)
throws IOException
Serialize the indicated value as an element with the name
indicated by elemQName.
The attributes are additional attribute to be serialized on the element.
The value is the object being serialized. (It may be serialized
directly or serialized as an mult-ref'd item)
The value is an Object, which may be a wrapped primitive.
The xmlType (if specified) is the QName of the type that is used to set
xsi:type.
The sendNull flag indicates whether to end an element with an xsi:nil="true" attribute for null
variables (if Boolean.TRUE), or nothing (if Boolean.FALSE).
The sendType flag indicates whether the xsi:type flag should be sent
(default is true).
elemQName
- is the QName of the elementattributes
- are additional attributesvalue
- is the object to serializexmlType
- is the qname of the type or null.sendNull
- determines whether to send null values.sendType
- determines whether to set xsi:type attribute.
serialize
public void serialize(QName elemQName,
Attributes attributes,
Object value,
QName xmlType,
boolean sendNull,
Boolean sendType)
throws IOException
use serialize(QName, Attributes, Object, QName,
Boolean, Boolean) instead.
Serialize the indicated value as an element with the name
indicated by elemQName.
The attributes are additional attribute to be serialized on the element.
The value is the object being serialized. (It may be serialized
directly or serialized as an mult-ref'd item)
The value is an Object, which may be a wrapped primitive.
The xmlType (if specified) is the QName of the type that is used to set
xsi:type.
The sendNull flag indicates whether null values should be sent over the
wire (default is to send such values with xsi:nil="true").
The sendType flag indicates whether the xsi:type flag should be sent
(default is true).
elemQName
- is the QName of the elementattributes
- are additional attributesvalue
- is the object to serializexmlType
- is the qname of the type or null.sendNull
- determines whether to send null values.sendType
- determines whether to set xsi:type attribute.
setDoMultiRefs
public void setDoMultiRefs(boolean shouldDo)
Set whether we are doing multirefs
setEncoding
public void setEncoding(String encoding)
set the encoding for the serialization
setItemQName
public void setItemQName(QName itemQName)
setItemType
public void setItemType(QName itemType)
setPretty
public void setPretty(boolean pretty)
Indicate whether the serialization should be pretty printed.
setSendDecl
public void setSendDecl(boolean sendDecl)
Set whether or not we should write XML declarations.
setTypeAttribute
public Attributes setTypeAttribute(Attributes attributes,
QName type)
Obtains the type attribute that should be serialized and returns the new list of Attributes
attributes
- of the qnametype
- is the qname of the type
setWriteXMLType
public void setWriteXMLType(QName type)
shouldSendXSIType
public boolean shouldSendXSIType()
Get whether or not to write xsi:type attributes.
startElement
public void startElement(QName qName,
Attributes attributes)
throws IOException
Writes (using the Writer) the start tag for element QName along with the
indicated attributes and namespace mappings.
qName
- is the name of the elementattributes
- are the attributes to write
writeChars
public void writeChars(char[] p1,
int p2,
int p3)
throws IOException
Convenience operation to write out (to Writer) the characters
in p1 starting at index p2 for length p3.
p1
- character array to writep2
- starting index in arrayp3
- length to write
writeDOMElement
public void writeDOMElement(Element el)
throws IOException
Output a DOM representation to a SerializationContext
writeSafeString
public void writeSafeString(String string)
throws IOException
Convenience operation to write out (to Writer) the String
properly encoded with xml entities (like &)
string
- is the String to write.
writeString
public void writeString(String string)
throws IOException
Convenience operation to write out (to Writer) the String
string
- is the String to write.
writeXMLDeclaration
public void writeXMLDeclaration()
throws IOException