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
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.
-
-
Constructor Summary
Constructors Constructor Description SimpleCollection()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Releases all resources consumed by theCollection.java.lang.StringcreateId()Creates a new unique ID within the context of theCollectionResourcecreateResource(java.lang.String id, java.lang.String type)Creates a new emptyResourcewith the provided id.CollectiongetChildCollection(java.lang.String name)Default behaviour for a non-hierarchical implementationintgetChildCollectionCount()Default behaviour for a non-hierarchical implementationjava.lang.StringgetName()Returns the name associated with the Configurable object.CollectiongetParentCollection()Default behaviour for a non-hierarchical implementationResourcegetResource(java.lang.String id)Retrieves aResourcefrom the database.intgetResourceCount()Returns the number of resources currently stored in this collection or 0 if the collection is empty.ServicegetService(java.lang.String name, java.lang.String version)Get a Service instance based on the name and version.Service[]getServices()Returns the list of Services supported by this Collection.booleanisOpen()Returns true if theCollectionis open false otherwise.java.lang.String[]listChildCollections()Default behaviour for a non-hierarchical implementationjava.lang.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 theResourcefrom the database.voidstoreResource(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
-
-
-
-
Method Detail
-
getName
public java.lang.String getName() throws XMLDBExceptionReturns the name associated with the Configurable object.- Specified by:
getNamein interfaceCollection- Returns:
- the name of the object.
- Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
-
getServices
public Service[] getServices() throws XMLDBException
Returns the list of Services supported by this Collection.- Specified by:
getServicesin interfaceCollection- Returns:
- A list of supported Services
- Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
ErrorCodes.COLLECTION_CLOSEDif theclosemethod has been called on theCollection
-
getService
public Service getService(java.lang.String name, java.lang.String version) throws XMLDBException
Get a Service instance based on the name and version.- Specified by:
getServicein 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_ERRORfor any vendor specific errors that occur.
ErrorCodes.COLLECTION_CLOSEDif theclosemethod has been called on theCollection
-
registerService
public void registerService(Service service) throws XMLDBException
Registers a new Service with this Collection.- Parameters:
service- Description of Parameter- Throws:
XMLDBException
-
getParentCollection
public Collection getParentCollection() throws XMLDBException
Default behaviour for a non-hierarchical implementation- Specified by:
getParentCollectionin interfaceCollection- Returns:
- the parent
Collectioninstance. - Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
ErrorCodes.COLLECTION_CLOSEDif theclosemethod has been called on theCollection
-
getChildCollectionCount
public int getChildCollectionCount() throws XMLDBExceptionDefault behaviour for a non-hierarchical implementation- Specified by:
getChildCollectionCountin interfaceCollection- Returns:
- the number of child collections.
- Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
ErrorCodes.COLLECTION_CLOSEDif theclosemethod has been called on theCollection
-
listChildCollections
public java.lang.String[] listChildCollections() throws XMLDBExceptionDefault behaviour for a non-hierarchical implementation- Specified by:
listChildCollectionsin interfaceCollection- Returns:
- an array containing collection names for all child collections.
- Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
ErrorCodes.COLLECTION_CLOSEDif theclosemethod has been called on theCollection
-
getChildCollection
public Collection getChildCollection(java.lang.String name) throws XMLDBException
Default behaviour for a non-hierarchical implementation- Specified by:
getChildCollectionin 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_ERRORfor any vendor specific errors that occur.
ErrorCodes.COLLECTION_CLOSEDif theclosemethod has been called on theCollection
-
getResourceCount
public int getResourceCount() throws XMLDBExceptionReturns the number of resources currently stored in this collection or 0 if the collection is empty.- Specified by:
getResourceCountin interfaceCollection- Returns:
- the number of resource in the collection.
- Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
-
listResources
public java.lang.String[] listResources() throws XMLDBExceptionReturns a list of the ids for all resources stored in the collection.- Specified by:
listResourcesin interfaceCollection- Returns:
- a string array containing the names for all
Resources in the collection. - Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
-
createResource
public Resource createResource(java.lang.String id, java.lang.String type) throws XMLDBException
Creates a new emptyResourcewith the provided id. The type ofResourcereturned is determined by thetypeparameter. The XML:DB API currently defines "XMLResource" and "BinaryResource" as valid resource types. Theidprovided must be unique within the scope of the collection. Ifidis null or its value is empty then an id is generated by callingcreateId(). TheResourcecreated is not stored to the database untilstoreResource()is called.- Specified by:
createResourcein interfaceCollection- Parameters:
id- the unique id to associate with the createdResource.type- theResourcetype to create.- Returns:
- an empty
Resourceinstance. - Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
ErrorCodes.UNKNOWN_RESOURCE_TYPEif thetypeparameter is not a knownResourcetype.
-
removeResource
public void removeResource(Resource res) throws XMLDBException
Removes theResourcefrom the database.- Specified by:
removeResourcein interfaceCollection- Parameters:
res- the resource to remove.- Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
ErrorCodes.INVALID_RESOURCEif theResourceis not valid.
ErrorCodes.NO_SUCH_RESOURCEif theResourceis not known to thisCollection.
-
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.- Specified by:
storeResourcein interfaceCollection- Parameters:
res- the resource to store in the database.- Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
ErrorCodes.INVALID_RESOURCEif theResourceis not valid.
-
getResource
public Resource getResource(java.lang.String id) throws XMLDBException
Retrieves aResourcefrom the database. If theResourcecould not be located a null value will be returned.- Specified by:
getResourcein interfaceCollection- Parameters:
id- the unique id for the requested resource.- Returns:
- The retrieved
Resourceinstance. - Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
-
createId
public java.lang.String createId() throws XMLDBExceptionCreates a new unique ID within the context of theCollection- Specified by:
createIdin interfaceCollection- Returns:
- the created id as a string.
- Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
-
isOpen
public boolean isOpen() throws XMLDBExceptionDescription copied from interface:CollectionReturns true if theCollectionis open false otherwise. Calling theclosemethod onCollectionwill result inisOpenreturning false. It is not safe to useCollectioninstances that have been closed.- Specified by:
isOpenin interfaceCollection- Returns:
- true if the
Collectionis open, false otherwise. - Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
-
close
public void close() throws XMLDBExceptionReleases all resources consumed by theCollection. Theclosemethod must always be called when use of aCollectionis complete.- Specified by:
closein interfaceCollection- Throws:
XMLDBException- with expected error codes.
ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
-
-