Package org.xmldb.api.modules
Interface XQueryService
-
- All Superinterfaces:
Configurable
,Service
public interface XQueryService extends Service
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
SERVICE_NAME
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clearNamespaces()
Clears all namespace mappings defined.CompiledExpression
compile(java.lang.String query)
Compiles the specified XQuery and returns a handle to the compiled code, which can then be passed toexecute(org.xmldb.api.base.CompiledExpression)
.void
declareVariable(java.lang.String qname, java.lang.Object initialValue)
Declare a global, external XQuery variable and assign a value to it.ResourceSet
execute(CompiledExpression expression)
Execute a compiled XQuery.java.lang.String
getNamespace(java.lang.String prefix)
Returns the URI string associated withprefix
from the internal namespace map.ResourceSet
query(java.lang.String query)
Executes the given query and returns the result as a resource set.ResourceSet
queryResource(java.lang.String id, java.lang.String query)
Executes the given query and returns the result as a resource set.void
removeNamespace(java.lang.String prefix)
Removes the namespace mapping associated withprefix
from the internal namespace map.void
setModuleLoadPath(java.lang.String path)
Sets the new module load path.void
setNamespace(java.lang.String prefix, java.lang.String uri)
Sets a namespace mapping in the internal namespace map used to evaluate queries.void
setXPathCompatibility(boolean backwardsCompatible)
Enable or disable XPath 1.0 compatibility mode.-
Methods inherited from interface org.xmldb.api.base.Configurable
getProperty, getProperty, setProperty
-
Methods inherited from interface org.xmldb.api.base.Service
getName, getVersion, setCollection
-
-
-
-
Field Detail
-
SERVICE_NAME
static final java.lang.String SERVICE_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
setNamespace
void setNamespace(java.lang.String prefix, java.lang.String uri) throws XMLDBException
Sets a namespace mapping in the internal namespace map used to evaluate queries. Ifprefix
is null or empty the default namespace is associated with the provided URI. A null or emptyuri
results in an exception being thrown.- Parameters:
prefix
- The prefix to set in the map. Ifprefix
is empty or null the default namespace will be associated with the provided URI.uri
- The URI for the namespace to be associated with prefix.- Throws:
XMLDBException
- if an error occurs whilst setting the namespace.
-
getNamespace
java.lang.String getNamespace(java.lang.String prefix) throws XMLDBException
Returns the URI string associated withprefix
from the internal namespace map. Ifprefix
is null or empty the URI for the default namespace will be returned. If a mapping for theprefix
can not be found null is returned.- Parameters:
prefix
- The prefix to retrieve from the namespace map.- Returns:
- The URI associated with
prefix
- Throws:
XMLDBException
- with expected error codes.ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.XMLDBException
- if an error occurs whilst getting the namespace.
-
removeNamespace
void removeNamespace(java.lang.String prefix) throws XMLDBException
Removes the namespace mapping associated withprefix
from the internal namespace map. Ifprefix
is null or empty the mapping for the default namespace will be removed.- Parameters:
prefix
- The prefix to remove from the namespace map. Ifprefix
is null or empty the mapping for the default namespace will be removed.- Throws:
XMLDBException
- with expected error codes.ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
-
clearNamespaces
void clearNamespaces() throws XMLDBException
Clears all namespace mappings defined.- Throws:
XMLDBException
- with expected error codes.ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
-
query
ResourceSet query(java.lang.String query) throws XMLDBException
Executes the given query and returns the result as a resource set.- Parameters:
query
- The query to be executed- Returns:
- The query result
- Throws:
XMLDBException
- with expected error codes.ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
-
queryResource
ResourceSet queryResource(java.lang.String id, java.lang.String query) throws XMLDBException
Executes the given query and returns the result as a resource set.- Parameters:
id
- The id of a resourcequery
- The query to be executed- Returns:
- The query result
- Throws:
XMLDBException
- with expected error codes.ErrorCodes.VENDOR_ERROR
for any vendor specific errors that occur.
-
compile
CompiledExpression compile(java.lang.String query) throws XMLDBException
Compiles the specified XQuery and returns a handle to the compiled code, which can then be passed toexecute(org.xmldb.api.base.CompiledExpression)
.- Parameters:
query
- the query to compile.- Returns:
- the compiled query expression
- Throws:
XMLDBException
- if an error occurs whilst compiling the query.
-
execute
ResourceSet execute(CompiledExpression expression) throws XMLDBException
Execute a compiled XQuery. The implementation should pass all namespaces and variables declared throughXQueryService
to the compiled XQuery code.- Parameters:
expression
- the compiled query expression- Returns:
- the result of the query
- Throws:
XMLDBException
- if an error occurs whilst executing the query.
-
declareVariable
void declareVariable(java.lang.String qname, java.lang.Object initialValue) throws XMLDBException
Declare a global, external XQuery variable and assign a value to it. The variable has the same status as a variable declare through thedeclare variable
statement in the XQuery prolog. The variable can be referenced inside the XQuery expression as$variable
. For example, if you declare a variable withdeclareVariable("name", "HAMLET");
you may use the variable in an XQuery expression as follows:// SPEECH[SPEAKER=$name]
- Parameters:
qname
- a valid QName by which the variable is identified. Any prefix should have been mapped to a namespace, usingsetNamespace(String, String)
. For example, if a variable is called x:name, a prefix/namespace mapping should have been defined for prefixx
before calling this method.initialValue
- the initial value, which is assigned to the variable- Throws:
XMLDBException
- if an error occurs whilst declaring the variable.
-
setXPathCompatibility
void setXPathCompatibility(boolean backwardsCompatible)
Enable or disable XPath 1.0 compatibility mode. In XPath 1.0 compatibility mode, some XQuery expressions will behave different. In particular, additional automatic type conversions will be applied to the operands of numeric operators.- Parameters:
backwardsCompatible
- true it XPath 1.0 compatibility mode should be enabled.
-
setModuleLoadPath
void setModuleLoadPath(java.lang.String path)
Sets the new module load path.- Parameters:
path
- The module load path to be set.
-
-