001: /**
002: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
003: * Unpublished - rights reserved under the Copyright Laws of the United States.
004: * Copyright © 2003 Sun Microsystems, Inc. All rights reserved.
005: * Copyright © 2005 BEA Systems, Inc. All rights reserved.
006: *
007: * Use is subject to license terms.
008: *
009: * This distribution may include materials developed by third parties.
010: *
011: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
012: *
013: * Module Name : JSIP Specification
014: * File Name : DialogState.java
015: * Author : Phelim O'Doherty
016: *
017: * HISTORY
018: * Version Date Author Comments
019: * 1.1 08/10/2002 Phelim O'Doherty Initial version
020: * 1.2 07/07/2005 Phelim O'Doherty Deprecated the completed state.
021: *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
022: */package javax.sip;
023:
024: import java.io.*;
025:
026: /**
027: * This class contains the enumerations that define the underlying state of an
028: * existing dialog.
029: *
030: * There are three explicit states for a dialog, namely:
031: * <ul>
032: * <li> Early - A dialog is in the "early" state, which occurs when it is
033: * created when a provisional response is recieved to the INVITE Request.
034: * <li> Confirmed - A dialog transitions to the "confirmed" state when a 2xx
035: * final response is received to the INVITE Request.
036: * <li> Terminated - A dialog transitions to the "terminated" state for all
037: * other reasons or if no response arrives at all on the dialog.
038: * </ul>
039: *
040: * @author BEA Systems, NIST
041: * @version 1.2
042: */
043: public final class DialogState implements Serializable {
044:
045: /**
046: * Constructor for the DialogState
047: *
048: * @param dialogState The integer value for the DialogueState
049: */
050: private DialogState(int dialogState) {
051: m_dialogState = dialogState;
052: m_dialogStateArray[m_dialogState] = this ;
053: }
054:
055: /**
056: * This method returns the object value of the DialogState
057: *
058: * @return The DialogState Object
059: * @param dialogState The integer value of the DialogState
060: */
061: public static DialogState getObject(int dialogState) {
062: if (dialogState >= 0 && dialogState < m_size) {
063: return m_dialogStateArray[dialogState];
064: } else {
065: throw new IllegalArgumentException(
066: "Invalid dialogState value");
067: }
068: }
069:
070: /**
071: * This method returns the integer value of the DialogState
072: *
073: * @return The integer value of the DialogState
074: */
075: public int getValue() {
076: return m_dialogState;
077: }
078:
079: /**
080: * Returns the designated type as an alternative object to be used when
081: * writing an object to a stream.
082: *
083: * This method would be used when for example serializing DialogState.EARLY
084: * and deserializing it afterwards results again in DialogState.EARLY.
085: * If you do not implement readResolve(), you would not get
086: * DialogState.EARLY but an instance with similar content.
087: *
088: * @return the DialogState
089: * @exception ObjectStreamException
090: */
091: private Object readResolve() throws ObjectStreamException {
092: return m_dialogStateArray[m_dialogState];
093: }
094:
095: /**
096: * Compare this dialog state for equality with another.
097: *
098: * @since 1.2
099: * @param obj the object to compare this with.
100: * @return <code>true</code> if <code>obj</code> is an instance of this class
101: * representing the same dialog state as this, <code>false</code> otherwise.
102: */
103: public boolean equals(Object obj) {
104: if (obj == this )
105: return true;
106:
107: return (obj instanceof DialogState)
108: && ((DialogState) obj).m_dialogState == m_dialogState;
109: }
110:
111: /**
112: * Get a hash code value for this dialog state.
113: *
114: * @since 1.2
115: * @return a hash code value.
116: */
117: public int hashCode() {
118: return m_dialogState;
119: }
120:
121: /**
122: * This method returns a string version of this class.
123: * @return The string version of the DialogState
124: */
125: public String toString() {
126: String text = "";
127: switch (m_dialogState) {
128: case _EARLY:
129: text = "Early Dialog";
130: break;
131: case _CONFIRMED:
132: text = "Confirmed Dialog";
133: break;
134: case _COMPLETED:
135: text = "Completed Dialog";
136: break;
137: case _TERMINATED:
138: text = "Terminated Dialog";
139: break;
140: default:
141: text = "Error while printing Dialog State";
142: break;
143: }
144: return text;
145: }
146:
147: // internal variables
148: private int m_dialogState;
149: private static int m_size = 4;
150: private static DialogState[] m_dialogStateArray = new DialogState[m_size];
151:
152: /**
153: * This constant value indicates the internal value of the "Early"
154: * constant.
155: * <br>This constant has an integer value of 0.
156: */
157: public static final int _EARLY = 0;
158:
159: /**
160: * This constant value indicates that the dialog state is "Early".
161: */
162: public final static DialogState EARLY = new DialogState(_EARLY);
163:
164: /**
165: * This constant value indicates the internal value of the "Confirmed"
166: * constant.
167: * <br>This constant has an integer value of 1.
168: */
169: public static final int _CONFIRMED = 1;
170:
171: /**
172: * This constant value indicates that the dialog state is "Confirmed".
173: */
174: public final static DialogState CONFIRMED = new DialogState(
175: _CONFIRMED);
176:
177: /**
178: * This constant value indicates the internal value of the "Completed"
179: * constant.
180: * <br>This constant has an integer value of 2.
181: * @deprecated Since v1.2. This state does not exist in a dialog.
182: */
183: public static final int _COMPLETED = 2;
184:
185: /**
186: * This constant value indicates that the dialog state is "Completed".
187: * @deprecated Since v1.2. This state does not exist in a dialog.
188: */
189: public final static DialogState COMPLETED = new DialogState(
190: _COMPLETED);
191:
192: /**
193: * This constant value indicates the internal value of the "Terminated"
194: * constant.
195: * <br>This constant has an integer value of 3.
196: */
197: public static final int _TERMINATED = 3;
198:
199: /**
200: * This constant value indicates that the dialog state is "Terminated".
201: */
202: public final static DialogState TERMINATED = new DialogState(
203: _TERMINATED);
204:
205: }
|