Source Code Cross Referenced for SessionDescriptionImpl.java in  » 6.0-JDK-Modules » j2me » gov » nist » javax » sdp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » gov.nist.javax.sdp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Portions Copyright  2000-2007 Sun Microsystems, Inc. All Rights
003:         * Reserved.  Use is subject to license terms.
004:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005:         * 
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License version
008:         * 2 only, as published by the Free Software Foundation.
009:         * 
010:         * This program is distributed in the hope that it will be useful, but
011:         * WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * General Public License version 2 for more details (a copy is
014:         * included at /legal/license.txt).
015:         * 
016:         * You should have received a copy of the GNU General Public License
017:         * version 2 along with this work; if not, write to the Free Software
018:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019:         * 02110-1301 USA
020:         * 
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022:         * Clara, CA 95054 or visit www.sun.com if you need additional
023:         * information or have any questions.
024:         */
025:        /*
026:         * SessionDescriptionImpl.java
027:         *
028:         * Created on January 10, 2002, 3:11 PM
029:         */
030:
031:        package gov.nist.javax.sdp;
032:
033:        import java.util.*;
034:        import gov.nist.javax.sdp.fields.*;
035:        import gov.nist.core.*;
036:
037:        /**
038:         * Implementation of the SessionDescription interface.
039:         *
040:         * 
041:         * a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
042:         *
043:         */
044:        public class SessionDescriptionImpl {
045:            /** Descriptive label for current time. */
046:            private TimeDescriptionImpl currentTimeDescription;
047:            /** Descriptive lavel for current media. */
048:            private MediaDescriptionImpl currentMediaDescription;
049:            /** Protocol version. */
050:            protected ProtoVersionField versionImpl;
051:            /** Session originator. */
052:            protected OriginField originImpl;
053:            /** Current session name. */
054:            protected SessionNameField sessionNameImpl;
055:            /** Descriptive session information. */
056:            protected InformationField infoImpl;
057:            /** Current URi. */
058:            protected URIField uriImpl;
059:            /** Current connection. */
060:            protected ConnectionField connectionImpl;
061:            /** Key field. */
062:            protected KeyField keyImpl;
063:            /** Vector of time descriptions. */
064:            protected Vector timeDescriptions;
065:            /** Vector of media types. */
066:            protected Vector mediaDescriptions;
067:            /** Vector of time zone adjustments. */
068:            protected Vector zoneAdjustments;
069:            /** Vector of email addresses. */
070:            protected Vector emailList;
071:            /** Vector of phone numbers. */
072:            protected Vector phoneList;
073:            /** Vector of bandwidths. */
074:            protected Vector bandwidthList;
075:            /** Vector of connection attributes. */
076:            protected Vector attributesList;
077:
078:            /** Creates new SessionDescriptionImpl */
079:            public SessionDescriptionImpl() {
080:                zoneAdjustments = new Vector();
081:                emailList = new Vector();
082:                phoneList = new Vector();
083:                bandwidthList = new Vector();
084:                timeDescriptions = new Vector();
085:                mediaDescriptions = new Vector();
086:                attributesList = new Vector();
087:
088:            }
089:
090:            /**
091:             * Adds a new SDP field.
092:             * @param sdpField the new field to be processed
093:             * @exception ParseException if a parsing error occurs.
094:             */
095:            public void addField(SDPField sdpField) throws ParseException {
096:                try {
097:                    if (sdpField instanceof  ProtoVersionField) {
098:                        versionImpl = (ProtoVersionField) sdpField;
099:                    } else if (sdpField instanceof  OriginField) {
100:                        originImpl = (OriginField) sdpField;
101:                    } else if (sdpField instanceof  SessionNameField) {
102:                        sessionNameImpl = (SessionNameField) sdpField;
103:                    } else if (sdpField instanceof  InformationField) {
104:                        if (currentMediaDescription != null)
105:                            currentMediaDescription
106:                                    .setInformationField((InformationField) sdpField);
107:                        else
108:                            this .infoImpl = (InformationField) sdpField;
109:                    } else if (sdpField instanceof  URIField) {
110:                        uriImpl = (URIField) sdpField;
111:                    } else if (sdpField instanceof  ConnectionField) {
112:                        if (currentMediaDescription != null)
113:                            currentMediaDescription
114:                                    .setConnectionField((ConnectionField) sdpField);
115:                        else
116:                            this .connectionImpl = (ConnectionField) sdpField;
117:                    } else if (sdpField instanceof  KeyField) {
118:                        if (currentMediaDescription != null)
119:                            currentMediaDescription.setKey((KeyField) sdpField);
120:                        else
121:                            keyImpl = (KeyField) sdpField;
122:                    } else if (sdpField instanceof  EmailField) {
123:                        emailList.addElement(sdpField);
124:                    } else if (sdpField instanceof  PhoneField) {
125:                        phoneList.addElement(sdpField);
126:                    } else if (sdpField instanceof  TimeField) {
127:                        currentTimeDescription = new TimeDescriptionImpl(
128:                                (TimeField) sdpField);
129:                        timeDescriptions.addElement(currentTimeDescription);
130:                    } else if (sdpField instanceof  RepeatField) {
131:                        if (currentTimeDescription == null) {
132:                            throw new ParseException("no time specified", 0);
133:                        } else {
134:                            currentTimeDescription
135:                                    .addRepeatField((RepeatField) sdpField);
136:                        }
137:                    } else if (sdpField instanceof  ZoneField) {
138:                        zoneAdjustments.addElement(sdpField);
139:                    } else if (sdpField instanceof  BandwidthField) {
140:                        if (currentMediaDescription != null) {
141:                            currentMediaDescription
142:                                    .addBandwidthField((BandwidthField) sdpField);
143:                        } else {
144:                            bandwidthList.addElement(sdpField);
145:                        }
146:                    } else if (sdpField instanceof  AttributeField) {
147:                        if (currentMediaDescription != null) {
148:                            AttributeField af = (AttributeField) sdpField;
149:                            String s = af.getName();
150:                            currentMediaDescription
151:                                    .addAttribute((AttributeField) sdpField);
152:                        } else {
153:                            attributesList.addElement(sdpField);
154:                        }
155:                    } else if (sdpField instanceof  MediaField) {
156:                        currentMediaDescription = new MediaDescriptionImpl();
157:                        mediaDescriptions.addElement(currentMediaDescription);
158:                        currentMediaDescription
159:                                .setMediaField((MediaField) sdpField);
160:                    }
161:                } catch (SdpException ex) {
162:                    throw new ParseException(sdpField.encode(), 0);
163:                }
164:            }
165:
166:            /**
167:             * Public clone declaration.
168:             * @throws CloneNotSupportedException if clone method is not supported
169:             * @return Object
170:             */
171:            public Object clone() {
172:                Class myClass = this .getClass();
173:                SessionDescriptionImpl hi;
174:                try {
175:                    hi = (SessionDescriptionImpl) myClass.newInstance();
176:                } catch (InstantiationException ex) {
177:                    return null;
178:                } catch (IllegalAccessException ex) {
179:                    return null;
180:                }
181:                hi.versionImpl = (ProtoVersionField) this .versionImpl.clone();
182:                hi.originImpl = (OriginField) this .originImpl.clone();
183:                hi.sessionNameImpl = (SessionNameField) this .sessionNameImpl
184:                        .clone();
185:                hi.infoImpl = (InformationField) this .infoImpl.clone();
186:                hi.uriImpl = (URIField) this .uriImpl.clone();
187:                hi.connectionImpl = (ConnectionField) this .connectionImpl
188:                        .clone();
189:                hi.keyImpl = (KeyField) this .keyImpl.clone();
190:                hi.timeDescriptions = cloneVector(this .timeDescriptions);
191:
192:                hi.emailList = cloneVector(this .emailList);
193:                hi.phoneList = cloneVector(this .phoneList);
194:                hi.zoneAdjustments = cloneVector(this .zoneAdjustments);
195:                hi.bandwidthList = cloneVector(this .bandwidthList);
196:                hi.attributesList = cloneVector(this .attributesList);
197:                hi.mediaDescriptions = cloneVector(this .mediaDescriptions);
198:                return hi;
199:            }
200:
201:            /**
202:             * Returns the version of SDP in use.
203:             * This corresponds to the v= field of the SDP data.
204:             * @return the integer version (-1 if not set).
205:             */
206:            public ProtoVersionField getVersion() {
207:                return versionImpl;
208:            }
209:
210:            /**
211:             * Sets the version of SDP in use.
212:             * This corresponds to the v= field of the SDP data.
213:             * @param v version - the integer version.
214:             * @throws SdpException if the version is null
215:             */
216:            public void setVersion(ProtoVersionField v) throws SdpException {
217:                if (v == null)
218:                    throw new SdpException("The parameter is null");
219:                if (v instanceof  ProtoVersionField) {
220:                    versionImpl = (ProtoVersionField) v;
221:                } else
222:                    throw new SdpException(
223:                            "The parameter must be an instance of VersionField");
224:            }
225:
226:            /**
227:             * Returns information about the originator of the session.
228:             * This corresponds to the o= field of the SDP data.
229:             * @return the originator data.
230:             */
231:            public OriginField getOrigin() {
232:                return originImpl;
233:            }
234:
235:            /**
236:             * Sets information about the originator of the session.
237:             * This corresponds to the o= field of the SDP data.
238:             * @param origin origin - the originator data.
239:             * @throws SdpException if the origin is null
240:             */
241:            public void setOrigin(OriginField origin) throws SdpException {
242:                if (origin == null)
243:                    throw new SdpException("The parameter is null");
244:                if (origin instanceof  OriginField) {
245:                    OriginField o = (OriginField) origin;
246:                    originImpl = o;
247:                } else
248:                    throw new SdpException("The parameter must be "
249:                            + "an instance of OriginField");
250:            }
251:
252:            /**
253:             * Returns the name of the session.
254:             * This corresponds to the s= field of the SDP data.
255:             * @return the session name.
256:             */
257:            public SessionNameField getSessionName() {
258:                return sessionNameImpl;
259:            }
260:
261:            /**
262:             * Sets the name of the session.
263:             * This corresponds to the s= field of the SDP data.
264:             * @param sessionName name - the session name.
265:             * @throws SdpException if the sessionName is null
266:             */
267:            public void setSessionName(SessionNameField sessionName)
268:                    throws SdpException {
269:                if (sessionName == null)
270:                    throw new SdpException("The parameter is null");
271:                if (sessionName instanceof  SessionNameField) {
272:                    SessionNameField s = (SessionNameField) sessionName;
273:                    sessionNameImpl = s;
274:                } else
275:                    throw new SdpException("The parameter must be "
276:                            + "an instance of SessionNameField");
277:            }
278:
279:            /**
280:             * Returns value of the info field (i=) of this object.
281:             * @return info
282:             */
283:            public InformationField getInfo() {
284:                return infoImpl;
285:            }
286:
287:            /**
288:             * Sets the i= field of this object.
289:             * @param i s - new i= value; if null removes the field
290:             * @throws SdpException if the info is null
291:             */
292:            public void setInfo(InformationField i) throws SdpException {
293:                if (i == null)
294:                    throw new SdpException("The parameter is null");
295:                if (i instanceof  InformationField) {
296:                    InformationField info = (InformationField) i;
297:                    infoImpl = info;
298:                } else
299:                    throw new SdpException("The parameter must be "
300:                            + "an instance of InformationField");
301:            }
302:
303:            /**
304:             * Returns a uri to the location of more details about the session.
305:             * This corresponds to the u=
306:             * field of the SDP data.
307:             * @return the uri.
308:             */
309:            public URIField getURI() {
310:                return uriImpl;
311:            }
312:
313:            /**
314:             * Sets the uri to the location of more details about the session. This
315:             * corresponds to the u=
316:             * field of the SDP data.
317:             * @param uri uri - the uri.
318:             * @throws SdpException if the uri is null
319:             */
320:            public void setURI(URIField uri) throws SdpException {
321:                if (uri == null)
322:                    throw new SdpException("The parameter is null");
323:                if (uri instanceof  URIField) {
324:                    URIField u = (URIField) uri;
325:                    uriImpl = u;
326:                } else
327:                    throw new SdpException(
328:                            "The parameter must be an instance of URIField");
329:            }
330:
331:            /**
332:             * Returns an email address to contact for further information
333:             * about the session.
334:             * This corresponds to the e= field of the SDP data.
335:             * @param create boolean to set
336:             * @throws SdpException
337:             * @return the email address.
338:             */
339:            public Vector getEmails(boolean create) throws SdpParseException {
340:                if (emailList == null) {
341:                    if (create)
342:                        emailList = new Vector();
343:                }
344:                return emailList;
345:            }
346:
347:            /**
348:             * Sets a an email address to contact for further information
349:             * about the session.
350:             * This corresponds to the e= field of the SDP data.
351:             * @param emails email - the email address.
352:             * @throws SdpException if the vector is null
353:             */
354:            public void setEmails(Vector emails) throws SdpException {
355:                if (emails == null)
356:                    throw new SdpException("The parameter is null");
357:                else
358:                    emailList = emails;
359:            }
360:
361:            /**
362:             * Returns a phone number to contact for further information about
363:             * the session. This corresponds to the p= field of the SDP data.
364:             * @param create boolean to set
365:             * @throws SdpException
366:             * @return the phone number.
367:             */
368:            public Vector getPhones(boolean create) throws SdpException {
369:                if (phoneList == null) {
370:                    if (create)
371:                        phoneList = new Vector();
372:                }
373:                return phoneList;
374:            }
375:
376:            /**
377:             * Sets a phone number to contact for further information about
378:             * the session. This corresponds to the p= field of the SDP data.
379:             * @param phones phone - the phone number.
380:             * @throws SdpException if the vector is null
381:             */
382:            public void setPhones(Vector phones) throws SdpException {
383:                if (phones == null)
384:                    throw new SdpException("The parameter is null");
385:                else
386:                    phoneList = phones;
387:            }
388:
389:            /**
390:             * Returns a TimeField indicating the start, stop, repetition and time zone
391:             * information of the
392:             * session. This corresponds to the t= field of the SDP data.
393:             * @param create boolean to set
394:             * @throws SdpException
395:             * @return the Time Field.
396:             */
397:            public Vector getTimeDescriptions(boolean create)
398:                    throws SdpException {
399:                if (timeDescriptions == null) {
400:                    if (create)
401:                        timeDescriptions = new Vector();
402:                }
403:                return timeDescriptions;
404:            }
405:
406:            /**
407:             * Sets a TimeField indicating the start, stop, repetition and time zone
408:             * information of the
409:             * session. This corresponds to the t= field of the SDP data.
410:             * @param times time - the TimeField.
411:             * @throws SdpException if the vector is null
412:             */
413:            public void setTimeDescriptions(Vector times) throws SdpException {
414:                if (times == null)
415:                    throw new SdpException("The parameter is null");
416:                else {
417:                    timeDescriptions = times;
418:                }
419:            }
420:
421:            /**
422:             * Returns the time zone adjustments for the Session
423:             * @param create boolean to set
424:             * @throws SdpException
425:             * @return a Hashtable containing the zone adjustments, where the key is the
426:             * Adjusted Time
427:             * Zone and the value is the offset.
428:             */
429:            public Vector getZoneAdjustments(boolean create)
430:                    throws SdpException {
431:                if (zoneAdjustments == null) {
432:                    if (create)
433:                        zoneAdjustments = new Vector();
434:                }
435:                return zoneAdjustments;
436:            }
437:
438:            /**
439:             * Sets the time zone adjustment for the TimeField.
440:             * @param zoneAdjustments zoneAdjustments - a Hashtable containing the zone
441:             * adjustments, where the key
442:             * is the Adjusted Time Zone and the value is the offset.
443:             * @throws SdpException if the vector is null
444:             */
445:            public void setZoneAdjustments(Vector zoneAdjustments)
446:                    throws SdpException {
447:                if (zoneAdjustments == null)
448:                    throw new SdpException("The parameter is null");
449:                else
450:                    this .zoneAdjustments = zoneAdjustments;
451:            }
452:
453:            /**
454:             * Returns the connection information associated with this object. This may
455:             * be null for SessionDescriptions if all Media objects have a connection
456:             * object and may be null
457:             * for Media objects if the corresponding session connection is non-null.
458:             * @return connection
459:             */
460:            public ConnectionField getConnection() {
461:                return connectionImpl;
462:            }
463:
464:            /**
465:             * Sets the connection data for this entity.
466:             * @param conn to set
467:             * @throws SdpException if the parameter is null
468:             */
469:            public void setConnection(ConnectionField conn) throws SdpException {
470:                if (conn == null)
471:                    throw new SdpException("The parameter is null");
472:                if (conn instanceof  ConnectionField) {
473:                    ConnectionField c = (ConnectionField) conn;
474:                    connectionImpl = c;
475:                } else
476:                    throw new SdpException(
477:                            "Bad implementation class ConnectionField");
478:            }
479:
480:            /**
481:             * Returns the Bandwidth of the specified type.
482:             * @param create type - type of the Bandwidth to return
483:             * @return the Bandwidth or null if undefined
484:             */
485:            public Vector getBandwidths(boolean create) {
486:                if (bandwidthList == null) {
487:                    if (create)
488:                        bandwidthList = new Vector();
489:                }
490:                return bandwidthList;
491:            }
492:
493:            /**
494:             * Sets the value of the Bandwidth with the specified type.
495:             * @param bandwidthList to set
496:             * @throws SdpException if the vector is null
497:             */
498:            public void setBandwidths(Vector bandwidthList) throws SdpException {
499:                if (bandwidthList == null)
500:                    throw new SdpException("The parameter is null");
501:                else
502:                    this .bandwidthList = bandwidthList;
503:            }
504:
505:            /**
506:             * Returns the integer value of the specified bandwidth name.
507:             * @param name name - the name of the bandwidth type
508:             * @throws SdpParseException
509:             * @return the value of the named bandwidth
510:             */
511:            public int getBandwidth(String name) throws SdpParseException {
512:                if (name == null)
513:                    return -1;
514:                else if (bandwidthList == null)
515:                    return -1;
516:                for (int i = 0; i < bandwidthList.size(); i++) {
517:                    Object o = bandwidthList.elementAt(i);
518:                    if (o instanceof  BandwidthField) {
519:                        BandwidthField b = (BandwidthField) o;
520:                        String type = b.getType();
521:                        if (type != null) {
522:                            if (name.equals(type)) {
523:                                return b.getValue();
524:                            }
525:                        }
526:                    }
527:                }
528:                return -1;
529:            }
530:
531:            /**
532:             * Sets the value of the specified bandwidth type.
533:             * @param name name - the name of the bandwidth type.
534:             * @param value value - the value of the named bandwidth type.
535:             * @throws SdpException if the name is null
536:             */
537:            public void setBandwidth(String name, int value)
538:                    throws SdpException {
539:                if (name == null)
540:                    throw new SdpException("The parameter is null");
541:                else if (bandwidthList != null) {
542:                    for (int i = 0; i < bandwidthList.size(); i++) {
543:                        Object o = bandwidthList.elementAt(i);
544:                        if (o instanceof  BandwidthField) {
545:                            BandwidthField b = (BandwidthField) o;
546:                            String type = b.getType();
547:                            if (type != null) {
548:                                if (name.equals(type)) {
549:                                    b.setValue(value);
550:                                }
551:                            }
552:                        }
553:                    }
554:                }
555:            }
556:
557:            /**
558:             * Removes the specified bandwidth type.
559:             * @param name name - the name of the bandwidth type
560:             */
561:            public void removeBandwidth(String name) {
562:                if (name != null)
563:                    if (bandwidthList != null) {
564:                        for (int i = 0; i < bandwidthList.size(); i++) {
565:                            Object o = bandwidthList.elementAt(i);
566:                            if (o instanceof  BandwidthField) {
567:                                BandwidthField b = (BandwidthField) o;
568:                                try {
569:                                    String type = b.getType();
570:                                    if (type != null) {
571:                                        if (name.equals(type)) {
572:                                            bandwidthList.removeElement(b);
573:                                        }
574:                                    }
575:                                } catch (SdpParseException e) {
576:                                }
577:                            }
578:                        }
579:                    }
580:            }
581:
582:            /**
583:             * Returns the key data.
584:             * @return key
585:             */
586:            public KeyField getKey() {
587:                return keyImpl;
588:            }
589:
590:            /**
591:             * Sets encryption key information.
592:             * This consists of a method and an encryption key included inline.
593:             * @param key key - the encryption key data; depending on method may be null
594:             * @throws SdpException if the parameter is null
595:             */
596:            public void setKey(KeyField key) throws SdpException {
597:                if (key == null)
598:                    throw new SdpException("The parameter is null");
599:                if (key instanceof  KeyField) {
600:                    KeyField k = (KeyField) key;
601:                    keyImpl = k;
602:                } else
603:                    throw new SdpException(
604:                            "The parameter must be an instance of KeyField");
605:            }
606:
607:            /**
608:             * Returns the value of the specified attribute.
609:             * @param name name - the name of the attribute
610:             * @throws SdpParseException
611:             * @return the value of the named attribute
612:             */
613:            public String getAttribute(String name) throws SdpParseException {
614:                if (name == null)
615:                    return null;
616:                else if (attributesList == null)
617:                    return null;
618:                for (int i = 0; i < attributesList.size(); i++) {
619:                    Object o = attributesList.elementAt(i);
620:                    if (o instanceof  AttributeField) {
621:                        AttributeField a = (AttributeField) o;
622:                        String n = a.getName();
623:                        if (n != null) {
624:                            if (name.equals(n)) {
625:                                return a.getValue();
626:                            }
627:                        }
628:                    }
629:                }
630:                return null;
631:            }
632:
633:            /**
634:             * Returns the set of attributes for this Description as a Vector
635:             * of Attribute objects in the order they were parsed.
636:             * @param create create - specifies whether to return null or a new empty
637:             * Vector in case no
638:             * attributes exists for this Description
639:             * @return attributes for this Description
640:             */
641:            public Vector getAttributes(boolean create) {
642:                if (attributesList == null) {
643:                    if (create)
644:                        attributesList = new Vector();
645:                }
646:                return attributesList;
647:            }
648:
649:            /**
650:             * Removes the attribute specified by the value parameter.
651:             * @param name name - the name of the attribute
652:             */
653:            public void removeAttribute(String name) {
654:                if (name != null)
655:                    if (attributesList != null) {
656:                        for (int i = 0; i < attributesList.size(); i++) {
657:                            Object o = attributesList.elementAt(i);
658:                            if (o instanceof  AttributeField) {
659:                                AttributeField a = (AttributeField) o;
660:                                try {
661:                                    String n = a.getName();
662:                                    if (n != null) {
663:                                        if (name.equals(n)) {
664:                                            attributesList.removeElement(a);
665:                                        }
666:                                    }
667:                                } catch (SdpParseException e) {
668:                                }
669:
670:                            }
671:                        }
672:                    }
673:            }
674:
675:            /**
676:             * Sets the value of the specified attribute.
677:             * @param name name - the name of the attribute.
678:             * @param value value - the value of the named attribute.
679:             * @throws SdpException if the name or the value is null
680:             */
681:            public void setAttribute(String name, String value)
682:                    throws SdpException {
683:                if (name == null || value == null)
684:                    throw new SdpException("The parameter is null");
685:                else if (attributesList != null) {
686:                    for (int i = 0; i < attributesList.size(); i++) {
687:                        Object o = attributesList.elementAt(i);
688:                        if (o instanceof  AttributeField) {
689:                            AttributeField a = (AttributeField) o;
690:                            String n = a.getName();
691:                            if (n != null) {
692:                                if (name.equals(n)) {
693:                                    a.setValue(value);
694:                                }
695:                            }
696:                        }
697:                    }
698:                }
699:            }
700:
701:            /**
702:             * Adds the specified Attribute to this Description object.
703:             * @param attributes the attributes to add
704:             * @throws SdpException if the vector is null
705:             */
706:            public void setAttributes(Vector attributes) throws SdpException {
707:                if (attributes == null)
708:                    throw new SdpException("The parameter is null");
709:                else
710:                    attributesList = attributes;
711:            }
712:
713:            /**
714:             * Adds a MediaDescription to the session description.
715:             * These correspond to the m=
716:             * fields of the SDP data.
717:             * @param create boolean to set
718:             * @throws SdpException
719:             * @return media - the field to add.
720:             */
721:            public Vector getMediaDescriptions(boolean create)
722:                    throws SdpException {
723:                if (mediaDescriptions == null) {
724:                    if (create)
725:                        mediaDescriptions = new Vector();
726:                }
727:                return mediaDescriptions;
728:            }
729:
730:            /**
731:             * Removes all MediaDescriptions from the session description.
732:             * @param mediaDescriptions to set
733:             * @throws SdpException if the parameter is null
734:             */
735:            public void setMediaDescriptions(Vector mediaDescriptions)
736:                    throws SdpException {
737:                if (mediaDescriptions == null)
738:                    throw new SdpException("The parameter is null");
739:                else
740:                    this .mediaDescriptions = mediaDescriptions;
741:            }
742:
743:            /** 
744:             * Returns an encoded string of vector contents.
745:             * @param vector the objects to process
746:             * @return encode string of vector contents
747:             */
748:            private String encodeVector(Vector vector) {
749:                StringBuffer encBuff = new StringBuffer();
750:
751:                for (int i = 0; i < vector.size(); i++)
752:                    encBuff.append(vector.elementAt(i));
753:
754:                return encBuff.toString();
755:            }
756:
757:            /**
758:             * Utility method for cloning a Vector 
759:             * Acknowledgement - this code was contributed by Sverker Abrahamsson.
760:             * @param v the vector to be copied
761:             * @return the cloned vector
762:             */
763:            private Vector cloneVector(Vector v) {
764:                Vector clone = new Vector(v.capacity());
765:
766:                int size = v.size();
767:                for (int i = 0; i < size; i++) {
768:                    clone.setElementAt(v.elementAt(i), i);
769:                }
770:                return clone;
771:            }
772:
773:            /**
774:             * Returns the canonical string representation of the
775:             * current SessionDescrption. Acknowledgement - this code
776:             *
777:             * @return Returns the canonical string representation
778:             * of the current SessionDescrption.
779:             */
780:            public String toString() {
781:                StringBuffer encBuff = new StringBuffer();
782:
783:                // Encode single attributes
784:                encBuff.append(getVersion() == null ? "" : getVersion()
785:                        .toString());
786:                encBuff.append(getOrigin() == null ? "" : getOrigin()
787:                        .toString());
788:                encBuff.append(getSessionName() == null ? "" : getSessionName()
789:                        .toString());
790:                encBuff.append(getInfo() == null ? "" : getInfo().toString());
791:
792:                // Encode attribute vectors
793:                try {
794:                    encBuff.append(getURI() == null ? "" : getURI().toString());
795:                    encBuff.append(encodeVector(getEmails(true)));
796:                    encBuff.append(encodeVector(getPhones(true)));
797:                    encBuff.append(getConnection() == null ? ""
798:                            : getConnection().toString());
799:                    encBuff.append(encodeVector(getBandwidths(true)));
800:                    encBuff.append(encodeVector(getTimeDescriptions(true)));
801:                    encBuff.append(encodeVector(getZoneAdjustments(true)));
802:                    encBuff.append(getKey() == null ? "" : getKey().toString());
803:                    encBuff.append(encodeVector(getAttributes(true)));
804:                    encBuff.append(encodeVector(getMediaDescriptions(true)));
805:                    // adds the final crlf
806:                } catch (SdpException exc) {
807:                    // add exception handling if necessary
808:                }
809:                return encBuff.toString();
810:            }
811:
812:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.