org.ephman.abra.tools
Class Marshaller

java.lang.Object
  |
  +--org.ephman.abra.tools.XmlProcessor
        |
        +--org.ephman.abra.tools.Marshaller

public class Marshaller
extends XmlProcessor

A class to marshall from Java classes to XML docs. instantiate with a mapping file conforming to http://charzard/codegen.dtd package org.ephman use the same package MapToJava to generate code from that map file with approptiate get/set methods and for a Vector foo, addToFoo

Version:
0.0.1 (11/3/00)
Author:
Paul M. Bethe

Field Summary
protected static java.lang.String _ID
          constants to handle circular links
protected static java.lang.String _IDREF
           
protected  java.lang.ClassLoader classLoader
           
protected  java.lang.Object[] dummyArray
           
protected static java.lang.String RUN_TIME
           
(package private)  java.lang.Class string
           
static java.lang.String VERSION_NUMBER
           
 
Fields inherited from class org.ephman.abra.tools.XmlProcessor
useAbraParser
 
Constructor Summary
Marshaller()
           
Marshaller(java.lang.String mapFileName)
           
 
Method Summary
 void addMapFile(java.io.Reader reader, boolean validating, java.lang.String inputName)
          to add a mapfile to a given marshaller thus extending the set of classes that the marshaller knows how to marshal and unmarshal
 void addMapFile(java.lang.String mapFileName)
           
 void addMapFile(java.lang.String mapFileName, boolean validating)
           
protected  void applyRules(org.w3c.dom.Element e, java.lang.String mapName)
           
protected  void applyRules(org.ephman.xml.XmlNode thisNode, java.lang.String mapFile)
           
protected  java.lang.Class getAClass(java.lang.String className)
          helper method to get a java.lang.Class object given a type (including primitives like int.class)
protected  java.lang.reflect.Method getASetMethod(java.lang.Class c, java.lang.String methodName, java.lang.Class paramClass)
           
protected  java.lang.reflect.Method getASetMethod(java.lang.Class c, java.lang.String methodName, java.lang.String paramClassName)
           
protected  java.lang.String getClassName(java.lang.Object obj)
           
protected  java.sql.Timestamp getDate(java.lang.String value, UnmarshalContext context)
           
protected  java.lang.String getFieldType(java.lang.String fieldType)
          get a native type primary class name (so for 'int' return 'java.lang.Integer'
protected  java.lang.String getNameFromMethod(java.lang.reflect.Method m)
           
(package private)  java.lang.Object getPrimitive(org.ephman.xml.XmlNode thisNode, JField jf, UnmarshalContext context)
           
protected  boolean isNativeType(java.lang.String typeName)
           
 java.lang.String marshal(java.lang.Object obj)
          a routine to marshal objects to xml strings uses descriptor class - if not found uses reflection from mapping..
protected  java.lang.String marshal(java.lang.Object obj, MarshalContext context, java.lang.String nodeName)
           
protected  java.lang.String marshal(java.lang.Object obj, MarshalContext context, java.lang.String nodeName, java.lang.String compileTimeType)
           
(package private)  java.lang.String objectOut(JField jf, java.lang.Object value, MarshalContext context)
          aroutine to find the text output for an object.
protected  void recurseOnChildList(java.util.Vector children, java.lang.Object obj, XmlDescriptor desc, UnmarshalContext context)
           
protected  java.lang.String reflectMarshal(java.lang.Object obj)
          try to use reflection to marshal a Java Class to an XML representation
protected  java.lang.String reflectMarshal(java.lang.Object obj, MarshalContext context)
           
protected  java.lang.String reflectMarshal(java.lang.Object obj, MarshalContext context, java.lang.String nodeName)
           
protected  void setAllAttributes(org.ephman.xml.XmlNode thisNode, java.lang.Object obj, XmlDescriptor desc, UnmarshalContext context)
           
protected  void setArray(JField jf, java.util.Vector nodes, java.lang.Object obj, XmlDescriptor desc, UnmarshalContext context)
          a method to set an array described by jf into obj (whose descriptor is desc
protected  void setDate(java.lang.Object o, java.lang.reflect.Method m, java.lang.String value, UnmarshalContext context)
           
protected  void setElement(org.ephman.xml.XmlNode thisNode, java.lang.Object obj, XmlDescriptor desc, UnmarshalContext context)
           
 void setIdTagsOff()
          method to remove "ID" tags (will throw exception if circular ref..)
 void setMarshalDateFormat(java.lang.String format)
           
 void setUnmarshalDateFormats(java.lang.String[] formats)
          method to allow setting of unmarshal formats..
 void setWriteRunTimeTypes(boolean b)
           
 java.lang.Object unmarshal(java.io.Reader r)
           
 java.lang.Object unmarshal(java.io.Reader r, boolean ignoreMissingFields)
           
 java.lang.Object unmarshal(java.lang.String xmlText)
          a routine to unmarshal xml text to a Java object - assumes that the class is loadable and that the object is described in the map file
 java.lang.Object unmarshal(java.lang.String xmlText, boolean ignoreMissingFields)
           
protected  java.lang.Object unmarshal(org.ephman.xml.XmlNode thisNode, UnmarshalContext context, XmlDescriptor desc)
          a routine to be called on a composite node - with the current context and the Xml descriptor for this object
 void useAbraXmlParser()
           
 
Methods inherited from class org.ephman.abra.tools.XmlProcessor
mapXMLFile, mapXMLFile, mapXMLFile, mapXMLFile, recurseOnChildList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_ID

protected static java.lang.String _ID
constants to handle circular links


_IDREF

protected static java.lang.String _IDREF

RUN_TIME

protected static java.lang.String RUN_TIME

classLoader

protected java.lang.ClassLoader classLoader

string

java.lang.Class string

dummyArray

protected java.lang.Object[] dummyArray

VERSION_NUMBER

public static final java.lang.String VERSION_NUMBER
See Also:
Constant Field Values
Constructor Detail

Marshaller

public Marshaller()
           throws java.lang.Exception

Marshaller

public Marshaller(java.lang.String mapFileName)
           throws java.lang.Exception
Method Detail

useAbraXmlParser

public void useAbraXmlParser()

setIdTagsOff

public void setIdTagsOff()
method to remove "ID" tags (will throw exception if circular ref..)


setWriteRunTimeTypes

public void setWriteRunTimeTypes(boolean b)

setUnmarshalDateFormats

public void setUnmarshalDateFormats(java.lang.String[] formats)
method to allow setting of unmarshal formats.. should be done while initializing mapFiles..


setMarshalDateFormat

public void setMarshalDateFormat(java.lang.String format)

addMapFile

public void addMapFile(java.lang.String mapFileName,
                       boolean validating)
                throws java.lang.Exception
Parameters:
mapFileName - the path and file name of an xml file conforming to codegen.dtd add a mapfile using a String fileName..
java.lang.Exception

addMapFile

public void addMapFile(java.lang.String mapFileName)
                throws java.lang.Exception
java.lang.Exception

addMapFile

public void addMapFile(java.io.Reader reader,
                       boolean validating,
                       java.lang.String inputName)
                throws java.lang.Exception
to add a mapfile to a given marshaller thus extending the set of classes that the marshaller knows how to marshal and unmarshal

Parameters:
reader - -
validating - whether or not to use any dtds to validate..
Throws:
java.io.IOException - if file un-openable
java.lang.Exception

marshal

public java.lang.String marshal(java.lang.Object obj)
                         throws java.lang.Exception
a routine to marshal objects to xml strings uses descriptor class - if not found uses reflection from mapping..

java.lang.Exception

marshal

protected java.lang.String marshal(java.lang.Object obj,
                                   MarshalContext context,
                                   java.lang.String nodeName)
                            throws java.lang.Exception
java.lang.Exception

marshal

protected java.lang.String marshal(java.lang.Object obj,
                                   MarshalContext context,
                                   java.lang.String nodeName,
                                   java.lang.String compileTimeType)
                            throws java.lang.Exception
java.lang.Exception

objectOut

java.lang.String objectOut(JField jf,
                           java.lang.Object value,
                           MarshalContext context)
aroutine to find the text output for an object.


reflectMarshal

protected java.lang.String reflectMarshal(java.lang.Object obj)
                                   throws java.lang.Exception
try to use reflection to marshal a Java Class to an XML representation

Parameters:
obj - any object
Returns:
the String which represents this class in XML
java.lang.Exception

isNativeType

protected boolean isNativeType(java.lang.String typeName)

getClassName

protected java.lang.String getClassName(java.lang.Object obj)

reflectMarshal

protected java.lang.String reflectMarshal(java.lang.Object obj,
                                          MarshalContext context)
                                   throws java.lang.Exception
java.lang.Exception

reflectMarshal

protected java.lang.String reflectMarshal(java.lang.Object obj,
                                          MarshalContext context,
                                          java.lang.String nodeName)
                                   throws java.lang.Exception
java.lang.Exception

getNameFromMethod

protected java.lang.String getNameFromMethod(java.lang.reflect.Method m)
                                      throws java.lang.Exception
java.lang.Exception

unmarshal

public java.lang.Object unmarshal(java.lang.String xmlText)
                           throws java.lang.Exception
a routine to unmarshal xml text to a Java object - assumes that the class is loadable and that the object is described in the map file

Parameters:
xmlText - an xml text string - whose root node was described in the map file
Returns:
Object a new instance with all data in place
Throws:
java.lang.Exception - - when the xml-Java descriptor is not found or the Java object is not found by the class loader - or when the xml is not well formed

unmarshal

public java.lang.Object unmarshal(java.lang.String xmlText,
                                  boolean ignoreMissingFields)
                           throws java.lang.Exception
java.lang.Exception

unmarshal

public java.lang.Object unmarshal(java.io.Reader r)
                           throws java.lang.Exception
java.lang.Exception

unmarshal

public java.lang.Object unmarshal(java.io.Reader r,
                                  boolean ignoreMissingFields)
                           throws java.lang.Exception
java.lang.Exception

unmarshal

protected java.lang.Object unmarshal(org.ephman.xml.XmlNode thisNode,
                                     UnmarshalContext context,
                                     XmlDescriptor desc)
                              throws java.lang.Exception
a routine to be called on a composite node - with the current context and the Xml descriptor for this object

Parameters:
thisNode - the org.w3c Element
context - a wrapper containing the ID and IDREF tags
desc - for the object to be built containing attributes and elements..
Returns:
Object a new object as described in descriptor with all fields set
java.lang.Exception

setArray

protected void setArray(JField jf,
                        java.util.Vector nodes,
                        java.lang.Object obj,
                        XmlDescriptor desc,
                        UnmarshalContext context)
                 throws java.lang.Exception
a method to set an array described by jf into obj (whose descriptor is desc

java.lang.Exception

setAllAttributes

protected void setAllAttributes(org.ephman.xml.XmlNode thisNode,
                                java.lang.Object obj,
                                XmlDescriptor desc,
                                UnmarshalContext context)
                         throws java.lang.Exception
java.lang.Exception

setDate

protected void setDate(java.lang.Object o,
                       java.lang.reflect.Method m,
                       java.lang.String value,
                       UnmarshalContext context)
                throws java.lang.Exception
java.lang.Exception

getDate

protected java.sql.Timestamp getDate(java.lang.String value,
                                     UnmarshalContext context)

getAClass

protected java.lang.Class getAClass(java.lang.String className)
                             throws java.lang.ClassNotFoundException
helper method to get a java.lang.Class object given a type (including primitives like int.class)

java.lang.ClassNotFoundException

getASetMethod

protected java.lang.reflect.Method getASetMethod(java.lang.Class c,
                                                 java.lang.String methodName,
                                                 java.lang.String paramClassName)
                                          throws java.lang.Exception
java.lang.Exception

getASetMethod

protected java.lang.reflect.Method getASetMethod(java.lang.Class c,
                                                 java.lang.String methodName,
                                                 java.lang.Class paramClass)
                                          throws java.lang.Exception
java.lang.Exception

setElement

protected void setElement(org.ephman.xml.XmlNode thisNode,
                          java.lang.Object obj,
                          XmlDescriptor desc,
                          UnmarshalContext context)
                   throws java.lang.Exception
java.lang.Exception

getPrimitive

java.lang.Object getPrimitive(org.ephman.xml.XmlNode thisNode,
                              JField jf,
                              UnmarshalContext context)
                        throws java.lang.Exception
java.lang.Exception

recurseOnChildList

protected void recurseOnChildList(java.util.Vector children,
                                  java.lang.Object obj,
                                  XmlDescriptor desc,
                                  UnmarshalContext context)
                           throws java.lang.Exception
java.lang.Exception

getFieldType

protected java.lang.String getFieldType(java.lang.String fieldType)
get a native type primary class name (so for 'int' return 'java.lang.Integer'


applyRules

protected void applyRules(org.w3c.dom.Element e,
                          java.lang.String mapName)
                   throws javax.xml.parsers.ParserConfigurationException,
                          java.io.FileNotFoundException,
                          java.io.IOException,
                          org.xml.sax.SAXException,
                          SchemaException
javax.xml.parsers.ParserConfigurationException
java.io.FileNotFoundException
java.io.IOException
org.xml.sax.SAXException
SchemaException

applyRules

protected void applyRules(org.ephman.xml.XmlNode thisNode,
                          java.lang.String mapFile)
                   throws org.ephman.xml.XmlException,
                          java.io.IOException,
                          SchemaException
Specified by:
applyRules in class XmlProcessor
org.ephman.xml.XmlException
java.io.IOException
SchemaException