Class QueryTemplate
java.lang.Object
org.gcube.resources.discovery.client.queries.impl.QueryBox
org.gcube.resources.discovery.client.queries.impl.QueryTemplate
- All Implemented Interfaces:
Query
- Direct Known Subclasses:
XQuery
A
Query that interpolates named parameters inside a template.
Templates are strings with empty XML elements, optionally with a DEFAULT attribute, e.g.:
all results that satisfy <cond1/> or <cond2 def='that'/> <extra/>
Whenever expression() is invoked, the elements in the template are replaced according to the first rule that applies
among the following:
- by the value of an equally named parameter, if one exists
- by the value of the
DEFAULTattribute, if one exists - by the empty string
cond1="this", expression() returns:
all results that satisfy this or that
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionQueryTemplate(String template) Creates an instance with a template.QueryTemplate(String template, Map<String, String> parameters) Creates an instance with a template and an initial set of parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddParameter(String name, String value) Adds a parameter to the query, overwriting any value that it may already have.voidappendParameter(String name, String value) Adds a parameter to the query, extending any value that it may already have.Returns the textual expression of the query.booleanhasParameter(String name) Returnstrueif the query has a given parameter.Returns the current value of a parameter.
-
Field Details
-
DEFAULT
- See Also:
-
-
Constructor Details
-
QueryTemplate
Creates an instance with a template.- Parameters:
template- the template
-
QueryTemplate
Creates an instance with a template and an initial set of parameters.- Parameters:
template- the template
-
-
Method Details
-
expression
Description copied from interface:QueryReturns the textual expression of the query.- Specified by:
expressionin interfaceQuery- Overrides:
expressionin classQueryBox- Returns:
- the expression.
-
addParameter
Adds a parameter to the query, overwriting any value that it may already have.- Parameters:
name- the parameter namevalue- the parameter value- Throws:
IllegalStateException- if the parameter name or value arenull
-
appendParameter
Adds a parameter to the query, extending any value that it may already have.- Parameters:
name- the parameter namevalue- the value- Throws:
IllegalStateException- if the parameter name or value arenull
-
parameter
Returns the current value of a parameter.- Parameters:
name- the parameter name- Returns:
- the value
- Throws:
IllegalStateException- if the parameter does not existIllegalStateException- if the parameter name isnull
-
hasParameter
Returnstrueif the query has a given parameter.- Parameters:
name- the parameter name- Returns:
trueif the query has a given parameter,falseotherwise- Throws:
IllegalStateException- if the parameter name isnull
-