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
public class QueryTemplate extends QueryBox implements Query
AQuerythat interpolates named parameters inside a template.Templates are strings with empty XML elements, optionally with a
DEFAULTattribute, 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
-
-
Constructor Summary
Constructors Constructor Description QueryTemplate(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddParameter(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.Stringexpression()Returns the textual expression of the query.booleanhasParameter(String name)Returnstrueif the query has a given parameter.Stringparameter(String name)Returns the current value of a parameter.
-
-
-
Field Detail
-
DEFAULT
public static final String DEFAULT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
QueryTemplate
public QueryTemplate(String template)
Creates an instance with a template.- Parameters:
template- the template
-
-
Method Detail
-
expression
public String expression()
Description copied from interface:QueryReturns the textual expression of the query.- Specified by:
expressionin interfaceQuery- Overrides:
expressionin classQueryBox- Returns:
- the expression.
-
addParameter
public void addParameter(String name, String value)
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
public void appendParameter(String name, String value)
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
public String parameter(String name) throws IllegalStateException
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
public boolean hasParameter(String name)
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
-
-