1 /*
  2  * Copyright © [2008-2009] Novell, Inc.  All Rights Reserved.
  3  * 
  4  * USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE DEVELOPER LICENSE AGREEMENT
  5  * OR OTHER AGREEMENT THROUGH WHICH NOVELL, INC. MAKES THE WORK AVAILABLE.  THIS WORK 
  6  * MAY NOT BE ADAPTED WITHOUT NOVELL'S PRIOR WRITTEN CONSENT.
  7  * 
  8  * NOVELL PROVIDES THE WORK "AS IS," WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, 
  9  * INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR 
 10  * A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  NOVELL, THE AUTHORS OF THE WORK, AND THE 
 11  * OWNERS OF COPYRIGHT IN THE WORK ARE NOT LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER 
 12  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, 
 13  * OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS IN THE WORK.
 14  */
 15 
 16 /**
 17  * @fileoverview This file defines some internal methods related to the Account class.
 18  * @see Account
 19  * @name AccountImpl Class
 20  * @private
 21  */
 22 JSDataObject(AccountImpl, Packages.esecurity.db.object.AccountFactory.getInstance(), {
 23     "Name": {
 24         required: true
 25     },
 26     "Authority": {
 27         required: true
 28     },
 29     "Status": {},
 30     "IdentityGuid": {},
 31     "SourceUserID": {},
 32     "CustomerId": {}
 33 });
 34 
 35 /**
 36  * Constructs an AccountImpl object from passed-in attributes.
 37  * @class
 38  * AccountImpl is the underlying infrastructure for managing Accounts.
 39  * DO NOT USE these functions directly - instead, use the methods defined for the Account class.
 40  * @constructor
 41  * @param {JSON} properties Initial properties to define identity
 42  * @see Account
 43  * @private
 44  */
 45 function AccountImpl(props){
 46     try {
 47         if (props && props.constructor != Object && props.constructor != AccountImpl) {
 48             throw "Account must be initialized with an object";
 49         }
 50         this.toDataObject(props);
 51     } 
 52     catch (e) {
 53         throw String(e.toString());
 54     }
 55 }
 56 
 57 /**
 58  * Do not use this method directly - use the Account class.
 59  * @param {Object} qcrit
 60  * @see Account
 61  * @private
 62  */
 63 AccountImpl.preFind = function(qcrit){
 64     try {
 65         var eqlCriterion = new Packages.esecurity.base.criteria.EqualToCriterion(Packages.esecurity.db.object.AccountFactory.getInstance().getStaticMetaData(), Packages.esecurity.db.object.Account.CURRENT, true);
 66         qcrit.addCriterion(eqlCriterion);
 67         return qcrit;
 68     } 
 69     catch (e) {
 70         throw String(e.toString());
 71     }
 72 };
 73 
 74 /**
 75 * Attach a trust to an account.
 76 * Before attaching, check whether the Trust API is supported on the platform or not.  Only when the Trust API is supported allow the
 77 * trust to be supported with an account.
 78 * @private
 79 */
 80 AccountImpl.prototype.attachTrust = function(trust) {
 81 	if ((typeof Trust != "undefined") && Trust.isSupported()) {
 82 	    var dobj = this.unwrap();
 83 	    dobj.addTrust(trust.unwrap());
 84 	} else {
 85 		throw "attachTrust is not supported on this platform"
 86 	}
 87 }
 88 
 89 /**
 90 * Retrieves all the trust(s) associated with an account
 91 *@see Account
 92 *@private
 93 */
 94 AccountImpl.prototype.getTrusts = function() {
 95 	var dobj = this.unwrap();
 96 	var ret = [];
 97 	
 98 	var list = dobj.getTrusts();
 99     if (list && (list.size() > 0)) {
100         for(var i = 0; i < list.size(); ++i ) {
101             ret[i] = TrustImpl.fromDataObject(list.get(i));
102         }
103     }		
104     
105     return ret;
106 }
107