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

MediaField

public class MediaField extends SDPField
Media field SDP header.
version
JSR141-PUBLIC-REVIEW (subject to change). This code is in the public domain.

Fields Summary
protected String
media
Type of media.
protected int
port
Current port number.
protected int
nports
Number of ports.
protected String
proto
Protocol used.
protected Vector
formats
Media formats.
Constructors Summary
public MediaField()
Default constructor.

	super(SDPFieldNames.MEDIA_FIELD); 
	formats = new Vector();
    
Methods Summary
public java.lang.Objectclone()
Copies the current instance.

return
the copy of this object

	MediaField retval = new MediaField();
	retval.media = media;
	retval.port = port;
	retval.nports = nports;
	retval.proto = proto;
	for (int i = 0; i < formats.size(); i++) {
	    retval.formats.addElement(formats.elementAt(i));
	}
	return retval;
    
public java.lang.Stringencode()
Gets the string encoded version of this object.

return
encoded string of instance contents
since
v1.0

	String encoded_string;
	encoded_string = MEDIA_FIELD;
	if (media != null) encoded_string += media + Separators.SP + port;
	// Leave out the nports parameter as this confuses the messenger.
	if (nports > 1) encoded_string += Separators.SLASH + nports; 

	if (proto != null) encoded_string += Separators.SP + proto;
 
	if (formats != null) 
	    encoded_string += Separators.SP + encodeFormats(); 

	encoded_string += Separators.NEWLINE;
	return encoded_string;
    
private java.lang.StringencodeFormats()
Gets the string encoded version of the media formats.

return
encoded string of media formats contents

	String retval = "";
	for (int i = 0; i < formats.size(); i++) {
	    retval += formats.elementAt(i);
	    if (i < formats.size() -1) 
		retval += Separators.SP;
	}
	return retval;
    
public java.util.VectorgetFormats()
Gets the vector of media formats

return
the formats

	return formats;
    
public java.lang.StringgetMedia()
Gets the media type.

return
the media type

	return media;
    
public java.util.VectorgetMediaFormats(boolean create)
Returns an Vector of the media formats supported by this description. Each element in this Vector will be an String value which matches one of the a=rtpmap: attribute fields of the media description.

param
create to set
throws
SdpException
return
the Vector.

 
	if (!create && formats.size() == 0) 
	    return null;
	else return formats;
    
public intgetMediaPort()
Returns the port of the media defined by this description

throws
SdpParseException if a parsing error occurs
return
the integer media port.

	return getPort();
    
public java.lang.StringgetMediaType()
Returns the type (audio,video etc) of the media defined by this description.

throws
SdpParseException if a parsing erro occurs
return
the string media type.

	return getMedia();
    
public intgetNports()
Gets the number of ports.

return
the number of ports

	return nports;
    
public intgetPort()
Gets the port information.

return
the current port number

	return port;
    
public intgetPortCount()
Returns the number of ports associated with this media description

throws
SdpParseException if a parsing error occurs
return
the integer port count.

	return getNports();
    
public java.lang.StringgetProto()
Gets the protocl information.

return
the protocol

	return proto;
    
public java.lang.StringgetProtocol()
Returns the protocol over which this media should be transmitted.

throws
SdpParseException if a parsing error occurs
return
the String protocol, e.g. RTP/AVP.

	return getProto();
    
public voidsetFormats(java.util.Vector formats)
Sets the formats member.

param
formats the new vector of media formats

	this.formats = formats;
    
public voidsetMedia(java.lang.String m)
Sets the media member.

param
m the new media type

	media = m;
    
public voidsetMediaFormats(java.util.Vector mediaFormats)
Adds a media format to the media description. Each element in this Vector should be an String value which matches one of the a=rtpmap: attribute fields of the media description.

param
mediaFormats the format to add.
throws
SdpException if the vector is null

	if (mediaFormats == null)
	    throw new SdpException("The mediaFormats is null");
	this.formats = mediaFormats;
    
public voidsetMediaPort(int port)
Sets the port of the media defined by this description

param
port to set
throws
SdpException if th eport is null

	if (port < 0)
	    throw new SdpException("The port is < 0");
	else setPort(port); 
    
public voidsetMediaType(java.lang.String mediaType)
Sets the type (audio,video etc) of the media defined by this description.

param
mediaType to set
throws
SdpException if mediaType is null

	if (mediaType == null)
	    throw new SdpException("The mediaType is null");
	else setMedia(mediaType); 
    
public voidsetNports(int n)
Sets the number of ports member.

param
n the new number of ports

	nports = n;
    
public voidsetPort(int p)
Sets the port member.

param
p the new port number

	port = p;
    
public voidsetPortCount(int portCount)
Sets the number of ports associated with this media description.

param
portCount portCount - the integer port count.
throws
SdpException if the count is less than zero

	if (portCount < 0)
	    throw new SdpException("The port count is < 0");
	else setNports(portCount);
    
public voidsetProto(java.lang.String p)
Sets the protocol type member.

param
p the protocol type

	proto = p;
    
public voidsetProtocol(java.lang.String protocol)
Sets the protocol over which this media should be transmitted.

param
protocol - the String protocol, e.g. RTP/AVP.
throws
SdpException if the protocol is null

	if (protocol == null)
	    throw new SdpException("The protocol is null");
	else setProto(protocol);