KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > el > ObjectValueExpression


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.el;
31
32 import com.caucho.util.L10N;
33
34 import javax.el.ELContext;
35 import javax.el.ELException;
36 import javax.el.PropertyNotFoundException;
37 import javax.el.PropertyNotWritableException;
38 import javax.el.ValueExpression;
39 import java.util.logging.Logger JavaDoc;
40
41 /**
42  * Abstract implementation class for an expression.
43  */

44 public class ObjectValueExpression extends ValueExpression
45 {
46   protected static final Logger JavaDoc log
47     = Logger.getLogger(ObjectValueExpression.class.getName());
48   protected static final L10N L = new L10N(Expr.class);
49
50   private final Expr _expr;
51   private final String JavaDoc _expressionString;
52   private final Class JavaDoc _expectedType;
53
54   public ObjectValueExpression(Expr expr,
55                    String JavaDoc expressionString,
56                    Class JavaDoc<?> expectedType)
57   {
58     _expr = expr;
59     _expressionString = expressionString;
60     _expectedType = expectedType;
61   }
62
63   public ObjectValueExpression(Expr expr, String JavaDoc expressionString)
64   {
65     _expr = expr;
66     _expressionString = expressionString;
67     _expectedType = Object JavaDoc.class;
68   }
69
70   public ObjectValueExpression(Expr expr)
71   {
72     _expr = expr;
73     _expressionString = _expr.toString();
74     _expectedType = Object JavaDoc.class;
75   }
76
77   public boolean isLiteralText()
78   {
79     return _expr.isLiteralText();
80   }
81
82   public String JavaDoc getExpressionString()
83   {
84     return _expressionString;
85   }
86
87   public Class JavaDoc<?> getExpectedType()
88   {
89     return _expectedType;
90   }
91
92   public Class JavaDoc<?> getType(ELContext context)
93     throws PropertyNotFoundException,
94        ELException
95   {
96     Object JavaDoc value = getValue(context);
97
98     if (value == null)
99       return null;
100     else
101       return value.getClass();
102   }
103
104   @Override JavaDoc
105   public Object JavaDoc getValue(ELContext context)
106     throws PropertyNotFoundException,
107        ELException
108   {
109     return _expr.getValue(context);
110   }
111
112   @Override JavaDoc
113   public boolean isReadOnly(ELContext context)
114     throws PropertyNotFoundException,
115        ELException
116   {
117     return _expr.isReadOnly(context);
118   }
119
120   public void setValue(ELContext context, Object JavaDoc value)
121     throws PropertyNotFoundException,
122        PropertyNotWritableException,
123        ELException
124   {
125     _expr.setValue(context, value);
126   }
127
128   public int hashCode()
129   {
130     return _expr.hashCode();
131   }
132   
133   public boolean equals(Object JavaDoc o)
134   {
135     if (this == o)
136       return true;
137     else if (! (o instanceof ObjectValueExpression))
138       return false;
139
140     ObjectValueExpression expr = (ObjectValueExpression) o;
141
142     return _expr.equals(expr._expr);
143   }
144
145   public String JavaDoc toString()
146   {
147     return "ObjectValueExpression[" + getExpressionString() + "]";
148   }
149 }
150
Popular Tags