PageRenderTime 18ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/protocols/jain-megaco/megaco-api/src/main/java/javax/megaco/association/DeleteTxnResp.java

http://mobicents.googlecode.com/
Java | 157 lines | 53 code | 20 blank | 84 comment | 15 complexity | 5eaddd9e382592d99102589bf60359d1 MD5 | raw file
  1/**
  2 * Start time:14:03:29 2009-01-30<br>
  3 * Project: mobicents-media-server-controllers<br>
  4 * 
  5 * @author <a href="mailto:baranowb@gmail.com">baranowb - Bartosz Baranowski
  6 *         </a>
  7 * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
  8 */
  9package javax.megaco.association;
 10
 11import javax.megaco.AssociationEvent;
 12import javax.megaco.ErrorCode;
 13
 14import javax.megaco.MethodInvocationException;
 15import javax.megaco.ReturnStatus;
 16
 17public class DeleteTxnResp extends AssociationEvent {
 18
 19	private int txnHandle = -1;
 20	protected ReturnStatus eventStatus = null;
 21	protected ErrorCode errorCode = null;
 22
 23	public DeleteTxnResp(Object source, int assocHandle) throws IllegalArgumentException {
 24		super(source, assocHandle);
 25		// TODO Auto-generated constructor stub
 26	}
 27
 28	public DeleteTxnResp(Object source, int assocHandle, int txnHandle) throws IllegalArgumentException {
 29		super(source, assocHandle);
 30		this.setTxnHandle(txnHandle);
 31	}
 32
 33	@Override
 34	public final int getAssocOperIdentifier() {
 35		return AssocEventType.M_DELETE_TXN_RESP;
 36	}
 37
 38	/**
 39	 * This method returns whether the delete transaction event was successful
 40	 * or not.
 41	 * 
 42	 * @return Returns an integer value that identifies whether the delete
 43	 *         transaction event issued earlier could be performed successfuly
 44	 *         or not. The values are field constants defined in class
 45	 *         ReturnStatus. If the returnStatus is not set, then this method
 46	 *         would return value null.
 47	 */
 48	public final ReturnStatus getEventStatus() {
 49		// return eventStatus == null ? 0 : eventStatus.getReturnStatus();
 50		return eventStatus;
 51	}
 52
 53	/**
 54	 * This method sets the status of whether the processing of the delete
 55	 * transaction event was successful or not.
 56	 * 
 57	 * @param returnStatus
 58	 *            - The return status of the processing of the delete
 59	 *            transaction event. The static object corresponding to the
 60	 *            return status which are one of the derived classes of the
 61	 *            ReturnStatus shall be set.
 62	 * @throws IllegalArgumentException
 63	 *             This exception is raised if the reference of Return Status
 64	 *             passed to this method is NULL.
 65	 */
 66	public final void setEventStatus(ReturnStatus returnStatus) throws IllegalArgumentException {
 67		if (returnStatus == null)
 68			throw new IllegalArgumentException("Event status can not be null.");
 69
 70		this.eventStatus = returnStatus;
 71	}
 72
 73	/**
 74	 * This method returns the error code qualifying why the modify association
 75	 * event could not be processed successfuly.
 76	 * 
 77	 * @return Returns an integer value that identifies the error code
 78	 *         specifying why the execution of the modify association event
 79	 *         could not be successful. The possible values are field constants
 80	 *         defined for the class ErrorCode. If the error code is not set,
 81	 *         then this method would return value null.
 82	 * @throws IllegalStateException
 83	 *             - This exception would be raised if the return status is set
 84	 *             to M_SUCCESS, the error code is not set and hence should not
 85	 *             invoke this method.
 86	 */
 87	public final ErrorCode getErrorCode() throws IllegalStateException {
 88		if (getEventStatus() == null || getEventStatus().getReturnStatus() == ReturnStatus.M_SUCCESS) {
 89			throw new IllegalStateException("Event status is success or not set, error code is not premited.");
 90		}
 91		// return errorCode == null ? 0 : errorCode.getErrorCode();
 92		return errorCode;
 93	}
 94
 95	/**
 96	 * This method sets the error code specifying why the delete transaction
 97	 * event could not be executed successfuly.
 98	 * 
 99	 * @param errorCode
100	 *            - The error code correspondingto why the delete transaction
101	 *            event could not be executed successfuly. The values are
102	 *            defined in AssocEventType.
103	 * @throws IllegalArgumentException
104	 *             This exception would be raised in following conditions <br>
105	 *             1. If the return status is not set to M_FAILURE, the error
106	 *             code should not be set. <br>
107	 *             2. If the error code is not valid for the DeleteTxnReq event.
108	 */
109	public final void setErrorCode(ErrorCode errorCode) throws IllegalArgumentException {
110		if (errorCode == null)
111			throw new IllegalArgumentException("Error code can not be null.");
112		if (getEventStatus() == null || getEventStatus().getReturnStatus() != ReturnStatus.M_FAILURE) {
113			throw new IllegalArgumentException("Event status is not failure or nto set, error code is not premited.");
114		}
115		this.errorCode = errorCode;
116	}
117
118	// FIXME those are nto defined in jdoc....
119
120	/**
121	 * Gets an object identifier that specifies the transaction identifier. If
122	 * the transaction identifier is set to 0, then this would be the case when
123	 * the transaction identifier is to represent all transactions.<br>
124	 * <br>
125	 * If the transaction identifier is not set, then this method returns 0,
126	 * indicating all transactions.
127	 * 
128	 * @return Returns an integer value that specifies the transaction
129	 *         identifier.
130	 */
131	public final int getTxnHandle() {
132		if (txnHandle == -1)
133			return 0;
134
135		return txnHandle;
136
137	}
138
139	/**
140	 * This method sets the transaction identifier. To delete all transactions,
141	 * the transaction identifier is set to 0.
142	 * 
143	 * @param transactionHandle
144	 *            A reference to transaction identifier.
145	 * @throws IllegalArgumentException
146	 *             This exception is raised if the value of transaction handle
147	 *             passed to this method is less than 0.
148	 */
149	public final void setTxnHandle(int transactionHandle) throws IllegalArgumentException {
150
151		if (transactionHandle < 0)
152			throw new IllegalArgumentException("Txn Handle can not be less than zero");
153
154		this.txnHandle = transactionHandle;
155	}
156
157}