Source code for DataObject.java

package PhoneApp.Data;

/**
 * Provides general-purpose Database functionality. At
 * present, only validation requirements have been identified,
 * and they are not even implemented. Simply put here as a place-
 * holder for future requirements.
 *
 * @version $Date: 2001/06/25 $
 * @author  Steve Franklin
 * @since   jdk 1.3.1
 */


abstract class DataObject {

 /**
  * Tests an object to see if it is valid under a number of conditions.
  * In actuality, you might want to add to this method (or new ones)
  * to support features such as format mask validation (i.e. using regex's).
  */

  protected boolean testInt(int newInt, int contentType, int condition, int maxLength) {
    boolean validity = true;
    if (contentType == VERIFY_POSITIVE && newInt < 0 ) {
      validity = false;
    }

    return validity;
  }
  
  protected boolean testString(String newString, int contentType, int condition, int maxLength) {
    boolean validity = true;
    if (contentType == VERIFY_TEXT) {

    }

    if (condition == VERIFY_MANDATORY) {
      if (newString == null ) {
        validity = false;
      } else if ( newString.length() == 0 ) {
        validity = false;
      }
    } else if ( condition == VERIFY_NOTNULL && newString == null ) {
      validity = false;
    } else if ( condition == VERIFY_EMPTY) {
      if ( newString == null ) {
        validity = false;
      } else if ( newString.length() > 0 ) {
        validity = false;
      }
    } else if ( condition == VERIFY_NULL && newString != null ) {
      validity=false;
    }

    if ( newString != null ) {
      if ( newString.length() > maxLength) {
        validity = false;
      }
    }

    return validity;
  }
  
 /**
  * Allows a quick method for dumping messages to the console
  */
  protected void debug(String method, String msg) {
    System.out.println(method + ": " + msg);
    System.out.flush();
  }

  /** Test for ASCII text */
  protected static final int VERIFY_TEXT = 0;

  /** Test for non-null and non-empty state of object */
  protected static final int VERIFY_MANDATORY = 1;
  
  /** Test for positive value */
  protected static final int VERIFY_POSITIVE = 2;
  
  /** Test for empty state of object */
  protected static final int VERIFY_EMPTY = 3;
  
  /** Test for non-null state of object */
  protected static final int VERIFY_NOTNULL = 4;
  
  /** Test for null state of object */
  protected static final int VERIFY_NULL = 5;
  
  /** Test for null state of object */
  protected static final int VERIFY_PHONENUMBER= 6;
  
  /** Test for positive value */
  protected static final int VERIFY_OPTIONAL = 7;
  
}