<taskModel xmlns="http://ce.org/cea-2018" about="urn:cetask.wpi.edu:examples:policytaskmodel:ACInit">
	<!-- Definitions for all objects and functions 
			related to the access control matrix.
		 Part of the initialization code for the task model in policytaskmodel.xml
		 (Project for CS 525U)
		 Author: Paul Freitas
		 Date: 4/8/08 -->
	<script init="true">
		//****************************************************
		//ACDecision class (Permit/Deny/NotApplicable)
		//****************************************************
		function ACDecision(value) {
			this._value = value;
		}
		
		ACDecision.prototype.toString = function () {
			return this._value;
		};
		
		ACDecision.PERMIT = new ACDecision('PERMIT');
		ACDecision.DENY = new ACDecision('DENY');
		ACDecision.NOTAPPLICABLE = new ACDecision('NOTAPPLICABLE');
		
		//****************************************************	
		//Matrix class
		//****************************************************
		var PERMITOVERRIDES = 0;
		var DENYOVERRIDES = 1;
		var FIRSTAPPLICABLE = 2;
		function ACMatrix(rowarr,colarr) {
			this.rownames = rowarr;
			this.colnames = colarr;
			this.combinator = PERMITOVERRIDES; //may extend this later
			this.matrix = new Array(rowarr.length);
			for(var i = 0; i &lt; rowarr.length; i++) {
				this.matrix[i] = new Array(colarr.length);
			}
		}
		
		ACMatrix.prototype.get = function(row,col) {
			var r = findVal(row,this.rownames);
			var c = findVal(col,this.colnames);
			if(r &lt; 0 || c &lt; 0) {
				return undefined;
			} else {
				return this.matrix[r][c];
			}
		}
		
		//getDecision
		//get the ACDecision for the given action, for a user with a list of roles.
		//any number of roles may be passed to this function, but at least one must be.
		ACMatrix.prototype.getDecision = function(action1,role1) {
			var dec = ACDecision.NOTAPPLICABLE;
			var thisdec;
			var i;
			for(i = 1; i &lt; this.getDecision.arguments.length; i++) {
				thisdec = this.get(this.getDecision.arguments[i],action1);
				if(this.combinator == PERMITOVERRIDES) {
				 	if(thisdec == ACDecision.PERMIT) {
						return ACDecision.PERMIT;
					} else {
						if(dec == ACDecision.NOTAPPLICABLE) {
							dec = thisdec;
						}
					}
				} else if(this.combinator == DENYOVERRIDES) {
					if(thisdec == ACDecision.DENY) {
						return ACDecision.DENY;
					} else {
						if(dec == ACDecision.NOTAPPLICABLE) {
							dec = thisdec;
						}
					}
				} else if(this.combinator == FIRSTAPPLIES) {
					if(thisdec != ACDecision.NOTAPPLICABLE) {
						return thisdec;
					}
				}
			}
			
			return dec;
		}
		
		ACMatrix.prototype.set = function(row,col,val) {
			var r = findVal(row,this.rownames);
			var c = findVal(col,this.colnames);
			if(r &lt; 0 || c &lt; 0) {
				return undefined;
			} else {
				this.matrix[r][c] = val;
				return val;
			}
		}
		
		ACMatrix.prototype.isFull = function() {
			for(var i = 0; i &lt; this.matrix.length; i++) {
				for(var j = 0; j &lt; this.matrix[i].length; j++) {
					if(this.matrix[i][j] == null) {
						return false;
					}
				}
			}
			
			return true;
		}
		
		ACMatrix.prototype.isRowFull = function(row) {
			var r = findVal(row,this.rownames);
			
			if(r &lt; 0) {
				return false;
			}
			
			for(var i = 0; i &lt; this.matrix[r].length; i++) {
				if(this.matrix[r][i] == undefined) {
					return false;
				}
			}
			
			return true;
		}
		
		ACMatrix.prototype.isColFull = function(col) {
			var c = findVal(col,this.colnames);
			
			if(c &lt; 0) {
				return false;
			}
			
			for(var i = 0; i &lt; this.rownames.length;i++) {
				if(this.matrix[i][c] == undefined) {
					return false;
				}
			}
			
			return true;
		}
	</script>
</taskModel>