KickJava   Java API By Example, From Geeks To Geeks.

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


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