## org.exist.xmldb
Class LocalCollection

    java.lang.Object
      java.util.Observable
          org.exist.xmldb.LocalCollection

All Implemented Interfaces:
  Collection, CollectionImpl, Configurable

public class LocalCollection
extends java.util.Observable
implements CollectionImpl

A local implementation of the Collection interface. This is used when the database is running in embedded mode. Extends Observable to allow status callbacks during indexing. Methods storeResource notifies registered observers about the progress of the indexer by passing an object of type ProgressIndicator to the observer.

Author:
  wolf

Constructor Summary
`LocalCollection(User user, BrokerPool brokerPool, LocalCollection parent, XmldbURI name, AccessContext accessCtx)` Create a collection identified by its name.
`LocalCollection(User user, BrokerPool brokerPool, XmldbURI collection, AccessContext accessCtx)` Create a collection with no parent (root collection).

Method Summary
`void` `addObserver(java.util.Observer o)` Add a new observer to the list.
`void` `close()` Close the current 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.
`AccessContext` `getAccessContext()`
`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[]` `getChildCollections()`
`java.util.Date` `getCreationTime()` Returns the time of creation of the collection.
`java.lang.String` `getName()` Returns the name associated with the Collection instance.
`Collection` `getParentCollection()` Returns the parent collection for this collection or null if no parent collection exists.
`java.lang.String` `getPath()`
`XmldbURI` `getPathURI()`
`java.lang.String` `getProperty(java.lang.String property)` Returns the value of the property identified by `name`.
`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.
`java.lang.String[]` `getResources()`
`Service` `getService(java.lang.String name, java.lang.String version)` Possible services: XPathQueryService, XQueryService, CollectionManagementService (CollectionManager), UserManagementService, DatabaseInstanceManager, XUpdateQueryService, IndexQueryService, ValidationService.
`Service[]` `getServices()` Provides a list of all services known to the collection.
`XmldbURI` `getURI()`
`boolean` `isOpen()` Returns true if the `Collection` is open false otherwise.
`boolean` `isRemoteCollection()`
`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.
`void` `registerService(Service serv)`
`void` `removeResource(Resource res)` Removes the `Resource` from the database.
`void` `setProperty(java.lang.String property, java.lang.String value)` Sets the property `name` to have the value provided in `value`.
`void` `setReader(org.xml.sax.XMLReader reader)` set user-defined Reader
`void` `storeResource(Resource resource)` Stores the provided resource into the database.
`void` `storeResource(Resource resource, java.util.Date a, java.util.Date b)`

Methods inherited from class java.util.Observable
`countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### LocalCollection

    public LocalCollection(User user,
                           BrokerPool brokerPool,
                           XmldbURI collection,
                           AccessContext accessCtx)
                    throws XMLDBException

  Create a collection with no parent (root collection).

Parameters:
  `user` -
  `brokerPool` -
  `collection` -
Throws:
  `XMLDBException`

### LocalCollection

    public LocalCollection(User user,
                           BrokerPool brokerPool,
                           LocalCollection parent,
                           XmldbURI name,
                           AccessContext accessCtx)
                    throws XMLDBException

  Create a collection identified by its name. Load the collection from the database.

Parameters:
  `user` -
  `brokerPool` -
  `parent` -
  `name` -
Throws:
  `XMLDBException`

Method Detail

### getAccessContext

    public AccessContext getAccessContext()

### close

    public void close()
               throws XMLDBException

  Close the current collection. Calling this method will flush all open buffers to disk.

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

### createId

    public java.lang.String createId()
                              throws XMLDBException

  Description copied from interface: `Collection`
  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.
    `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### createResource

    public Resource createResource(java.lang.String id,
                                   java.lang.String type)
                            throws XMLDBException

  Description copied from interface: `Collection`
  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.

  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. `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### getChildCollection

    public Collection getChildCollection(java.lang.String name)
                                  throws XMLDBException

  Description copied from interface: `Collection`
  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` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.
    `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### getChildCollectionCount

    public int getChildCollectionCount()
                                throws XMLDBException

  Description copied from interface: `Collection`
  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` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.
    `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### getName

    public java.lang.String getName()
                             throws XMLDBException

  Description copied from interface: `Collection`
  Returns the name associated with the Collection instance.

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

### getParentCollection

    public Collection getParentCollection()
                                   throws XMLDBException

  Description copied from interface: `Collection`
  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` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.
    `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### getPath

    public java.lang.String getPath()
                             throws XMLDBException

  Throws:
    `XMLDBException`

### getPathURI

    public XmldbURI getPathURI()

  Specified by:
    `getPathURI` in interface `CollectionImpl`

### getProperty

    public java.lang.String getProperty(java.lang.String property)
                                 throws XMLDBException

  Description copied from interface: `Configurable`
  Returns the value of the property identified by `name`.

  Specified by:
    `getProperty` in interface `Configurable`
  Parameters:
    `property` - the name of the property to retrieve.
  Returns:
    the property value or null if no property exists.
  Throws:
    `XMLDBException` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.

### 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.
    `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### 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.
    `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### getService

    public Service getService(java.lang.String name,
                              java.lang.String version)
                       throws XMLDBException

  Possible services: XPathQueryService, XQueryService, CollectionManagementService (CollectionManager), UserManagementService, DatabaseInstanceManager, XUpdateQueryService, IndexQueryService, ValidationService.

  Specified by:
    `getService` in interface `Collection`
  Parameters:
    `name` - Description of Parameter
    `version` - Description of Parameter
  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.
    `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### 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:
    An array of registered `Service` implementations.
  Throws:
    `XMLDBException` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.
    `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### isOpen

    public boolean isOpen()
                   throws XMLDBException

  Description copied from interface: `Collection`
  Returns true if the `Collection` is open false otherwise. Calling the `close` method on `Collection` will result in `isOpen` returning false. It is not safe to use `Collection` instances that have been closed.

  Specified by:
    `isOpen` in interface `Collection`
  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.

### listChildCollections

    public java.lang.String[] listChildCollections()
                                            throws XMLDBException

  Description copied from interface: `Collection`
  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` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.
    `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### getChildCollections

    public java.lang.String[] getChildCollections()
                                           throws XMLDBException

  Specified by:
    `getChildCollections` in interface `CollectionImpl`
  Throws:
    `XMLDBException`

### listResources

    public java.lang.String[] listResources()
                                     throws XMLDBException

  Description copied from interface: `Collection`
  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 `Resource`s in the collection.
  Throws:
    `XMLDBException` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.
    `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### getResources

    public java.lang.String[] getResources()
                                    throws XMLDBException

  Specified by:
    `getResources` in interface `CollectionImpl`
  Throws:
    `XMLDBException`

### registerService

    public void registerService(Service serv)
                         throws XMLDBException

  Throws:
    `XMLDBException`

### removeResource

    public void removeResource(Resource res)
                        throws XMLDBException

  Description copied from interface: `Collection`
  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`. `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### setProperty

    public void setProperty(java.lang.String property,
                            java.lang.String value)
                     throws XMLDBException

  Description copied from interface: `Configurable`
  Sets the property `name` to have the value provided in `value`.

  Specified by:
    `setProperty` in interface `Configurable`
  Parameters:
    `property` - the name of the property to set.
    `value` - the value to set for the property.
  Throws:
    `XMLDBException` - with expected error codes.
    `ErrorCodes.VENDOR_ERROR` for any vendor specific errors that occur.

### storeResource

    public void storeResource(Resource resource)
                       throws XMLDBException

  Description copied from interface: `Collection`
  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 interface `Collection`
  Parameters:
    `resource` - 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. `ErrorCodes.COLLECTION_CLOSED` if the `close` method has been called on the `Collection`

### storeResource

    public void storeResource(Resource resource,
                              java.util.Date a,
                              java.util.Date b)
                       throws XMLDBException

  Specified by:
    `storeResource` in interface `CollectionImpl`
  Throws:
    `XMLDBException`

### getCreationTime

    public java.util.Date getCreationTime()
                                   throws XMLDBException

  Description copied from interface: `CollectionImpl`
  Returns the time of creation of the collection.

  Specified by:
    `getCreationTime` in interface `CollectionImpl`
  Throws:
    `XMLDBException`

### addObserver

    public void addObserver(java.util.Observer o)

  Add a new observer to the list. Observers are just passed on to the indexer to be notified about the indexing progress.

### isRemoteCollection

    public boolean isRemoteCollection()
                               throws XMLDBException

  Specified by:
    `isRemoteCollection` in interface `CollectionImpl`
  Throws:
    `XMLDBException`

### setReader

    public void setReader(org.xml.sax.XMLReader reader)

  set user-defined Reader

  Parameters:
    `reader` -

### getURI

    public XmldbURI getURI()

  Specified by:
    `getURI` in interface `CollectionImpl`

Copyright (C) Wolfgang Meier. All rights reserved.