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: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.el;
031:
032: import com.caucho.util.L10N;
033:
034: import javax.el.ELContext;
035: import javax.el.ELException;
036: import javax.el.PropertyNotFoundException;
037: import javax.el.PropertyNotWritableException;
038: import javax.el.ValueExpression;
039: import java.util.logging.Logger;
040:
041: /**
042: * Abstract implementation class for an expression.
043: */
044: abstract public class AbstractValueExpression extends ValueExpression {
045: protected static final Logger log = Logger
046: .getLogger(AbstractValueExpression.class.getName());
047: protected static final L10N L = new L10N(
048: AbstractValueExpression.class);
049:
050: protected final Expr _expr;
051: private final String _expressionString;
052:
053: protected AbstractValueExpression() {
054: _expr = null;
055: _expressionString = "";
056: }
057:
058: protected AbstractValueExpression(Expr expr, String expressionString) {
059: _expr = expr;
060: _expressionString = expressionString;
061: }
062:
063: protected AbstractValueExpression(Expr expr) {
064: _expr = expr;
065:
066: if (_expr != null)
067: _expressionString = _expr.toString();
068: else
069: _expressionString = "";
070: }
071:
072: public boolean isLiteralText() {
073: return _expr.isLiteralText();
074: }
075:
076: public String getExpressionString() {
077: return _expressionString;
078: }
079:
080: abstract public Class<?> getExpectedType();
081:
082: public Class<?> getType(ELContext context)
083: throws PropertyNotFoundException, ELException {
084: Object value = getValue(context);
085:
086: if (value == null)
087: return null;
088: else
089: return value.getClass();
090: }
091:
092: @Override
093: public Object getValue(ELContext context)
094: throws PropertyNotFoundException, ELException {
095: return _expr.getValue(context);
096: }
097:
098: @Override
099: public boolean isReadOnly(ELContext context)
100: throws PropertyNotFoundException, ELException {
101: return _expr.isReadOnly(context);
102: }
103:
104: public void setValue(ELContext context, Object value)
105: throws PropertyNotFoundException,
106: PropertyNotWritableException, ELException {
107: _expr.setValue(context, value);
108: }
109:
110: public int hashCode() {
111: return _expr.hashCode();
112: }
113:
114: public boolean equals(Object o) {
115: if (this == o)
116: return true;
117: else if (!(o instanceof AbstractValueExpression))
118: return false;
119:
120: AbstractValueExpression expr = (AbstractValueExpression) o;
121:
122: return _expr.equals(expr._expr);
123: }
124:
125: public String toString() {
126: String name = getClass().getName();
127: int p = name.lastIndexOf('.');
128: name = name.substring(p + 1);
129:
130: return name + "[" + getExpressionString() + "]";
131: }
132: }
|