KickJava   Java API By Example, From Geeks To Geeks.

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


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.vfs.WriteStream;
33
34 import javax.el.ELContext;
35 import javax.el.ELException;
36 import javax.el.ValueExpression;
37 import java.io.IOException JavaDoc;
38
39 /**
40  * ValueExpression expression.
41  */

42 public class ValueExpr extends Expr {
43   // The identifier name
44
private final String JavaDoc _name;
45   
46   private final ValueExpression _valExpr;
47
48   /**
49    * Creates the identifier
50    */

51   public ValueExpr(String JavaDoc name, ValueExpression valExpr)
52   {
53     _name = name;
54     _valExpr = valExpr;
55   }
56
57   /**
58    * Creates a field reference using this expression as the base object.
59    *
60    * @param field the string reference for the field.
61    */

62   @Override JavaDoc
63   public Expr createField(String JavaDoc field)
64   {
65     Expr arrayExpr = createField(new StringLiteral(field));
66
67     return new PathExpr(arrayExpr, _name + '.' + field);
68   }
69
70   /**
71    * Evaluate the expr as an object.
72    *
73    * @param env the variable environment
74    *
75    * @return the value as an object
76    */

77   @Override JavaDoc
78   public Object JavaDoc getValue(ELContext env)
79     throws ELException
80   {
81     return _valExpr.getValue(env);
82   }
83
84   /**
85    * Prints the code to create an IdExpr.
86    */

87   @Override JavaDoc
88   public void printCreate(WriteStream os)
89     throws IOException JavaDoc
90   {
91     os.print("new com.caucho.el.ValueExpr(\"");
92     printEscapedString(os, _name);
93     os.print("\")");
94   }
95
96   public boolean equals(Object JavaDoc o)
97   {
98     if (o == null || ! o.getClass().equals(ValueExpr.class))
99       return false;
100
101     ValueExpr expr = (ValueExpr) o;
102
103     return _valExpr.equals(expr._valExpr);
104   }
105
106   public String JavaDoc toString()
107   {
108     return _name;
109   }
110 }
111
Popular Tags