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: public class ObjectValueExpression extends ValueExpression {
045: protected static final Logger log = Logger
046: .getLogger(ObjectValueExpression.class.getName());
047: protected static final L10N L = new L10N(Expr.class);
048:
049: private final Expr _expr;
050: private final String _expressionString;
051: private final Class _expectedType;
052:
053: public ObjectValueExpression(Expr expr, String expressionString,
054: Class<?> expectedType) {
055: _expr = expr;
056: _expressionString = expressionString;
057: _expectedType = expectedType;
058: }
059:
060: public ObjectValueExpression(Expr expr, String expressionString) {
061: _expr = expr;
062: _expressionString = expressionString;
063: _expectedType = Object.class;
064: }
065:
066: public ObjectValueExpression(Expr expr) {
067: _expr = expr;
068: _expressionString = _expr.toString();
069: _expectedType = Object.class;
070: }
071:
072: /**
073: * For serialization
074: */
075: public ObjectValueExpression() {
076: _expr = null;
077: _expressionString = null;
078: _expectedType = Object.class;
079: }
080:
081: public boolean isLiteralText() {
082: return _expr.isLiteralText();
083: }
084:
085: public String getExpressionString() {
086: return _expressionString;
087: }
088:
089: public Class<?> getExpectedType() {
090: return _expectedType;
091: }
092:
093: public Class<?> getType(ELContext context)
094: throws PropertyNotFoundException, ELException {
095: return _expr.getType(context);
096: }
097:
098: @Override
099: public Object getValue(ELContext context)
100: throws PropertyNotFoundException, ELException {
101: return _expr.getValue(context);
102: }
103:
104: @Override
105: public boolean isReadOnly(ELContext context)
106: throws PropertyNotFoundException, ELException {
107: return _expr.isReadOnly(context);
108: }
109:
110: public void setValue(ELContext context, Object value)
111: throws PropertyNotFoundException,
112: PropertyNotWritableException, ELException {
113: _expr.setValue(context, value);
114: }
115:
116: public int hashCode() {
117: return _expr.hashCode();
118: }
119:
120: public boolean equals(Object o) {
121: if (this == o)
122: return true;
123: else if (!(o instanceof ObjectValueExpression))
124: return false;
125:
126: ObjectValueExpression expr = (ObjectValueExpression) o;
127:
128: return _expr.equals(expr._expr);
129: }
130:
131: public String toString() {
132: return "ObjectValueExpression[" + getExpressionString() + "]";
133: }
134: }
|