|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.exolab.castor.xml.Marshaller
public class 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. |
static class |
Marshaller.NilObject
A wrapper for a "Nil" object |
| Field Summary | |
|---|---|
static String |
LANG_ATTR
The xml:lang attribute, without the "xml:" prefix. |
static String |
NIL_ATTR
The xsi:nil attribute, without the "xsi:" prefix. |
static String |
SPACE_ATTR
The xml:space attribute name, without the "xml:" prefix. |
static String |
TRUE_VALUE
The value of 'true'. |
static String |
TYPE_ATTR
The xsi:type attribute name, without the "xsi:" prefix. |
static String |
XML_LANG_ATTR
The xml:lang attribute name. |
static String |
XML_SPACE_ATTR
The xml:space attribute name. |
static String |
XSI_NAMESPACE
The XSI Namespace URI. |
static String |
XSI_NIL_ATTR
The xsi:nil attribute. |
static String |
XSI_NO_NAMESPACE_SCHEMA_LOCATION
The name of the no namespace schema location attribute. |
static 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(ContentHandler contentHandler)
Creates a new Marshaller with the given SAX ContentHandler. |
|
Marshaller(DocumentHandler handler)
Creates a new Marshaller with the given SAX DocumentHandler. |
|
Marshaller(InternalContext internalContext)
The one Marshaller constructor that is used by XMLContext which
sets an InternalContext that comes from outside. |
|
Marshaller(Node node)
Creates a new Marshaller for the given DOM Node. |
|
Marshaller(Writer out)
Creates a new Marshaller with the given writer. |
|
Marshaller(javax.xml.stream.XMLEventWriter xmlEventWriter)
Creates a new Marshaller with the given XMLEventWriter. |
|
Marshaller(javax.xml.stream.XMLStreamWriter xmlStreamWriter)
Creates a new Marshaller with the given XMLStreamWriter. |
|
| Method Summary | |
|---|---|
void |
addProcessingInstruction(String target,
String data)
Adds the given processing instruction data to the set of processing instructions to output during marshalling. |
CollectionHandler |
getCollectionHandler(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. |
String |
getProperty(String name)
Returns the value of the given Castor XML-specific property. |
XMLClassDescriptorResolver |
getResolver()
Returns the ClassDescriptorResolver for use during marshalling |
String |
getRootElement()
Returns the name of the root element to use |
boolean |
getValidation()
|
static boolean |
isCollection(Class clazz)
Returns true if the given Class is a considered a collection by the marshalling framework. |
void |
marshal(Object object)
Marshals the given Object as XML using the DocumentHandler for this Marshaller. |
static void |
marshal(Object object,
ContentHandler handler)
Marshals the given Object as XML using the given ContentHandler to send events to. |
static void |
marshal(Object object,
DocumentHandler handler)
Marshals the given Object as XML using the given DocumentHandler to send events to. |
static void |
marshal(Object object,
Node node)
Marshals the given Object as XML using the given DOM Node to send events to. |
static void |
marshal(Object object,
Writer out)
Marshals the given Object as XML using the given writer. |
static boolean |
namespaceEquals(String ns1,
String ns2)
Compares the given namespaces (as strings) for equality. |
protected MarshalFramework.InheritanceMatch[] |
searchInheritance(String name,
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(ContentHandler contentHandler)
To set the SAX ContentHandler which is used as destination at marshalling. |
void |
setDoctype(String publicId,
String systemId)
Sets the document type definition for the serializer. |
void |
setDocumentHandler(DocumentHandler handler)
Sets the given SAX DocumentHandler to 'marshal' into. |
void |
setEncoding(String encoding)
Sets the encoding for the serializer. |
void |
setInternalContext(InternalContext internalContext)
To set the InternalContext to use, and to
initialize Marshaller properties linked to it. |
void |
setLogWriter(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(String nsPrefix,
String nsURI)
Sets the mapping for the given Namespace prefix. |
void |
setNode(Node node)
Sets the W3C Node instance to marshal to. |
void |
setNoNamespaceSchemaLocation(String schemaLocation)
Sets the value for the xsi:noNamespaceSchemaLocation attribute. |
void |
setNSPrefixAtRoot(boolean nsPrefixAtRoot)
Deprecated. |
void |
setProperty(String name,
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 |
setResult(Result result)
Sets the Result into which the output xml will be written. |
void |
setRootElement(String rootElement)
Sets the name of the root element to use. |
void |
setSchemaLocation(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(Writer out)
Sets the java.io.Writer to be used during marshalling. |
void |
setXmlEventWriter(javax.xml.stream.XMLEventWriter xmlEventWriter)
Sets the XMLEventWriter to use. |
void |
setXmlStreamWriter(javax.xml.stream.XMLStreamWriter xmlStreamWriter)
Sets the XMLStreamWriter to use. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String XSI_NAMESPACE
public static final String XSI_SCHEMA_LOCATION
public static final String XSI_NO_NAMESPACE_SCHEMA_LOCATION
public static final String XML_LANG_ATTR
public static final String LANG_ATTR
public static final String NIL_ATTR
public static final String XSI_NIL_ATTR
public static final String XML_SPACE_ATTR
public static final String SPACE_ATTR
public static final String TYPE_ATTR
public static final String TRUE_VALUE
| Constructor Detail |
|---|
public Marshaller(DocumentHandler handler)
Marshaller with the given SAX DocumentHandler.
handler - the SAX DocumentHandler to "marshal" to.
IllegalArgumentException - if the given DocumentHandler is nullXMLContext#createMarshaller()},
Marshaller#setDocumentHandler(DocumentHandler)},
XMLContextpublic Marshaller(ContentHandler contentHandler)
Marshaller with the given SAX ContentHandler.
contentHandler - the ContentHandler to "marshal" to.
IllegalArgumentException - if the gievn ContentHandler is nullXMLContext#createMarshaller()},
Marshaller#setContentHandler(ContentHandler)},
XMLContextpublic Marshaller(InternalContext internalContext)
Marshaller constructor that is used by XMLContext which
sets an InternalContext that comes from outside. Writer or ContentHandler
have to be set in a second step.
internalContext - the InternalContext to initialize the Marshaller
instance withpublic Marshaller()
public Marshaller(Writer out)
throws IOException
Marshaller with the given writer.
out - the Writer to serialise to.
IllegalArgumentException - if the given Writer is null
IOException - If the given Writer instance cannot be opened.XMLContext#createMarshaller()},
Marshaller#setWriter(Writer)},
XMLContextpublic Marshaller(javax.xml.stream.XMLStreamWriter xmlStreamWriter)
Marshaller with the given XMLStreamWriter.
xmlStreamWriter - the XMLStreamWriter
IllegalArgumentException - if the given XMLStreamWriter is nullXMLContext#createMarshaller()},
Marshaller#setXmlStreamWriter(javax.xml.stream.XMLStreamWriter)},
XMLContextpublic Marshaller(javax.xml.stream.XMLEventWriter xmlEventWriter)
Marshaller with the given XMLEventWriter.
xmlEventWriter - the XMLEventWriter
IllegalArgumentException - if the given XMLEventWriter is nullXMLContext#createMarshaller()},
Marshaller#setXmlEventWriter(javax.xml.stream.XMLEventWriter)},
XMLContextpublic Marshaller(Node node)
Marshaller for the given DOM Node.
node - the DOM Node to marshal into.
IllegalArgumentException - if node is nullXMLContext#createMarshaller()},
Marshaller#setNode(Node)},
XMLContext| Method Detail |
|---|
public void setDocumentHandler(DocumentHandler handler)
DocumentHandler to 'marshal' into.
handler - the SAX DocumentHandler to "marshal" to.
IllegalArgumentException - if the given DocumentHandler is null
public void setWriter(Writer out)
throws IOException
out - The writer to use for marshalling
IllegalArgumentException - if out is null
IOException - If there's a problem accessing the java.io.Writer provided
public void setResult(Result result)
throws IOException
Result into which the output xml will be written. Currently this method supports
DOMResult, SAXResult and StreamResult.
result - the Result instance to set
IllegalArgumentException - if the result is null or it is not supported
IOExceptionpublic void setNode(Node node)
Node instance to marshal to.
node - the DOM Node to marshal into.
IllegalArgumentException - if node is nullpublic void setXmlStreamWriter(javax.xml.stream.XMLStreamWriter xmlStreamWriter)
XMLStreamWriter to use.
xmlStreamWriter - the XMLStreamWriter instance to use
IllegalArgumentException - if the xmlStreamWriter is nullpublic void setXmlEventWriter(javax.xml.stream.XMLEventWriter xmlEventWriter)
XMLEventWriter to use.
xmlEventWriter - the XMLEventWriter instance to use
IllegalArgumentException - if the xmlEventReader is nullpublic void setInternalContext(InternalContext internalContext)
InternalContext to use, and to
initialize Marshaller properties linked to it.
internalContext - the InternalContext to use
public void addProcessingInstruction(String target,
String data)
target - the processing instruction targetdata - the processing instruction data
IllegalArgumentException - if target is null or empty string or data is null
public void setDoctype(String publicId,
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(String nsPrefix,
String nsURI)
nsPrefix - the namespace prefixnsURI - the namespace that the prefix resolves to
IllegalArgumentException - if nsURI is null or empty stringpublic void setRootElement(String rootElement)
rootElement - The name of the root element to use.public 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 boolean getValidation()
public void setMarshalExtendedType(boolean marshalExtendedType)
public boolean getMarshalExtendedType()
public static void marshal(Object object,
Writer out)
throws MarshalException,
ValidationException
object - The Object to marshal.out - The writer to marshal to.
MarshalException
ValidationException
public static void marshal(Object object,
DocumentHandler handler)
throws MarshalException,
ValidationException
object - The Object to marshal.handler - The DocumentHandler to marshal to.
MarshalException
ValidationException
public static void marshal(Object object,
ContentHandler handler)
throws MarshalException,
ValidationException
object - The Object to marshal.handler - The ContentHandler to marshal to.
MarshalException
ValidationException
public static void marshal(Object object,
Node node)
throws MarshalException,
ValidationException
object - The Object to marshal.node - The DOM Node to marshal to.
MarshalException
ValidationException
public void marshal(Object object)
throws MarshalException,
ValidationException
object - The Object to marshal.
MarshalException
ValidationExceptionpublic void setLogWriter(PrintWriter printWriter)
printWriter - the PrintWriter to use for loggingpublic void setEncoding(String encoding)
encoding - the encoding to setpublic void setNoNamespaceSchemaLocation(String schemaLocation)
schemaLocation - the URI location of the schema
to which the marshalled document is an instance of.public void setSchemaLocation(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 String getProperty(String name)
name - Qualified name of the CASTOR XML-specific property.
public void setProperty(String name,
String value)
name - Name of the Castor XML propertyvalue - Custom value to set.public void setContentHandler(ContentHandler contentHandler)
ContentHandler which is used as destination at marshalling.
contentHandler - the SAX ContentHandler to use as destination at marshallingpublic JavaNaming getJavaNaming()
JavaNaming instance to be used.
public InternalContext getInternalContext()
AbstractInternalContext to use.
AbstractInternalContext to usepublic static boolean isCollection(Class clazz)
clazz - the Class to check
public CollectionHandler getCollectionHandler(Class clazz)
clazz - the Class to check
public static boolean namespaceEquals(String ns1,
String ns2)
ns1 - the namespace to compare to argument ns2ns2 - the namespace to compare to argument ns1
protected MarshalFramework.InheritanceMatch[] searchInheritance(String name,
String namespace,
XMLClassDescriptor classDesc)
throws MarshalException
name - XML name of the fieldnamespace - namespace of the fieldclassDesc - the class descriptor to match againstcdResolver - the class descriptor resolver to use
MarshalException - if the resolver called fails fatally
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||