• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Conditions Of Use
3 *
4 * This software was developed by employees of the National Institute of
5 * Standards and Technology (NIST), an agency of the Federal Government.
6 * Pursuant to title 15 Untied States Code Section 105, works of NIST
7 * employees are not subject to copyright protection in the United States
8 * and are considered to be in the public domain.  As a result, a formal
9 * license is not needed to use the software.
10 *
11 * This software is provided by NIST as a service and is expressly
12 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
13 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
14 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
15 * AND DATA ACCURACY.  NIST does not warrant or make any representations
16 * regarding the use of the software or the results thereof, including but
17 * not limited to the correctness, accuracy, reliability or usefulness of
18 * the software.
19 *
20 * Permission to use this software is contingent upon your acceptance
21 * of the terms of this agreement
22 *
23 * .
24 *
25 */
26 /*******************************************************************************
27 * Product of NIST/ITL Advanced Networking Technologies Division (ANTD).        *
28 *******************************************************************************/
29 package gov.nist.javax.sip.header;
30 
31 import javax.sip.header.*;
32 import java.text.ParseException;
33 
34 /**
35 * Event SIP Header.
36 *
37 *@version 1.2 $Revision: 1.7 $ $Date: 2007/06/28 15:08:42 $
38 *@since 1.1
39 *
40 *@author M. Ranganathan   <br/>
41 *@author Olivier Deruelle <br/>
42 *
43 *
44 */
45 public class Event extends ParametersHeader implements EventHeader {
46 
47     /**
48      * Comment for <code>serialVersionUID</code>
49      */
50     private static final long serialVersionUID = -6458387810431874841L;
51 
52     protected String eventType;
53 
54     /**
55      * Creates a new instance of Event
56      */
Event()57     public Event() {
58         super(EVENT);
59     }
60 
61     /**
62     * Sets the eventType to the newly supplied eventType string.
63     *
64     * @param eventType - the  new string defining the eventType supported
65     * in this EventHeader
66     * @throws ParseException which signals that an error has been reached
67     * unexpectedly while parsing the eventType value.
68     */
setEventType(String eventType)69     public void setEventType(String eventType) throws ParseException {
70         if (eventType == null)
71             throw new NullPointerException(" the eventType is null");
72         this.eventType = eventType;
73     }
74 
75     /**
76      * Gets the eventType of the EventHeader.
77      *
78      * @return the string object identifing the eventType of EventHeader.
79      */
getEventType()80     public String getEventType() {
81         return eventType;
82     }
83 
84     /**
85      * Sets the id to the newly supplied <var>eventId</var> string.
86      *
87      * @param eventId - the new string defining the eventId of this EventHeader
88      * @throws ParseException which signals that an error has been reached
89      * unexpectedly while parsing the eventId value.
90      */
setEventId(String eventId)91     public void setEventId(String eventId) throws ParseException {
92         if (eventId == null)
93             throw new NullPointerException(" the eventId parameter is null");
94         setParameter(ParameterNames.ID, eventId);
95     }
96 
97     /**
98      * Gets the id of the EventHeader. This method may return null if the
99      * "eventId" is not set.
100      * @return the string object identifing the eventId of EventHeader.
101      */
getEventId()102     public String getEventId() {
103         return getParameter(ParameterNames.ID);
104     }
105 
106     /**
107      * Encode in canonical form.
108      * @return String
109      */
encodeBody()110     public String encodeBody() {
111         return encodeBody(new StringBuffer()).toString();
112     }
113 
encodeBody(StringBuffer buffer)114     protected StringBuffer encodeBody(StringBuffer buffer) {
115         if (eventType != null)
116             buffer.append(eventType);
117 
118         if (!parameters.isEmpty()) {
119             buffer.append(SEMICOLON);
120             this.parameters.encode(buffer);
121         }
122         return buffer;
123     }
124 
125     /**
126      *  Return true if the given event header matches the supplied one.
127      *
128      * @param matchTarget -- event header to match against.
129      */
match(Event matchTarget)130     public boolean match(Event matchTarget) {
131         if (matchTarget.eventType == null && this.eventType != null)
132             return false;
133         else if (matchTarget.eventType != null && this.eventType == null)
134             return false;
135         else if (this.eventType == null && matchTarget.eventType == null)
136             return false;
137         else if (getEventId() == null && matchTarget.getEventId() != null)
138             return false;
139         else if (getEventId() != null && matchTarget.getEventId() == null)
140             return false;
141         return matchTarget.eventType.equalsIgnoreCase(this.eventType)
142             && ((this.getEventId() == matchTarget.getEventId())
143                 || this.getEventId().equalsIgnoreCase(matchTarget.getEventId()));
144     }
145 }
146