org.ozoneDB.xml.cli
Class CollectionImpl

java.lang.Object
  extended byorg.ozoneDB.xml.cli.AbstractConfigurable
      extended byorg.ozoneDB.xml.cli.CollectionImpl
All Implemented Interfaces:
Collection, Configurable

public class CollectionImpl
extends AbstractConfigurable
implements Collection

A Collection represents a collection of Resources stored within an XML database. An XML database may expose collections as a hierarchical set of parent and child collections.

A Collection provides access to the Resources stored by the Collection and to Service instances that can operate against the Collection and the Resources stored within it. The Service mechanism provides the ability to extend the functionality of a Collection in ways that allows optional functionality to be enabled for the Collection.

Version:
$Revision: 1.1 $
Author:
SMB, Per Nyfelt

Constructor Summary
protected CollectionImpl(org.ozoneDB.ExternalDatabase database, XMLCollection collection)
          Constuctor
 
Method Summary
 void close()
          Releases all resources consumed by the Collection.
 java.lang.String createId()
          Creates a new unique ID within the context of the Collection
 Resource createResource(java.lang.String id, java.lang.String type)
          Creates a new empty Resource with the provided id.
protected static Collection forName(org.ozoneDB.ExternalDatabase database, java.lang.String collectionName)
          gets the Collection using the corresponding name from the given database
 Collection getChildCollection(java.lang.String name)
          Returns a Collection instance for the requested child collection if it exists.
 int getChildCollectionCount()
          Returns the number of child collections under this collection or 0 if no child collections exist.
 java.lang.String getName()
          Returns the name of this Collection.
 Collection getParentCollection()
          Returns the parent collection for this collection or null if no parent collection exists.
 Resource getResource(java.lang.String id)
          Retrieves a Resource from the database.
 int getResourceCount()
          Returns the number of resources currently stored in this collection or 0 if the collection is empty.
 Service getService(java.lang.String name, java.lang.String version)
          Returns the Service with the provided name and version.
 Service[] getServices()
          Provides a list of all services known to the collection.
 java.lang.String[] listChildCollections()
          Returns a list of Collection names naming all child collections of the current collection.
 java.lang.String[] listResources()
          Returns a list of the ids for all resources stored in the collection.
protected static Collection newCollection(org.ozoneDB.ExternalDatabase database, java.lang.String collectionName)
          creates a new Collection and stores it in the database
 void registerService(Service service)
          Registers the provided Service for this Collection.
 void removeResource(Resource res)
          Removes the Resource from the database.
 void storeResource(Resource res)
          Stores the provided resource into the database.
 
Methods inherited from class org.ozoneDB.xml.cli.AbstractConfigurable
getProperty, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xmldb.api.base.Configurable
getProperty, setProperty
 

Constructor Detail

CollectionImpl

protected CollectionImpl(org.ozoneDB.ExternalDatabase database,
                         XMLCollection collection)
Constuctor

Method Detail

forName

protected static Collection forName(org.ozoneDB.ExternalDatabase database,
                                    java.lang.String collectionName)
                             throws java.lang.Exception
gets the Collection using the corresponding name from the given database

Throws:
java.lang.Exception

newCollection

protected static Collection newCollection(org.ozoneDB.ExternalDatabase database,
                                          java.lang.String collectionName)
                                   throws java.lang.Exception
creates a new Collection and stores it in the database

Throws:
java.lang.Exception

getName

public java.lang.String getName()
                         throws XMLDBException
Returns the name of this Collection. The name is unique.

Specified by:
getName in interface Configurable
Returns:
The name of this Collection.
Throws:
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

getServices

public Service[] getServices()
                      throws XMLDBException
Description copied from interface: Collection
Provides a list of all services known to the collection. If no services are known an empty list is returned.

Specified by:
getServices in interface Collection
Returns:
a String array of Services registered for this Collection.
Throws:
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

getService

public Service getService(java.lang.String name,
                          java.lang.String version)
                   throws XMLDBException
Returns the Service with the provided name and version.

Specified by:
getService in interface Collection
Parameters:
name - the name of the requested Service
version - the version of the requested Service if any
Returns:
the Service instance or null if no Service could be found.
Throws:
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

registerService

public void registerService(Service service)
                     throws XMLDBException
Registers the provided Service for this Collection.

Specified by:
registerService in interface Collection
Parameters:
service - The Service to be registered for this Collection.
Throws:
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
ErrorCodes.INVALID_SERVICE if the Service instance does not have a proper name or version or the instance is null.

getParentCollection

public Collection getParentCollection()
                               throws XMLDBException
Returns the parent collection for this collection or null if no parent collection exists.

Specified by:
getParentCollection in interface Collection
Returns:
the parent Collection instance.
Throws:
XMLDBException

getChildCollectionCount

public int getChildCollectionCount()
                            throws XMLDBException
Returns the number of child collections under this collection or 0 if no child collections exist.

Specified by:
getChildCollectionCount in interface Collection
Returns:
the number of child collections.
Throws:
XMLDBException

listChildCollections

public java.lang.String[] listChildCollections()
                                        throws XMLDBException
Returns a list of Collection names naming all child collections of the current collection. If no child collections exist an empty list is returned.

Specified by:
listChildCollections in interface Collection
Returns:
an array containing Collection names for all child collections.
Throws:
XMLDBException

getChildCollection

public Collection getChildCollection(java.lang.String name)
                              throws XMLDBException
Returns a Collection instance for the requested child collection if it exists.

Specified by:
getChildCollection in interface Collection
Parameters:
name - the name of the child collection to retrieve.
Returns:
the requested child collection or null if it couldn't be found.
Throws:
XMLDBException

getResourceCount

public int getResourceCount()
                     throws XMLDBException
Description copied from interface: Collection
Returns the number of resources currently stored in this collection or 0 if the collection is empty.

Specified by:
getResourceCount in interface Collection
Returns:
the number of resource in the collection.
Throws:
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

listResources

public java.lang.String[] listResources()
                                 throws XMLDBException
Returns a list of the ids for all resources stored in the collection.

Specified by:
listResources in interface Collection
Returns:
a string array containing the names for all Resources in the collection.
Throws:
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

createResource

public Resource createResource(java.lang.String id,
                               java.lang.String type)
                        throws XMLDBException
Creates a new empty Resource with the provided id.

Specified by:
createResource in interface Collection
Parameters:
id - the unique id to associate with the created Resource.
type - the Resource type to create.
Returns:
an empty Resource instance.
Throws:
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
ErrorCodes.UNKNOWN_RESOURCE_TYPE if the type parameter is not a known Resource type.

removeResource

public void removeResource(Resource res)
                    throws XMLDBException
Removes the Resource from the database.

Specified by:
removeResource in interface Collection
Parameters:
res - the resource to remove.
Throws:
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
ErrorCodes.INVALID_RESOURCE if the Resource is not valid.
ErrorCodes.NO_SUCH_RESOURCE if the Resource is not known to this Collection.

storeResource

public void storeResource(Resource res)
                   throws XMLDBException
Stores the provided resource into the database.

Specified by:
storeResource in interface Collection
Parameters:
res - the resource to store in the database.
Throws:
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
ErrorCodes.INVALID_RESOURCE if the Resource is not valid.

getResource

public Resource getResource(java.lang.String id)
                     throws XMLDBException
Description copied from interface: Collection
Retrieves a Resource from the database. If the Resource could not be located a null value will be returned.

Specified by:
getResource in interface Collection
Parameters:
id - the unique id for the requested resource.
Returns:
The retrieved Resource instance.
Throws:
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

createId

public java.lang.String createId()
                          throws XMLDBException
Creates a new unique ID within the context of the Collection

Specified by:
createId in interface Collection
Returns:
the created id as a string.
Throws:
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

close

public void close()
           throws XMLDBException
Releases all resources consumed by the Collection. The close method must always be called when use of a Collection is complete.

Specified by:
close in interface Collection
Throws:
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.


Copyright © 2004 The Ozone Database Project - www.ozone-db.org. All Rights Reserved.