org.exolab.castor.xml
Class Marshaller

java.lang.Object
  |
  +--org.exolab.castor.xml.MarshalFramework
        |
        +--org.exolab.castor.xml.Marshaller

public class Marshaller
extends org.exolab.castor.xml.MarshalFramework

A Marshaller to allowing serializing Java Object's to XML

Version:
$Revision: 1.57 $ $Date: 2001/03/15 08:58:09 $
Author:
Keith Visco

Field Summary
static java.lang.String XSI_NAMESPACE
          The XSI Namespace URI
 
Constructor Summary
Marshaller(org.xml.sax.DocumentHandler handler)
          Creates a new Marshaller
Marshaller(org.w3c.dom.Node node)
          Creates a new Marshaller
Marshaller(java.io.Writer out)
          Creates a new Marshaller with the given writer
 
Method Summary
 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()
          Returns True if the given namespace mappings will be declared at the root node.
 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.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
 void setDebug(boolean debug)
          Sets the flag to turn on and off debugging
 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 marshallExtendedType)
          If True the marshaller will use the 'xsi:type' attribute to marshall a field value that extended the defined field type.
 void setNamespaceMapping(java.lang.String nsPrefix, java.lang.String nsURI)
          Sets the mapping for the given Namespace prefix
 void setNSPrefixAtRoot(boolean nsPrefixAtRoot)
          Set to True to declare the given namespace mappings at the root node.
 void setResolver(ClassDescriptorResolver cdr)
          Sets the ClassDescriptorResolver to use during unmarshalling
 void setValidation(boolean validate)
          Sets whether or not to validate the object model before marshalling.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XSI_NAMESPACE

public static final java.lang.String XSI_NAMESPACE
The XSI Namespace URI
Constructor Detail

Marshaller

public Marshaller(org.xml.sax.DocumentHandler handler)
Creates a new Marshaller

Marshaller

public Marshaller(java.io.Writer out)
           throws java.io.IOException
Creates a new Marshaller with the given writer
Parameters:
out - the Writer to serialize to

Marshaller

public Marshaller(org.w3c.dom.Node node)
Creates a new Marshaller
Method Detail

setMarshalAsDocument

public void setMarshalAsDocument(boolean asDocument)
Sets whether or not to marshal as a document which includes the XML declaration, and if necessary the DOCTYPE declaration. By default the Marshaller will marshal as a well formed XML fragment (no XML declaration or DOCTYPE).
Parameters:
asDocument - a boolean, when true, indicating to marshal as a complete XML document.

setMapping

public void setMapping(Mapping mapping)
                throws MappingException
Sets the given mapping to be used by the marshalling Framework. If a ClassDescriptorResolver exists This mapping will be added to the existing Resolver. Otherwise a new ClassDescriptorResolver will be created.
Parameters:
mapping - the mapping to using during marshalling

setNamespaceMapping

public void setNamespaceMapping(java.lang.String nsPrefix,
                                java.lang.String nsURI)
Sets the mapping for the given Namespace prefix
Parameters:
nsPrefix - the namespace prefix
nsURI - the namespace that the prefix resolves to

setNSPrefixAtRoot

public void setNSPrefixAtRoot(boolean nsPrefixAtRoot)
Set to True to declare the given namespace mappings at the root node. Default is False.
Parameters:
nsPrefixAtRoot -  

getNSPrefixAtRoot

public boolean getNSPrefixAtRoot()
Returns True if the given namespace mappings will be declared at the root node.

setResolver

public void setResolver(ClassDescriptorResolver cdr)
Sets the ClassDescriptorResolver to use during unmarshalling
Parameters:
cdr - the ClassDescriptorResolver to use
See Also:

Note: This method will nullify any Mapping currently being used by this Marshaller

setValidation

public void setValidation(boolean validate)
Sets whether or not to validate the object model before marshalling. By default validation is enabled. This method is really for debugging. I do not recommend turning off validation, since you could marshal a document, which you can then not unmarshal. If you know the object model is guaranteed to be valid, disabling validation will improve performace.
Parameters:
validate - the boolean indicating whether or not to validate the object model before marshalling.

setMarshalExtendedType

public void setMarshalExtendedType(boolean marshallExtendedType)
If True the marshaller will use the 'xsi:type' attribute to marshall a field value that extended the defined field type. Default is True.

getMarshalExtendedType

public boolean getMarshalExtendedType()
If True the marshaller will use the 'xsi:type' attribute to marshall a field value that extended the defined field type. Default is True.

marshal

public static void marshal(java.lang.Object object,
                           java.io.Writer out)
                    throws MarshalException,
                           ValidationException
Marshals the given Object as XML using the given writer
Parameters:
obj - the Object to marshal
out - the writer to marshal to
Throws:
MarshalException -  
ValidationException -  

marshal

public static void marshal(java.lang.Object object,
                           org.xml.sax.DocumentHandler handler)
                    throws MarshalException,
                           ValidationException
Marshals the given Object as XML using the given DocumentHandler to send events to.
Parameters:
obj - the Object to marshal
handler - the DocumentHandler to marshal to
Throws:
MarshalException -  
ValidationException -  

marshal

public static void marshal(java.lang.Object object,
                           org.w3c.dom.Node node)
                    throws MarshalException,
                           ValidationException
Marshals the given Object as XML using the given DOM Node to send events to.
Parameters:
obj - the Object to marshal
node - the DOM Node to marshal to
Throws:
MarshalException -  
ValidationException -  

marshal

public void marshal(java.lang.Object object)
             throws MarshalException,
                    ValidationException
Marshals the given Object as XML using the DocumentHandler for this Marshaller.
Parameters:
obj - the Object to marshal
Throws:
MarshalException -  
ValidationException -  

setDebug

public void setDebug(boolean debug)
Sets the flag to turn on and off debugging
Parameters:
debug - the flag indicating whether or not debug information should be generated

setLogWriter

public void setLogWriter(java.io.PrintWriter printWriter)
Sets the PrintWriter used for logging
Parameters:
printWriter - the PrintWriter to use for logging


Intalio Inc. (C) 1999-2001. All rights reserved http://www.intalio.com