org.tinyradius.attribute
Class RadiusAttribute

java.lang.Object
  extended by org.tinyradius.attribute.RadiusAttribute
Direct Known Subclasses:
IntegerAttribute, IpAttribute, StringAttribute, VendorSpecificAttribute

public class RadiusAttribute
extends java.lang.Object

This class represents a generic Radius attribute. Subclasses implement methods to access the fields of special attributes.


Constructor Summary
RadiusAttribute()
          Constructs an empty Radius attribute.
RadiusAttribute(int type, byte[] data)
          Constructs a Radius attribute with the specified type and data.
 
Method Summary
static RadiusAttribute createRadiusAttribute(Dictionary dictionary, int vendorId, int attributeType)
          Creates a RadiusAttribute object of the appropriate type.
static RadiusAttribute createRadiusAttribute(int attributeType)
          Creates a Radius attribute.
static RadiusAttribute createRadiusAttribute(int vendorId, int attributeType)
          Creates a Radius attribute, including vendor-specific attributes.
 byte[] getAttributeData()
          Returns the data for this attribute.
 int getAttributeType()
          Returns the type of this Radius attribute.
 AttributeType getAttributeTypeObject()
          Retrieves an AttributeType object for this attribute.
 java.lang.String getAttributeValue()
          Gets the value of this attribute as a string.
 Dictionary getDictionary()
          Returns the dictionary this Radius attribute uses.
 int getVendorId()
          Gets the Vendor-Id of the Vendor-Specific attribute this attribute belongs to.
 void readAttribute(byte[] data, int offset, int length)
          Reads in this attribute from the passed byte array.
 void setAttributeData(byte[] attributeData)
          Sets the data for this attribute.
 void setAttributeType(int attributeType)
          Sets the type of this Radius attribute.
 void setAttributeValue(java.lang.String value)
          Sets the value of the attribute using a string.
 void setDictionary(Dictionary dictionary)
          Sets a custom dictionary to use.
 void setVendorId(int vendorId)
          Sets the Vendor-Id of the Vendor-Specific attribute this attribute belongs to.
 java.lang.String toString()
          String representation for debugging purposes.
 byte[] writeAttribute()
          Returns this attribute encoded as a byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RadiusAttribute

public RadiusAttribute()
Constructs an empty Radius attribute.


RadiusAttribute

public RadiusAttribute(int type,
                       byte[] data)
Constructs a Radius attribute with the specified type and data.

Parameters:
type - attribute type, see AttributeTypes.*
data - attribute data
Method Detail

getAttributeData

public byte[] getAttributeData()
Returns the data for this attribute.

Returns:
attribute data

setAttributeData

public void setAttributeData(byte[] attributeData)
Sets the data for this attribute.

Parameters:
attributeData - attribute data

getAttributeType

public int getAttributeType()
Returns the type of this Radius attribute.

Returns:
type code, 0-255

setAttributeType

public void setAttributeType(int attributeType)
Sets the type of this Radius attribute.

Parameters:
attributeType - type code, 0-255

setAttributeValue

public void setAttributeValue(java.lang.String value)
Sets the value of the attribute using a string.

Parameters:
value - value as a string

getAttributeValue

public java.lang.String getAttributeValue()
Gets the value of this attribute as a string.

Returns:
value
Throws:
RadiusException - if the value is invalid

getVendorId

public int getVendorId()
Gets the Vendor-Id of the Vendor-Specific attribute this attribute belongs to. Returns -1 if this attribute is not a sub attribute of a Vendor-Specific attribute.

Returns:
vendor ID

setVendorId

public void setVendorId(int vendorId)
Sets the Vendor-Id of the Vendor-Specific attribute this attribute belongs to. The default value of -1 means this attribute is not a sub attribute of a Vendor-Specific attribute.

Parameters:
vendorId - vendor ID

getDictionary

public Dictionary getDictionary()
Returns the dictionary this Radius attribute uses.

Returns:
Dictionary instance

setDictionary

public void setDictionary(Dictionary dictionary)
Sets a custom dictionary to use. If no dictionary is set, the default dictionary is used.

Parameters:
dictionary - Dictionary class to use
See Also:
DefaultDictionary

writeAttribute

public byte[] writeAttribute()
Returns this attribute encoded as a byte array.

Returns:
attribute

readAttribute

public void readAttribute(byte[] data,
                          int offset,
                          int length)
                   throws RadiusException
Reads in this attribute from the passed byte array.

Parameters:
data -
Throws:
RadiusException

toString

public java.lang.String toString()
String representation for debugging purposes.

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

getAttributeTypeObject

public AttributeType getAttributeTypeObject()
Retrieves an AttributeType object for this attribute.

Returns:
AttributeType object for (sub-)attribute or null

createRadiusAttribute

public static RadiusAttribute createRadiusAttribute(Dictionary dictionary,
                                                    int vendorId,
                                                    int attributeType)
Creates a RadiusAttribute object of the appropriate type.

Parameters:
dictionary - Dictionary to use
vendorId - vendor ID or -1
attributeType - attribute type
Returns:
RadiusAttribute object

createRadiusAttribute

public static RadiusAttribute createRadiusAttribute(int vendorId,
                                                    int attributeType)
Creates a Radius attribute, including vendor-specific attributes. The default dictionary is used.

Parameters:
vendorId - vendor ID or -1
attributeType - attribute type
Returns:
RadiusAttribute instance

createRadiusAttribute

public static RadiusAttribute createRadiusAttribute(int attributeType)
Creates a Radius attribute. The default dictionary is used.

Parameters:
attributeType - attribute type
Returns:
RadiusAttribute instance