org.xmldb.api.sdk
Class SimpleCollection
- Collection, Configurable
public abstract class SimpleCollection
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.
isOpen
protected boolean isOpen
services
protected Hashtable services
SimpleCollection
public SimpleCollection()
checkOpen
protected void checkOpen()
throws XMLDBException Throws an exception if the collection is not open.
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.
- close in interface Collection
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor
specific errors that occur.
createId
public String createId()
throws XMLDBException Creates a new unique ID within the context of the Collection
- createId in interface Collection
- the created id as a string.
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor
specific errors that occur.
createResource
public Resource createResource(String id,
String type)
throws XMLDBException 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.
- createResource in interface Collection
id - the unique id to associate with the created Resource.type - the Resource type to create.
- an empty
Resource instance.
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)
throws XMLDBException Default behaviour for a non-hierarchical implementation
- getChildCollection in interface Collection
name - the name of the child collection to retrieve.
- the requested child collection or null if it couldn't be found.
getResource
public Resource getResource(String id)
throws XMLDBException Retrieves a Resource from the database. If the
Resource could not be
located a null value will be returned.
- getResource in interface Collection
id - the unique id for the requested resource.
- The retrieved
Resource instance.
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor
specific errors that occur.
getResourceCount
public int getResourceCount()
throws XMLDBException Returns the number of resources currently stored in this collection or 0
if the collection is empty.
- getResourceCount in interface Collection
- the number of resource in the collection.
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor
specific errors that occur.
getService
public Service getService(String name,
String version)
throws XMLDBException Get a Service instance based on the name and version.
- getService in interface Collection
name - The Service instance to retrieveversion - The version of the service to retrieve.
- The Service instance or null if no service was found.
listChildCollections
public String[] listChildCollections()
throws XMLDBException Default behaviour for a non-hierarchical implementation
- listChildCollections in interface Collection
- an array containing collection names for all child
collections.
listResources
public String[] listResources()
throws XMLDBException Returns a list of the ids for all resources stored in the collection.
- listResources in interface Collection
- a string array containing the names for all
Resources in the collection.
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor
specific errors that occur.
registerService
public void registerService(Service service)
throws XMLDBException Registers a new Service with this Collection.
service - Description of Parameter
removeResource
public void removeResource(Resource res)
throws XMLDBException Removes the Resource from the database.
- removeResource in interface Collection
res - the resource to remove.
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. If the resource does not
already exist it will be created. If it does already exist it will be
updated.
- storeResource in interface Collection
res - the resource to store in the database.
XMLDBException - with expected error codes.
ErrorCodes.VENDOR_ERROR for any vendor
specific errors that occur.
ErrorCodes.INVALID_RESOURCE if the Resource is
not valid.