gov.loc.repository.bagit
Class BagFactory

java.lang.Object
  extended by gov.loc.repository.bagit.BagFactory

public class BagFactory
extends java.lang.Object

Provides all methods for instantiating new Bag objects, as well as reading bags from disk and serializations. You should not create a Bag instance directly, instead creating them with methods from this class.

New in-memory bags can be created using the no-argument createBag() method, while clones of an existing bag can be created using the createBag(Bag) method. A bag on-disk can be loaded using the createBag(File) method.

Additionally, there are overloads for specifying the BagFactory.Version and the LoadOptions.

See Also:
Bag

Nested Class Summary
static class BagFactory.LoadOption
          Specifies the mechanism used to load a bag from disk.
static class BagFactory.Version
          The version of the bag to load.
 
Field Summary
static BagFactory.Version LATEST
          The latest version of the BagIt spec.
 
Constructor Summary
BagFactory()
          Creates an instance of a bag factory.
 
Method Summary
 Bag createBag()
          Creates a new Bag of the latest version.
 Bag createBag(Bag bag)
          Creates a Bag from an existing Bag.
 Bag createBag(BagFactory.Version version)
          Creates a new Bag of the specified version.
 Bag createBag(java.io.File bagFile)
          Creates a Bag from an existing bag.
 Bag createBag(java.io.File bagFile, BagFactory.LoadOption loadOption)
          Creates a Bag from an existing bag.
 Bag createBag(java.io.File bagFile, BagFactory.Version version, BagFactory.LoadOption loadOption)
          Creates a Bag from an existing bag using the specified version.
 PreBag createPreBag(java.io.File dir)
          Creates a PreBag which can be bagged-in-place.
 Bag.BagConstants getBagConstants()
          Gets BagConstants of the latest version.
 Bag.BagConstants getBagConstants(BagFactory.Version version)
          Gets BagConstants of the specified version.
 Bag.BagPartFactory getBagPartFactory()
          Gets a BagPartFactory of the latest version.
 Bag.BagPartFactory getBagPartFactory(BagFactory.Version version)
          Gets a BagPartFactory of the specified version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LATEST

public static final BagFactory.Version LATEST
The latest version of the BagIt spec. Currently, this is 0.96.

Constructor Detail

BagFactory

public BagFactory()
Creates an instance of a bag factory.

Method Detail

createBag

public Bag createBag()
Creates a new Bag of the latest version.


createBag

public Bag createBag(BagFactory.Version version)
Creates a new Bag of the specified version.

Parameters:
version - The version of the bag to be created.
Throws:
java.lang.RuntimeException - Thrown if an unsupported version is passed.

createBag

public Bag createBag(java.io.File bagFile)
Creates a Bag from an existing bag. The version of the bag is determined by examining the bag. If it cannot be determined, the latest version is assumed. If the specified version is not supported, the latest version is used. The bag is loaded from the payload manifests.

Parameters:
bagFile - The File from which to load the bag. This may be either a filesystem directory, or a file containing a serialized bag.

createBag

public Bag createBag(java.io.File bagFile,
                     BagFactory.LoadOption loadOption)
Creates a Bag from an existing bag. The version of the bag is determined by examining the bag. If it cannot be determined, the latest version is assumed. If the version of the bag is not supported by this library, the latest version is used.

Parameters:
bagFile - The File containing the bag to load.
loadOption - The mechanism to use for loading the bag.

createBag

public Bag createBag(java.io.File bagFile,
                     BagFactory.Version version,
                     BagFactory.LoadOption loadOption)
Creates a Bag from an existing bag using the specified version.

Parameters:
bagFile - The File containing the bag to load.
version - The version to load the bag as.
loadOption - The mechanism to use for loading the bag.

createBag

public Bag createBag(Bag bag)
Creates a Bag from an existing Bag. The version and bagFile (if present) are taken from the existing Bag. The bag is not loaded.

Parameters:
bag - The bag to copy.

getBagPartFactory

public Bag.BagPartFactory getBagPartFactory()
Gets a BagPartFactory of the latest version.


getBagPartFactory

public Bag.BagPartFactory getBagPartFactory(BagFactory.Version version)
Gets a BagPartFactory of the specified version.

Parameters:
version - The version for which to retrieve a Bag.BagPartFactory.

getBagConstants

public Bag.BagConstants getBagConstants()
Gets BagConstants of the latest version.


getBagConstants

public Bag.BagConstants getBagConstants(BagFactory.Version version)
Gets BagConstants of the specified version.

Parameters:
version - The version for which to retrieve a Bag.BagConstants.

createPreBag

public PreBag createPreBag(java.io.File dir)
Creates a PreBag which can be bagged-in-place.

Parameters:
dir - The File containing the data to be pre-bagged.