com.gridsystems.config.tools
Class IpVerifier

java.lang.Object
  extended by javax.swing.InputVerifier
      extended by com.gridsystems.config.tools.TextVerifier
          extended by com.gridsystems.config.tools.IpVerifier

public class IpVerifier
extends TextVerifier

Verifies that the String has a valid IP format. Verifies that the String is a valid IP number. It just checks that the String is formed by 4 or 6 groups of digits separed by dot, each group ranging from 0 to 255.

Author:
SJM

Field Summary
static java.lang.String ID_ERROR
          Errors detected by this verifier.
static int IP_4
          IP version 4 address type.
static int IP_4_IP_6
          IP versions 4 and 6 type.
static int IP_6
          IP version 6 address type.
 
Fields inherited from class com.gridsystems.config.tools.TextVerifier
support
 
Constructor Summary
IpVerifier(ErrorSupport support, java.lang.String id)
          Creates an instance that matches IPs with both 4 and 6 numeric fields.
IpVerifier(ErrorSupport support, java.lang.String id, int validIp)
          Creates an instance.
 
Method Summary
 void cleanErrors()
          Removes from the error support manager the list of errors of this verifier.
static boolean isLoopbackAddress(java.lang.String ip, int ipVersion)
          Tells if an IP is a loopback address.
 void setEmptyAllowed(boolean value)
          Sets the "Empty allowed" flag.
 void setErrorLoopbackId(java.lang.String errorLoopbackId)
          Sets the error shown if the validation fails due to the loopback address check.
 void setLoopbackAddressAllowed(boolean allowLoopbackAddress)
          Sets the "Loopback Address allowed" flag.
 boolean verify(java.lang.String text)
          Validates a text string.
 
Methods inherited from class com.gridsystems.config.tools.TextVerifier
updateError, verify
 
Methods inherited from class javax.swing.InputVerifier
shouldYieldFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID_ERROR

public static final java.lang.String ID_ERROR
Errors detected by this verifier.

See Also:
Constant Field Values

IP_4

public static final int IP_4
IP version 4 address type.

See Also:
Constant Field Values

IP_6

public static final int IP_6
IP version 6 address type.

See Also:
Constant Field Values

IP_4_IP_6

public static final int IP_4_IP_6
IP versions 4 and 6 type.

See Also:
Constant Field Values
Constructor Detail

IpVerifier

public IpVerifier(ErrorSupport support,
                  java.lang.String id)
Creates an instance that matches IPs with both 4 and 6 numeric fields.

Parameters:
support - The error support instance
id - The error identifier for the event of an invalid IP.

IpVerifier

public IpVerifier(ErrorSupport support,
                  java.lang.String id,
                  int validIp)
Creates an instance.

Parameters:
support - The error support instance.
id - The error identifier for the event of an invalid IP.
validIp - an int that tells if the verifier must accept only IPs with four numeric fields (IP_4), only IPs with 6 numeric fields (IP_6) or both types (IP_4_IP_6). If the parameter is not any of these values, it default to IP_4_IP_6.
Method Detail

setEmptyAllowed

public void setEmptyAllowed(boolean value)
Sets the "Empty allowed" flag.

Parameters:
value - The flag value

setLoopbackAddressAllowed

public void setLoopbackAddressAllowed(boolean allowLoopbackAddress)
Sets the "Loopback Address allowed" flag. The default value is true.

Parameters:
allowLoopbackAddress - The flag value. Loopback addresses will be allowed only and only if this value is set to true.
See Also:
setErrorLoopbackId(String)

setErrorLoopbackId

public void setErrorLoopbackId(java.lang.String errorLoopbackId)
Sets the error shown if the validation fails due to the loopback address check.

Parameters:
errorLoopbackId - the id of the error to show.

verify

public boolean verify(java.lang.String text)
Validates a text string.

Specified by:
verify in class TextVerifier
Parameters:
text - The string to validate
Returns:
true if the text is valid

cleanErrors

public void cleanErrors()
Description copied from class: TextVerifier
Removes from the error support manager the list of errors of this verifier.

This method will be used on field deactivation.

Specified by:
cleanErrors in class TextVerifier
See Also:
TextVerifier.cleanErrors()

isLoopbackAddress

public static boolean isLoopbackAddress(java.lang.String ip,
                                        int ipVersion)
Tells if an IP is a loopback address.

Parameters:
ip - the IP to check. It must be a valid IP.
ipVersion - the version of the IP. If it is an invalid value, it will return false.
Returns:
true if and only if ip is a valid IPv4 or IPv6 address and it is a loopback address.


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.