Package org.apache.axis.encoding
Class SerializationContext
java.lang.Object
org.apache.axis.encoding.SerializationContext
- All Implemented Interfaces:
SerializationContext
- Direct Known Subclasses:
AttributeSerializationContextImpl
,TextSerializationContext
Manage a serialization, including keeping track of namespace mappings
and element stacks.
- Author:
- Glen Daniels (gdaniels@apache.org), Rich Scheuerle invalid input: '<'scheu@us.ibm.com>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static org.apache.commons.logging.Log
protected boolean
The flag whether the XML decl should be written -
Constructor Summary
ConstructorsConstructorDescriptionSerializationContext
(Writer writer) Construct SerializationContext with associated writerSerializationContext
(Writer writer, MessageContext msgContext) Construct SerializationContext with associated writer and MessageContext -
Method Summary
Modifier and TypeMethodDescriptionattributeQName2String
(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 void
Writes the end element tag for the open element.Return the current messageGet the currently prefered xmlTypeboolean
Are we doing multirefs?get the encoding for the serializationReturns this context's encoding style.Get the MessageContext we're operating withgetPrefixForURI
(String uri) Get a prefix for a namespace URI.getPrefixForURI
(String uri, String defaultPrefix) Get a prefix for the given namespace URI.getPrefixForURI
(String uri, String defaultPrefix, boolean attribute) Get a prefix for the given namespace URI.boolean
Get whether the serialization should be pretty printed.getQNameForClass
(Class cls) Get the QName associated with the specified class.final Serializer
getSerializerForJavaType
(Class javaType) Convenience method to get the Serializer for a specific java typeGet the TypeMapping we're using.Get the TypeMappingRegistry we're using.getValueAsString
(Object value, QName xmlType, Class javaClass) boolean
Returns whether this context should be encoded or not.boolean
isPrimitive
(Object value) Indicates whether the object should be interpretted as a primitive for the purposes of multi-ref processing.void
The serialize method uses hrefs to reference all non-primitive values.qName2String
(QName qName) qName2String
(QName qName, boolean writeNS) Convert QName to a string of the form: void
registerPrefixForURI
(String prefix, String uri) Register prefix for the indicated urivoid
serialize
(QName elemQName, Attributes attributes, Object value) Serialize the indicated value as an element with the name indicated by elemQName.void
serialize
(QName elemQName, Attributes attributes, Object value, QName xmlType) Deprecated.use serialize(QName, Attributes, Object, QName, Class) insteadvoid
serialize
(QName elemQName, Attributes attributes, Object value, QName xmlType, boolean sendNull, Boolean sendType) Deprecated.use serialize(QName, Attributes, Object, QName, Boolean, Boolean) instead.void
serialize
(QName elemQName, Attributes attributes, Object value, QName xmlType, Boolean sendNull, Boolean sendType) Serialize the indicated value as an element with the name indicated by elemQName.void
Serialize the indicated value as an element with the name indicated by elemQName.void
serialize
(QName elemQName, Attributes attributes, Object value, QName xmlType, Class javaClass, Boolean sendNull, Boolean sendType) Serialize the indicated value as an element with the name indicated by elemQName.void
setDoMultiRefs
(boolean shouldDo) Set whether we are doing multirefsvoid
setEncoding
(String encoding) set the encoding for the serializationvoid
setItemQName
(QName itemQName) void
setItemType
(QName itemType) void
setPretty
(boolean pretty) Indicate whether the serialization should be pretty printed.void
setSendDecl
(boolean sendDecl) Set whether or not we should write XML declarations.setTypeAttribute
(Attributes attributes, QName type) Obtains the type attribute that should be serialized and returns the new list of Attributesvoid
setWriteXMLType
(QName type) boolean
Get whether or not to write xsi:type attributes.void
startElement
(QName qName, Attributes attributes) Writes (using the Writer) the start tag for element QName along with the indicated attributes and namespace mappings.void
writeChars
(char[] p1, int p2, int p3) Convenience operation to write out (to Writer) the characters in p1 starting at index p2 for length p3.void
Output a DOM representation to a SerializationContextvoid
writeSafeString
(String string) Convenience operation to write out (to Writer) the String properly encoded with xml entities (like invalid input: '&')void
writeString
(String string) Convenience operation to write out (to Writer) the Stringvoid
-
Field Details
-
log
protected static org.apache.commons.logging.Log log -
startOfDocument
protected boolean startOfDocumentThe flag whether the XML decl should be written
-
-
Constructor Details
-
SerializationContext
Construct SerializationContext with associated writer- Parameters:
writer
- java.io.Writer
-
SerializationContext
Construct SerializationContext with associated writer and MessageContext- Parameters:
writer
- java.io.WritermsgContext
- is the MessageContext
-
-
Method Details
-
getPretty
public boolean getPretty()Get whether the serialization should be pretty printed.- Returns:
- true/false
-
setPretty
public void setPretty(boolean pretty) Indicate whether the serialization should be pretty printed.- Parameters:
pretty
- true/false
-
getDoMultiRefs
public boolean getDoMultiRefs()Are we doing multirefs?- Returns:
- true or false
-
setDoMultiRefs
public void setDoMultiRefs(boolean shouldDo) Set whether we are doing multirefs -
setSendDecl
public void setSendDecl(boolean sendDecl) Set whether or not we should write XML declarations.- Parameters:
sendDecl
- true/false
-
shouldSendXSIType
public boolean shouldSendXSIType()Get whether or not to write xsi:type attributes.- Returns:
- true/false
-
getTypeMapping
Get the TypeMapping we're using.- Returns:
- TypeMapping or null
-
getTypeMappingRegistry
Get the TypeMappingRegistry we're using.- Returns:
- TypeMapping or null
-
getPrefixForURI
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". - Parameters:
uri
- is the namespace uri- Returns:
- prefix
-
getPrefixForURI
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
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" -
registerPrefixForURI
Register prefix for the indicated uri- Parameters:
prefix
-uri
- is the namespace uri
-
getCurrentMessage
Return the current message -
getMessageContext
Get the MessageContext we're operating with -
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.- Returns:
- a
String
value
-
isEncoded
public boolean isEncoded()Returns whether this context should be encoded or not.- Returns:
- a
boolean
value
-
qName2String
Convert QName to a string of the form: - Parameters:
qName
-- Returns:
- prefixed qname representation for serialization.
-
qName2String
-
attributeQName2String
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 - Parameters:
qName
- QName- Returns:
- prefixed qname representation for serialization.
-
getQNameForClass
Get the QName associated with the specified class.- Parameters:
cls
- Class of an object requiring serialization.- Returns:
- appropriate QName associated with the class.
-
isPrimitive
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.- Parameters:
value
- to be serialized- Returns:
- true/false
-
serialize
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.- Parameters:
elemQName
- is the QName of the elementattributes
- are additional attributesvalue
- is the object to serialize- Throws:
IOException
-
serialize
public void serialize(QName elemQName, Attributes attributes, Object value, QName xmlType) throws IOException Deprecated.use serialize(QName, Attributes, Object, QName, Class) insteadSerialize 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.- Parameters:
elemQName
- is the QName of the elementattributes
- are additional attributesvalue
- is the object to serializexmlType
- is the qname of the type or null.- Throws:
IOException
-
serialize
public void serialize(QName elemQName, Attributes attributes, Object value, QName xmlType, Class javaType) 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.- Parameters:
elemQName
- is the QName of the elementattributes
- are additional attributesvalue
- is the object to serializexmlType
- is the qname of the type or null.javaType
- is the java type of the value- Throws:
IOException
-
serialize
public void serialize(QName elemQName, Attributes attributes, Object value, QName xmlType, boolean sendNull, Boolean sendType) throws IOException Deprecated.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).- Parameters:
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.- Throws:
IOException
-
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).- Parameters:
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.- Throws:
IOException
-
serialize
public void serialize(QName elemQName, Attributes attributes, Object value, QName xmlType, Class javaClass, 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).- Parameters:
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.javaType
- is the java type of the value- Throws:
IOException
-
outputMultiRefs
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.- Throws:
IOException
-
writeXMLDeclaration
- Throws:
IOException
-
startElement
Writes (using the Writer) the start tag for element QName along with the indicated attributes and namespace mappings.- Parameters:
qName
- is the name of the elementattributes
- are the attributes to write- Throws:
IOException
-
endElement
Writes the end element tag for the open element.- Throws:
IOException
-
writeChars
Convenience operation to write out (to Writer) the characters in p1 starting at index p2 for length p3.- Parameters:
p1
- character array to writep2
- starting index in arrayp3
- length to write- Throws:
IOException
-
writeString
Convenience operation to write out (to Writer) the String- Parameters:
string
- is the String to write.- Throws:
IOException
-
writeSafeString
Convenience operation to write out (to Writer) the String properly encoded with xml entities (like invalid input: '&')- Parameters:
string
- is the String to write.- Throws:
IOException
-
writeDOMElement
Output a DOM representation to a SerializationContext- Parameters:
el
- is a DOM Element- Throws:
IOException
-
getSerializerForJavaType
Convenience method to get the Serializer for a specific java type- Parameters:
javaType
- is Class for a type to serialize- Returns:
- Serializer
-
setTypeAttribute
Obtains the type attribute that should be serialized and returns the new list of Attributes- Parameters:
attributes
- of the qnametype
- is the qname of the type- Returns:
- new list of Attributes
-
getCurrentXMLType
Get the currently prefered xmlType- Returns:
- QName of xmlType or null
-
getValueAsString
- Throws:
IOException
-
setWriteXMLType
-
getEncoder
-
getEncoding
get the encoding for the serialization- Returns:
-
setEncoding
set the encoding for the serialization -
getItemQName
-
setItemQName
-
getItemType
-
setItemType
-