Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Conditions Of Use
   *
   * This software was developed by employees of the National Institute of
   * Standards and Technology (NIST), an agency of the Federal Government.
   * Pursuant to title 15 Untied States Code Section 105, works of NIST
   * employees are not subject to copyright protection in the United States
   * and are considered to be in the public domain.  As a result, a formal
   * license is not needed to use the software.
  *
  * This software is provided by NIST as a service and is expressly
  * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
  * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
  * AND DATA ACCURACY.  NIST does not warrant or make any representations
  * regarding the use of the software or the results thereof, including but
  * not limited to the correctness, accuracy, reliability or usefulness of
  * the software.
  *
  * Permission to use this software is contingent upon your acceptance
  * of the terms of this agreement
  *
  * .
  *
  */
 package gov.nist.javax.sdp;
 
 import javax.sdp.*;
 import java.util.*;
 
 /*
  * Includes code contributed by
  * Miguel Freitas (IT) PTInovacao -- modifications for IMS.
  */

Fieldementation of Media Description interface.

Author(s):
Olivier Deruelle <deruelle@antd.nist.gov>
M. Ranganathan
Version:
JSR141-PUBLIC-REVIEW (subject to change).
 
 public class MediaDescriptionImpl implements javax.sdp.MediaDescription {
 
     protected MediaField mediaField;
 
     protected InformationField informationField;
 
     protected ConnectionField connectionField;
 
     protected Vector bandwidthFields;
 
     protected KeyField keyField;
 
     protected Vector attributeFields;

    
Encode to a canonical form.

Since:
v1.0
 
     public String encode() {
         StringBuffer retval = new StringBuffer();
 
         if ( != null)
             retval.append(.encode());
 
         if ( != null)
             retval.append(.encode());
 
         if ( != null)
             retval.append(.encode());
 
         if ( != null) {
             for (int i = 0; i < .size(); i++) {
 
                 // issued by Miguel Freitas (IT) PTInovacao
                 retval.append(((SDPField.elementAt(i))
                         .encode());
 
                 /*
                  * original code BandwidthField bandwidthField =
                  * (BandwidthField) bandwidthFields.elementAt(i);
                  * retval.append(bandwidthField.encode());
                  */
                 // end //
             }
             if ( != null) {
                 int precondSize = .getPreconditionSize();
                 for (int i = 0; i < precondSizei++) {
                     retval.append(((SDPField
                             .getPreconditions().elementAt(i)).encode());
                 }
             }
        }
        if ( != null)
            retval.append(.encode());
        if ( != null) {
            for (int i = 0; i < .size(); i++)
                retval.append(((SDPField.elementAt(i))
                        .encode());
        }
        return retval.toString();
    }
    public String toString() {
        return this.encode();
    }
    public MediaDescriptionImpl() {
        this. = new Vector();
        this. = new Vector();
        // issued by Miguel Freitas (AV) PTInovacao
        this. = new PreconditionFields();
    }
    public MediaField getMediaField() {
        return ;
    }
        return ;
    }
        return ;
    }
    public KeyField getKeyField() {
        return ;
    }
    public Vector getAttributeFields() {
        return ;
    }

    
Set the mediaField member
    public void setMediaField(MediaField m) {
         = m;
    }

    
Set the informationField member
    public void setInformationField(InformationField i) {
         = i;
    }

    
Set the connectionField member
    public void setConnectionField(ConnectionField c) {
         = c;
    }

    
Set the bandwidthField member
    public void addBandwidthField(BandwidthField b) {
        .add(b);
    }

    
Set the keyField member
    public void setKeyField(KeyField k) {
         = k;
    }

    
Set the attributeFields member
    public void setAttributeFields(Vector a) {
         = a;
    }

    
Return the Media field of the description.

Returns:
the Media field of the description.
    public Media getMedia() {
        return ;
    }
    // issued by Miguel Freitas //
    public void addAttribute(AttributeField af) {
        // protected void addAttribute(AttributeField af) {
        // end //
        this..add(af);
    }
    protected boolean hasAttribute(String name) {
        for (int i = 0; i < this..size(); i++) {
            AttributeField af = (AttributeFieldthis.
                    .elementAt(i);
            if (af.getAttribute().getName().equals(name))
                return true;
        }
        return false;
    }

    
Set the Media field of the description.

Parameters:
media to set
Throws:
javax.sdp.SdpException if the media field is null
    public void setMedia(Media mediathrows SdpException {
        if (media == null)
            throw new SdpException("The media is null");
        if (media instanceof MediaField) {
             = (MediaFieldmedia;
        } else
            throw new SdpException("A mediaField parameter is required");
    }

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

Returns:
value of the info field (i=) of this object.
    public Info getInfo() {
        InformationField informationField = getInformationField();
        if (informationField == null)
            return null;
        else {
            return informationField;
        }
    }

    
Sets the i= field of this object.

Parameters:
i to set
Throws:
javax.sdp.SdpException if the info is null
    public void setInfo(Info ithrows SdpException {
        if (i == null)
            throw new SdpException("The info is null");
        if (i instanceof InformationField) {
            this. = (InformationFieldi;
        } else
            throw new SdpException("A informationField parameter is required");
    }

    
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.

Returns:
connection
    public Connection getConnection() {
        return ;
    }

    
Set the connection data for this entity

Parameters:
conn to set
Throws:
javax.sdp.SdpException if the connexion is null
    public void setConnection(Connection connthrows SdpException {
        if (conn == null)
            throw new SdpException("The conn is null");
        if (conn instanceof ConnectionField) {
             = (ConnectionFieldconn;
        } else
            throw new SdpException("bad implementation");
    }

    
Returns the Bandwidth of the specified type.

Parameters:
create type of the Bandwidth to return
Returns:
the Bandwidth or null if undefined
    public Vector getBandwidths(boolean create) {
        return ;
    }

    
set the value of the Bandwidth with the specified type

Parameters:
bandwidths type of the Bandwidth object whose value is requested
Throws:
javax.sdp.SdpException if vector is null
    public void setBandwidths(Vector bandwidthsthrows SdpException {
        if (bandwidths == null)
            throw new SdpException("The vector bandwidths is null");
        this. = bandwidths;
    }

    
Returns the integer value of the specified bandwidth name.

Parameters:
name the name of the bandwidth type.
Returns:
the value of the named bandwidth
Throws:
javax.sdp.SdpParseException
    public int getBandwidth(String namethrows SdpParseException {
        if (name == null)
            throw new NullPointerException("null parameter");
        if ( == null)
            return -1;
        else {
            for (int i = 0; i < .size(); i++) {
                BandwidthField bandwidthField = (BandwidthField
                        .elementAt(i);
                String type = bandwidthField.getBwtype();
                if (type != null && type.equals(name))
                    return bandwidthField.getBandwidth();
            }
            return -1;
        }
    }

    
Sets the value of the specified bandwidth type.

Parameters:
name the name of the bandwidth type.
value the value of the named bandwidth type.
Throws:
javax.sdp.SdpException if the name is null
    public void setBandwidth(String nameint valuethrows SdpException {
        if (name == null)
            throw new SdpException("The name is null");
        else {
            int i = 0; // issued by Miguel Freitas (IT) PTInovacao
            for (i = 0; i < .size(); i++) {
                BandwidthField bandwidthField = (BandwidthFieldthis.
                        .elementAt(i);
                String type = bandwidthField.getBwtype();
                if (type != null && type.equals(name)) {
                    bandwidthField.setBandwidth(value);
                    break// issued by Miguel Freitas (IT) PTInovacao
                }
            }
            // issued by Miguel Freitas (IT) PTInovacao
            if (i == this..size()) {
                BandwidthField bandwidthField = new BandwidthField();
                bandwidthField.setType(name);
                bandwidthField.setValue(value);
                this..add(bandwidthField);
            }
            // end //
        }
    }

    
Removes the specified bandwidth type.

Parameters:
name the name of the bandwidth type.
    public void removeBandwidth(String name) {
        if (name == null) {
            throw new NullPointerException("null bandwidth type");
        } else {
            int i = 0;
            for (i = 0; i < .size(); i++) {
                BandwidthField bandwidthField = (BandwidthField
                        .elementAt(i);
                String type = bandwidthField.getBwtype();
                if (type != null && type.equals(name))
                    break;
            }
            if (i < .size())
                .removeElementAt(i);
        }
    }

    
Returns the key data.

Returns:
the key data.
    public Key getKey() {
        if ( == null)
            return null;
        else {
            return ;
        }
    }

    
Sets encryption key information. This consists of a method and an encryption key included inline.

Parameters:
key the encryption key data; depending on method may be null
Throws:
javax.sdp.SdpException if the key is null
    public void setKey(Key keythrows SdpException {
        if (key == null)
            throw new SdpException("The key is null");
        if (key instanceof KeyField) {
            KeyField keyField = (KeyFieldkey;
            setKeyField(keyField);
        } else
            throw new SdpException("A keyField parameter is required");
    }

    
Returns the set of attributes for this Description as a Vector of Attribute objects in the order they were parsed.

Parameters:
create specifies whether to return null or a new empty Vector in case no attributes exists for this Description
Returns:
attributes for this Description
    public Vector getAttributes(boolean create) {
        return ;
    }

    
Adds the specified Attribute to this Description object.

Parameters:
attributes -- the attribute to add
Throws:
javax.sdp.SdpException -- if the attributes is null
    public void setAttributes(Vector attributesthrows SdpException {
        this. = attributes;
    }

    
Returns the value of the specified attribute.

Parameters:
name the name of the attribute.
Returns:
the value of the named attribute
Throws:
javax.sdp.SdpParseException
    public String getAttribute(String namethrows SdpParseException {
        if (name != null) {
            for (int i = 0; i < this..size(); i++) {
                AttributeField af = (AttributeFieldthis.
                        .elementAt(i);
                if (name.equals(af.getAttribute().getName()))
                    return (Stringaf.getAttribute().getValueAsObject();
            }
            return null;
        } else
            throw new NullPointerException("null arg!");
    }

    
Sets the value of the specified attribute

Parameters:
name the name of the attribute.
value the value of the named attribute.
Throws:
javax.sdp.SdpException if the parameters are null
    public void setAttribute(String nameString valuethrows SdpException {
        if (name == null)
            throw new SdpException("The parameters are null");
        else {
            int i = 0;
            for (i = 0; i < this..size(); i++) {
                AttributeField af = (AttributeFieldthis.
                        .elementAt(i);
                if (af.getAttribute().getName().equals(name)) {
                    NameValue nv = af.getAttribute();
                    nv.setValueAsObject(value);
                    break;
                }
            }
            if (i == this..size()) {
                AttributeField af = new AttributeField();
                NameValue nv = new NameValue(namevalue);
                af.setAttribute(nv);
                // Bug fix by Emil Ivov.
                this..add(af);
            }
        }
    }
    public String getDuplexity() {
    	  int i = 0;
          for (i = 0; i < this..size(); i++) {
              AttributeField af = (AttributeFieldthis.
                      .elementAt(i);
              if (af.getAttribute().getName().equalsIgnoreCase("sendrecv") ||
                      af.getAttribute().getName().equalsIgnoreCase("recvonly") ||
                      af.getAttribute().getName().equalsIgnoreCase("sendonly") ||
                      af.getAttribute().getName().equalsIgnoreCase("inactive")) {
            	  return af.getAttribute().getName();
              }
          }
          return null;
         
    }
    
    
    public void setDuplexity(String duplexity) {
        if ( duplexity == null ) throw new NullPointerException("Null arg");
        int i = 0;
        for (i = 0; i < this..size(); i++) {
            AttributeField af = (AttributeFieldthis.
                    .elementAt(i);
            if (af.getAttribute().getName().equalsIgnoreCase("sendrecv") ||
                    af.getAttribute().getName().equalsIgnoreCase("recvonly") ||
                    af.getAttribute().getName().equalsIgnoreCase("sendonly") ||
                    af.getAttribute().getName().equalsIgnoreCase("inactive")) {
                NameValue nv = new NameValue(duplexitynull);
                af.setAttribute(nv);
                return;
            }
        }
        if (i == this..size()) {
            AttributeField af = new AttributeField();
            NameValue nv = new NameValue(duplexitynull);
            af.setAttribute(nv);
            // Bug fix by Emil Ivov.
            this..add(af);
        }
    }

    
Removes the attribute specified by the value parameter.

Parameters:
name the name of the attribute.
    public void removeAttribute(String name) {
        if (name == null)
            throw new NullPointerException("null arg!");
        if (name != null) {
            int i = 0;
            for (i = 0; i < this..size(); i++) {
                AttributeField af = (AttributeFieldthis.
                        .elementAt(i);
                if (af.getAttribute().getName().equals(name))
                    break;
            }
            if (i < .size())
                .removeElementAt(i);
        }
    }

    
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

Returns:
a Vector containing a string indicating the MIME type for each of the codecs in this description
Throws:
javax.sdp.SdpException if there is a problem extracting the parameters.
    public Vector getMimeTypes() throws SdpException {
        MediaField mediaField = (MediaFieldgetMedia();
        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(.) != null)
                    result = type + "/" + protocol;
                else {
                }
            } else
                result = type + "/" + protocol;
            v.addElement(result);
        }
        return v;
    }

    
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.

Returns:
a Vector containing a string of parameters for each of the codecs in this description.
Throws:
javax.sdp.SdpException if there is a problem extracting the parameters.
    public Vector getMimeParameters() throws SdpException {
        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;
    }

    
Adds dynamic media types to the description.

Parameters:
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).
payloadValues a Vector of String - each contains the value describing the correlated dynamic payloads to be added
Throws:
javax.sdp.SdpException if either vector is null or empty. if the vector sizes are unequal.
    public void addDynamicPayloads(Vector payloadNamesVector payloadValues)
            throws SdpException {
        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 = (StringpayloadNames.elementAt(i);
                        String value = (StringpayloadValues.elementAt(i);
                        setAttribute(namevalue);
                    }
                }
            }
        }
    }
    // /////////////////////////////////////////////////////////////////
    // Precondition Mechanism
    // based in 3GPP TS 24.229 and precondition mechanism (RFC 3312)
    // issued by Miguel Freitas (IT) PTinovacao
    // /////////////////////////////////////////////////////////////////

    
Precondition Mechanism - precondition fields for the media description
    // Precondition Attribute Fields
    protected PreconditionFields preconditionFields;

    

Set the Media Description's Precondition Fields

issued by Miguel Freitas (IT) PTInovacao

Parameters:
precondition Vector containing PreconditionFields
Throws:
javax.sdp.SdpException
    public void setPreconditionFields(Vector preconditionthrows SdpException {
        this..setPreconditions(precondition);
    }

    

Set the Media Description's Precondition Fields

issued by Miguel Freitas (IT) PTInovacao

Parameters:
precondition PreconditionFields parameter
    public void setPreconditions(PreconditionFields precondition) {
        this. = precondition;
    }

    

Get attribute fields of segmented precondition

issued by Miguel Freitas (IT) PTInovacao

Returns:
Vector of attribute fields (segmented precondition)
    public Vector getPreconditionFields() {
        return this..getPreconditions();
    }
    // end //
New to GrepCode? Check out our FAQ X