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

MediaDescriptionImpl

public class MediaDescriptionImpl extends Object
Field implementation of Media Description interface.
version
JSR141-PUBLIC-REVIEW (subject to change). This code is in the public domain.

Fields Summary
protected MediaField
mediaField
Media type field.
protected InformationField
informationField
Extra information field.
protected ConnectionField
connectionField
Current connection.
protected Vector
bandwidthFields
Vector of bandwidths.
protected KeyField
keyField
Key field.
protected Vector
attributeFields
Connection attributes.
Constructors Summary
public MediaDescriptionImpl()
Default constructor.

 
	this.bandwidthFields = new Vector(); 
	this.attributeFields = new Vector();
    
Methods Summary
protected voidaddAttribute(AttributeField af)
Adds a new attirbute to the list.

param
af the attribute field to be processed

 
	this.attributeFields.addElement(af);
    
public voidaddBandwidthField(BandwidthField b)
Sets the bandwidth field member.

param
b the new bandwidth field

	bandwidthFields.addElement(b);
    
public voidaddDynamicPayloads(java.util.Vector payloadNames, java.util.Vector payloadValues)
Adds dynamic media types to the description.

param
payloadNames a Vector of String - each one the name of a dynamic payload to be added (usually an integer larger than SdpConstants.AVP_DYNAMIC_MIN).
param
payloadValues a Vector of String - each contains the value describing the correlated dynamic payloads to be added
throws
SdpException if either vector is null or empty. if the vector sizes are unequal.

	MediaField mediaField = (MediaField)getMedia();
	if (payloadNames == null || payloadValues == null)
	    throw new SdpException(" The vectors are null");
	else {
	    if (payloadNames.isEmpty() || payloadValues.isEmpty())
		throw new SdpException(" The vectors are empty");
	    else {
		if (payloadNames.size() != payloadValues.size())
		    throw new SdpException(" The vector sizes are unequal");
		else {
		    for (int i = 0; i < payloadNames.size(); i++) {
			String name = (String)payloadNames.elementAt(i);
			String value = (String)payloadValues.elementAt(i);
			setAttribute(name, value);
		    }
		}
	    }
	}
    
public java.lang.Stringencode()
Encodes to a canonical form.

return
encoded string of object contents
since
v1.0

	StringBuffer retval = new StringBuffer();

	if (mediaField != null) 
	    retval.append(mediaField.encode());

	if (informationField != null) 
	    retval.append(informationField.encode());

	if (connectionField != null) 
	    retval.append(connectionField.encode());

	if (bandwidthFields != null) {
	    for (int i = 0; i < bandwidthFields.size(); i++) {
		BandwidthField bandwidthField = 
		    (BandwidthField) bandwidthFields.elementAt(i);
		retval.append(bandwidthField.encode());
	    }
	}

	if (keyField != null) 
	    retval.append(keyField.encode());

	if (attributeFields != null) {
	    for (int i = 0; i < attributeFields.size(); i++) 
		retval.append(((SDPField)attributeFields.elementAt(i)).
			      encode());
	}

	return retval.toString();
    
public java.lang.StringgetAttribute(java.lang.String name)
Returns the value of the specified attribute.

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

	if (name != null) {
	    for (int i = 0; i < this.attributeFields.size(); i++) {
		AttributeField af = (AttributeField)
		    this.attributeFields.elementAt(i);
		if (name.equals(af.getAttribute().getName())) 
		    return (String) af.getAttribute().getValue();
	    }
	    return null; 
	} else throw new NullPointerException("null arg!");
    
public java.util.VectorgetAttributeFields()
Gets the attributes filed.

return
the vector of attributes

	return attributeFields;
    
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 specifies whether to return null or a new empty Vector in case no attributes exists for this Description
return
attributes for this Description

	return attributeFields;
    
public intgetBandwidth(java.lang.String name)
Returns the integer value of the specified bandwidth name.

param
name the name of the bandwidth type.
throws
SdpParseException if a parsing error occurs
return
the value of the named bandwidth

 
	if (name == null)
	    throw new NullPointerException("null parameter");
	if (bandwidthFields == null)
	    return -1;
	else {
	    for (int i = 0; i < bandwidthFields.size(); i++) {
		BandwidthField bandwidthField = (BandwidthField) 
		    bandwidthFields.elementAt(i);
		String type = bandwidthField.getBwtype();
		if (type != null && 
		    type.equals(name)) 
		    return bandwidthField.getBandwidth();
	    }
	    return -1;
	}
    
public java.util.VectorgetBandwidths(boolean create)
Returns the Bandwidth of the specified type.

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

 
	return bandwidthFields;
    
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 connectionField;
 
    
public ConnectionFieldgetConnectionField()
Gets the connection filed

return
the connection firld

	return connectionField;
    
public InformationFieldgetInfo()
Returns value of the info field (i=) of this object.

return
value of the info field (i=) of this object.

	return informationField;
    
public InformationFieldgetInformationField()
Gets the information field.

return
the information field

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

return
the key data.

	return keyField;
    
public KeyFieldgetKeyField()
Gets the key field.

return
the key field

	return keyField;
    
public MediaFieldgetMedia()
Returns the Media field of the description.

return
the Media field of the description.

	return mediaField;
 
    
public MediaFieldgetMediaField()
Gets the media field

return
the media field

	return mediaField;
    
public java.util.VectorgetMimeParameters()
Returns a Vector containing a string of parameters for each of the codecs in this description.

A parameter string is computed for each codec.

The parameter string is computed in the following fashion.

The rate is extracted from the rtpmap or static data.

The number of channels is extracted from the rtpmap or static data.

The ptime is extracted from the ptime attribute.

The maxptime is extracted from the maxptime attribute.

Any additional parameters are extracted from the ftmp attribute.

throws
SdpException if there is a problem extracting the parameters.
return
a Vector containing a string of parameters for each of the codecs in this description.

	String rate = getAttribute("rate");
	String ptime = getAttribute("ptime");
	String maxptime = getAttribute("maxptime");
	String ftmp = getAttribute("ftmp");
	Vector result = new Vector();
	result.addElement(rate);
	result.addElement(ptime);
	result.addElement(maxptime);
	result.addElement(ftmp);
	return result;
    
public java.util.VectorgetMimeTypes()
Returns a Vector containing a string indicating the MIME type for each of the codecs in this description.

A MIME value is computed for each codec in the media description.

The MIME type is computed in the following fashion: The type is the mediaType from the media field. The subType is determined by the protocol.

The result is computed as the string of the form:

type + '/' + subType
The subType portion is computed in the following fashion. RTP/AVP the subType is returned as the codec name. This will either be extracted from the rtpmap attribute or computed. other the protocol is returned as the subType.

If the protocol is RTP/AVP and the rtpmap attribute for a codec is absent, then the codec name will be computed in the following fashion. String indexed in table SdpConstants.avpTypeNames if the value is an int greater than or equal to 0 and less than AVP_DEFINED_STATIC_MAX, and has been assigned a value. SdpConstant.RESERVED if the value is an int greater than or equal to 0 and less than AVP_DEFINED_STATIC_MAX, and has not been assigned a value. SdpConstant.UNASSIGNED An int greater than or equal to AVP_DEFINED_STATIC_MAX and less than AVP_DYNAMIC_MIN - currently unassigned. SdpConstant.DYNAMIC Any int less than 0 or greater than or equal to AVP_DYNAMIC_MIN

throws
SdpException if there is a problem extracting the parameters.
return
a Vector containing a string indicating the MIME type for each of the codecs in this description

	MediaField mediaField = (MediaField)getMedia();
	String type = mediaField.getMediaType();
	String protocol = mediaField.getProtocol();
	Vector formats = mediaField.getMediaFormats(false);
 
	Vector v = new Vector();
	for (int i = 0; i < formats.size(); i++) {
	    String result = null;
	    if (protocol.equals("RTP/AVP")) {
		if (getAttribute(SdpConstants.RTPMAP) != null)
		    result = type + "/"+protocol;
		else {
 
		}
	    } else
		result = type + "/" + protocol;
	    v.addElement(result);
	}
	return v;
    
protected booleanhasAttribute(java.lang.String name)
Checks if named attribute exists.

param
name the attribute to check
return
true is attribute is found

	for (int i = 0; i < this.attributeFields.size(); i++) {
	    AttributeField af = 
		(AttributeField) this.attributeFields.elementAt(i);
	    if (af.getAttribute().getName().equals(name))
		return true;
	}
	return false;
    
public voidremoveAttribute(java.lang.String name)
Removes the attribute specified by the value parameter.

param
name the name of the attribute.

	if (name == null)
	    throw new NullPointerException("null arg!");
	if (name != null) {
	    int i = 0;
	    for (i = 0; i < this.attributeFields.size(); i++) {
		AttributeField af = (AttributeField) 
		    this.attributeFields.elementAt(i);
		if (af.getAttribute().getName().equals(name)) break;
	    }
	    if (i < attributeFields.size())
		attributeFields.removeElementAt(i);
	}
    
public voidremoveBandwidth(java.lang.String name)
Removes the specified bandwidth type.

param
name the name of the bandwidth type.

	if (name == null) {
	    throw new NullPointerException("null bandwidth type");
	} else {
	    int i = 0;
	    for (i = 0; i < bandwidthFields.size(); i++) {
		BandwidthField bandwidthField = (BandwidthField) 
		    bandwidthFields.elementAt(i);
		String type = bandwidthField.getBwtype();
		if (type != null && 
		    type.equals(name))
		    break;
 
	    }
	    if (i < bandwidthFields.size()) 
		bandwidthFields.removeElementAt(i);
	}
    
public voidsetAttribute(java.lang.String name, java.lang.String value)
Sets the value of the specified attribute

param
name the name of the attribute.
param
value the value of the named attribute.
throws
SdpException if the parameters are null

	if (name == null)
	    throw new SdpException("The parameters are null");
	else {
 
	    int i = 0;
	    for (i = 0; i < this.attributeFields.size(); i++) {
		AttributeField af = (AttributeField) 
		    this.attributeFields.elementAt(i);
		if (af.getAttribute().getName().equals(name)) {
		    NameValue nv = af.getAttribute();
		    nv.setValue(value);
		    break;
		}
 
	    }
 
	    if (i == this.attributeFields.size()) {
		AttributeField af = new AttributeField();
		NameValue nv = new NameValue(name, value);
		af.setAttribute(nv);
		this.attributeFields.addElement(af);
	    }
 
	}
    
public voidsetAttributeFields(java.util.Vector a)
Sets the attribute fields member.

param
a the new vector of attributes

	attributeFields = a;
    
public voidsetAttributes(java.util.Vector attributes)
Adds the specified Attribute to this Description object.

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

	this.attributeFields = attributes;
    
public voidsetBandwidth(java.lang.String name, int value)
Sets the value of the specified bandwidth type.

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

	if (name == null)
	    throw new SdpException("The name is null");
	else {
	    for (int i = 0; i < bandwidthFields.size(); i++) {
		BandwidthField bandwidthField = (BandwidthField) 
		    bandwidthFields.elementAt(i);
		String type = bandwidthField.getBwtype();
		if (type != null && 
		    type.equals(name)) 
		    bandwidthField.setBandwidth(value);
	    }
 
	}
    
public voidsetBandwidths(java.util.Vector bandwidths)
Sets the value of the Bandwidth with the specified type.

param
bandwidths type of the Bandwidth object whose value is requested
throws
SdpException if vector is null

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

param
conn to set
throws
SdpException if the connexion is null

	if (conn == null)
	    throw new SdpException("The conn is null");
	connectionField = conn;
 
    
public voidsetConnectionField(ConnectionField c)
Sets the connection field member.

param
c the new connection field

	connectionField = c;
    
public voidsetInfo(InformationField i)
Sets the i= field of this object.

param
i to set
throws
SdpException if the info is null

	if (i == null)
	    throw new SdpException("The info is null");
	this.informationField = i;
    
public voidsetInformationField(InformationField i)
Sets the information field member.

param
i the new information filed

	informationField = i;
    
public voidsetKey(KeyField key)
Sets encryption key information. This consists of a method and an encryption key included inline.

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

	if (key == null)
	    throw new SdpException("The key is null");
	setKeyField(key);
    
public voidsetKeyField(KeyField k)
Sets the key field member.

param
k the new key field

	keyField = k;
    
public voidsetMedia(MediaField media)
Sets the Media field of the description.

param
media to set
throws
SdpException if the media field is null

	if (media == null)
	    throw new SdpException("The media is null");
	mediaField = media;
    
public voidsetMediaField(MediaField m)
Sets the media field member.

param
m the new media field

	mediaField = m;
    
public java.lang.StringtoString()
Returns encoded text.

return
encoded string of object contents

	return this.encode();