<taskModel xmlns="http://ce.org/cea-2018" about="urn:cetask.wpi.edu:examples:policytaskmodel:ConflictInit">
	<!-- Definitions for all objects and 
		 	functions related to conflicts between the access
		 	control matrix and the constraints list
		 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">
		//****************************************************
		//ConflictDesignator class
		//****************************************************
		function ConflictResolver() {
			this.crType = undefined;
			this.conflicts = new Array(0);
			
			this.equals = function(otherCR) {
				if(this.crType == otherCR.crType) {
					return true;
				}
				return false;
			}
		
			this.apply = function(matrix,constraints) {
			}
		}
		
		function AddConstraintCR(cons) {
			this.crType = "addConstraint";
			this.constraint = cons;
			this.conflicts = new Array(0);
			
			this.equals = function(otherCR) {
				if(this.crType == otherCR.crType) {
					if(this.constraint.equals(otherCR.constraint)) {
						return true;
					}
				}
				
				return false;
			}
			
			this.apply = function(matrix,constraints) {
				constraints.push(this.constraint);
			}
		}
		
		AddConstraintCR.prototype = new ConflictResolver();
		
		function RemConstraintCR(cons) {
			this.crType = "remConstraint";
			this.constraint = cons;
			this.conflicts = new Array(0);
			
			this.equals = function(otherCR) {
				if(this.crType == otherCR.crType) {
					if(this.constraint.equals(otherCR.constraint)) {
						return true;
					}
				}
				
				return false;
			}
			
			this.apply = function(matrix,constraints) {
				//find the constraint to remove
				var remidx = 0;
				while(!constraints[i].equals(this.constraint)) {
					remidx++;
				}
				
				//remove that value from the list
				constraints.splice(remidx,1);
			}
		}
		
		RemConstraintCR.prototype = new ConflictResolver();
		
		function ChangeDecCR(row,col,newdec) {
			this.crType = "changeDec";
			this.row = row;
			this.col = col;
			this.newDec = newdec;
			this.conflicts = new Array(0);
			
			this.equals = function(otherCR) {
				if(this.crType == otherCR.crType) {
					if(this.row == otherCR.row &amp;&amp; this.col == otherCR.col 
						&amp;&amp; this.newDec == otherCR.newDec) {
						return true;
					}
				}
				
				return false;
			}
			
			this.apply = function(matrix,constraints) {
				print("setting (" + this.row + "," + this.col + ") to " + this.newDec);
				matrix.set(this.row,this.col,this.newDec);
			}
		}
		
		ChangeDecCR.prototype = new ConflictResolver();
		
		
		function ConflictDesignator(constraint,roles,col,cresolve) {
			//cresolve is an array of conflict resolvers
			this.constraint = constraint;
			this.roleset = roles;
			this.col = col;
			this.cresolvers = cresolve;
			this.updateCR();
		}
		
		ConflictDesignator.prototype.updateCR = function() {
			for(var i = 0; i &lt; this.cresolvers.length; i++) {
				this.cresolvers[i].conflicts.push(this);
			}
		}
		
		//**************************************
		//* GENERIC ConflictResolver UTILITIES *
		//**************************************
		
		//checks if a ConflictResolver is a duplicate of one in a list.
		//if it is, returns the index of that ConflictResolver.
		//otherwise, returns -1
		function checkDupCR(CRlist,newCR) {
			for(var i = 0; i &lt; CRlist.length; i++) {
				if(CRlist[i].equals(newCR)) {
					return i;
				}
			}
			
			return -1;
		}
		
		//Checks if a list of ConflictDesignators contains one with the given parameters
		//returns true if it does, false otherwise
		function containsCDinSet(cdlist,constraint,rolearr,actionarr) {
			for(var j = 0; j &lt; actionarr.length; j++) {
				for(var k = 0; k &lt; cdlist.length; k++) {
					var c = cdlist[k];
					if(c.constraint.equals(constraint) &amp;&amp;
						c.col == actionarr[j] &amp;&amp;
						isSubset(c.roleset,rolearr)) {
						
						return true;
					}
				}
			}
			return false;
		}
	</script>
</taskModel>