01: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.layout.dlm.providers;
07:
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10: import org.jasig.portal.layout.dlm.Evaluator;
11: import org.jasig.portal.security.IPerson;
12:
13: /**
14: * @version $Revision: 35705 $ $Date: 2005-05-01 20:14:20 -0700 (Sun, 01 May 2005) $
15: * @since uPortal 2.5
16: */
17: public class Paren implements Evaluator {
18: public static final String RCS_ID = "@(#) $Header$";
19: private static Log LOG = LogFactory.getLog(Paren.class);
20:
21: public static final ParenType OR = new ParenType("OR");
22: public static final ParenType AND = new ParenType("AND");
23: public static final ParenType NOT = new ParenType("NOT");
24:
25: private ParenType type = null;
26:
27: protected Evaluator[] evaluators = new Evaluator[] {};
28:
29: public Paren(ParenType t) {
30: type = t;
31: }
32:
33: public void addEvaluator(Evaluator e) {
34: if (evaluators == null)
35: evaluators = new Evaluator[] { e };
36:
37: Evaluator[] arr = new Evaluator[evaluators.length + 1];
38: System.arraycopy(evaluators, 0, arr, 0, evaluators.length);
39: arr[evaluators.length] = e;
40: evaluators = arr;
41: }
42:
43: public boolean isApplicable(IPerson toPerson) {
44: boolean isApplicable = false;
45: if (LOG.isDebugEnabled())
46: LOG.debug(" >>>> calling paren[" + this + ", op=" + type
47: + "].isApplicable()");
48: if (type == OR) {
49: for (int i = 0; i < evaluators.length; i++)
50: if (evaluators[i].isApplicable(toPerson)) {
51: isApplicable = true;
52: break;
53: }
54: } else if (type == AND) {
55: int i = 0;
56: for (; i < evaluators.length; i++)
57: if (evaluators[i].isApplicable(toPerson) == false) {
58: isApplicable = false;
59: break;
60: }
61: if (i == evaluators.length) // ran to end without finding one
62: isApplicable = true;
63: } else if (type == NOT) {
64: for (int i = 0; i < evaluators.length; i++)
65: if (evaluators[i].isApplicable(toPerson)) {
66: isApplicable = true;
67: break;
68: }
69: isApplicable = !isApplicable;
70: }
71: if (LOG.isDebugEnabled())
72: LOG.debug(" ---- paren[" + this + ", op=" + type
73: + "].isApplicable()=" + isApplicable);
74: return isApplicable;
75: }
76: }
77:
78: class ParenType {
79: String type = null;
80:
81: public ParenType(String type) {
82: this .type = type;
83: }
84:
85: public String toString() {
86: return type;
87: }
88: }
|