com.partnersoft.cog
Class CogXmlLib

java.lang.Object
  extended by com.partnersoft.cog.CogXmlLib
All Implemented Interfaces:
Lib

public class CogXmlLib
extends java.lang.Object
implements Lib

Convenience methods for reading and writing Cogs as XML.

There are a good number of methods here, but they follow a common pattern:

The difference between "Cog" and "Object" methods is that "Cog" methods read or write directly from Cog structures, while "Object" methods convert Coggables to/from Cog structures first. Generally an "Object" method will call the corresponding "Cog" method with this converted Cog structure.

Otherwise the methods only differ in terms of source or destination - streams, Strings, Files, VfsFiles, and Preferences are all supported.

One exception is the writeCogToString/readCogFromString/writeObjectToString/readObjectFromString methods. The syntax for these differs from the others so it seemed worth having different nomenclature.

Copyright 2003-2009 Partner Software, Inc.

Version:
$Id: CogXmlLib.java 2474 2010-03-13 14:28:43Z paul $
Author:
Paul Reavis

Method Summary
static Cog readCogFrom(java.io.File file)
          Reads a cog in XML format from the given File.
static Cog readCogFrom(java.util.prefs.Preferences preferences)
          Read the cog in XML format from a Preferences node.
static Cog readCogFrom(java.io.Reader reader, java.lang.String context)
          Reads a cog in XMl format from the given Reader.
static Cog readCogFrom(VfsFile file)
          Reads a cog in XML format from the given File.
static Cog readCogFromString(java.lang.String xmlString)
          Reads a cog from the given XML string.
static java.lang.String readCogTypeFrom(VfsFile file)
          Reads just the cog type name from the given VfsFile.
static java.lang.Object readObjectFrom(java.io.File file)
          Reads a Coggable object from the given File in XML format.
static java.lang.Object readObjectFrom(java.io.File file, CogSchema schema)
          Reads a Coggable object from the given File using the given schema.
static java.lang.Object readObjectFrom(java.util.prefs.Preferences preferences)
          Reads a Coggable object from a Preferences node.
static java.lang.Object readObjectFrom(java.util.prefs.Preferences preferences, CogSchema schema)
          Reads a Coggable object from a Preferences node, converting using the given schema.
static java.lang.Object readObjectFrom(java.io.Reader reader, java.lang.String context)
          Reads a Coggable object from the given reader in XML format.
static java.lang.Object readObjectFrom(java.io.Reader reader, java.lang.String context, CogSchema schema)
          Reads a Coggable object from the given Reader using the given schema.
static java.lang.Object readObjectFrom(VfsFile file)
          Reads a Coggable object from the given VfsFile in XML format.
static java.lang.Object readObjectFrom(VfsFile file, CogSchema schema)
          Reads a Coggable object from the given VfsFile using the given schema.
static java.lang.Object readObjectFromString(java.lang.String xmlString)
          Reads a Coggable object from the given XML string.
static java.lang.Object readObjectFromString(java.lang.String xmlString, CogSchema schema)
          Reads a Coggable object from the given XML string.
static Naming<java.lang.Object> readObjectsFrom(VfsDirectory directory, CogSchema schema)
          Reads a Naming of objects from the given directory containing one XML file per object.
static CogSchema readSchemaFrom(VfsDirectory directory)
          Reads a schema from the given directory containing one XML file per type.
static void writeCogTo(Cog cog, java.io.File file)
          Writes the given cog to the given file in XML format.
static void writeCogTo(Cog cog, java.util.prefs.Preferences prefs)
          Writes a Cog to a Preferences node.
static void writeCogTo(Cog cog, VfsFile file)
          Writes the given cog to the given VfsFile in XML format.
static void writeCogTo(Cog cog, java.io.Writer writer)
          Writes the given cog in XML format to the given writer.
static void writeCogTo(Cog cog, java.io.Writer writer, boolean compact)
          Writes the given cog in XML format to the given writer.
static java.lang.String writeCogToString(Cog cog)
          Returns a String representation of the given cog in XML format.
static void writeObjectsTo(Naming<java.lang.Object> objects, VfsDirectory directory)
          Writes out the Naming as individual Cog XML files in the given directory.
static void writeObjectTo(java.lang.Object object, java.io.File file)
          Write the given Coggable object to the given File in XML format.
static void writeObjectTo(java.lang.Object object, java.util.prefs.Preferences prefs)
          Writes a Coggable object to a Preferences node.
static void writeObjectTo(java.lang.Object object, VfsFile file)
          Write the given Coggable object to the given VfsFile in XML format.
static void writeObjectTo(java.lang.Object object, java.io.Writer writer)
          Write the given Coggable object to the given Writer in XML format.
static void writeObjectTo(java.lang.Object object, java.io.Writer writer, boolean compact)
          Write the given Coggable object to the given Writer in XML format.
static java.lang.String writeObjectToString(java.lang.Object object)
          Returns a String representation of the given Coggable object out in XML format.
static java.lang.String writeObjectToString(java.lang.Object object, boolean compact)
          Returns a String representation of the given Coggable object out in XML format.
static void writeSchemaTo(CogSchema schema, VfsDirectory directory)
          Writes out the schema as individual type files in the given directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readCogTypeFrom

public static java.lang.String readCogTypeFrom(VfsFile file)
Reads just the cog type name from the given VfsFile. Returns null if it can't determine one.


readCogFrom

public static Cog readCogFrom(java.io.File file)
                       throws java.io.IOException
Reads a cog in XML format from the given File.

Throws:
java.io.IOException

readCogFrom

public static Cog readCogFrom(java.util.prefs.Preferences preferences)
                       throws java.io.IOException
Read the cog in XML format from a Preferences node.

Throws:
java.io.IOException

readCogFrom

public static Cog readCogFrom(java.io.Reader reader,
                              java.lang.String context)
                       throws java.io.IOException
Reads a cog in XMl format from the given Reader. The context should be used to indicate where exactly the data is coming from - the file path, the IP address/socket, or whatever - in case there are errors in parsing.

Throws:
java.io.IOException

readCogFrom

public static Cog readCogFrom(VfsFile file)
                       throws java.io.IOException
Reads a cog in XML format from the given File.

Throws:
java.io.IOException

readCogFromString

public static Cog readCogFromString(java.lang.String xmlString)
                             throws java.io.IOException
Reads a cog from the given XML string.

Throws:
java.io.IOException

readObjectFrom

public static java.lang.Object readObjectFrom(java.io.File file)
                                       throws java.io.IOException
Reads a Coggable object from the given File in XML format.

Throws:
java.io.IOException

readObjectFrom

public static java.lang.Object readObjectFrom(java.io.File file,
                                              CogSchema schema)
                                       throws java.io.IOException
Reads a Coggable object from the given File using the given schema.

Throws:
java.io.IOException

readObjectFrom

public static java.lang.Object readObjectFrom(java.util.prefs.Preferences preferences)
                                       throws java.io.IOException
Reads a Coggable object from a Preferences node.

Throws:
java.io.IOException

readObjectFrom

public static java.lang.Object readObjectFrom(java.util.prefs.Preferences preferences,
                                              CogSchema schema)
                                       throws java.io.IOException
Reads a Coggable object from a Preferences node, converting using the given schema.

Throws:
java.io.IOException

readObjectFrom

public static java.lang.Object readObjectFrom(java.io.Reader reader,
                                              java.lang.String context)
                                       throws java.io.IOException
Reads a Coggable object from the given reader in XML format. The context should be used to indicate where exactly the data is coming from - the file path, the IP address/socket, or whatever - in case there are errors in parsing.

Throws:
java.io.IOException

readObjectFrom

public static java.lang.Object readObjectFrom(java.io.Reader reader,
                                              java.lang.String context,
                                              CogSchema schema)
                                       throws java.io.IOException
Reads a Coggable object from the given Reader using the given schema. The context should be used to indicate where exactly the data is coming from - the file path, the IP address/socket, or whatever - in case there are errors in parsing.

Throws:
java.io.IOException

readObjectFrom

public static java.lang.Object readObjectFrom(VfsFile file)
                                       throws java.io.IOException
Reads a Coggable object from the given VfsFile in XML format.

Throws:
java.io.IOException

readObjectFrom

public static java.lang.Object readObjectFrom(VfsFile file,
                                              CogSchema schema)
                                       throws java.io.IOException
Reads a Coggable object from the given VfsFile using the given schema.

Throws:
java.io.IOException

readObjectFromString

public static java.lang.Object readObjectFromString(java.lang.String xmlString)
                                             throws java.io.IOException
Reads a Coggable object from the given XML string.

Throws:
java.io.IOException

readObjectFromString

public static java.lang.Object readObjectFromString(java.lang.String xmlString,
                                                    CogSchema schema)
                                             throws java.io.IOException
Reads a Coggable object from the given XML string.

Throws:
java.io.IOException

readObjectsFrom

public static Naming<java.lang.Object> readObjectsFrom(VfsDirectory directory,
                                                       CogSchema schema)
                                                throws java.io.IOException
Reads a Naming of objects from the given directory containing one XML file per object.

Throws:
java.io.IOException

readSchemaFrom

public static CogSchema readSchemaFrom(VfsDirectory directory)
                                throws java.io.IOException
Reads a schema from the given directory containing one XML file per type.

Throws:
java.io.IOException

writeCogTo

public static void writeCogTo(Cog cog,
                              java.io.File file)
                       throws java.io.IOException
Writes the given cog to the given file in XML format.

Throws:
java.io.IOException

writeCogTo

public static void writeCogTo(Cog cog,
                              java.util.prefs.Preferences prefs)
                       throws java.io.IOException
Writes a Cog to a Preferences node.

Throws:
java.io.IOException

writeCogTo

public static void writeCogTo(Cog cog,
                              VfsFile file)
                       throws java.io.IOException
Writes the given cog to the given VfsFile in XML format.

Throws:
java.io.IOException

writeCogTo

public static void writeCogTo(Cog cog,
                              java.io.Writer writer)
                       throws java.io.IOException
Writes the given cog in XML format to the given writer.

Throws:
java.io.IOException

writeCogTo

public static void writeCogTo(Cog cog,
                              java.io.Writer writer,
                              boolean compact)
                       throws java.io.IOException
Writes the given cog in XML format to the given writer.

Throws:
java.io.IOException

writeCogToString

public static java.lang.String writeCogToString(Cog cog)
Returns a String representation of the given cog in XML format.


writeObjectsTo

public static void writeObjectsTo(Naming<java.lang.Object> objects,
                                  VfsDirectory directory)
                           throws java.io.IOException
Writes out the Naming as individual Cog XML files in the given directory. ERASES THE CURRENT CONTENTS, so use with care.

Throws:
java.io.IOException

writeObjectTo

public static void writeObjectTo(java.lang.Object object,
                                 java.io.File file)
                          throws java.io.IOException
Write the given Coggable object to the given File in XML format.

Throws:
java.io.IOException

writeObjectTo

public static void writeObjectTo(java.lang.Object object,
                                 java.util.prefs.Preferences prefs)
                          throws java.io.IOException
Writes a Coggable object to a Preferences node.

Throws:
java.io.IOException

writeObjectTo

public static void writeObjectTo(java.lang.Object object,
                                 VfsFile file)
                          throws java.io.IOException
Write the given Coggable object to the given VfsFile in XML format.

Parameters:
object -
file -
Throws:
java.io.IOException

writeObjectTo

public static void writeObjectTo(java.lang.Object object,
                                 java.io.Writer writer)
                          throws java.io.IOException
Write the given Coggable object to the given Writer in XML format.

Throws:
java.io.IOException

writeObjectTo

public static void writeObjectTo(java.lang.Object object,
                                 java.io.Writer writer,
                                 boolean compact)
                          throws java.io.IOException
Write the given Coggable object to the given Writer in XML format.

Throws:
java.io.IOException

writeObjectToString

public static java.lang.String writeObjectToString(java.lang.Object object)
                                            throws java.io.IOException
Returns a String representation of the given Coggable object out in XML format.

Throws:
java.io.IOException

writeObjectToString

public static java.lang.String writeObjectToString(java.lang.Object object,
                                                   boolean compact)
                                            throws java.io.IOException
Returns a String representation of the given Coggable object out in XML format.

Throws:
java.io.IOException

writeSchemaTo

public static void writeSchemaTo(CogSchema schema,
                                 VfsDirectory directory)
                          throws java.io.IOException
Writes out the schema as individual type files in the given directory. ERASES THE CURRENT CONTENTS, so use with care.

Throws:
java.io.IOException