com.ibm.di.server
Class SearchCriteria

java.lang.Object
  extended by com.ibm.di.server.SearchCriteria

public class SearchCriteria
extends Object

This class contains a list of generic search criteria and methods to generate them. The search criteria is e.g. attr equals value. The class also has a number of methods to convert the generic criteria to standard expressions like LDAP search filters, SQL select statements etc.

The class also provides a means to define templates which can be expanded using a com.ibm.di.entry.Entry object. The expanded templates can then be accessed through the criteria methods.

The typical use of this class is to:

Then for every entry you can use the buildCriteria method to expand the templates into the criteria array and use the getLDAPFilter etc to construct a search filter usable with specific connectors. The connectors themselves will use the getXXFilter methods to obtain the search filter in order to search for entries. However, if you write your own connector or for some other reason need to get hold of the expanded filters you can always use the getXX>Filter methods. These methods only build a string from the criteria array so no changes are done to the class variables.

All getXXXFilter methods first check if the class was created with a user defined script to return the search string. Thus, if you create an istance of this class with a script/ScriptEngine and use f.ex the LDAP connector, the search filter used by the LDAP connector will be the result of the script evaluation rather than the getLDAPFilter method.


Nested Class Summary
 class SearchCriteria.rscSearch
          This class is used internally.
 
Field Summary
static int EXACT
           
static int EXCACT
           
 String filter
           
static int FINAL_STRING
           
static int INITIAL_STRING
           
static int NOT_STRING
           
 ParameterSubstitutionCache psc
           
static int SEARCH_AND
           
static int SEARCH_NOT
           
static int SEARCH_OR
           
static int SUBSTRING
           
 
Constructor Summary
SearchCriteria()
           
SearchCriteria(int matchtype)
           
SearchCriteria(String name, int match, Object value)
           
SearchCriteria(String criteriaScript, ScriptEngine engine)
           
 
Method Summary
 void addCriteria(String name, int match, Object value)
          Add expression to criteria array.
 void addCriteria(String name, int match, Object value, boolean negate)
          Add expression to criteria array.
 void addTemplate(String name, int match, String defvalue)
          Add a criteria to the templates array.
 void addTemplate(String name, String match, String defvalue)
          Add a criteria to the templates array.
 void buildCriteria(Entry e)
          Build the criteria array using provided entry.
 void buildCriteria(Entry e, BaseConfiguration config, Object task)
           
 void buildCriteriaScript(Entry entry)
          Call user defined script to build the search filter.
 String buildLdapFilter(SearchCriteria.rscSearch rs)
          Constructs an LDAP search filter from an rscSearch class.
 String buildNotesFilter(SearchCriteria.rscSearch rs)
          Constructs an Notes search filter from an rscSearch class.
 String buildNotesFTFilter(SearchCriteria.rscSearch rs)
          Constructs an Notes FullText search filter from an rscSearch class.
 String buildSQLFilter(SearchCriteria.rscSearch rs)
          Constructs an SQL where expression from an rscSearch class.
 Vector getCriteria()
           
 SearchCriteria.rscSearch getCriteria(int index)
          Return criteria class at specified index.
 Entry getCurrentEntry()
          Return the working entry used to generate the criteria array from the templates array.
 int getFirstCriteriaMatch()
          Return match operator of first criteria entry.
 String getFirstCriteriaName()
          Return name of first criteria entry.
 String getFirstCriteriaValue()
          Return value of first criteria entry.
 String getLDAPFilter()
          Return complete LDAP filter from criteria array.
 String getNotesFilter()
          Return complete Notes search expression from criteria array.
 String getNotesFTFilter()
          Return complete Notes FullText search expression from criteria array.
 String getScriptFilter()
          This method executes a script that returns a user-defined search filter.
 String getSearchString(int i)
           
 String getSimpleFilter()
           
 String getSQLFilter()
          Return complete SQL search expression from criteria array.
 SearchCriteria.rscSearch getTemplate(int index)
          Returns the criteria template at a specific location.
 int getType()
          Return search type.
 boolean isConfigured()
           
 void replaceCriteria(String name, Object value)
          Add expression to criteria array, replacing all previous occurences with the same attribute name.
 void setType(int type)
          Set type (SEARCH_AND, SEARCH_OR) for the search criteria.
 int size()
          Return number of templates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXACT

public static final int EXACT
See Also:
Constant Field Values

EXCACT

public static final int EXCACT
See Also:
Constant Field Values

SUBSTRING

public static final int SUBSTRING
See Also:
Constant Field Values

INITIAL_STRING

public static final int INITIAL_STRING
See Also:
Constant Field Values

FINAL_STRING

public static final int FINAL_STRING
See Also:
Constant Field Values

NOT_STRING

public static final int NOT_STRING
See Also:
Constant Field Values

SEARCH_AND

public static final int SEARCH_AND
See Also:
Constant Field Values

SEARCH_OR

public static final int SEARCH_OR
See Also:
Constant Field Values

SEARCH_NOT

public static final int SEARCH_NOT
See Also:
Constant Field Values

filter

public String filter

psc

public ParameterSubstitutionCache psc
Constructor Detail

SearchCriteria

public SearchCriteria()

SearchCriteria

public SearchCriteria(int matchtype)

SearchCriteria

public SearchCriteria(String name,
                      int match,
                      Object value)

SearchCriteria

public SearchCriteria(String criteriaScript,
                      ScriptEngine engine)
Method Detail

size

public int size()
Return number of templates.

Returns:
Number of entries in the templates array

getCriteria

public SearchCriteria.rscSearch getCriteria(int index)
Return criteria class at specified index.

Returns:
The rscSearch class at the specified index

getCriteria

public Vector getCriteria()

addCriteria

public void addCriteria(String name,
                        int match,
                        Object value)
Add expression to criteria array.

Parameters:
name - The attribute name
match - The match operator (e.g. EXACT, FINAL_STRING ..)
value - The matching value.

addCriteria

public void addCriteria(String name,
                        int match,
                        Object value,
                        boolean negate)
Add expression to criteria array.

Parameters:
name - The attribute name
match - The match operator (e.g. EXACT, FINAL_STRING ..)
value - The matching value.
negate - Specify true to negate the expression

replaceCriteria

public void replaceCriteria(String name,
                            Object value)
Add expression to criteria array, replacing all previous occurences with the same attribute name. The match operator will always be EXACT.

Parameters:
name - The attribute name
value - The matching value.

getFirstCriteriaName

public String getFirstCriteriaName()
Return name of first criteria entry.

Returns:
The name contained in the first criteria entry

getFirstCriteriaValue

public String getFirstCriteriaValue()
Return value of first criteria entry.

Returns:
The value contained in the first criteria entry

getFirstCriteriaMatch

public int getFirstCriteriaMatch()
Return match operator of first criteria entry.

Returns:
The match operator contained in the first criteria entry

setType

public void setType(int type)
Set type (SEARCH_AND, SEARCH_OR) for the search criteria. This govers how multiple criterias are constructed.

Parameters:
type - SEARCH_AND, SEARCH_OR

getType

public int getType()
Return search type.

Returns:
SEARCH_AND or SEARCH_OR

getTemplate

public SearchCriteria.rscSearch getTemplate(int index)
Returns the criteria template at a specific location.

Parameters:
index - The index into the templates array
Returns:
The rscSearch class at location index

addTemplate

public void addTemplate(String name,
                        int match,
                        String defvalue)
Add a criteria to the templates array.

Parameters:
name - The attribute name
match - The match operator (e.g. EXACT, FINAL_STRING ..)
defvalue - The value to match

addTemplate

public void addTemplate(String name,
                        String match,
                        String defvalue)
Add a criteria to the templates array.

Parameters:
name - The attribute name
match - The match operator as a String, e.g. '=','~', '^', '$' or '!'.
defvalue - The value to match

buildLdapFilter

public String buildLdapFilter(SearchCriteria.rscSearch rs)
Constructs an LDAP search filter from an rscSearch class.

Returns:
The LDAP search filter

buildSQLFilter

public String buildSQLFilter(SearchCriteria.rscSearch rs)
Constructs an SQL where expression from an rscSearch class.

Returns:
The SQL where expression

buildNotesFilter

public String buildNotesFilter(SearchCriteria.rscSearch rs)
Constructs an Notes search filter from an rscSearch class.

Returns:
The Notes search filter

buildNotesFTFilter

public String buildNotesFTFilter(SearchCriteria.rscSearch rs)
Constructs an Notes FullText search filter from an rscSearch class.

Returns:
The Notes FullText search filter

getLDAPFilter

public String getLDAPFilter()
Return complete LDAP filter from criteria array.

Returns:
The complete LDAP filter from the values in the criteria array.

getSQLFilter

public String getSQLFilter()
Return complete SQL search expression from criteria array.

Returns:
The complete SQL search expression from the values in the criteria array.

getSimpleFilter

public String getSimpleFilter()

getNotesFilter

public String getNotesFilter()
Return complete Notes search expression from criteria array.

Returns:
The complete Notes search expression from the values in the criteria array.

getNotesFTFilter

public String getNotesFTFilter()
Return complete Notes FullText search expression from criteria array.

Returns:
The complete Notes FullText search expression from the values in the criteria array.

getSearchString

public String getSearchString(int i)

getCurrentEntry

public Entry getCurrentEntry()
Return the working entry used to generate the criteria array from the templates array.

Returns:
The working entry
See Also:
Entry

buildCriteria

public void buildCriteria(Entry e)
                   throws Exception
Build the criteria array using provided entry. This method uses the templates array to generate the criteria array. Each criteria in the template array holds an attribute name, a matching operator and a value. The value, if prefixed by a dollar sign, causes this method to substitute the value with the corresponding attribute value in the work entry. The attribute name is derived from the value by removing the first dollar sign using the remainder as the attribute name. For example, "$test" becomes "test".

When the method completes the criteria array has been built so it contains a copy of the templates array with expanded values.

You typically create an instance of this class and then add the templates. Then for each entry you are using in a search you can call the buildCriteria method to populate the criteria array. Then, having done that you can use the getLDAPFilter, getNotesFilter etc to obtain the search filter as a string.

Parameters:
e - The work entry used in parameter substitution
Throws:
Exception

buildCriteria

public void buildCriteria(Entry e,
                          BaseConfiguration config,
                          Object task)
                   throws Exception
Throws:
Exception

buildCriteriaScript

public void buildCriteriaScript(Entry entry)
                         throws Exception
Call user defined script to build the search filter. The filter has access to the entry object as a scriptable object called work. The class instance (this) is available as ret. The script is expected at some point to assign a value to the ret.filter property. The value of that property will be returned to the caller.

Parameters:
entry - The work entry used in parameter substitution
Throws:
Exception

getScriptFilter

public String getScriptFilter()
This method executes a script that returns a user-defined search filter.

Returns:
The search filter

isConfigured

public boolean isConfigured()