|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.exolab.castor.xml.MarshalFramework
org.exolab.castor.xml.Marshaller
A Marshaller that serializes Java Object's to XML Note: This class is not thread safe, and not intended to be, so please create a new Marshaller for each thread if it is to be used in a multithreaded environment.
| Nested Class Summary | |
static class |
MarshalFramework.InheritanceMatch
Used to store the information when we find a possible inheritance. |
(package private) class |
MarshalFramework.InternalXMLClassDescriptor
An internal implementation of XMLClassDescriptor used by the Unmarshaller and Marshaller... |
(package private) static class |
Marshaller.MarshalState
|
static class |
Marshaller.NilObject
A wrapper for a "Nil" object |
(package private) static class |
Marshaller.WrapperInfo
Inner-class used for handling wrapper elements and locations |
| Field Summary | |
(package private) int |
depth
The depth of the sub tree, 0 denotes document level |
(package private) static java.lang.String |
INTERNAL_XML_NAME
A constant to indicate a wrong name without setting null. |
(package private) static java.lang.String |
JAVA_PREFIX
The default prefix used for specifying the xsi:type as a classname instead of a schema name. |
static java.lang.String |
LANG_ATTR
The xml:lang attribute, without the "xml:" prefix. |
static java.lang.String |
NIL_ATTR
The xsi:nil attribute, without the "xsi:" prefix. |
(package private) static XMLFieldDescriptor[] |
NO_FIELD_DESCRIPTORS
An empty array of field descriptors. |
(package private) static java.lang.String |
QNAME_NAME
The name of the QName type. |
static java.lang.String |
SPACE_ATTR
The xml:space attribute name, without the "xml:" prefix. |
static java.lang.String |
TRUE_VALUE
The value of 'true'. |
static java.lang.String |
TYPE_ATTR
The xsi:type attribute name, without the "xsi:" prefix. |
static java.lang.String |
XML_LANG_ATTR
The xml:lang attribute name. |
static java.lang.String |
XML_SPACE_ATTR
The xml:space attribute name. |
static java.lang.String |
XSI_NAMESPACE
The XSI Namespace URI. |
static java.lang.String |
XSI_NIL_ATTR
The xsi:nil attribute. |
static java.lang.String |
XSI_NO_NAMESPACE_SCHEMA_LOCATION
The name of the no namespace schema location attribute. |
static java.lang.String |
XSI_SCHEMA_LOCATION
The name of the Schema location attribute. |
| Constructor Summary | |
Marshaller()
Creates a default instance of Marshaller, where the sink needs to be set separately. |
|
Marshaller(org.xml.sax.ContentHandler handler)
Creates a new Marshaller with the given SAX ContentHandler. |
|
Marshaller(org.xml.sax.DocumentHandler handler)
Creates a new Marshaller with the given DocumentHandler. |
|
Marshaller(org.w3c.dom.Node node)
Creates a new Marshaller for the given DOM Node. |
|
Marshaller(java.io.Writer out)
Creates a new Marshaller with the given writer. |
|
| Method Summary | |
void |
addProcessingInstruction(java.lang.String target,
java.lang.String data)
Adds the given processing instruction data to the set of processing instructions to output during marshalling. |
CollectionHandler |
getCollectionHandler(java.lang.Class clazz)
Returns the CollectionHandler associated with the given collection, or null if no such handler exists. |
InternalContext |
getInternalContext()
To get the AbstractInternalContext to use. |
JavaNaming |
getJavaNaming()
To get the JavaNaming instance to be used. |
boolean |
getMarshalExtendedType()
If True the marshaller will use the 'xsi:type' attribute to marshall a field value that extended the defined field type. |
boolean |
getNSPrefixAtRoot()
Deprecated. |
java.lang.String |
getProperty(java.lang.String name)
Returns the value of the given Castor XML-specific property. |
XMLClassDescriptorResolver |
getResolver()
Returns the ClassDescriptorResolver for use during marshalling |
java.lang.String |
getRootElement()
Returns the name of the root element to use |
(package private) static boolean |
hasFieldsAtLocation(java.lang.String location,
XMLClassDescriptor classDesc)
Returns true if any of the fields associated with the given XMLClassDescriptor are located at, or beneath, the given location. |
static boolean |
isCollection(java.lang.Class clazz)
Returns true if the given Class is a considered a collection by the marshalling framework. |
(package private) static boolean |
isEnum(java.lang.Class type)
Returns true if the given class should be treated as an enum type. |
(package private) static boolean |
isPrimitive(java.lang.Class type)
Returns true if the given class should be treated as a primitive type. |
void |
marshal(java.lang.Object object)
Marshals the given Object as XML using the DocumentHandler for this Marshaller. |
static void |
marshal(java.lang.Object object,
org.xml.sax.ContentHandler handler)
Marshals the given Object as XML using the given ContentHandler to send events to. |
static void |
marshal(java.lang.Object object,
org.xml.sax.DocumentHandler handler)
Marshals the given Object as XML using the given DocumentHandler to send events to. |
static void |
marshal(java.lang.Object object,
org.w3c.dom.Node node)
Marshals the given Object as XML using the given DOM Node to send events to. |
static void |
marshal(java.lang.Object object,
java.io.Writer out)
Marshals the given Object as XML using the given writer. |
static boolean |
namespaceEquals(java.lang.String ns1,
java.lang.String ns2)
Compares the given namespaces (as strings) for equality. |
(package private) static boolean |
primitiveOrWrapperEquals(java.lang.Class a,
java.lang.Class b)
Returns true if the given classes are both the same primitive or primitive wrapper class. |
protected MarshalFramework.InheritanceMatch[] |
searchInheritance(java.lang.String name,
java.lang.String namespace,
XMLClassDescriptor classDesc)
Search there is a field descriptor which can accept one of the class descriptor which match the given name and namespace. |
void |
setContentHandler(org.xml.sax.ContentHandler contentHandler)
To set the content handler which is used as destination at marshalling. |
void |
setDoctype(java.lang.String publicId,
java.lang.String systemId)
Sets the document type definition for the serializer. |
void |
setEncoding(java.lang.String encoding)
Sets the encoding for the serializer. |
void |
setInternalContext(InternalContext internalContext)
To set the AbstractInternalContext to use. |
void |
setLogWriter(java.io.PrintWriter printWriter)
Sets the PrintWriter used for logging |
void |
setMapping(Mapping mapping)
Sets the given mapping to be used by the marshalling Framework. |
void |
setMarshalAsDocument(boolean asDocument)
Sets whether or not to marshal as a document which includes the XML declaration, and if necessary the DOCTYPE declaration. |
void |
setMarshalExtendedType(boolean marshalExtendedType)
If True the marshaller will use the 'xsi:type' attribute to marshall a field value that extended the defined field type. |
void |
setMarshalListener(MarshalListener listener)
Sets an optional MarshalListener to recieve pre and post marshal notification for each Object in the tree. |
void |
setNamespaceMapping(java.lang.String nsPrefix,
java.lang.String nsURI)
Sets the mapping for the given Namespace prefix |
void |
setNoNamespaceSchemaLocation(java.lang.String schemaLocation)
Sets the value for the xsi:noNamespaceSchemaLocation attribute. |
void |
setNSPrefixAtRoot(boolean nsPrefixAtRoot)
Deprecated. |
void |
setProperty(java.lang.String name,
java.lang.String value)
Sets a custom value of a given Castor XML-specific property. |
void |
setResolver(XMLClassDescriptorResolver cdr)
Sets the ClassDescriptorResolver to use during marshalling. |
void |
setRootElement(java.lang.String rootElement)
Sets the name of the root element to use. |
void |
setSchemaLocation(java.lang.String schemaLocation)
Sets the value for the xsi:schemaLocation attribute. |
void |
setSuppressNamespaces(boolean suppressNamespaces)
Sets whether or not namespaces are output. |
void |
setSuppressXSIType(boolean suppressXSIType)
Sets whether or not the xsi:type attribute should appear on the marshalled document. |
void |
setSupressXMLDeclaration(boolean supressXMLDeclaration)
Sets whether or not to marshal as a document which includes the XML declaration, and if necessary the DOCTYPE declaration. |
void |
setUseXSITypeAtRoot(boolean useXSITypeAtRoot)
Sets whether or not to output the xsi:type at the root element. |
void |
setValidation(boolean validate)
Sets whether or not to validate the object model before marshalling. |
void |
setWriter(java.io.Writer out)
Sets the java.io.Writer to be used during marshalling. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
int depth
public static final java.lang.String XSI_NAMESPACE
public static final java.lang.String XSI_SCHEMA_LOCATION
public static final java.lang.String XSI_NO_NAMESPACE_SCHEMA_LOCATION
public static final java.lang.String XML_LANG_ATTR
public static final java.lang.String LANG_ATTR
public static final java.lang.String NIL_ATTR
public static final java.lang.String XSI_NIL_ATTR
public static final java.lang.String XML_SPACE_ATTR
public static final java.lang.String SPACE_ATTR
public static final java.lang.String TYPE_ATTR
public static final java.lang.String TRUE_VALUE
static final java.lang.String INTERNAL_XML_NAME
static final java.lang.String JAVA_PREFIX
static final java.lang.String QNAME_NAME
static final XMLFieldDescriptor[] NO_FIELD_DESCRIPTORS
| Constructor Detail |
public Marshaller(org.xml.sax.DocumentHandler handler)
handler - the DocumentHandler to "marshal" to.
public Marshaller(org.xml.sax.ContentHandler handler)
throws java.io.IOException
handler - the ContentHandler to "marshal" to.public Marshaller()
public Marshaller(java.io.Writer out)
throws java.io.IOException
out - the Writer to serialize topublic Marshaller(org.w3c.dom.Node node)
node - the DOM node to marshal into.| Method Detail |
public void setWriter(java.io.Writer out)
throws java.io.IOException
out - The writer to use for marshalling
java.io.IOException - If there's a problem accessing the java.io.Writer provided
public void addProcessingInstruction(java.lang.String target,
java.lang.String data)
target - the processing instruction targetdata - the processing instruction data
public void setDoctype(java.lang.String publicId,
java.lang.String systemId)
publicId - the public identifiersystemId - the system identifierpublic void setSupressXMLDeclaration(boolean supressXMLDeclaration)
supressXMLDeclaration - a boolean that when true
includes that generated XML should not contain
the XML declaration.setMarshalAsDocument(boolean)public void setMarshalAsDocument(boolean asDocument)
asDocument - a boolean, when true, indicating to marshal
as a complete XML document.setSupressXMLDeclaration(boolean)
public void setMapping(Mapping mapping)
throws MappingException
mapping - Mapping to using during marshalling.
MappingExceptionpublic void setMarshalListener(MarshalListener listener)
listener - the MarshalListener to set.
public void setNamespaceMapping(java.lang.String nsPrefix,
java.lang.String nsURI)
nsPrefix - the namespace prefixnsURI - the namespace that the prefix resolves topublic void setRootElement(java.lang.String rootElement)
rootElement - The name of the root element to use.public java.lang.String getRootElement()
public void setNSPrefixAtRoot(boolean nsPrefixAtRoot)
nsPrefixAtRoot - public boolean getNSPrefixAtRoot()
public XMLClassDescriptorResolver getResolver()
setResolver(org.exolab.castor.xml.XMLClassDescriptorResolver)public void setResolver(XMLClassDescriptorResolver cdr)
cdr - the ClassDescriptorResolver to usesetMapping(org.exolab.castor.mapping.Mapping),
getResolver()public void setValidation(boolean validate)
validate - the boolean indicating whether or not to
validate the object model before marshalling.public void setMarshalExtendedType(boolean marshalExtendedType)
public boolean getMarshalExtendedType()
public static void marshal(java.lang.Object object,
java.io.Writer out)
throws MarshalException,
ValidationException
object - The Object to marshal.out - The writer to marshal to.
MarshalException
ValidationException
public static void marshal(java.lang.Object object,
org.xml.sax.DocumentHandler handler)
throws MarshalException,
ValidationException
object - The Object to marshal.handler - The DocumentHandler to marshal to.
MarshalException
ValidationException
public static void marshal(java.lang.Object object,
org.xml.sax.ContentHandler handler)
throws MarshalException,
ValidationException,
java.io.IOException
object - The Object to marshal.handler - The ContentHandler to marshal to.
MarshalException
ValidationException
java.io.IOException
public static void marshal(java.lang.Object object,
org.w3c.dom.Node node)
throws MarshalException,
ValidationException
object - The Object to marshal.node - The DOM Node to marshal to.
MarshalException
ValidationException
public void marshal(java.lang.Object object)
throws MarshalException,
ValidationException
object - The Object to marshal.
MarshalException
ValidationExceptionpublic void setLogWriter(java.io.PrintWriter printWriter)
printWriter - the PrintWriter to use for loggingpublic void setEncoding(java.lang.String encoding)
encoding - the encoding to setpublic void setNoNamespaceSchemaLocation(java.lang.String schemaLocation)
schemaLocation - the URI location of the schema
to which the marshalled document is an instance of.public void setSchemaLocation(java.lang.String schemaLocation)
schemaLocation - the URI location of the schema
to which the marshalled document is an instance of.public void setSuppressNamespaces(boolean suppressNamespaces)
suppressNamespaces - a boolean that when true
will prevent namespaces from being output.public void setSuppressXSIType(boolean suppressXSIType)
suppressXSIType - a boolean that when true will prevent
xsi:type attribute from being used in the marshalling process.public void setUseXSITypeAtRoot(boolean useXSITypeAtRoot)
useXSITypeAtRoot - a boolean that when true indicates
that the xsi:type should be output on the root element.public java.lang.String getProperty(java.lang.String name)
name - Qualified name of the CASTOR XML-specific property.
public void setProperty(java.lang.String name,
java.lang.String value)
name - Name of the Castor XML propertyvalue - Custom value to set.public void setContentHandler(org.xml.sax.ContentHandler contentHandler)
contentHandler - the content handler to use as destination at marshallingpublic JavaNaming getJavaNaming()
JavaNaming instance to be used.
public InternalContext getInternalContext()
AbstractInternalContext to use.
AbstractInternalContext to usepublic void setInternalContext(InternalContext internalContext)
AbstractInternalContext to use.
internalContext - the AbstractInternalContext to usepublic static boolean isCollection(java.lang.Class clazz)
clazz - the Class to check
public CollectionHandler getCollectionHandler(java.lang.Class clazz)
clazz - the Class to check
static boolean isPrimitive(java.lang.Class type)
type - the Class to check
static boolean isEnum(java.lang.Class type)
type - the Class to check
static final boolean hasFieldsAtLocation(java.lang.String location,
XMLClassDescriptor classDesc)
location - the location to compare againstclassDesc - the XMLClassDescriptor in which to check the field
locations
public static boolean namespaceEquals(java.lang.String ns1,
java.lang.String ns2)
ns1 - the namespace to compare to argument ns2ns2 - the namespace to compare to argument ns1
static boolean primitiveOrWrapperEquals(java.lang.Class a,
java.lang.Class b)
a - compare a with bb - compare a with b
protected MarshalFramework.InheritanceMatch[] searchInheritance(java.lang.String name,
java.lang.String namespace,
XMLClassDescriptor classDesc)
throws MarshalException
name - XML name of the fieldnamespace - namespace of the fieldclassDesc - the class descriptor to match against
MarshalException - if the resolver called fails fatally
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||