FileDocCategorySizeDatePackage
SessionDescriptionImpl.javaAPI DocphoneME MR2 API (J2ME)25065Wed May 02 18:00:42 BST 2007gov.nist.javax.sdp

SessionDescriptionImpl

public class SessionDescriptionImpl extends Object
Implementation of the SessionDescription interface. a href="{@docRoot}/uncopyright.html">This code is in the public domain.

Fields Summary
private TimeDescriptionImpl
currentTimeDescription
Descriptive label for current time.
private MediaDescriptionImpl
currentMediaDescription
Descriptive lavel for current media.
protected ProtoVersionField
versionImpl
Protocol version.
protected OriginField
originImpl
Session originator.
protected SessionNameField
sessionNameImpl
Current session name.
protected InformationField
infoImpl
Descriptive session information.
protected URIField
uriImpl
Current URi.
protected ConnectionField
connectionImpl
Current connection.
protected KeyField
keyImpl
Key field.
protected Vector
timeDescriptions
Vector of time descriptions.
protected Vector
mediaDescriptions
Vector of media types.
protected Vector
zoneAdjustments
Vector of time zone adjustments.
protected Vector
emailList
Vector of email addresses.
protected Vector
phoneList
Vector of phone numbers.
protected Vector
bandwidthList
Vector of bandwidths.
protected Vector
attributesList
Vector of connection attributes.
Constructors Summary
public SessionDescriptionImpl()
Creates new SessionDescriptionImpl

	zoneAdjustments = new Vector();
	emailList = new Vector();
	phoneList = new Vector();
	bandwidthList = new Vector();
	timeDescriptions = new Vector();
	mediaDescriptions = new Vector();
	attributesList = new Vector();
 
    
Methods Summary
public voidaddField(SDPField sdpField)
Adds a new SDP field.

param
sdpField the new field to be processed
exception
ParseException if a parsing error occurs.

	try {
	    if (sdpField instanceof ProtoVersionField) {
		versionImpl = (ProtoVersionField)sdpField;
	    } else if (sdpField instanceof OriginField) {
		originImpl = (OriginField) sdpField;
	    } else if (sdpField instanceof SessionNameField) {
		sessionNameImpl = (SessionNameField) sdpField;
	    } else if (sdpField instanceof InformationField) {
		if (currentMediaDescription != null)
		    currentMediaDescription.setInformationField
			((InformationField) sdpField);
		else this.infoImpl = (InformationField) sdpField;
	    } else if (sdpField instanceof URIField) {
		uriImpl = (URIField) sdpField;
	    } else if (sdpField instanceof ConnectionField) {
		if (currentMediaDescription != null)
		    currentMediaDescription.setConnectionField
			((ConnectionField) sdpField);
		else this.connectionImpl = (ConnectionField) sdpField;
	    } else if (sdpField instanceof KeyField) {
		if (currentMediaDescription != null)
		    currentMediaDescription.setKey((KeyField)sdpField);
		else keyImpl = (KeyField) sdpField;
	    } else if (sdpField instanceof EmailField) {
		emailList.addElement(sdpField);
	    } else if (sdpField instanceof PhoneField) {
		phoneList.addElement(sdpField);
	    } else if (sdpField instanceof TimeField) {
		currentTimeDescription = new TimeDescriptionImpl
		    ((TimeField)sdpField);
		timeDescriptions.addElement(currentTimeDescription);
	    } else if (sdpField instanceof RepeatField) {
		if (currentTimeDescription == null) {
		    throw new ParseException("no time specified", 0);
		} else {
		    currentTimeDescription.addRepeatField
			((RepeatField) sdpField);
		}
	    } else if (sdpField instanceof ZoneField) {
		zoneAdjustments.addElement(sdpField);
	    } else if (sdpField instanceof BandwidthField) {
		if (currentMediaDescription != null) {
		    currentMediaDescription.addBandwidthField
			((BandwidthField) sdpField);
		} else {
		    bandwidthList.addElement(sdpField);
		} 
	    } else if (sdpField instanceof AttributeField) {
		if (currentMediaDescription != null) {
		    AttributeField af = (AttributeField) sdpField;
		    String s = af.getName();
		    currentMediaDescription.addAttribute
			((AttributeField) sdpField);
		} else { 
		    attributesList.addElement(sdpField);
		}
	    } else if (sdpField instanceof MediaField) {
		currentMediaDescription = new MediaDescriptionImpl();
		mediaDescriptions.addElement(currentMediaDescription);
		currentMediaDescription.setMediaField((MediaField)sdpField);
	    }
	} catch (SdpException ex) {
	    throw new ParseException(sdpField.encode(), 0);
	}
    
public java.lang.Objectclone()
Public clone declaration.

throws
CloneNotSupportedException if clone method is not supported
return
Object

	Class myClass = this.getClass();
	SessionDescriptionImpl hi;
	try {
	    hi = (SessionDescriptionImpl) myClass.newInstance();
	} catch (InstantiationException ex) {
	    return null;
	} catch (IllegalAccessException ex) {
	    return null;
	}
	hi.versionImpl = (ProtoVersionField) this.versionImpl.clone();
	hi.originImpl = (OriginField) this.originImpl.clone();
	hi.sessionNameImpl = (SessionNameField) this.sessionNameImpl.clone();
	hi.infoImpl = (InformationField) this.infoImpl.clone();
	hi.uriImpl = (URIField) this.uriImpl.clone();
	hi.connectionImpl = (ConnectionField) this.connectionImpl.clone();
	hi.keyImpl = (KeyField) this.keyImpl.clone();
	hi.timeDescriptions = cloneVector(this.timeDescriptions);
 
	hi.emailList = cloneVector(this.emailList);
	hi.phoneList = cloneVector(this.phoneList);
	hi.zoneAdjustments = cloneVector(this.zoneAdjustments);
	hi.bandwidthList = cloneVector(this.bandwidthList);
	hi.attributesList = cloneVector(this.attributesList);
	hi.mediaDescriptions = cloneVector(this.mediaDescriptions);
	return hi;
    
private java.util.VectorcloneVector(java.util.Vector v)
Utility method for cloning a Vector Acknowledgement - this code was contributed by Sverker Abrahamsson.

param
v the vector to be copied
return
the cloned vector

	Vector clone = new Vector(v.capacity());

	int size = v.size();
	for (int i = 0; i < size; i++) {
	    clone.setElementAt(v.elementAt(i), i);
	}
	return clone;
    
private java.lang.StringencodeVector(java.util.Vector vector)
Returns an encoded string of vector contents.

param
vector the objects to process
return
encode string of vector contents

	StringBuffer encBuff = new StringBuffer();
 
	for (int i = 0; i < vector.size(); i++)
	    encBuff.append(vector.elementAt(i));
 
	return encBuff.toString();
    
public java.lang.StringgetAttribute(java.lang.String name)
Returns the value of the specified attribute.

param
name name - the name of the attribute
throws
SdpParseException
return
the value of the named attribute

	if (name == null)
	    return null;
	else if (attributesList == null)
	    return null;
	for (int i = 0; i < attributesList.size(); i++) {
	    Object o = attributesList.elementAt(i);
	    if (o instanceof AttributeField) {
		AttributeField a = (AttributeField)o;
		String n = a.getName();
		if (n != null) {
		    if (name.equals(n)) {
			return a.getValue();
		    }
		}
	    }
	}
	return null;
    
public java.util.VectorgetAttributes(boolean create)
Returns the set of attributes for this Description as a Vector of Attribute objects in the order they were parsed.

param
create create - specifies whether to return null or a new empty Vector in case no attributes exists for this Description
return
attributes for this Description

	if (attributesList == null) {
	    if (create)
		attributesList = new Vector();
	}
	return attributesList;
    
public intgetBandwidth(java.lang.String name)
Returns the integer value of the specified bandwidth name.

param
name name - the name of the bandwidth type
throws
SdpParseException
return
the value of the named bandwidth

	if (name == null)
	    return -1;
	else if (bandwidthList == null)
	    return -1;
	for (int i = 0; i < bandwidthList.size(); i++) {
	    Object o = bandwidthList.elementAt(i);
	    if (o instanceof BandwidthField) {
		BandwidthField b = (BandwidthField)o;
		String type = b.getType();
		if (type != null) {
		    if (name.equals(type)) {
			return b.getValue();
		    }
		}
	    }
	}
	return -1;
    
public java.util.VectorgetBandwidths(boolean create)
Returns the Bandwidth of the specified type.

param
create type - type of the Bandwidth to return
return
the Bandwidth or null if undefined

	if (bandwidthList == null) {
	    if (create)
		bandwidthList = new Vector();
	}
	return bandwidthList;
    
public ConnectionFieldgetConnection()
Returns the connection information associated with this object. This may be null for SessionDescriptions if all Media objects have a connection object and may be null for Media objects if the corresponding session connection is non-null.

return
connection

	return connectionImpl;
    
public java.util.VectorgetEmails(boolean create)
Returns an email address to contact for further information about the session. This corresponds to the e= field of the SDP data.

param
create boolean to set
throws
SdpException
return
the email address.

	if (emailList == null) {
	    if (create)
		emailList = new Vector();
	}
	return emailList;
    
public InformationFieldgetInfo()
Returns value of the info field (i=) of this object.

return
info

	return infoImpl;
    
public KeyFieldgetKey()
Returns the key data.

return
key

	return keyImpl;
    
public java.util.VectorgetMediaDescriptions(boolean create)
Adds a MediaDescription to the session description. These correspond to the m= fields of the SDP data.

param
create boolean to set
throws
SdpException
return
media - the field to add.

	if (mediaDescriptions == null) {
	    if (create)
		mediaDescriptions = new Vector();
	}
	return mediaDescriptions;
    
public OriginFieldgetOrigin()
Returns information about the originator of the session. This corresponds to the o= field of the SDP data.

return
the originator data.

	return originImpl;
    
public java.util.VectorgetPhones(boolean create)
Returns a phone number to contact for further information about the session. This corresponds to the p= field of the SDP data.

param
create boolean to set
throws
SdpException
return
the phone number.

	if (phoneList == null) {
	    if (create)
		phoneList = new Vector();
	}
	return phoneList;
    
public SessionNameFieldgetSessionName()
Returns the name of the session. This corresponds to the s= field of the SDP data.

return
the session name.

	return sessionNameImpl;
    
public java.util.VectorgetTimeDescriptions(boolean create)
Returns a TimeField indicating the start, stop, repetition and time zone information of the session. This corresponds to the t= field of the SDP data.

param
create boolean to set
throws
SdpException
return
the Time Field.

	if (timeDescriptions == null) {
	    if (create)
		timeDescriptions = new Vector();
	}
	return timeDescriptions;
    
public URIFieldgetURI()
Returns a uri to the location of more details about the session. This corresponds to the u= field of the SDP data.

return
the uri.

	return uriImpl;
    
public ProtoVersionFieldgetVersion()
Returns the version of SDP in use. This corresponds to the v= field of the SDP data.

return
the integer version (-1 if not set).

	return versionImpl;
    
public java.util.VectorgetZoneAdjustments(boolean create)
Returns the time zone adjustments for the Session

param
create boolean to set
throws
SdpException
return
a Hashtable containing the zone adjustments, where the key is the Adjusted Time Zone and the value is the offset.

	if (zoneAdjustments == null) {
	    if (create)
		zoneAdjustments = new Vector();
	}
	return zoneAdjustments;
    
public voidremoveAttribute(java.lang.String name)
Removes the attribute specified by the value parameter.

param
name name - the name of the attribute

	if (name != null)
	    if (attributesList != null) {
		for (int i = 0; i < attributesList.size(); i++) {
		    Object o = attributesList.elementAt(i);
		    if (o instanceof AttributeField) {
			AttributeField a = (AttributeField)o;
			try {
			    String n = a.getName();
			    if (n != null) {
				if (name.equals(n)) {
				    attributesList.removeElement(a);
				}
			    }
			}
			catch (SdpParseException e) {}
 
		    }
		}
	    }
    
public voidremoveBandwidth(java.lang.String name)
Removes the specified bandwidth type.

param
name name - the name of the bandwidth type

	if (name != null)
	    if (bandwidthList != null) {
		for (int i = 0; i < bandwidthList.size(); i++) {
		    Object o = bandwidthList.elementAt(i);
		    if (o instanceof BandwidthField) {
			BandwidthField b = (BandwidthField)o;
			try {
			    String type = b.getType();
			    if (type != null) {
				if (name.equals(type)) {
				    bandwidthList.removeElement(b);
				}
			    }
			}
			catch (SdpParseException e) {}
		    }
		}
	    }
    
public voidsetAttribute(java.lang.String name, java.lang.String value)
Sets the value of the specified attribute.

param
name name - the name of the attribute.
param
value value - the value of the named attribute.
throws
SdpException if the name or the value is null

	if (name == null || value == null)
	    throw new SdpException("The parameter is null");
	else
	    if (attributesList != null) {
		for (int i = 0; i < attributesList.size(); i++) {
		    Object o = attributesList.elementAt(i);
		    if (o instanceof AttributeField) {
			AttributeField a = (AttributeField)o;
			String n = a.getName();
			if (n != null) {
			    if (name.equals(n)) {
				a.setValue(value);
			    }
			}
		    }
		}
	    }
    
public voidsetAttributes(java.util.Vector attributes)
Adds the specified Attribute to this Description object.

param
attributes the attributes to add
throws
SdpException if the vector is null

	if (attributes == null)
	    throw new SdpException("The parameter is null");
	else attributesList = attributes;
    
public voidsetBandwidth(java.lang.String name, int value)
Sets the value of the specified bandwidth type.

param
name name - the name of the bandwidth type.
param
value value - the value of the named bandwidth type.
throws
SdpException if the name is null

	if (name == null)
	    throw new SdpException("The parameter is null");
	else
	    if (bandwidthList != null) {
		for (int i = 0; i < bandwidthList.size(); i++) {
		    Object o = bandwidthList.elementAt(i);
		    if (o instanceof BandwidthField) {
			BandwidthField b = (BandwidthField)o;
			String type = b.getType();
			if (type != null) {
			    if (name.equals(type)) {
				b.setValue(value);
			    }
			}
		    }
		}
	    }
    
public voidsetBandwidths(java.util.Vector bandwidthList)
Sets the value of the Bandwidth with the specified type.

param
bandwidthList to set
throws
SdpException if the vector is null

	if (bandwidthList == null)
	    throw new SdpException("The parameter is null");
	else
	    this.bandwidthList = bandwidthList;
    
public voidsetConnection(ConnectionField conn)
Sets the connection data for this entity.

param
conn to set
throws
SdpException if the parameter is null

	if (conn == null)
	    throw new SdpException("The parameter is null");
	if (conn instanceof ConnectionField) {
	    ConnectionField c = (ConnectionField)conn;
	    connectionImpl = c;
	} else
	    throw new
		SdpException("Bad implementation class ConnectionField");
    
public voidsetEmails(java.util.Vector emails)
Sets a an email address to contact for further information about the session. This corresponds to the e= field of the SDP data.

param
emails email - the email address.
throws
SdpException if the vector is null

	if (emails == null)
	    throw new SdpException("The parameter is null");
	else 
	    emailList = emails;
    
public voidsetInfo(InformationField i)
Sets the i= field of this object.

param
i s - new i= value; if null removes the field
throws
SdpException if the info is null

	if (i == null)
	    throw new SdpException("The parameter is null");
	if (i instanceof InformationField) {
	    InformationField info = (InformationField)i;
	    infoImpl = info;
	} else 
	    throw new SdpException("The parameter must be "
				   + "an instance of InformationField");
    
public voidsetKey(KeyField key)
Sets encryption key information. This consists of a method and an encryption key included inline.

param
key key - the encryption key data; depending on method may be null
throws
SdpException if the parameter is null

	if (key == null)
	    throw new SdpException("The parameter is null");
	if (key instanceof KeyField) {
	    KeyField k = (KeyField)key;
	    keyImpl = k;
	} else 
	    throw new
		SdpException("The parameter must be an instance of KeyField");
    
public voidsetMediaDescriptions(java.util.Vector mediaDescriptions)
Removes all MediaDescriptions from the session description.

param
mediaDescriptions to set
throws
SdpException if the parameter is null

	if (mediaDescriptions == null)
	    throw new SdpException("The parameter is null");
	else this.mediaDescriptions = mediaDescriptions;
    
public voidsetOrigin(OriginField origin)
Sets information about the originator of the session. This corresponds to the o= field of the SDP data.

param
origin origin - the originator data.
throws
SdpException if the origin is null

	if (origin == null)
	    throw new SdpException("The parameter is null");
	if (origin instanceof OriginField) {
	    OriginField o = (OriginField)origin;
	    originImpl = o;
	} else
	    throw new SdpException("The parameter must be "
				   + "an instance of OriginField");
    
public voidsetPhones(java.util.Vector phones)
Sets a phone number to contact for further information about the session. This corresponds to the p= field of the SDP data.

param
phones phone - the phone number.
throws
SdpException if the vector is null

	if (phones == null)
	    throw new SdpException("The parameter is null");
	else
	    phoneList = phones;
    
public voidsetSessionName(SessionNameField sessionName)
Sets the name of the session. This corresponds to the s= field of the SDP data.

param
sessionName name - the session name.
throws
SdpException if the sessionName is null

	if (sessionName == null) 
	    throw new SdpException("The parameter is null");
	if (sessionName instanceof SessionNameField) {
	    SessionNameField s = (SessionNameField)sessionName;
	    sessionNameImpl = s;
	} else
	    throw new SdpException("The parameter must be "
				   + "an instance of SessionNameField");
    
public voidsetTimeDescriptions(java.util.Vector times)
Sets a TimeField indicating the start, stop, repetition and time zone information of the session. This corresponds to the t= field of the SDP data.

param
times time - the TimeField.
throws
SdpException if the vector is null

	if (times == null)
	    throw new SdpException("The parameter is null");
	else {
	    timeDescriptions = times;
	}
    
public voidsetURI(URIField uri)
Sets the uri to the location of more details about the session. This corresponds to the u= field of the SDP data.

param
uri uri - the uri.
throws
SdpException if the uri is null

	if (uri == null)
	    throw new SdpException("The parameter is null");
	if (uri instanceof URIField) {
	    URIField u = (URIField)uri;
	    uriImpl = u;
	} else
	    throw new SdpException
		("The parameter must be an instance of URIField");
    
public voidsetVersion(ProtoVersionField v)
Sets the version of SDP in use. This corresponds to the v= field of the SDP data.

param
v version - the integer version.
throws
SdpException if the version is null

	if (v == null)
	    throw new SdpException("The parameter is null");
	if (v instanceof ProtoVersionField) {
	    versionImpl = (ProtoVersionField)v;
	} else
	    throw new SdpException
		("The parameter must be an instance of VersionField");
    
public voidsetZoneAdjustments(java.util.Vector zoneAdjustments)
Sets the time zone adjustment for the TimeField.

param
zoneAdjustments zoneAdjustments - a Hashtable containing the zone adjustments, where the key is the Adjusted Time Zone and the value is the offset.
throws
SdpException if the vector is null

	if (zoneAdjustments == null)
	    throw new SdpException("The parameter is null");
	else this.zoneAdjustments = zoneAdjustments;
    
public java.lang.StringtoString()
Returns the canonical string representation of the current SessionDescrption. Acknowledgement - this code

return
Returns the canonical string representation of the current SessionDescrption.

	StringBuffer encBuff = new StringBuffer();
 
	// Encode single attributes
	encBuff.append(getVersion() == null ? "" : getVersion().toString());
	encBuff.append(getOrigin() == null ? "" : getOrigin().toString());
	encBuff.append(getSessionName() == null ? "" : getSessionName().toString
		       ());
	encBuff.append(getInfo() == null ? "" : getInfo().toString());
 
	// Encode attribute vectors
	try {
	    encBuff.append(getURI() == null ? "" : getURI().toString());
	    encBuff.append(encodeVector(getEmails(true)));
	    encBuff.append(encodeVector(getPhones(true)));
	    encBuff.append(getConnection() == null ? "" :
			   getConnection().toString
			   ());
	    encBuff.append(encodeVector(getBandwidths(true)));
	    encBuff.append(encodeVector(getTimeDescriptions(true)));
	    encBuff.append(encodeVector(getZoneAdjustments(true)));
	    encBuff.append(getKey() == null ? "" : getKey().toString());
	    encBuff.append(encodeVector(getAttributes(true)));
	    encBuff.append(encodeVector(getMediaDescriptions(true)));
	    // adds the final crlf
	}
	catch (SdpException exc) {
	    // add exception handling if necessary
	}
	return encBuff.toString();