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
  *
  * .
  *
  */
  /*
   * SessionDescriptionImpl.java
   *
   * Created on January 10, 2002, 3:11 PM
   */
  package gov.nist.javax.sdp;
  
  import java.util.*;
  import javax.sdp.*;
  
  
Implementation of the SessionDescription interface.

Author(s):
Olivier Deruelle
M. Ranganathan
Version:
JSR141-PUBLIC-REVIEW
  
  public class SessionDescriptionImpl implements SessionDescription {
  
  
      protected ProtoVersionField versionImpl;
  
      protected OriginField originImpl;
  
      protected SessionNameField sessionNameImpl;
  
      protected InformationField infoImpl;
  
      protected URIField uriImpl;
  
      protected ConnectionField connectionImpl;
  
      protected KeyField keyImpl;
  
      protected Vector timeDescriptions;
  
      protected Vector mediaDescriptions;
  
      protected Vector zoneAdjustments;
  
      protected Vector emailList;
  
      protected Vector phoneList;
  
      protected Vector bandwidthList;
  
      protected Vector attributesList;

    
Creates new SessionDescriptionImpl
  
      public SessionDescriptionImpl() {
      }

    
Copy constructor, creates a deep copy of another SessionDescription.

Parameters:
otherSessionDescription - the SessionDescription to copy from.
Throws:
javax.sdp.SdpException - if there is a problem constructing the SessionDescription.
  
      public SessionDescriptionImpl(SessionDescription otherSessionDescription)
              throws SdpException
      {
          // If the other session description is null there's nothing to initialize
          if (otherSessionDescription == nullreturn;
 
         // OK to clone the version field, no deep copy required
         Version otherVersion = otherSessionDescription.getVersion();
         if (otherVersion != null) {
             this.setVersion((VersionotherVersion.clone());
         }
 
         // OK to clone the origin field, class already does a deep copy
         Origin otherOrigin = otherSessionDescription.getOrigin();
         if (otherOrigin != null) {
             this.setOrigin((OriginotherOrigin.clone());
         }
 
         // OK to clone the session name, no deep copy required
         SessionName otherSessionName = otherSessionDescription.getSessionName();
         if (otherSessionName != null) {
             this.setSessionName((SessionNameotherSessionName.clone());
         }
 
         // OK to clone the information field, just a string, no deep copy required
         Info otherInfo = otherSessionDescription.getInfo();
         if (otherInfo != null) {
             this.setInfo((InfootherInfo.clone());
         }
 
         // URI field requires deep copy
         URIField otherUriField = (URIFieldotherSessionDescription.getURI();
         if (otherUriField != null) {
             URIField newUF = new URIField();
             newUF.setURI(otherUriField.toString());
             this.setURI(newUF);
         }
 
         // OK to clone the connection field, class already does a deep copy
         Connection otherConnection = (ConnectionotherSessionDescription.getConnection();
         if (otherConnection != null) {
             this.setConnection((ConnectionotherConnection.clone());
         }
 
         // OK to clone the key field, just a couple of strings
         Key otherKey = (KeyotherSessionDescription.getKey();
         if (otherKey != null) {
             this.setKey((KeyotherKey.clone());
         }
 
         // Deep copy each vector, starting with time descriptions
         Vector otherTimeDescriptions = otherSessionDescription.getTimeDescriptions(false);
         if (otherTimeDescriptions != null) {
             Vector newTDs = new Vector();
             Iterator itTimeDescriptions = otherTimeDescriptions.iterator();
             while (itTimeDescriptions.hasNext()) {
                 TimeDescriptionImpl otherTimeDescription = (TimeDescriptionImplitTimeDescriptions.next();
                 if (otherTimeDescription != null) {
                     TimeField otherTimeField = (TimeFieldotherTimeDescription.getTime().clone();
                     TimeDescriptionImpl newTD = new TimeDescriptionImpl(otherTimeField);
                     Vector otherRepeatTimes = otherTimeDescription.getRepeatTimes(false);
                     if (otherRepeatTimes != null) {
                         Iterator itRepeatTimes = otherRepeatTimes.iterator();
                         while (itRepeatTimes.hasNext()) {
                             RepeatField otherRepeatField = (RepeatFielditRepeatTimes.next();
                             if (otherRepeatField != null) {
                                 // RepeatField clone is a deep copy
                                 RepeatField newRF = (RepeatFieldotherRepeatField.clone();
                                 newTD.addRepeatField(newRF);
                             }
                         }
                     }
                     newTDs.add(newTD);
                 }
             }
             this.setTimeDescriptions(newTDs);
         }
 
         // Deep copy the email list
         Vector otherEmails = otherSessionDescription.getEmails(false);
         if (otherEmails != null) {
             Vector newEmails = new Vector();
             Iterator itEmails = otherEmails.iterator();
             while (itEmails.hasNext()) {
                 EmailField otherEmailField = (EmailFielditEmails.next();
                 if (otherEmailField != null) {
                     // Email field clone is a deep copy
                     EmailField newEF = (EmailFieldotherEmailField.clone();
                     newEmails.add(newEF);
                 }
             }
             this.setEmails(newEmails);
         }
 
         // Deep copy the phone list
         Vector otherPhones = otherSessionDescription.getPhones(false);
         if (otherPhones != null) {
             Vector newPhones = new Vector();
             Iterator itPhones = otherPhones.iterator();
             while (itPhones.hasNext()) {
                 PhoneField otherPhoneField = (PhoneFielditPhones.next();
                 if (otherPhoneField != null) {
                     // Phone field clone is a deep copy
                     PhoneField newPF = (PhoneFieldotherPhoneField.clone();
                     newPhones.add(newPF);
                 }
             }
             this.setPhones(newPhones);
         }
 
         // Deep copy the zone adjustments list
         Vector otherZAs = otherSessionDescription.getZoneAdjustments(false);
         if (otherZAs != null) {
             Vector newZAs = new Vector();
             Iterator itZAs = otherZAs.iterator();
             while (itZAs.hasNext()) {
                 ZoneField otherZoneField = (ZoneFielditZAs.next();
                 if (otherZoneField != null) {
                     // Zone field clone is a deep copy
                     ZoneField newPF = (ZoneFieldotherZoneField.clone();
                     newZAs.add(newPF);
                 }
             }
             this.setZoneAdjustments(newZAs);
         }
 
         // Deep copy the bandwidth list
         Vector otherBandwidths = otherSessionDescription.getBandwidths(false);
         if (otherBandwidths != null) {
             Vector newBandwidths = new Vector();
             Iterator itBandwidths = otherBandwidths.iterator();
             while (itBandwidths.hasNext()) {
                 BandwidthField otherBandwidthField = (BandwidthFielditBandwidths.next();
                 if (otherBandwidthField != null) {
                     // Bandwidth field clone() is a shallow copy but object is not deep
                     BandwidthField newBF = (BandwidthFieldotherBandwidthField.clone();
                     newBandwidths.add(newBF);
                 }
             }
             this.setBandwidths(newBandwidths);
         }
 
         // Deep copy the attribute list
         Vector otherAttributes = otherSessionDescription.getAttributes(false);
         if (otherAttributes != null) {
             Vector newAttributes = new Vector();
             Iterator itAttributes = otherAttributes.iterator();
             while (itAttributes.hasNext()) {
                 AttributeField otherAttributeField = (AttributeFielditAttributes.next();
                 if (otherAttributeField != null) {
                     // Attribute field clone() makes a deep copy but be careful: it may use reflection to copy one of its members
                     AttributeField newBF = (AttributeFieldotherAttributeField.clone();
                     newAttributes.add(newBF);
                 }
             }
             this.setAttributes(newAttributes);
         }
 
         // Deep copy the media descriptions
         Vector otherMediaDescriptions = otherSessionDescription.getMediaDescriptions(false);
         if (otherMediaDescriptions != null) {
             Vector newMDs = new Vector();
             Iterator itMediaDescriptions = otherMediaDescriptions.iterator();
             while (itMediaDescriptions.hasNext()) {
                 MediaDescriptionImpl otherMediaDescription = (MediaDescriptionImplitMediaDescriptions.next();
                 if (otherMediaDescription != null) {
                     MediaDescriptionImpl newMD = new MediaDescriptionImpl();
 
                     // Copy the media field
                     MediaField otherMediaField = otherMediaDescription.getMediaField();
                     if (otherMediaField != null) {
                         // Media field clone() makes a shallow copy, so don't use clone()
                         MediaField newMF = new MediaField();
                         newMF.setMedia(otherMediaField.getMedia());
                         newMF.setPort(otherMediaField.getPort());
                         newMF.setNports(otherMediaField.getNports());
                         newMF.setProto(otherMediaField.getProto());
                         Vector otherFormats = otherMediaField.getFormats();
                         if (otherFormats != null) {
                             Vector newFormats = new Vector();
                             Iterator itFormats = otherFormats.iterator();
                             while (itFormats.hasNext()) {
                                 Object otherFormat = itFormats.next();
                                 if (otherFormat != null) {
                                     // Convert all format objects to strings in order to avoid reflection
                                     newFormats.add(String.valueOf(otherFormat));
                                 }
                             }
                             newMF.setFormats(newFormats);
                         }
                         newMD.setMedia(newMF);
                     }
 
                     // Copy the information field (it's a shallow object, ok to clone)
                     InformationField otherInfoField = otherMediaDescription.getInformationField();
                     if (otherInfoField != null) {
                         newMD.setInformationField((InformationFieldotherInfoField.clone());
                     }
 
                     // Copy the connection field. OK to use clone(), already does a deep copy.
                     ConnectionField otherConnectionField = otherMediaDescription.getConnectionField();
                     if (otherConnectionField != null) {
                         newMD.setConnectionField((ConnectionFieldotherConnectionField.clone());
                     }
 
                     // Copy the bandwidth fields
                     Vector otherBFs = otherMediaDescription.getBandwidths(false);
                     if (otherBFs != null) {
                         Vector newBFs = new Vector();
                         Iterator itBFs = otherBFs.iterator();
                         while (itBFs.hasNext()) {
                             BandwidthField otherBF = (BandwidthFielditBFs.next();
                             if (otherBF != null) {
                                 // BandwidthField is a shallow object, ok to use clone
                                 newBFs.add((BandwidthFieldotherBF.clone());
                             }
                         }
                         newMD.setBandwidths(newBFs);
                     }
 
                     // Copy the key field (shallow object)
                     KeyField otherKeyField = otherMediaDescription.getKeyField();
                     if (otherKeyField != null) {
                         newMD.setKeyField((KeyFieldotherKeyField.clone());
                     }
 
                     // Copy the attributes
                     Vector otherAFs = otherMediaDescription.getAttributeFields();
                     if (otherAFs != null) {
                         Vector newAFs = new Vector();
                         Iterator itAFs = otherAFs.iterator();
                         while (itAFs.hasNext()) {
                             AttributeField otherAF = (AttributeFielditAFs.next();
                             if (otherAF != null) {
                                 // AttributeField clone() already makes a deep copy, but be careful. It will use reflection
                                 // unless the attribute is a String or any other immutable object.
                                 newAFs.add((AttributeFieldotherAF.clone());
                             }
                         }
                         newMD.setAttributeFields(newAFs);
                     }
                     newMDs.add(newMD);
                 }
             }
             this.setMediaDescriptions(newMDs);
         }
     }
 
     public void addField(SDPField sdpFieldthrows ParseException {
         try {
             if (sdpField instanceof ProtoVersionField) {
                  = (ProtoVersionFieldsdpField;
             } else if (sdpField instanceof OriginField) {
                  = (OriginFieldsdpField;
             } else if (sdpField instanceof SessionNameField) {
                  = (SessionNameFieldsdpField;
             } else if (sdpField instanceof InformationField) {
                 if ( != null)
                     
                             .setInformationField((InformationFieldsdpField);
                 else
                     this. = (InformationFieldsdpField;
             } else if (sdpField instanceof URIField) {
                  = (URIFieldsdpField;
             } else if (sdpField instanceof ConnectionField) {
                 if ( != null)
                     
                             .setConnectionField((ConnectionFieldsdpField);
                 else
                     this. = (ConnectionFieldsdpField;
             } else if (sdpField instanceof KeyField) {
                 if ( != null)
                     .setKey((KeyFieldsdpField);
                 else
                      = (KeyFieldsdpField;
             } else if (sdpField instanceof EmailField) {
                 getEmails(true).add(sdpField);
             } else if (sdpField instanceof PhoneField) {
                 getPhones(true).add(sdpField);
             } else if (sdpField instanceof TimeField) {
                  = new TimeDescriptionImpl(
                         (TimeFieldsdpField);
                 getTimeDescriptions(true).add();
             } else if (sdpField instanceof RepeatField) {
                 if ( == null) {
                     throw new ParseException("no time specified", 0);
                 } else {
                     
                             .addRepeatField((RepeatFieldsdpField);
                 }
             } else if (sdpField instanceof ZoneField) {
                 getZoneAdjustments(true).add(sdpField);
             } else if (sdpField instanceof BandwidthField) {
                 if ( != null)
                     
                             .addBandwidthField((BandwidthFieldsdpField);
                 else
                     getBandwidths(true).add(sdpField);
             } else if (sdpField instanceof AttributeField) {
                 if ( != null) {
                     AttributeField af = (AttributeFieldsdpField;
                     String s = af.getName();
                     // Bug report from Andreas Bystrom
                     
                             .addAttribute((AttributeFieldsdpField);
                 } else {
                     getAttributes(true).add(sdpField);
                 }
 
             } else if (sdpField instanceof MediaField) {
                  = new MediaDescriptionImpl();
                 getMediaDescriptions(true).add();
                 // Bug report from Andreas Bystrom
                 .setMediaField((MediaFieldsdpField);
             }
         } catch (SdpException ex) {
             throw new ParseException(sdpField.encode(), 0);
         }
     }

    
Creates and returns a deep copy of this object

Returns:
a clone of this instance.
Throws:
java.lang.CloneNotSupportedException if this instance cannot be cloned.
 
     public Object clone() throws CloneNotSupportedException {
         try {
             return new SessionDescriptionImpl(this);
         } catch (SdpException e) {
             // throw this exception to indicate that this instance cannot be cloned
             throw new CloneNotSupportedException();
         }
     }

    
Returns the version of SDP in use. This corresponds to the v= field of the SDP data.

Returns:
the integer version (-1 if not set).
 
     public Version getVersion() {
         return ;
     }

    
Sets the version of SDP in use. This corresponds to the v= field of the SDP data.

Parameters:
v version - the integer version.
Throws:
javax.sdp.SdpException if the version is null
 
     public void setVersion(Version vthrows SdpException {
         if (v == null)
             throw new SdpException("The parameter is null");
         if (v instanceof ProtoVersionField) {
              = (ProtoVersionFieldv;
         } else
             throw new SdpException(
                     "The parameter must be an instance of VersionField");
     }

    
Returns information about the originator of the session. This corresponds to the o= field of the SDP data.

Returns:
the originator data.
 
     public Origin getOrigin() {
         return ;
     }

    
Sets information about the originator of the session. This corresponds to the o= field of the SDP data.

Parameters:
origin origin - the originator data.
Throws:
javax.sdp.SdpException if the origin is null
 
     public void setOrigin(Origin originthrows SdpException {
         if (origin == null)
             throw new SdpException("The parameter is null");
         if (origin instanceof OriginField) {
             OriginField o = (OriginFieldorigin;
              = o;
         } else
             throw new SdpException(
                     "The parameter must be an instance of OriginField");
     }

    
Returns the name of the session. This corresponds to the s= field of the SDP data.

Returns:
the session name.
 
     public SessionName getSessionName() {
         return ;
     }

    
Sets the name of the session. This corresponds to the s= field of the SDP data.

Parameters:
sessionName name - the session name.
Throws:
javax.sdp.SdpException if the sessionName is null
 
     public void setSessionName(SessionName sessionNamethrows SdpException {
         if (sessionName == null)
             throw new SdpException("The parameter is null");
         if (sessionName instanceof SessionNameField) {
             SessionNameField s = (SessionNameFieldsessionName;
              = s;
         } else
             throw new SdpException(
                     "The parameter must be an instance of SessionNameField");
     }

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

Returns:
info
 
     public Info getInfo() {
         return ;
     }

    
Sets the i= field of this object.

Parameters:
i s - new i= value; if null removes the field
Throws:
javax.sdp.SdpException if the info is null
 
     public void setInfo(Info ithrows SdpException {
         if (i == null)
             throw new SdpException("The parameter is null");
         if (i instanceof InformationField) {
             InformationField info = (InformationFieldi;
              = info;
         } else
             throw new SdpException(
                     "The parameter must be an instance of InformationField");
     }

    
Returns a uri to the location of more details about the session. This corresponds to the u= field of the SDP data.

Returns:
the uri.
 
     public URI getURI() {
         return ;
     }

    
Sets the uri to the location of more details about the session. This corresponds to the u= field of the SDP data.

Parameters:
uri uri - the uri.
Throws:
javax.sdp.SdpException if the uri is null
 
     public void setURI(URI urithrows SdpException {
         if (uri == null)
             throw new SdpException("The parameter is null");
         if (uri instanceof URIField) {
             URIField u = (URIFielduri;
              = u;
         } else
             throw new SdpException(
                     "The parameter must be an instance of URIField");
     }

    
Returns an email address to contact for further information about the session. This corresponds to the e= field of the SDP data.

Parameters:
create boolean to set
Returns:
the email address.
Throws:
javax.sdp.SdpParseException
 
     public Vector getEmails(boolean createthrows SdpParseException {
         if ( == null) {
             if (create)
                  = new Vector();
         }
         return ;
     }

    
Sets a an email address to contact for further information about the session. This corresponds to the e= field of the SDP data.

Parameters:
emails email - the email address.
Throws:
javax.sdp.SdpException if the vector is null
 
     public void setEmails(Vector emailsthrows SdpException {
         if (emails == null)
             throw new SdpException("The parameter is null");
         else
              = emails;
     }

    
Returns a phone number to contact for further information about the session. This corresponds to the p= field of the SDP data.

Parameters:
create boolean to set
Returns:
the phone number.
Throws:
javax.sdp.SdpException
 
     public Vector getPhones(boolean createthrows SdpException {
         if ( == null) {
             if (create)
                  = new Vector();
         }
         return ;
     }

    
Sets a phone number to contact for further information about the session. This corresponds to the p= field of the SDP data.

Parameters:
phones phone - the phone number.
Throws:
javax.sdp.SdpException if the vector is null
 
     public void setPhones(Vector phonesthrows SdpException {
         if (phones == null)
             throw new SdpException("The parameter is null");
         else
              = phones;
     }

    
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.

Parameters:
create boolean to set
Returns:
the Time Field.
Throws:
javax.sdp.SdpException
 
     public Vector getTimeDescriptions(boolean createthrows SdpException {
         if ( == null) {
             if (create)
                  = new Vector();
         }
         return ;
     }

    
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.

Parameters:
times time - the TimeField.
Throws:
javax.sdp.SdpException if the vector is null
 
     public void setTimeDescriptions(Vector timesthrows SdpException {
         if (times == null)
             throw new SdpException("The parameter is null");
         else {
              = times;
         }
     }

    
Returns the time zone adjustments for the Session

Parameters:
create boolean to set
Returns:
a Hashtable containing the zone adjustments, where the key is the Adjusted Time Zone and the value is the offset.
Throws:
javax.sdp.SdpException
 
     public Vector getZoneAdjustments(boolean createthrows SdpException {
         if ( == null) {
             if (create)
                  = new Vector();
         }
         return ;
     }

    
Sets the time zone adjustment for the TimeField.

Parameters:
zoneAdjustments zoneAdjustments - a Hashtable containing the zone adjustments, where the key is the Adjusted Time Zone and the value is the offset.
Throws:
javax.sdp.SdpException if the vector is null
 
     public void setZoneAdjustments(Vector zoneAdjustmentsthrows SdpException {
         if (zoneAdjustments == null)
             throw new SdpException("The parameter is null");
         else
             this. = zoneAdjustments;
     }

    
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 parameter is null
 
     public void setConnection(Connection connthrows SdpException {
         if (conn == null)
             throw new SdpException("The parameter is null");
         if (conn instanceof ConnectionField) {
             ConnectionField c = (ConnectionFieldconn;
              = c;
         } else
             throw new SdpException("Bad implementation class ConnectionField");
     }

    
Returns the Bandwidth of the specified type.

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

    
set the value of the Bandwidth with the specified type.

Parameters:
bandwidthList to set
Throws:
javax.sdp.SdpException if the vector is null
 
     public void setBandwidths(Vector bandwidthListthrows SdpException {
         if (bandwidthList == null)
             throw new SdpException("The parameter is null");
         else
             this. = bandwidthList;
     }

    
Returns the integer value of the specified bandwidth name.

Parameters:
name 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)
             return -1;
         else if ( == null)
             return -1;
         for (int i = 0; i < .size(); i++) {
             Object o = .elementAt(i);
             if (o instanceof BandwidthField) {
                 BandwidthField b = (BandwidthFieldo;
                 String type = b.getType();
                 if (type != null) {
                     if (name.equals(type)) {
                         return b.getValue();
                     }
                 }
             }
         }
         return -1;
     }

    
Sets the value of the specified bandwidth type.

Parameters:
name name - the name of the bandwidth type.
value 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 parameter is null");
         else if ( != null) {
             for (int i = 0; i < .size(); i++) {
                 Object o = .elementAt(i);
                 if (o instanceof BandwidthField) {
                     BandwidthField b = (BandwidthFieldo;
                     String type = b.getType();
                     if (type != null) {
                         if (name.equals(type)) {
                             b.setValue(value);
                         }
                     }
                 }
             }
         }
     }

    
Removes the specified bandwidth type.

Parameters:
name name - the name of the bandwidth type
 
     public void removeBandwidth(String name) {
         if (name != null)
             if ( != null) {
                 for (int i = 0; i < .size(); i++) {
                     Object o = .elementAt(i);
                     if (o instanceof BandwidthField) {
                         BandwidthField b = (BandwidthFieldo;
                         try {
                             String type = b.getType();
                             if (type != null) {
                                 if (name.equals(type)) {
                                     .remove(b);
                                 }
                             }
                         } catch (SdpParseException e) {
                         }
                     }
                 }
             }
     }

    
Returns the key data.

Returns:
key
 
     public Key getKey() {
         return ;
     }

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

Parameters:
key key - the encryption key data; depending on method may be null
Throws:
javax.sdp.SdpException if the parameter is null
 
     public void setKey(Key keythrows SdpException {
         if (key == null)
             throw new SdpException("The parameter is null");
         if (key instanceof KeyField) {
             KeyField k = (KeyFieldkey;
              = k;
         } else
             throw new SdpException(
                     "The parameter must be an instance of KeyField");
     }

    
Returns the value of the specified attribute.

Parameters:
name 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)
             return null;
         else if ( == null)
             return null;
         for (int i = 0; i < .size(); i++) {
             Object o = .elementAt(i);
             if (o instanceof AttributeField) {
                 AttributeField a = (AttributeFieldo;
                 String n = a.getName();
                 if (n != null) {
                     if (name.equals(n)) {
                         return a.getValue();
                     }
                 }
             }
         }
         return null;
     }

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

Parameters:
create 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) {
         if ( == null) {
             if (create)
                  = new Vector();
         }
         return ;
     }

    
Removes the attribute specified by the value parameter.

Parameters:
name name - the name of the attribute
 
     public void removeAttribute(String name) {
         if (name != null)
             if ( != null) {
                 for (int i = 0; i < .size(); i++) {
                     Object o = .elementAt(i);
                     if (o instanceof AttributeField) {
                         AttributeField a = (AttributeFieldo;
                         try {
                             String n = a.getName();
                             if (n != null) {
                                 if (name.equals(n)) {
                                     .remove(a);
                                 }
                             }
                         } catch (SdpParseException e) {
                         }
 
                     }
                 }
             }
     }

    
Sets the value of the specified attribute.

Parameters:
name name - the name of the attribute.
value value - the value of the named attribute.
Throws:
javax.sdp.SdpException if the name or the value is null
 
     public void setAttribute(String nameString valuethrows SdpException {
         if (name == null || value == null)
             throw new SdpException("The parameter is null");
         else if ( != null) {
             for (int i = 0; i < .size(); i++) {
                 Object o = .elementAt(i);
                 if (o instanceof AttributeField) {
                     AttributeField a = (AttributeFieldo;
                     String n = a.getName();
                     if (n != null) {
                         if (name.equals(n)) {
                             a.setValue(value);
                         }
                     }
                 }
             }
         }
     }

    
Adds the specified Attribute to this Description object.

Parameters:
attributes - the attribute to add
Throws:
javax.sdp.SdpException if the vector is null
 
     public void setAttributes(Vector attributesthrows SdpException {
         if (attributes == null)
             throw new SdpException("The parameter is null");
         else
              = attributes;
    }

    
Adds a MediaDescription to the session description. These correspond to the m= fields of the SDP data.

Parameters:
create boolean to set
Returns:
media - the field to add.
Throws:
javax.sdp.SdpException
    public Vector getMediaDescriptions(boolean createthrows SdpException {
        if ( == null) {
            if (create)
                 = new Vector();
        }
        return ;
    }

    
Removes all MediaDescriptions from the session description.

Parameters:
mediaDescriptions to set
Throws:
javax.sdp.SdpException if the parameter is null
    public void setMediaDescriptions(Vector mediaDescriptions)
            throws SdpException {
        if (mediaDescriptions == null)
            throw new SdpException("The parameter is null");
        else
            this. = mediaDescriptions;
    }
    private String encodeVector(Vector vector) {
        StringBuilder encBuff = new StringBuilder();
        for (int i = 0; i < vector.size(); i++)
            encBuff.append(vector.elementAt(i));
        return encBuff.toString();
    }

    
Returns the canonical string representation of the current SessionDescrption. Acknowledgement - this code was contributed by Emil Ivov.

Returns:
Returns the canonical string representation of the current SessionDescrption.
    public String toString() {
        StringBuilder encBuff = new StringBuilder();
        // 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(getEmails(false) == null ? ""
                    : encodeVector(getEmails(false)));
            encBuff.append(getPhones(false) == null ? ""
                    : encodeVector(getPhones(false)));
            encBuff.append(getConnection() == null ? "" : getConnection()
                    .toString());
            encBuff.append(getBandwidths(false) == null ? ""
                    : encodeVector(getBandwidths(false)));
            encBuff.append(getTimeDescriptions(false) == null ? ""
                    : encodeVector(getTimeDescriptions(false)));
            encBuff.append(getZoneAdjustments(false) == null ? ""
                    : encodeVector(getZoneAdjustments(false)));
            encBuff.append(getKey() == null ? "" : getKey().toString());
            encBuff.append(getAttributes(false) == null ? ""
                    : encodeVector(getAttributes(false)));
            encBuff.append(getMediaDescriptions(false) == null ? ""
                    : encodeVector(getMediaDescriptions(false)));
            // adds the final crlf
        } catch (SdpException exc) {
            // add exception handling if necessary
        }
        return encBuff.toString();
    }
New to GrepCode? Check out our FAQ X