com.bbn.swede.core.libraries
Class Library

java.lang.Object
  extended bycom.bbn.swede.core.libraries.Library
All Implemented Interfaces:
ILibrary

class Library
extends Object
implements ILibrary

This is a concrete implementation of the ILibrary interface, with methods for implementing most of the functionality required for library support in SWeDE.

Libraries are basically magic ZIP files containing OWL files and metadata. They are arranged according to a strict structure. Each library file has an extension as defined in Libraries.LIBRARY_EXTENSION and they are stored in a special directory called Libraries.LIBRARY_DIRECTORY found in the workspace root (e.g. eclipse/workspace/.swlib/ontology-library.swlib where both the LIBRARY_EXTENSION and the LIBRARY_DIRECTORY are ".swlib"). Keeping libraries in that central location allows each users to create and manipulate projects as they see fit without concerning themselves with how libraries are managed. Another option would have been to store the libraries in the SWeDE plugin directory, but then difficulties would arise when upgrading to new versions of SWeDE.

Within a single library file, there is a tripartite structure. Each of the files in the library, referred to as Entrys exist within a subdirectory of the ZIP called '/entry', and each file is automatically appended the extension '.entry'. So for instance, a file called 'vehicle-ont.owl' would, in the ZIP, have an file called '/entry/vehicle-ont.owl.entry'. Associated meta-data is stored in a separate directory, this one called '/metadata', and each file has a file there as well, similarly appended with an extension, in this case, '.metadata'. So 'vehicle-ont.owl' would also have an file in the '/entry' directory as mentioned above, and also a file in the 'metadata' directory (i.e. '/metadata/vehicle-ont.owl.metadata').

Author:
aperezlo

Field Summary
(package private) static int ENTRY_REFRESHED
           
(package private) static int NO_CHANGE
           
 
Constructor Summary
(package private) Library(File zipFile)
          Creates a library based on a zip file that already exists on disk.
(package private) Library(File zipFile, LibraryDescriptor owner)
          Creates a library based on a zip file that already exists on disk, owned by a specific descriptor.
(package private) Library(String filename)
          This constructor is used to create a new library on the disk.
 
Method Summary
(package private)  void addEntry(ILibraryEntryDescriptor newEntry)
          Adds an entry to the library.
(package private)  boolean close()
          Attempts to close the zip file and free all other system resources.
 ILibraryDescriptor createDescriptor()
          This method will create a descriptor if one does not exist; if one has already been created, then this method will return that object.
(package private)  List getEntries()
          Retrieves the descriptors for all entries in this library.
(package private)  String getFilename()
          Retrieves the name of the file that holds this library (e.g.
(package private)  Properties getProperties()
          Retrieves the properties associated with this library, as stored in its configuration.
(package private)  ZipFile getZipFile()
          Retrieves the ZIP file that holds this library.
(package private)  boolean isOpen()
          Indicates whether the library is open.
(package private)  IStatus rebuild(File infileLocation, IProgressMonitor progress)
          This method looks in the particular directory specified by infileLocation, and adds each of the .owl files in the directory to itself.
(package private)  void removeEntry(ILibraryEntryDescriptor toRemove)
          Removes an ILibraryEntryDescriptor from the library.
(package private)  void setProperties(Properties props)
          Sets the properties stored in this library's configuration.
(package private)  void unzipAll(File outDirectory)
          Extracts all entries in the library.
(package private)  IStatus unzipOne(File outDirectory, LibraryEntryDescriptor le, IProgressMonitor progress)
          Extracts an entry from the library.
(package private)  void writeLibrary(String path)
          This method writes the contents into a new file in the directory specified by path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_CHANGE

static final int NO_CHANGE
See Also:
Constant Field Values

ENTRY_REFRESHED

static final int ENTRY_REFRESHED
See Also:
Constant Field Values
Constructor Detail

Library

Library(String filename)
This constructor is used to create a new library on the disk. Given a name, this constructor creates a new file for the library in the standard library location as defined by Libraries.getLibraryLocationPath() with an extension as defined by Libraries.LIBRARY_EXTENSION.

Parameters:
filename - the name of the new library; it is incorporated into the name of the file

Library

Library(File zipFile,
        LibraryDescriptor owner)
Creates a library based on a zip file that already exists on disk, owned by a specific descriptor.

Parameters:
zipFile - The zip file containing the existing library
owner - The descriptor for the library

Library

Library(File zipFile)
Creates a library based on a zip file that already exists on disk.

Parameters:
zipFile - The zip file containing the existing library
Method Detail

getZipFile

ZipFile getZipFile()
Retrieves the ZIP file that holds this library.

Returns:
the zip file

removeEntry

void removeEntry(ILibraryEntryDescriptor toRemove)
Removes an ILibraryEntryDescriptor from the library. This change is not permanent until the library is re-written to disk.

Parameters:
toRemove - a ILibraryEntryDescriptor which should be removed from the library.

unzipOne

IStatus unzipOne(File outDirectory,
                 LibraryEntryDescriptor le,
                 IProgressMonitor progress)
Extracts an entry from the library.

Parameters:
outDirectory - The destination directory for the unzipped file
le - The entry to extract
progress - A progress monitor for the unzip operation
Returns:
IStatus.OK if the entry is extracted successfully, IStatus.CANCEL if the operation is cancelled, or IStatus.ERROR if something goes wrong.

unzipAll

void unzipAll(File outDirectory)
Extracts all entries in the library.

Parameters:
outDirectory - The destination directory for the extracted files.

rebuild

IStatus rebuild(File infileLocation,
                IProgressMonitor progress)
This method looks in the particular directory specified by infileLocation, and adds each of the .owl files in the directory to itself.

Parameters:
infileLocation - the location where this library should look for its constituent files
progress - an object to receive updates about the progress of this operation
Returns:
IStatus.OK if a success, IStatus.CANCEL if it was canceled, and IStatus.ERROR otherwise

isOpen

boolean isOpen()
Indicates whether the library is open.

Returns:
true if the library is open, false if not.

addEntry

void addEntry(ILibraryEntryDescriptor newEntry)
Adds an entry to the library. This change is not permanent until the library is written to disk.

Parameters:
newEntry - the new entry to add

close

boolean close()
Attempts to close the zip file and free all other system resources.

Returns:
true if the operation was a success, false otherwise

createDescriptor

public ILibraryDescriptor createDescriptor()
Description copied from interface: ILibrary
This method will create a descriptor if one does not exist; if one has already been created, then this method will return that object.

Specified by:
createDescriptor in interface ILibrary
Returns:
a handle to this library upon which operations can be performed

getProperties

Properties getProperties()
Retrieves the properties associated with this library, as stored in its configuration.

Returns:
the library's properties

setProperties

void setProperties(Properties props)
Sets the properties stored in this library's configuration.

Parameters:
props - the properties to associated with this library

getFilename

String getFilename()
Retrieves the name of the file that holds this library (e.g. "library.swlib").

Returns:
The name of the library file

getEntries

List getEntries()
Retrieves the descriptors for all entries in this library.

Returns:
a list of the ILibraryEntryDescriptor objects this library holds

writeLibrary

void writeLibrary(String path)
This method writes the contents into a new file in the directory specified by path. E.g. if path = "/home/user/files/libraries/", and the library is named 'ont-library', then after a call to this method, there should exists a new file called 'ont-library.swlib' in "/home/user/files/libraries/".

Parameters:
path - the location of the new library


Copyright © 2004-2005 BBN Technologies. All Rights Reserved.