Package org.xmldb.api
Class DatabaseManager
- java.lang.Object
-
- org.xmldb.api.DatabaseManager
-
public class DatabaseManager extends java.lang.ObjectDatabaseManageris the entry point for the API and enables you to get the initialCollectionreferences necessary to do anything useful with the API.DatabaseManageris intended to be provided as a concrete implementation in a particular programming language. Individual language mappings should define the exact syntax and semantics of its use.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.util.Map<java.lang.String,Database>databases(package private) static java.util.concurrent.locks.StampedLockdbLock(package private) static java.util.Propertiesproperties(package private) static booleanstrictRegistrationBehaviorprotected static java.lang.StringURI_PREFIX
-
Constructor Summary
Constructors Constructor Description DatabaseManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidderegisterDatabase(Database database)Deregisters aDatabaseimplementation from theDatabaseManager.static CollectiongetCollection(java.lang.String uri)Retrieves aCollectioninstance from the database for the given URI.static CollectiongetCollection(java.lang.String uri, java.lang.String username, java.lang.String password)Retrieves aCollectioninstance from the database for the given URI.static java.lang.StringgetConformanceLevel(java.lang.String uri)Returns the Core Level conformance value for the provided URI.protected static DatabasegetDatabase(java.lang.String uri)Retrieves the registeredDatabaseinstance associated with the provided URI.static Database[]getDatabases()Returns a list of all availableDatabaseimplementations that have been registered with thisDatabaseManager.static java.lang.StringgetProperty(java.lang.String name)Retrieves a property that has been set for theDatabaseManager.static voidregisterDatabase(Database database)Registers a newDatabaseimplementation with theDatabaseManager.static voidsetProperty(java.lang.String name, java.lang.String value)Sets a property for theDatabaseManager.protected static java.lang.StringstripURIPrefix(java.lang.String uri)Removes the URI_PREFIX from the front of the URI.private static voidupdateDatabases(java.lang.String databaseName, Database database)
-
-
-
Field Detail
-
URI_PREFIX
protected static final java.lang.String URI_PREFIX
- See Also:
- Constant Field Values
-
properties
static final java.util.Properties properties
-
dbLock
static final java.util.concurrent.locks.StampedLock dbLock
-
databases
static final java.util.Map<java.lang.String,Database> databases
-
strictRegistrationBehavior
static boolean strictRegistrationBehavior
-
-
Method Detail
-
getDatabases
public static Database[] getDatabases()
Returns a list of all availableDatabaseimplementations that have been registered with thisDatabaseManager.- Returns:
- An array of
Databaseinstances. One for eachDatabaseregistered with theDatabaseManager. If noDatabaseinstances exist then an empty array is returned.
-
registerDatabase
public static void registerDatabase(Database database) throws XMLDBException
Registers a newDatabaseimplementation with theDatabaseManager.- Parameters:
database- The database instance to register.- Throws:
XMLDBException- with expected error codes.ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.ErrorCodes.INVALID_DATABASEif the providedDatabaseinstance is invalid.
-
updateDatabases
private static void updateDatabases(java.lang.String databaseName, Database database) throws XMLDBException- Throws:
XMLDBException
-
deregisterDatabase
public static void deregisterDatabase(Database database) throws XMLDBException
Deregisters aDatabaseimplementation from theDatabaseManager. Once aDatabasehas been deregistered it can no longer be used to handle requests.- Parameters:
database- TheDatabaseinstance to deregister.- Throws:
XMLDBException- with expected error codes.ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.
-
getCollection
public static Collection getCollection(java.lang.String uri) throws XMLDBException
Retrieves aCollectioninstance from the database for the given URI. The format of the majority of the URI is database implementation specific however the uri must begin with characters xmldb: and be followed by the name of the database instance as returned byDatabase.getName()and a colon character. An example would be for the database named "vendordb" the URI handed to getCollection would look something like the following.xmldb:vendordb://host:port/path/to/collection. The xmldb: prefix will be removed from the URI prior to handing the URI to theDatabaseinstance for handling. This method is called when no authentication is necessary for the database.- Parameters:
uri- The database specific URI to use to locate the collection.- Returns:
- A
Collectioninstance for the requested collection or null if the collection could not be found. - Throws:
XMLDBException- with expected error codes.ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.ErrroCodes.INVALID_URIIf the URI is not in a valid format.ErrroCodes.NO_SUCH_DATABASEIf aDatabaseinstance could not be found to handle the provided URI.
-
getCollection
public static Collection getCollection(java.lang.String uri, java.lang.String username, java.lang.String password) throws XMLDBException
Retrieves aCollectioninstance from the database for the given URI. The format of the majority of the URI is database implementation specific however the uri must begin with characters xmldb: and be followed by the name of the database instance as returned byDatabase.getName()and a colon character. An example would be for the database named "vendordb" the URI handed to getCollection would look something like the following.xmldb:vendordb://host:port/path/to/collection. The xmldb: prefix will be removed from the URI prior to handing the URI to theDatabaseinstance for handling.- Parameters:
uri- The database specific URI to use to locate the collection.username- The username to use for authentication to the database or null if the database does not support authentication.password- The password to use for authentication to the database or null if the database does not support authentication.- Returns:
- A
Collectioninstance for the requested collection or null if the collection could not be found. - Throws:
XMLDBException- with expected error codes.ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.ErrroCodes.INVALID_URIIf the URI is not in a valid format.ErrroCodes.NO_SUCH_DATABASEIf aDatabaseinstance could not be found to handle the provided URI.ErrroCodes.PERMISSION_DENIEDIf theusernameandpasswordwere not accepted by the database.
-
getConformanceLevel
public static java.lang.String getConformanceLevel(java.lang.String uri) throws XMLDBExceptionReturns the Core Level conformance value for the provided URI. The current API defines valid resuls of "0" or "1" as defined in the XML:DB API specification.- Parameters:
uri- The database specific URI to use to locate the collection.- Returns:
- The XML:DB Core Level conformance for the uri.
- Throws:
XMLDBException- with expected error codes.ErrorCodes.VENDOR_ERRORfor any vendor specific errors that occur.ErrroCodes.INVALID_URIIf the URI is not in a valid format.ErrroCodes.NO_SUCH_DATABASEIf aDatabaseinstance could not be found to handle the provided URI.
-
getProperty
public static java.lang.String getProperty(java.lang.String name)
Retrieves a property that has been set for theDatabaseManager.- Parameters:
name- The property name- Returns:
- The property value
-
setProperty
public static void setProperty(java.lang.String name, java.lang.String value)Sets a property for theDatabaseManager.- Parameters:
name- The property namevalue- The value to set.
-
getDatabase
protected static Database getDatabase(java.lang.String uri) throws XMLDBException
Retrieves the registeredDatabaseinstance associated with the provided URI.- Parameters:
uri- The uri containing the database reference.- Returns:
- the requested
Databaseinstance. - Throws:
XMLDBException- if an error occurs whilst getting the database
-
stripURIPrefix
protected static java.lang.String stripURIPrefix(java.lang.String uri) throws XMLDBExceptionRemoves the URI_PREFIX from the front of the URI. This is so the database can focus on handling its own URIs.- Parameters:
uri- The full URI to strip.- Returns:
- The database specific portion of the URI.
- Throws:
XMLDBException- if an error occurs whilst stripping the URI prefix
-
-