org.gcube.resources.discovery.client.queries.impl
Class QueryTemplate

java.lang.Object
  extended by org.gcube.resources.discovery.client.queries.impl.QueryBox
      extended by org.gcube.resources.discovery.client.queries.impl.QueryTemplate
All Implemented Interfaces:
Query
Direct Known Subclasses:
XQuery

public class QueryTemplate
extends QueryBox
implements Query

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:

For example, given the previous template and the single parameter cond1="this", expression() returns:

all results that satisfy this or that


Field Summary
static String DEFAULT
           
 
Constructor Summary
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
 void addParameter(String name, String value)
          Adds a parameter to the query, overwriting any value that it may already have.
 void appendParameter(String name, String value)
          Adds a parameter to the query, extending any value that it may already have.
 String expression()
          Returns the textual expression of the query.
 boolean hasParameter(String name)
          Returns true if the query has a given parameter.
 String parameter(String name)
          Returns the current value of a parameter.
 
Methods inherited from class org.gcube.resources.discovery.client.queries.impl.QueryBox
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

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

QueryTemplate

public QueryTemplate(String template,
                     Map<String,String> parameters)
Creates an instance with a template and an initial set of parameters.

Parameters:
template - the template
Method Detail

expression

public String expression()
Description copied from interface: Query
Returns the textual expression of the query.

Specified by:
expression in interface Query
Overrides:
expression in class QueryBox
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 name
value - the parameter value
Throws:
IllegalStateException - if the parameter name or value are null

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 name
value - the value
Throws:
IllegalStateException - if the parameter name or value are null

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 exist
IllegalStateException - if the parameter name is null

hasParameter

public boolean hasParameter(String name)
Returns true if the query has a given parameter.

Parameters:
name - the parameter name
Returns:
true if the query has a given parameter, false otherwise
Throws:
IllegalStateException - if the parameter name is null


Copyright © 2013. All Rights Reserved.