/* * Copyright 2008-2009 (c) Lance Pollard * www.systemsofseven.com/blog * www.4ddesignlab.com * LanceJPollard@gmail.com * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ package com.fourD.core { [Bindable] public class ConditionsUtil { public static function validateConditions(conditions:Array):Boolean { var value:Boolean; var condition:*; var i:int=0, len:int = conditions.length; for (i; i < len; i++) { condition = conditions[i]; if (condition is SimpleCondition) { value = ConditionsUtil.validateSimpleCondition(condition); } else if (condition is ComplexCondition) { value = ConditionsUtil.validateComplexCondition(condition); } if (value == false) { return value; } } return value; } public static function validateSimpleCondition(condition:Object):Boolean { var valid:Boolean = false; var source:* = condition.source; var property:* = condition.firstStatement; var value:Boolean = condition.value; if (!source[property]) { // THROW ERROR } if (source[property] == value) { valid = true } return valid; } public static function validateComplexCondition(condition:Object):Boolean { var valid:Boolean; var source:* = condition.source; var first:* = condition.firstStatement; var second:* = condition.secondStatement; var operator:String = condition.operator; if (operator == "==") { valid = (first == second); } else if (operator == "!=") { valid = (first != second) } else if (operator == "===") { valid = (first === second) } else if (operator == "!==") { valid = (first !== second) } else { valid = false; } return valid; } } }