站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss 4.0.1 sp1 jaxrpc API Documentation 英文版文档

SerializationContextImpl (JAXRPC API) - JBoss 4.0.1 sp1 jaxrpc API Documentation 英文版文档


org.apache.axis.encoding
Class SerializationContextImpl

java.lang.Object
  extended byorg.apache.axis.encoding.SerializationContextImpl
All Implemented Interfaces:
SerializationContext, javax.xml.rpc.encoding.SerializationContext
Direct Known Subclasses:
AttributeSerializationContextImpl

public class SerializationContextImpl
extends Object
implements SerializationContext

Manage a serialization, including keeping track of namespace mappings and element stacks.

Author:
Glen Daniels (gdaniels@macromedia.com), Rich Scheuerle

Constructor Summary
SerializationContextImpl(Writer writer)
          Construct SerializationContextImpl with associated writer
SerializationContextImpl(Writer writer, MessageContext msgContext)
          Construct SerializationContextImpl with associated writer and MessageContext
 
Method Summary
 String attributeQName2String(javax.xml.namespace.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 endDocument()
          Output anything in the end.
 void endElement()
          Writes the end element tag for the open element.
 Message getCurrentMessage()
          Return the current message
 javax.xml.namespace.QName getCurrentXMLType()
          Get the currently prefered xmlType
 boolean getDoMultiRefs()
          Are we doing multirefs?
 Stack getElementStack()
          Get the stack of element qnames.
 MessageContext getMessageContext()
          Get the MessageContext we're operating with
 String getPrefixForURI(String uri)
          Get a prefix for a namespace URI.
 String getPrefixForURI(String uri, String defaultPrefix)
          Get a prefix for the given namespace URI.
 String getPrefixForURI(String uri, String defaultPrefix, boolean attribute)
          Get a prefix for the given namespace URI.
 boolean getPretty()
          Get whether the serialization should be pretty printed.
 javax.xml.namespace.QName getQNameForClass(Class cls)
          Get the QName associated with the specified class.
 Serializer getSerializerForJavaType(Class javaType)
          Convenience method to get the Serializer for a specific java type
 TypeMapping getTypeMapping()
          Get the TypeMapping we're using.
 TypeMappingRegistry getTypeMappingRegistry()
          Get the TypeMappingRegistry we're using.
 String getValueAsString(Object value, javax.xml.namespace.QName xmlType)
           
 boolean isNoDefaultNamespace()
          Get whether or not to write the default namespace.
 boolean isPrimitive(Object value)
          Indicates whether the object should be interpretted as a primitive for the purposes of multi-ref processing.
 void outputMultiRefs()
          The serialize method uses hrefs to reference all non-primitive values.
 String qName2String(javax.xml.namespace.QName qName)
          Convert QName to a string of the form :
 String qName2String(javax.xml.namespace.QName qName, boolean writeNS)
          Convert QName to a string of the form :
 void registerPrefixForURI(String prefix, String uri)
          Register prefix for the indicated uri
 void serialize(javax.xml.namespace.QName elemQName, Attributes attributes, Object value)
          Serialize the indicated value as an element with the name indicated by elemQName.
 void serialize(javax.xml.namespace.QName elemQName, Attributes attributes, Object value, javax.xml.namespace.QName xmlType, 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 multirefs
 void setNoDefaultNamespace(boolean noDefaultNamespace)
          Set whether or not to write the default namespace.
 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.
 Attributes setTypeAttribute(Attributes attributes, javax.xml.namespace.QName type)
          Obtains the type attribute that should be serialized and returns the new list of Attributes
 boolean shouldSendXSIType()
          Get whether or not to write xsi:type attributes.
 void startDocument()
          Output anything in the beginning.
 void startElement(javax.xml.namespace.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 writeDOMElement(Element el)
          Output a DOM representation to a SerializationContext
 void writeSafeString(String string)
          Convenience operation to write out (to Writer) the String properly encoded with xml entities (like &)
 void writeString(String string)
          Convenience operation to write out (to Writer) the String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerializationContextImpl

public SerializationContextImpl(Writer writer)
Construct SerializationContextImpl with associated writer

Parameters:
writer - java.io.Writer

SerializationContextImpl

public SerializationContextImpl(Writer writer,
                                MessageContext msgContext)
Construct SerializationContextImpl with associated writer and MessageContext

Parameters:
writer - java.io.Writer
msgContext - is the MessageContext
Method Detail

getPretty

public boolean getPretty()
Get whether the serialization should be pretty printed.

Specified by:
getPretty in interface SerializationContext
Returns:
true/false

setPretty

public void setPretty(boolean pretty)
Indicate whether the serialization should be pretty printed.

Specified by:
setPretty in interface SerializationContext
Parameters:
pretty - true/false

getDoMultiRefs

public boolean getDoMultiRefs()
Are we doing multirefs?

Specified by:
getDoMultiRefs in interface SerializationContext
Returns:
true or false

setDoMultiRefs

public void setDoMultiRefs(boolean shouldDo)
Set whether we are doing multirefs

Specified by:
setDoMultiRefs in interface SerializationContext
Parameters:
shouldDo - true/false

setSendDecl

public void setSendDecl(boolean sendDecl)
Set whether or not we should write XML declarations.

Specified by:
setSendDecl in interface SerializationContext
Parameters:
sendDecl - true/false

shouldSendXSIType

public boolean shouldSendXSIType()
Get whether or not to write xsi:type attributes.

Specified by:
shouldSendXSIType in interface SerializationContext
Returns:
true/false

isNoDefaultNamespace

public boolean isNoDefaultNamespace()
Get whether or not to write the default namespace.

Specified by:
isNoDefaultNamespace in interface SerializationContext
Returns:
true/false

setNoDefaultNamespace

public void setNoDefaultNamespace(boolean noDefaultNamespace)
Set whether or not to write the default namespace.

Specified by:
setNoDefaultNamespace in interface SerializationContext

getTypeMapping

public TypeMapping getTypeMapping()
Get the TypeMapping we're using.

Specified by:
getTypeMapping in interface SerializationContext
Returns:
TypeMapping or null

getTypeMappingRegistry

public TypeMappingRegistry getTypeMappingRegistry()
Get the TypeMappingRegistry we're using.

Specified by:
getTypeMappingRegistry in interface SerializationContext
Returns:
TypeMapping or null

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".

Specified by:
getPrefixForURI in interface SerializationContext
Parameters:
uri - is the namespace uri
Returns:
prefix

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"

Specified by:
getPrefixForURI in interface SerializationContext
Parameters:
uri - is the namespace uri
defaultPrefix - optional parameter which is the default prefix
Returns:
prefix

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"


registerPrefixForURI

public void registerPrefixForURI(String prefix,
                                 String uri)
Register prefix for the indicated uri

Specified by:
registerPrefixForURI in interface SerializationContext
Parameters:
prefix -
uri - is the namespace uri

getCurrentMessage

public Message getCurrentMessage()
Return the current message

Specified by:
getCurrentMessage in interface SerializationContext
Returns:
Message

getMessageContext

public MessageContext getMessageContext()
Get the MessageContext we're operating with

Specified by:
getMessageContext in interface SerializationContext

qName2String

public String qName2String(javax.xml.namespace.QName qName,
                           boolean writeNS)
Convert QName to a string of the form :

Parameters:
qName -
Returns:
prefixed qname representation for serialization.

qName2String

public String qName2String(javax.xml.namespace.QName qName)
Description copied from interface: SerializationContext
Convert QName to a string of the form :

Specified by:
qName2String in interface SerializationContext
Parameters:
qName -
Returns:
prefixed qname representation for serialization.

attributeQName2String

public String attributeQName2String(javax.xml.namespace.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

Specified by:
attributeQName2String in interface SerializationContext
Parameters:
qName - QName
Returns:
prefixed qname representation for serialization.

getQNameForClass

public javax.xml.namespace.QName getQNameForClass(Class cls)
Get the QName associated with the specified class.

Specified by:
getQNameForClass in interface SerializationContext
Parameters:
cls - Class of an object requiring serialization.
Returns:
appropriate QName associated with the class.

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.

Specified by:
isPrimitive in interface SerializationContext
Parameters:
value - to be serialized
Returns:
true/false

serialize

public void serialize(javax.xml.namespace.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. The xmlType (if specified) 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. 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).

Specified by:
serialize in interface SerializationContext
Parameters:
elemQName - is the QName of the element
attributes - are additional attributes
value - is the object to serialize
Throws:
IOException

serialize

public void serialize(javax.xml.namespace.QName elemQName,
                      Attributes attributes,
                      Object value,
                      javax.xml.namespace.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 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).

Specified by:
serialize in interface SerializationContext
Parameters:
elemQName - is the QName of the element
attributes - are additional attributes
value - is the object to serialize
xmlType - 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

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.

Specified by:
outputMultiRefs in interface SerializationContext
Throws:
IOException

startDocument

public void startDocument()
                   throws IOException
Description copied from interface: SerializationContext
Output anything in the beginning.

Specified by:
startDocument in interface SerializationContext
Throws:
IOException

endDocument

public void endDocument()
                 throws IOException
Description copied from interface: SerializationContext
Output anything in the end.

Specified by:
endDocument in interface SerializationContext
Throws:
IOException

startElement

public void startElement(javax.xml.namespace.QName qName,
                         Attributes attributes)
                  throws IOException
Writes (using the Writer) the start tag for element QName along with the indicated attributes and namespace mappings.

Specified by:
startElement in interface SerializationContext
Parameters:
qName - is the name of the element
attributes - are the attributes to write
Throws:
IOException

endElement

public void endElement()
                throws IOException
Writes the end element tag for the open element.

Specified by:
endElement in interface SerializationContext
Throws:
IOException

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.

Specified by:
writeChars in interface SerializationContext
Parameters:
p1 - character array to write
p2 - starting index in array
p3 - length to write
Throws:
IOException

writeString

public void writeString(String string)
                 throws IOException
Convenience operation to write out (to Writer) the String

Specified by:
writeString in interface SerializationContext
Parameters:
string - is the String to write.
Throws:
IOException

writeSafeString

public void writeSafeString(String string)
                     throws IOException
Convenience operation to write out (to Writer) the String properly encoded with xml entities (like &)

Specified by:
writeSafeString in interface SerializationContext
Parameters:
string - is the String to write.
Throws:
IOException

writeDOMElement

public void writeDOMElement(Element el)
                     throws IOException
Output a DOM representation to a SerializationContext

Specified by:
writeDOMElement in interface SerializationContext
Parameters:
el - is a DOM Element
Throws:
IOException

getSerializerForJavaType

public final Serializer getSerializerForJavaType(Class javaType)
Convenience method to get the Serializer for a specific java type

Specified by:
getSerializerForJavaType in interface SerializationContext
Parameters:
javaType - is Class for a type to serialize
Returns:
Serializer

setTypeAttribute

public Attributes setTypeAttribute(Attributes attributes,
                                   javax.xml.namespace.QName type)
Obtains the type attribute that should be serialized and returns the new list of Attributes

Specified by:
setTypeAttribute in interface SerializationContext
Parameters:
attributes - of the qname
type - is the qname of the type
Returns:
new list of Attributes

getCurrentXMLType

public javax.xml.namespace.QName getCurrentXMLType()
Get the currently prefered xmlType

Specified by:
getCurrentXMLType in interface SerializationContext
Returns:
QName of xmlType or null

getValueAsString

public String getValueAsString(Object value,
                               javax.xml.namespace.QName xmlType)
                        throws IOException
Specified by:
getValueAsString in interface SerializationContext
Throws:
IOException

getElementStack

public Stack getElementStack()
Get the stack of element qnames.

Specified by:
getElementStack in interface SerializationContext


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.