1 29 30 package com.caucho.el; 31 32 import com.caucho.vfs.WriteStream; 33 34 import javax.el.ELContext; 35 import javax.el.ELException; 36 import java.io.IOException ; 37 import java.util.logging.Level ; 38 39 42 public class BooleanExpr extends AbstractBooleanExpr { 43 private int _op; 44 private Expr _left; 45 private Expr _right; 46 47 54 public BooleanExpr(int op, Expr left, Expr right) 55 { 56 _op = op; 57 _left = left; 58 _right = right; 59 } 60 61 64 @Override 65 public boolean isConstant() 66 { 67 return _left.isConstant() && _right.isConstant(); 68 } 69 70 77 @Override 78 public boolean evalBoolean(ELContext env) 79 throws ELException 80 { 81 if (_op == AND) 82 return _left.evalBoolean(env) && _right.evalBoolean(env); 83 else if (_op == OR) 84 return _left.evalBoolean(env) || _right.evalBoolean(env); 85 86 ELException e = new ELException(L.l("can't compare.")); 87 log.log(Level.FINE, e.getMessage(), e); 88 89 return false; 90 } 91 92 95 @Override 96 public void printCreate(WriteStream os) 97 throws IOException 98 { 99 os.print("new com.caucho.el.BooleanExpr("); 100 os.print(_op + ", "); 101 _left.printCreate(os); 102 os.print(", "); 103 _right.printCreate(os); 104 os.print(")"); 105 } 106 107 110 public boolean equals(Object o) 111 { 112 if (! (o instanceof BooleanExpr)) 113 return false; 114 115 BooleanExpr expr = (BooleanExpr) o; 116 117 return (_op == expr._op && 118 _left.equals(expr._left) && 119 _right.equals(expr._right)); 120 } 121 122 125 public String toString() 126 { 127 String op; 128 129 switch (_op) { 130 case OR: 131 op = " or "; 132 break; 133 case AND: 134 op = " and "; 135 break; 136 default: 137 op = " unknown(" + _op + ") "; 138 break; 139 } 140 141 return "(" + _left + op + _right + ")"; 142 } 143 } 144 | Popular Tags |