org.xmldb.api.sdk

Class SimpleCollection

public abstract class SimpleCollection extends SimpleConfigurable implements Collection

SimpleCollection provides an easy starting point for implementing the Collection interface. It provides a default Service management functionality but all other functionality must be implemented by the extending class.
Field Summary
protected booleanisOpen
protected Hashtableservices
Constructor Summary
SimpleCollection()
Method Summary
protected voidcheckOpen()
Throws an exception if the collection is not open.
voidclose()
Releases all resources consumed by the Collection.
StringcreateId()
Creates a new unique ID within the context of the Collection
ResourcecreateResource(String id, String type)
Creates a new empty Resource with the provided id.
CollectiongetChildCollection(String name)
Default behaviour for a non-hierarchical implementation
intgetChildCollectionCount()
Default behaviour for a non-hierarchical implementation
StringgetName()
Returns the name associated with the Configurable object.
CollectiongetParentCollection()
Default behaviour for a non-hierarchical implementation
ResourcegetResource(String id)
Retrieves a Resource from the database.
intgetResourceCount()
Returns the number of resources currently stored in this collection or 0 if the collection is empty.
ServicegetService(String name, String version)
Get a Service instance based on the name and version.
Service[]getServices()
Returns the list of Services supported by this Collection.
booleanisOpen()
String[]listChildCollections()
Default behaviour for a non-hierarchical implementation
String[]listResources()
Returns a list of the ids for all resources stored in the collection.
voidregisterService(Service service)
Registers a new Service with this Collection.
voidremoveResource(Resource res)
Removes the Resource from the database.
voidstoreResource(Resource res)
Stores the provided resource into the database.

Field Detail

isOpen

protected boolean isOpen

services

protected Hashtable services

Constructor Detail

SimpleCollection

public SimpleCollection()

Method Detail

checkOpen

protected void checkOpen()
Throws an exception if the collection is not open.

close

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

Throws: XMLDBException with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

createId

public String createId()
Creates a new unique ID within the context of the Collection

Returns: the created id as a string.

Throws: XMLDBException with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

createResource

public Resource createResource(String id, String type)
Creates a new empty Resource with the provided id. The type of Resource returned is determined by the type parameter. The XML:DB API currently defines "XMLResource" and "BinaryResource" as valid resource types. The id provided must be unique within the scope of the collection. If id is null or its value is empty then an id is generated by calling createId(). The Resource created is not stored to the database until storeResource() is called.

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.

getChildCollection

public Collection getChildCollection(String name)
Default behaviour for a non-hierarchical implementation

Parameters: name the name of the child collection to retrieve.

Returns: the requested child collection or null if it couldn't be found.

getChildCollectionCount

public int getChildCollectionCount()
Default behaviour for a non-hierarchical implementation

Returns: the number of child collections.

getName

public String getName()
Returns the name associated with the Configurable object.

Returns: the name of the object.

getParentCollection

public Collection getParentCollection()
Default behaviour for a non-hierarchical implementation

Returns: the parent Collection instance.

getResource

public Resource getResource(String id)
Retrieves a Resource from the database. If the Resource could not be located a null value will be returned.

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.

getResourceCount

public int getResourceCount()
Returns the number of resources currently stored in this collection or 0 if the collection is empty.

Returns: the number of resource in the collection.

Throws: XMLDBException with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.

getService

public Service getService(String name, String version)
Get a Service instance based on the name and version.

Parameters: name The Service instance to retrieve version The version of the service to retrieve.

Returns: The Service instance or null if no service was found.

getServices

public Service[] getServices()
Returns the list of Services supported by this Collection.

Returns: A list of supported Services

isOpen

public boolean isOpen()

listChildCollections

public String[] listChildCollections()
Default behaviour for a non-hierarchical implementation

Returns: an array containing collection names for all child collections.

listResources

public String[] listResources()
Returns a list of the ids for all resources stored in the 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.

registerService

public void registerService(Service service)
Registers a new Service with this Collection.

Parameters: service Description of Parameter

Throws: XMLDBException

removeResource

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

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)
Stores the provided resource into the database. If the resource does not already exist it will be created. If it does already exist it will be updated.

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.