org.opennms.bb.common.filter
Class BBFilter

java.lang.Object
  |
  +--org.opennms.bb.common.filter.BBFilter

public class BBFilter
extends Object

This class is the main entry point for filtering the rules expressions. By creating a BBFilter object the application can parse a rules expression and get back the list of applicable ip addresses or verify if an ip address adhers to a certain rule.

Version:
$Revision: 1.8 $
Author:
Jason Johns, OpenNMS

Field Summary
private  DBConnection dbConn
          This is the connection to the database.
private  SQLConstruct sqlStatement
          This is the sql statement that is generated from an expression
static String VALID_RULE
          This is the constant string indicating if a rule is valid
 
Constructor Summary
BBFilter()
          Default constructor, initializes the database connection variable.
 
Method Summary
 List getIPList(String aRule)
          This method returns a list of all ip addresses that match the rule that is passed in.
private  String getRuleSQL(String aRule)
          This method parses a rule and returns the SQL select statement equivalent of the rule.
 String getSQLStatement()
          This method returns the SQL statement in string form, useful for examining how the expression is parsed and for displaying the statement in GUIs.
 boolean isValid(String anIP, String aRule)
          This method verifies if an ip address adhers to a given rule.
static String validateRule(String aRule)
          This method is used to validate that a rule is syntactically correct.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

VALID_RULE

public static final String VALID_RULE
This is the constant string indicating if a rule is valid

dbConn

private DBConnection dbConn
This is the connection to the database.

sqlStatement

private SQLConstruct sqlStatement
This is the sql statement that is generated from an expression
Constructor Detail

BBFilter

public BBFilter()
         throws DBOpenFailureException
Default constructor, initializes the database connection variable.
Throws:
DBOpenFailureException, - on unsuccessful attempt to connect to the database.
Method Detail

isValid

public boolean isValid(String anIP,
                       String aRule)
                throws FailedParseException
This method verifies if an ip address adhers to a given rule.
Parameters:
String - anIP, an octet string ip to be validated against a rule.
String - aRule, an expression rule to be parsed and executed.
Returns:
boolean indicating that the ip is included in the rule
Throws:
FailedParseException, - if a rule is syntactically incorrect or failed in executing the SQL statement.

getIPList

public List getIPList(String aRule)
               throws FailedParseException
This method returns a list of all ip addresses that match the rule that is passed in.
Parameters:
String - aRule, an expression rule to be parsed and executed.
Returns:
List interface containing all ip addresses selected by the rule.
Throws:
FailedParseException, - if a rule is syntactically incorrect or failed in executing the SQL statement.

getSQLStatement

public String getSQLStatement()
This method returns the SQL statement in string form, useful for examining how the expression is parsed and for displaying the statement in GUIs.
Returns:
String, the sql statement string

getRuleSQL

private String getRuleSQL(String aRule)
                   throws FailedParseException
This method parses a rule and returns the SQL select statement equivalent of the rule.
Parameters:
String - aRule, the rule to be parsed
Returns:
String, the sql select statement
Throws:
FailedParseException, - if the rule is syntactically invalid

validateRule

public static String validateRule(String aRule)
This method is used to validate that a rule is syntactically correct. The method returns a string indicating if the rule is valid or not. The method is static to enable a rule to be validated without having a connection to the database (a database connection is not needed to validate the syntax of a rule).
Parameters:
String - aRule, the expression rule to validate
Returns:
String, a constant string indicating success or an error message