org.apache.lenya.ac.impl
Class AbstractIPRange

java.lang.Object
  extended by org.apache.lenya.ac.impl.AbstractItem
      extended by org.apache.lenya.ac.impl.AbstractGroupable
          extended by org.apache.lenya.ac.impl.AbstractIPRange
All Implemented Interfaces:
Accreditable, Groupable, IPRange, Item
Direct Known Subclasses:
FileIPRange

public abstract class AbstractIPRange
extends AbstractGroupable
implements IPRange

A range of IP addresses, expressed by a network address and a subnet mask.

Note: this class does not enforce that the network address and the subnet mask have the same size (i.e. either both IPv4 or both IPv6 addresses). If the the network address and subnet mask have different sizes, the range does not contain any hosts, that is contains(Machine) will always return false.


Constructor Summary
AbstractIPRange()
          Initializes the the IP range with the local host (127.0.0.1/24 for IPv4, ::1/128 for IPv6).
AbstractIPRange(java.lang.String id)
          Ctor.
 
Method Summary
 boolean contains(Machine machine)
          Checks if this IP range contains a certain machine.
 void delete()
          Delete an IP range
 java.io.File getConfigurationDirectory()
          Returns the configuration directory.
 java.net.InetAddress getNetworkAddress()
          Returns the network address.
 java.net.InetAddress getSubnetMask()
          Returns the subnet mask.
static boolean isValidSubnet(java.net.InetAddress networkAddress, java.net.InetAddress subnetMask)
          Deprecated. This method is currently not implemented, probably not necessary.and could be removed in the future. Therefore it should not be used.
abstract  void save()
          Save the IP range
 void setConfigurationDirectory(java.io.File configurationDirectory)
          Sets the configuration directory of this item.
 void setNetworkAddress(byte[] address)
          Sets the network address.
 void setNetworkAddress(java.lang.String address)
          Sets the network address.
 void setSubnetMask(byte[] mask)
          Sets the subnet mask.
 void setSubnetMask(java.lang.String mask)
          Sets the subnet mask.
 
Methods inherited from class org.apache.lenya.ac.impl.AbstractGroupable
addedToGroup, getAccreditables, getGroups, removedFromGroup, removeFromAllGroups
 
Methods inherited from class org.apache.lenya.ac.impl.AbstractItem
equals, getDescription, getId, getName, hashCode, isValidId, setDescription, setId, setName, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.lenya.ac.Accreditable
getAccreditables
 
Methods inherited from interface org.apache.lenya.ac.Item
configure, getDescription, getId, getName, setDescription, setName
 
Methods inherited from interface org.apache.lenya.ac.Groupable
addedToGroup, getGroups, removedFromGroup, removeFromAllGroups
 

Constructor Detail

AbstractIPRange

public AbstractIPRange()
Initializes the the IP range with the local host (127.0.0.1/24 for IPv4, ::1/128 for IPv6).


AbstractIPRange

public AbstractIPRange(java.lang.String id)
Ctor.

Parameters:
id - The IP range ID.
Method Detail

getConfigurationDirectory

public java.io.File getConfigurationDirectory()
Returns the configuration directory.

Returns:
A file object.

setConfigurationDirectory

public void setConfigurationDirectory(java.io.File configurationDirectory)
Description copied from interface: Item
Sets the configuration directory of this item.

Specified by:
setConfigurationDirectory in interface Item
Parameters:
configurationDirectory - The configuration directory.
See Also:
Item.setConfigurationDirectory(java.io.File)

save

public abstract void save()
                   throws AccessControlException
Save the IP range

Throws:
AccessControlException - if the save failed

delete

public void delete()
            throws AccessControlException
Delete an IP range

Throws:
AccessControlException - if the delete failed

setNetworkAddress

public void setNetworkAddress(java.lang.String address)
                       throws AccessControlException
Sets the network address. This method accepts numeric IPv4 addresses like "129.168.0.32", numeric IPv6 addresses like "1080::8:800:200C:417A" as well as hostnames (if DNS resolution is available) like "localhost" or "www.apache.com".

Specified by:
setNetworkAddress in interface IPRange
Parameters:
address - a String like "192.168.0.32", "::1", ...
Throws:
AccessControlException - when the conversion of the String to an InetAddress failed
See Also:
setNetworkAddress(byte[])

setNetworkAddress

public void setNetworkAddress(byte[] address)
                       throws AccessControlException
Sets the network address. The method accepts numeric IPv4 addresses (specified by byte arrays of length 4) or IPv6 addresses (specified by byte arrays of length 16).

Specified by:
setNetworkAddress in interface IPRange
Parameters:
address - a byte array of the length 4 or 16
Throws:
AccessControlException - when the conversion of the byte array to an InetAddress failed.
See Also:
setNetworkAddress(String)

getNetworkAddress

public java.net.InetAddress getNetworkAddress()
Returns the network address.

Specified by:
getNetworkAddress in interface IPRange
Returns:
an InetAddress representing the network address

setSubnetMask

public void setSubnetMask(java.lang.String mask)
                   throws AccessControlException
Sets the subnet mask. See setNetworkAddress(String) for the allowed formats of the mask string. (However, the hostname format will usually not be of much use for setting the mask.)

Only valid subnet masks are accepted, for which the binary representation is a sequence of 1-bits followed by a sequence of 0-bits. For example "255.128.0.0" is valid while "255.128.0.1" is not.

Specified by:
setSubnetMask in interface IPRange
Parameters:
mask - a String like "255.255.255.0"
Throws:
AccessControlException - when the conversion of the String to an InetAddress failed.
See Also:
setSubnetMask(byte[])

setSubnetMask

public void setSubnetMask(byte[] mask)
                   throws AccessControlException
Sets the subnet mask.

Only valid subnet masks are accepted, for which the binary representation is a sequence of 1-bits followed by a sequence of 0-bits. For example { 255, 128, 0, 0 } is valid while { 255, 128, 0, 1 } is not.

Specified by:
setSubnetMask in interface IPRange
Parameters:
mask - A byte array of the length 4.
Throws:
AccessControlException - when the conversion of the byte array to an InetAddress failed.
See Also:
setSubnetMask(String)

getSubnetMask

public java.net.InetAddress getSubnetMask()
Returns the subnet mask.

Specified by:
getSubnetMask in interface IPRange
Returns:
An InetAddress value.

isValidSubnet

public static boolean isValidSubnet(java.net.InetAddress networkAddress,
                                    java.net.InetAddress subnetMask)
Deprecated. This method is currently not implemented, probably not necessary.and could be removed in the future. Therefore it should not be used.

Checks if a network address / subnet mask combination describes a valid subnet.

Parameters:
networkAddress - The network address.
subnetMask - The subnet mask.
Returns:
A boolean value.

contains

public boolean contains(Machine machine)
Checks if this IP range contains a certain machine.

Note: if the network address and the subnet mask of this IP range have different sizes (i.e. one is IPv4 and one is IPv6), this method will always return false, no matter what machine has been specified!

Further, if the machine address and the IP range (i.e. network address and subnet mask) have different sizes, the method will return false. (In other words: an IPv4 range never contains an IPv6 address and the other way round.)

Note that the above can lead to confusion. For example the local subnet in IPv4 ( 127.0.0.0/8) will not contain the localhost in IPv6 ( ::1), and the localhost in IPv4 (127.0.0.1) will not be contained in the local subnet in IPv6 (::1/128).

Specified by:
contains in interface IPRange
Parameters:
machine - the machine to check for
Returns:
a boolean value
See Also:
InetAddressUtil.contains(java.net.InetAddress, java.net.InetAddress, java.net.InetAddress)


Copyright © 1999-2005 Apache Software Foundation. All Rights Reserved.