java.module
Class Query

java.lang.Object
  extended by java.module.Query
All Implemented Interfaces:
Serializable

public abstract class Query
extends Object
implements Serializable

This class represents a query that determines whether or not a particular module definition matches some criteria. The static methods provided return query that may be used in matching ModuleDefinition. Composition of calls can construct arbitrary nestings of constraints, as the following example illustrates:

 Query query = Query.and(Query.name("com.wombat.webservice"),
                           Query.versionRange("2.0.0+"));
 

Since:
1.7.0
Author:
Stanley M. Ho
See Also:
ModuleDefinition, VersionConstraint, Serialized Form

Field Summary
static Query ANY
          A Query object that matches everything.
 
Constructor Summary
protected Query()
          Creates a new Query instance.
 
Method Summary
static Query and(Query query1, Query query2)
          Returns a Query that is the conjunction of two other queries.
static Query attribute(String name)
          Returns a Query that requires the specified name of a module attribute exists.
static Query attribute(String name, String value)
          Returns a Query that requires an attribute of a module definition matches the specified name and value.
abstract  boolean match(ModuleDefinition target)
          Determine if the specified module definition matches this query.
static Query name(String name)
          Returns a Query that requires the name of a module definition equals to the specified name.
static Query not(Query query)
          Returns a Query that inverts the specified query.
static Query or(Query query1, Query query2)
          Returns a Query that is the disjunction of two other queries.
static Query version(String source)
          Returns a Query that requires the version of a module definition to be contained within any of the ranges known to the specified version constraint.
static Query version(VersionConstraint versionConstraint)
          Returns a Query that requires the version of a module definition to be contained within any of the ranges known to the specified version constraint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANY

public static final Query ANY
A Query object that matches everything.

Constructor Detail

Query

protected Query()
Creates a new Query instance.

Method Detail

not

public static Query not(Query query)
Returns a Query that inverts the specified query.

Parameters:
query - the specified query.
Returns:
the Query object.
Throws:
NullPointerException - if query is null.

and

public static Query and(Query query1,
                        Query query2)
Returns a Query that is the conjunction of two other queries.

Parameters:
query1 - A query.
query2 - Another query.
Returns:
the Query object.
Throws:
NullPointerException - if query1 is null or query2 is null.

or

public static Query or(Query query1,
                       Query query2)
Returns a Query that is the disjunction of two other queries.

Parameters:
query1 - A query.
query2 - Another query.
Returns:
the Query object.
Throws:
NullPointerException - if query1 is null or query2 is null.

version

public static Query version(String source)
Returns a Query that requires the version of a module definition to be contained within any of the ranges known to the specified version constraint. The string must not contain any leading or trailing whitespace.

Parameters:
source - the string to be parsed.
Returns:
the Query object.
Throws:
IllegalArgumentException - if the string does not follow the version constraint format.
NullPointerException - if source is null.

version

public static Query version(VersionConstraint versionConstraint)
Returns a Query that requires the version of a module definition to be contained within any of the ranges known to the specified version constraint.

Parameters:
versionConstraint - the VersionConstraint object.
Returns:
the Query object.
Throws:
NullPointerException - if versionConstraint is null.

name

public static Query name(String name)
Returns a Query that requires the name of a module definition equals to the specified name.

Parameters:
name - the name of the module definition.
Returns:
the Query object.
Throws:
NullPointerException - if name is null.

attribute

public static Query attribute(String name)
Returns a Query that requires the specified name of a module attribute exists.

Parameters:
name - the name of the module attribute.
Returns:
the Query object.
Throws:
NullPointerException - if name is null.

attribute

public static Query attribute(String name,
                              String value)
Returns a Query that requires an attribute of a module definition matches the specified name and value.

Parameters:
name - the name of the module attribute.
value - the value of the module attribute.
Returns:
the Query object.
Throws:
NullPointerException - if name is null or value is null.

match

public abstract boolean match(ModuleDefinition target)
Determine if the specified module definition matches this query.

Parameters:
target - the ModuleDefinition to be matched.
Returns:
true if the ModuleDefinition matches this query.