Class RMXMLWriter

java.lang.Object
com.ribs.datasource.RMXMLWriter
Direct Known Subclasses:
RMXMLWriter

public class RMXMLWriter extends Object
This class turns any Java dataset into XML. The most common use of this class is simply the writeObject() method, which takes a Java dataset and results in a very clean XML description (at the given path):

   new RMXMLWriter().writeObject(myObjects, "MyDataset.xml");
 

The Java dataset can take almost any form: a list, map or hierarchy of EJBs, custom Java classes, Java collections classes or even JDBC ResultSets. The resulting XML file is a very clean description of all the public fields, methods and keys/values in the dataset (out to three levels deep, which is the default "degree of separation").

RMXMLWriter performs its conversion in two steps, first abstracting the object into Java Collections and core types using RMMapMaker, then writing the abstraction to XML.

This code currently supports entity subclasses (eg, Vehicle->Car, Vehicle->Truck) by folding them into their base class (eg, Vehicle). A future version might consider buiding an RMSchema that includes an entity "parent" attribute, so that a hierarchy of entities could be mapped instead of just a list. Subtype's would then refer to the base class for a given relation, and each member of the relation would have to specify it's "Class" if different from base.

Copyright (c) 2004 ReportMill Software, Inc. All Rights Reserved. Contact ReportMill <info@reportmill.com>.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a basic instance of RMXMLWriter.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns whether every written entity should automatically have "id" tag.
    Returns the schema.
    getXML(Object anObj, Object userInfo, int degreeOfSeparation)
    Writes given Java dataset and optional userInfo to given path as XML, out to given degree of separation.
    boolean
    ignore(String aName)
    Returns whether writer should ignore class/method/field with given name from the serialized object graph.
    void
    Tells writer to ignore any member of the given class from the serialized object graph.
    void
    ignoreClass(String aClassName)
    Tells writer to ignore any member of the given class name from the serialized object graph.
    void
    ignoreMember(String aFieldName)
    Tells writer to ignore any member with the given method/field name from the serialized object graph.
    boolean
    Returns whether XML should include "Class" attribute when class differs from schema (subclasses only).
    void
    setForceIds(boolean aFlag)
    Sets whether every written entity should automatically have "id" tag.
    void
    setIncludeSubclassNames(boolean aFlag)
    Sets whether XML should include "Class" attribute when class differs from schema (subclasses only).
    void
    setUseShortClassNames(boolean aFlag)
    Sets whether class names should omit path (don't use if full classpath needed or if duplicate class names).
    boolean
    Returns whether class names should omit path (don't use if full classpath needed or if duplicate class names).
    void
    writeObject(Object anObj, Object userInfo, String aPath, int degreeOfSeparation)
    Writes given Java dataset and optional userInfo to given path as XML, out to given degree of separation.
    void
    writeObject(Object anObj, String aPath)
    Writes given Java dataset to given path as XML, out to three levels deep, which is default degree of separation.
    void
    writeObject(Object anObj, String aPath, int dos)
    Writes given Java dataset to given path as XML, out to given degree of separation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • RMXMLWriter

      public RMXMLWriter()
      Creates a basic instance of RMXMLWriter.
  • Method Details

    • forceIds

      public boolean forceIds()
      Returns whether every written entity should automatically have "id" tag.
    • setForceIds

      public void setForceIds(boolean aFlag)
      Sets whether every written entity should automatically have "id" tag.
    • includeSublassNames

      public boolean includeSublassNames()
      Returns whether XML should include "Class" attribute when class differs from schema (subclasses only).
    • setIncludeSubclassNames

      public void setIncludeSubclassNames(boolean aFlag)
      Sets whether XML should include "Class" attribute when class differs from schema (subclasses only).
    • useShortClassNames

      public boolean useShortClassNames()
      Returns whether class names should omit path (don't use if full classpath needed or if duplicate class names).
    • setUseShortClassNames

      public void setUseShortClassNames(boolean aFlag)
      Sets whether class names should omit path (don't use if full classpath needed or if duplicate class names).
    • ignoreClass

      public void ignoreClass(Class aClass)
      Tells writer to ignore any member of the given class from the serialized object graph.
    • ignoreClass

      public void ignoreClass(String aClassName)
      Tells writer to ignore any member of the given class name from the serialized object graph.
    • ignoreMember

      public void ignoreMember(String aFieldName)
      Tells writer to ignore any member with the given method/field name from the serialized object graph.
    • ignore

      public boolean ignore(String aName)
      Returns whether writer should ignore class/method/field with given name from the serialized object graph.
    • writeObject

      public void writeObject(Object anObj, String aPath)
      Writes given Java dataset to given path as XML, out to three levels deep, which is default degree of separation.
    • writeObject

      public void writeObject(Object anObj, String aPath, int dos)
      Writes given Java dataset to given path as XML, out to given degree of separation.
    • writeObject

      public void writeObject(Object anObj, Object userInfo, String aPath, int degreeOfSeparation)
      Writes given Java dataset and optional userInfo to given path as XML, out to given degree of separation.
    • getXML

      public RXElement getXML(Object anObj, Object userInfo, int degreeOfSeparation)
      Writes given Java dataset and optional userInfo to given path as XML, out to given degree of separation.
    • getSchema

      public RMSchema getSchema()
      Returns the schema.