jgnash.engine.xml
Class XMLContainer

java.lang.Object
  extended by jgnash.engine.xml.XMLContainer

public class XMLContainer
extends java.lang.Object

Simple object container for StoredObjects that reads and writes a xml file

Version:
$Id$
Author:
Craig Cavanaugh

Nested Class Summary
private static class XMLContainer.StoredObjectReflectionProvider
           
 
Field Summary
private  java.io.File file
           
private  java.nio.channels.FileLock fileLock
           
private  java.nio.channels.FileChannel lockChannel
           
private  java.util.List<StoredObject> objects
           
private  java.util.concurrent.locks.ReadWriteLock readWriteLock
           
 
Constructor Summary
protected XMLContainer(java.io.File file)
           
 
Method Summary
private  boolean acquireFileLock()
           
(package private)  java.util.List<StoredObject> asList()
          Returns of list of all StoredObjects held within this container.
(package private)  void close()
           
(package private)  void commit()
           
private static com.thoughtworks.xstream.XStream configureXStream(com.thoughtworks.xstream.XStream xstream)
           
(package private)  void delete(StoredObject object)
           
(package private)  StoredObject get(java.lang.String uuid)
           
(package private)  java.lang.String getFileName()
           
(package private)
<T extends StoredObject>
java.util.List<T>
query(java.lang.Class<T> clazz)
           
private static
<T extends StoredObject>
java.util.List<T>
query(java.util.Collection<StoredObject> values, java.lang.Class<T> clazz)
           
(package private)  void readXML()
           
private  boolean releaseFileLock()
           
(package private)  boolean set(StoredObject object)
           
private  void writeXML()
           
static void writeXML(java.util.Collection<StoredObject> objects, java.io.File file)
          Writes an XML file given a collection of StoredObjects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

objects

private final java.util.List<StoredObject> objects

readWriteLock

private final java.util.concurrent.locks.ReadWriteLock readWriteLock

file

private final java.io.File file

fileLock

private java.nio.channels.FileLock fileLock

lockChannel

private java.nio.channels.FileChannel lockChannel
Constructor Detail

XMLContainer

protected XMLContainer(java.io.File file)
Method Detail

acquireFileLock

private boolean acquireFileLock()

releaseFileLock

private boolean releaseFileLock()

commit

void commit()

set

boolean set(StoredObject object)

delete

void delete(StoredObject object)

get

StoredObject get(java.lang.String uuid)

query

<T extends StoredObject> java.util.List<T> query(java.lang.Class<T> clazz)

close

void close()

getFileName

java.lang.String getFileName()

query

private static <T extends StoredObject> java.util.List<T> query(java.util.Collection<StoredObject> values,
                                                                java.lang.Class<T> clazz)

asList

java.util.List<StoredObject> asList()
Returns of list of all StoredObjects held within this container. The returned list is a defensive copy.

Returns:
A list of all StoredObjects
See Also:
StoredObject

writeXML

private void writeXML()

writeXML

public static void writeXML(java.util.Collection<StoredObject> objects,
                            java.io.File file)
Writes an XML file given a collection of StoredObjects. TrashObjects and objects marked for removal are not written. If the file already exists, it will be overwritten.

Parameters:
objects - Collection of StoredObjects to write
file - file to write

readXML

void readXML()
       throws java.io.FileNotFoundException,
              java.io.UnsupportedEncodingException
Throws:
java.io.FileNotFoundException
java.io.UnsupportedEncodingException

configureXStream

private static com.thoughtworks.xstream.XStream configureXStream(com.thoughtworks.xstream.XStream xstream)