edu.udo.cs.miningmart.m4.utils
Class M4Xml

java.lang.Object
  extended byedu.udo.cs.miningmart.m4.utils.M4Xml

public class M4Xml
extends java.lang.Object

Version:
$Id: M4Xml.java,v 1.5 2006/04/11 14:10:10 euler Exp $
Author:
Martin Scholz

Constructor Summary
M4Xml()
           
 
Method Summary
static java.lang.String createClosingTag(java.lang.String tagName)
           
static java.lang.Object createObjectFromXml(java.lang.String tag, java.lang.String embedded)
          This is a service method for importing from XML.
static java.lang.String createOpeningTag(java.lang.String tagName)
           
static java.lang.String createXmlDescription(XmlInfo m4o, M4InfoEntry entry, java.io.Writer out, java.util.Collection dependent)
          Method creating an XML description of an attribute.
static long export(XmlInfo m4d, java.io.Writer out, java.util.Collection dependent)
          This method serializes a given object and writes the String using a given Writer object.
static void exportCase(Case m4Case, java.io.Writer writer)
           
static java.util.Collection exportContainedObjects(XmlInfo m4d, java.io.Writer out, java.util.Collection dependent)
           
static java.lang.Long getExistingXmlId(XmlInfo object)
           
static Case importCase(java.io.InputStream in, DB db, java.lang.String xmlVersion)
          Import a Case from the given input stream.
static java.lang.String putInXmlTags(java.lang.String text, java.lang.String xmlTag)
          Simple service method.
static java.lang.String serializeM4DataCollection(java.util.Collection col, java.io.Writer out, java.util.Collection dependent)
          Service method to serialize an arbitrary Collection of M4Data objects to XML.
static long setNewXmlId(XmlInfo object)
           
static java.lang.String[] stripOuterTag(java.lang.String xml)
           
static java.lang.Long xmlImport(XmlInfo m4d, java.lang.String description)
          Sets the fields of this object according to the provided XML description
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

M4Xml

public M4Xml()
Method Detail

getExistingXmlId

public static java.lang.Long getExistingXmlId(XmlInfo object)

setNewXmlId

public static long setNewXmlId(XmlInfo object)

exportCase

public static void exportCase(Case m4Case,
                              java.io.Writer writer)
                       throws java.io.IOException
Throws:
java.io.IOException

export

public static long export(XmlInfo m4d,
                          java.io.Writer out,
                          java.util.Collection dependent)
                   throws java.io.IOException
This method serializes a given object and writes the String using a given Writer object. All objects referenced by this object will also be serialized (before) and be referenced by their XML ID. To be able to reach all objects of a specified Case it is necessary to collect all objects referencing this object. Thus the method will add all objects not yet serialized and having a reference to (!) this object to the given Collection.

Parameters:
out - the Writer to write the serialization String to
dependent - a Collection to be filled with objects referencing this object
Returns:
the XML ID of this object. Please note that this ID is different from the object's M4 ID! A return value of 0 indicates that the object was not exported but skipped, because it refers to the relational level which is not to be exported.
Throws:
java.io.IOException

exportContainedObjects

public static java.util.Collection exportContainedObjects(XmlInfo m4d,
                                                          java.io.Writer out,
                                                          java.util.Collection dependent)
                                                   throws java.io.IOException
Parameters:
out - the Writer object to write the serialization with
dependent - a Collection of objects referencing the objects already serialized
Returns:
a Collection of Strings, each of which is a reference to a primitive datatype, or an XML Id reference to an M4Data Java object this object holds a foreign key reference to.
Throws:
java.io.IOException

createXmlDescription

public static java.lang.String createXmlDescription(XmlInfo m4o,
                                                    M4InfoEntry entry,
                                                    java.io.Writer out,
                                                    java.util.Collection dependent)
                                             throws M4Exception,
                                                    java.io.IOException
Method creating an XML description of an attribute. If the attributes holds a foreign key reference to a object that was not yet serialized, then the serialization is done before returning a description based on the referenced objects new XML ID.

Parameters:
entry - an M4InfoEntry describing one of this objects attributes and the corresponding getter and datatype.
out - a Writer for writing serialization of referenced objects to if not yet done.
dependent - a Collection of objects referencing the objects already serialized. Just to be used when calling export for another object referenced by this object.
Returns:
an XML string describing corresponding value for the specified entry or null, if the value of the entry was null.
Throws:
M4Exception
java.io.IOException

serializeM4DataCollection

public static java.lang.String serializeM4DataCollection(java.util.Collection col,
                                                         java.io.Writer out,
                                                         java.util.Collection dependent)
                                                  throws M4Exception,
                                                         java.io.IOException
Service method to serialize an arbitrary Collection of M4Data objects to XML.

Parameters:
col - the Collection of XmlInfo objects
out - the Writer of the serialization
dependent - the Collection of dependent objects
Returns:
a String describing the collection or null if the Collection was null or empty
Throws:
M4Exception
java.io.IOException

putInXmlTags

public static java.lang.String putInXmlTags(java.lang.String text,
                                            java.lang.String xmlTag)
Simple service method.

Parameters:
text - a text to put in XML tags.
xmlTag - the tag text without > and <
Returns:
the tagged text String

createOpeningTag

public static java.lang.String createOpeningTag(java.lang.String tagName)

createClosingTag

public static java.lang.String createClosingTag(java.lang.String tagName)

importCase

public static Case importCase(java.io.InputStream in,
                              DB db,
                              java.lang.String xmlVersion)
                       throws java.io.IOException,
                              XmlException,
                              M4Exception
Import a Case from the given input stream. Set the DB object for the case to the given one. Check that the file in the input stream was created with the given xmlVersion. Version Strings are stored in the interface XmlInfo.java.

Throws:
java.io.IOException
XmlException
M4Exception

xmlImport

public static java.lang.Long xmlImport(XmlInfo m4d,
                                       java.lang.String description)
                                throws M4Exception,
                                       XmlException
Sets the fields of this object according to the provided XML description

Throws:
M4Exception
XmlException

stripOuterTag

public static java.lang.String[] stripOuterTag(java.lang.String xml)
Parameters:
xml - an XML String to be split into tag and embedded String
Returns:
a String[3] object with
  • String[0]: the tag
  • String[1]: the embedded String
  • String[2]: the substring after the closing tag
if the specified String could be split, and null otherwise.

createObjectFromXml

public static java.lang.Object createObjectFromXml(java.lang.String tag,
                                                   java.lang.String embedded)
                                            throws XmlException
This is a service method for importing from XML. For a known tag and a String embedded by the tag an object is returned.

Parameters:
tag - the name of the tag (case sensitive)
embedded - the text between the opening and closing tag
Returns:
the deserialized object. null is never returned.
Throws:
XmlException


Copyright © 2001-2005