001/** 002 * Copyright 2011-2013 The Kuali Foundation Licensed under the 003 * Educational Community License, Version 2.0 (the "License"); you may 004 * not use this file except in compliance with the License. You may 005 * obtain a copy of the License at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, 010 * software distributed under the License is distributed on an "AS IS" 011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing 013 * permissions and limitations under the License. 014 */ 015 016package org.kuali.mobility.security.authz.expression; 017 018import org.kuali.mobility.security.user.api.User; 019 020import java.util.ArrayList; 021import java.util.List; 022 023public class NotExpression implements NonLeafExpression { 024 025 private static final long serialVersionUID = -777343514543759642L; 026 027 private List<Expression> children; 028 029 public NotExpression() { 030 children = new ArrayList<Expression>(); 031 } 032 033 public boolean evaluate(User user) { 034 for (Expression child : children) { 035 if (child.evaluate(user)) { 036 return false; 037 } 038 } 039 return true; 040 } 041 042 public NonLeafExpression addChild(Expression expression) { 043 children.add(expression); 044 return this; 045 } 046 047 private Object readResolve() { 048 if (children == null) { 049 children = new ArrayList<Expression>(); 050 } 051 return this; 052 } 053 054 @Override 055 public boolean equals(Object obj) { 056 if (obj instanceof NotExpression) { 057 NotExpression other = (NotExpression)obj; 058 return children.equals(other.children); 059 } 060 return false; 061 } 062 063 @Override 064 public List<Expression> getChildren() { 065 return children; 066 } 067 068}