/* The Java RTP/I library, Version 0.1 alpha.
*
* This library provides the functionality of RTP/I as it is specified in
* Internet Draft draft-mauve-rtpi-00.txt.
*
* Copyright (C) 2000 Martin Mauve
* University of Mannheim / Germany
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Martin Mauve
*
* e-mail:
* mauve@informatik.uni-mannheim.de
*
* paper mail:
* Martin Mauve
* University of Mannheim
* Lehrstuhl Praktische Informatik IV
* L15, 16
* 68131 Mannheim
* Germany
*/
package rtpi.packets;
import rtpi.IllegalValueException;
/**
* This class is used to define SDES items that are to be
* used for the creation of SDES packets.
*/
public class SourceDescriptionItem {
/**
* The ID for a CNAME item.
*/
public static final int CNAME=1;
/**
* The ID for a NAME item.
*/
public static final int NAME=2;
/**
* The ID for an EMAIL item.
*/
public static final int EMAIL=3;
/**
* The ID for a PHONE item.
*/
public static final int PHONE=4;
/**
* The ID for a LOCation item.
*/
public static final int LOC=5;
/**
* The ID for a TOOL item.
*/
public static final int TOOL=6;
/**
* The ID for a NOTE item.
*/
public static final int NOTE=7;
/**
* The ID for a PRIVate extension item.
*/
public static final int PRIV=8;
private int type;
private byte[] data;
private byte[] prefix;
/**
* This creates a new SDES item (not a PRIV item!).
*
* @param t The type ID of this item.
* @param d The item data.
*/
public SourceDescriptionItem(int t, byte[] d) throws IllegalValueException {
if (t<1 || t>7) {
throw new IllegalValueException("SourceDescriptionItem: illegal SDES type");
}
if (d.length>255) {
throw new IllegalValueException("SourceDescriptionItem: item too long (more than 255 bytes)");
}
type=t;
data=d;
}
/**
* This creates a new PRIV SDES item.
*
* @param d The item data.
* @param p The PRIV item prefix.
*/
public SourceDescriptionItem(byte[] d, byte[] p) throws IllegalValueException {
if (d.length+p.length>253) {
throw new IllegalValueException("SourceDescriptionItem: item too long (more than 255 bytes,including prefix info)");
}
type=PRIV;
data=d;
prefix=p;
}
/**
* This returns the type ID of the SDES item.
*
* @return The type ID for this SDES item.
*/
public int getType() {
return type;
}
/**
* This returns the item data.
*
* @return The data of this SDES item.
*/
public byte[] getData() {
return data;
}
/**
* This returns the prefix of a PRIV SDES item. It may only
* be called when the type of this SDES item is PRIV.
*
* @return The prefix of this PRIV item.
*/
public byte[] getPrefix() throws IllegalValueException {
if (type!=PRIV) {
throw new IllegalValueException("SourceDescriptionItem: cannot get prefix for a non PRIV item");
}
return prefix;
}
/**
* This returns this SDES item as a string.
*/
public String toString() {
String returnValue=" Type: "+type;
if (type==PRIV) {
returnValue += " prefix "+new String(prefix);
}
returnValue +=" data: "+new String(data)+"\n";
return returnValue;
}
}