Package org.xmldb.api.sdk
Class SimpleCollection
java.lang.Object
org.xmldb.api.sdk.SimpleConfigurable
org.xmldb.api.sdk.SimpleCollection
- All Implemented Interfaces:
Collection
,Configurable
- Direct Known Subclasses:
CollectionImpl
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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Releases all resources consumed by theCollection
.createId()
Creates a new unique ID within the context of theCollection
createResource
(String id, String type) Creates a new emptyResource
with the provided id.getChildCollection
(String name) Default behaviour for a non-hierarchical implementationint
Default behaviour for a non-hierarchical implementationgetName()
Returns the name associated with the Configurable object.Default behaviour for a non-hierarchical implementationgetResource
(String id) Retrieves aResource
from the database.int
Returns the number of resources currently stored in this collection or 0 if the collection is empty.getService
(String name, String version) Get a Service instance based on the name and version.Service[]
Returns the list of Services supported by this Collection.boolean
isOpen()
Returns true if theCollection
is open false otherwise.String[]
Default behaviour for a non-hierarchical implementationString[]
Returns a list of the ids for all resources stored in the collection.void
registerService
(Service service) Registers a new Service with this Collection.void
removeResource
(Resource res) Removes theResource
from the database.void
storeResource
(Resource res) Stores the provided resource into the database.Methods inherited from class org.xmldb.api.sdk.SimpleConfigurable
getProperty, setProperty
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xmldb.api.base.Configurable
getProperty, setProperty
-
Constructor Details
-
SimpleCollection
public SimpleCollection()
-
-
Method Details
-
getName
Returns the name associated with the Configurable object.- Specified by:
getName
in interfaceCollection
- Returns:
- the name of the object.
- Throws:
XMLDBException
- with expected error codes.
ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
-
getServices
Returns the list of Services supported by this Collection.- Specified by:
getServices
in interfaceCollection
- Returns:
- A list of supported Services
- Throws:
XMLDBException
- with expected error codes.
ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
ErrorCodes.COLLECTION_CLOSED
if theclose
method has been called on theCollection
-
getService
Get a Service instance based on the name and version.- Specified by:
getService
in interfaceCollection
- Parameters:
name
- The Service instance to retrieveversion
- The version of the service to retrieve.- Returns:
- The Service instance or null if no service was found.
- Throws:
XMLDBException
- with expected error codes.
ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
ErrorCodes.COLLECTION_CLOSED
if theclose
method has been called on theCollection
-
registerService
Registers a new Service with this Collection.- Parameters:
service
- Description of Parameter- Throws:
XMLDBException
-
getParentCollection
Default behaviour for a non-hierarchical implementation- Specified by:
getParentCollection
in interfaceCollection
- Returns:
- the parent
Collection
instance. - Throws:
XMLDBException
- with expected error codes.
ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
ErrorCodes.COLLECTION_CLOSED
if theclose
method has been called on theCollection
-
getChildCollectionCount
Default behaviour for a non-hierarchical implementation- Specified by:
getChildCollectionCount
in interfaceCollection
- Returns:
- the number of child collections.
- Throws:
XMLDBException
- with expected error codes.
ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
ErrorCodes.COLLECTION_CLOSED
if theclose
method has been called on theCollection
-
listChildCollections
Default behaviour for a non-hierarchical implementation- Specified by:
listChildCollections
in interfaceCollection
- Returns:
- an array containing collection names for all child collections.
- Throws:
XMLDBException
- with expected error codes.
ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
ErrorCodes.COLLECTION_CLOSED
if theclose
method has been called on theCollection
-
getChildCollection
Default behaviour for a non-hierarchical implementation- Specified by:
getChildCollection
in interfaceCollection
- 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
- with expected error codes.
ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
ErrorCodes.COLLECTION_CLOSED
if theclose
method has been called on theCollection
-
getResourceCount
Returns the number of resources currently stored in this collection or 0 if the collection is empty.- Specified by:
getResourceCount
in interfaceCollection
- 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
Returns a list of the ids for all resources stored in the collection.- Specified by:
listResources
in interfaceCollection
- Returns:
- a string array containing the names for all
Resource
s in the collection. - Throws:
XMLDBException
- with expected error codes.
ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
-
createResource
Creates a new emptyResource
with the provided id. The type ofResource
returned is determined by thetype
parameter. The XML:DB API currently defines "XMLResource" and "BinaryResource" as valid resource types. Theid
provided must be unique within the scope of the collection. Ifid
is null or its value is empty then an id is generated by callingcreateId()
. TheResource
created is not stored to the database untilstoreResource()
is called.- Specified by:
createResource
in interfaceCollection
- Parameters:
id
- the unique id to associate with the createdResource
.type
- theResource
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 thetype
parameter is not a knownResource
type.
-
removeResource
Removes theResource
from the database.- Specified by:
removeResource
in interfaceCollection
- 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 theResource
is not valid.
ErrorCodes.NO_SUCH_RESOURCE
if theResource
is not known to thisCollection
.
-
storeResource
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.- Specified by:
storeResource
in interfaceCollection
- 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 theResource
is not valid.
-
getResource
Retrieves aResource
from the database. If theResource
could not be located a null value will be returned.- Specified by:
getResource
in interfaceCollection
- 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
Creates a new unique ID within the context of theCollection
- Specified by:
createId
in interfaceCollection
- Returns:
- the created id as a string.
- Throws:
XMLDBException
- with expected error codes.
ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
-
isOpen
Description copied from interface:Collection
Returns true if theCollection
is open false otherwise. Calling theclose
method onCollection
will result inisOpen
returning false. It is not safe to useCollection
instances that have been closed.- Specified by:
isOpen
in interfaceCollection
- Returns:
- true if the
Collection
is open, false otherwise. - Throws:
XMLDBException
- with expected error codes.
ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
-
close
Releases all resources consumed by theCollection
. Theclose
method must always be called when use of aCollection
is complete.- Specified by:
close
in interfaceCollection
- Throws:
XMLDBException
- with expected error codes.
ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
-