001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.el;
030:
031: import com.caucho.vfs.WriteStream;
032:
033: import javax.el.ELContext;
034: import javax.el.ELException;
035: import java.io.IOException;
036:
037: /**
038: * A boolean literal expression.
039: */
040: public class BooleanLiteral extends AbstractBooleanExpr {
041: private boolean _value;
042:
043: /**
044: * Creates a new boolean literal.
045: *
046: * @param value the value
047: */
048: public BooleanLiteral(boolean value) {
049: _value = value;
050: }
051:
052: /**
053: * Returns true if the expression is constant.
054: */
055: public boolean isConstant() {
056: return true;
057: }
058:
059: /**
060: * Evaluate the expression as an boolean
061: *
062: * @param env the variable environment
063: *
064: * @return the value as a boolean
065: */
066: @Override
067: public boolean evalBoolean(ELContext env) throws ELException {
068: return _value;
069: }
070:
071: /**
072: * Prints the Java code to recreate the BooleanLiteral.
073: *
074: * @param os the output stream to the *.java code.
075: */
076: public void printCreate(WriteStream os) throws IOException {
077: os.print("new com.caucho.el.BooleanLiteral(");
078: os.print(_value);
079: os.print(")");
080: }
081:
082: /**
083: * Returns true for equal strings.
084: */
085: public boolean equals(Object o) {
086: if (!(o instanceof BooleanLiteral))
087: return false;
088:
089: BooleanLiteral literal = (BooleanLiteral) o;
090:
091: return _value == literal._value;
092: }
093:
094: /**
095: * Returns a readable representation of the expr.
096: */
097: public String toString() {
098: return String.valueOf(_value);
099: }
100: }
|