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 java.util.ArrayList; 019import java.util.List; 020 021import org.kuali.mobility.security.user.api.User; 022 023public class AndExpression implements NonLeafExpression { 024 025 private static final long serialVersionUID = -7257967361622679088L; 026 private List<Expression> children; 027 028 public AndExpression() { 029 children = new ArrayList<Expression>(); 030 } 031 032 public boolean evaluate(User user) { 033 for (Expression child : children) { 034 if (!child.evaluate(user)) { 035 return false; 036 } 037 } 038 return true; 039 } 040 041 public void addChild(Expression expression) { 042 children.add(expression); 043 } 044 045 private Object readResolve() { 046 if (children == null) { 047 children = new ArrayList<Expression>(); 048 } 049 return this; 050 } 051 052 @Override 053 public boolean equals(Object obj) { 054 if (obj instanceof AndExpression) { 055 AndExpression other = (AndExpression)obj; 056 return children.equals(other.children); 057 } 058 return false; 059 } 060 061 @Override 062 public List<Expression> getChildren() { 063 return children; 064 } 065 066}