1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2012, 2013, 2014, 2016 Synacor, Inc.
  5  *
  6  * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License");
  7  * you may not use this file except in compliance with the License.
  8  * You may obtain a copy of the License at: https://www.zimbra.com/license
  9  * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15
 10  * have been added to cover use of software over a computer network and provide for limited attribution
 11  * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
 12  *
 13  * Software distributed under the License is distributed on an "AS IS" basis,
 14  * WITHOUT WARRANTY OF ANY KIND, either express or implied.
 15  * See the License for the specific language governing rights and limitations under the License.
 16  * The Original Code is Zimbra Open Source Web Client.
 17  * The Initial Developer of the Original Code is Zimbra, Inc.  All rights to the Original Code were
 18  * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015.
 19  *
 20  * All portions of the code are Copyright (C) 2005, 2006, 2007, 2009, 2010, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 /**
 25  * @overview
 26  * This file contains the result class.
 27  */
 28 
 29 /**
 30  * Creates a CSFE result object.
 31  * @class
 32  * This class represents the result of a CSFE request. The data is either the 
 33  * response that was received, or an exception. If the request resulted in a 
 34  * SOAP fault from the server, there will also be a SOAP header present.
 35  *
 36  * @author Conrad Damon
 37  * 
 38  * @param {Object}	data			the response data
 39  * @param {Boolean}	isException	if <code>true</code>, the data is an exception object
 40  * @param {Object}	header			the SOAP header
 41  * 
 42  */
 43 ZmCsfeResult = function(data, isException, header) {
 44 	this.set(data, isException, header);
 45 };
 46 
 47 ZmCsfeResult.prototype.isZmCsfeResult = true;
 48 ZmCsfeResult.prototype.toString = function() { return "ZmCsfeResult"; };
 49 
 50 /**
 51  * Sets the content of the result.
 52  *
 53  * @param {Object}	data			the response data
 54  * @param {Boolean}	isException	if <code>true</code>, the data is an exception object
 55  * @param {Object}	header			the SOAP header
 56  */
 57 ZmCsfeResult.prototype.set =
 58 function(data, isException, header) {
 59 	this._data = data;
 60 	this._isException = (isException === true);
 61 	this._header = header;
 62 };
 63 
 64 /**
 65  * Gets the response data. If there was an exception, throws the exception.
 66  * 
 67  * @return	{Object}	the data
 68  */
 69 ZmCsfeResult.prototype.getResponse =
 70 function() {
 71 	if (this._isException) {
 72 		throw this._data;
 73 	} else {
 74 		return this._data;
 75 	}
 76 };
 77 
 78 /**
 79  * Gets the exception object, if any.
 80  * 
 81  * @return	{ZmCsfeException}	the exception or <code>null</code> for none
 82  */
 83 ZmCsfeResult.prototype.getException =
 84 function() {
 85 	return this._isException ? this._data : null;
 86 };
 87 
 88 /**
 89  * Checks if this result is an exception.
 90  * 
 91  * @return	{Boolean}	<code>true</code> if an exception
 92  */
 93 ZmCsfeResult.prototype.isException = 
 94 function() {
 95 	return this._isException;
 96 };
 97 
 98 /**
 99  * Gets the SOAP header that came with a SOAP fault.
100  * 
101  * @return	{String}	the header
102  */
103 ZmCsfeResult.prototype.getHeader =
104 function() {
105 	return this._header;
106 };
107