KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > expr > FieldGetExpr


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.quercus.expr;
31
32 import com.caucho.quercus.Location;
33 import com.caucho.quercus.env.Env;
34 import com.caucho.quercus.env.Value;
35 import com.caucho.util.L10N;
36
37 /**
38  * Represents a PHP field reference.
39  */

40 public class FieldGetExpr extends AbstractVarExpr {
41   private static final L10N L = new L10N(FieldGetExpr.class);
42
43   protected final Expr _objExpr;
44   protected final String JavaDoc _name;
45
46   public FieldGetExpr(Location location, Expr objExpr, String JavaDoc name)
47   {
48     super(location);
49     _objExpr = objExpr;
50
51     _name = name.intern();
52   }
53
54   public FieldGetExpr(Expr objExpr, String JavaDoc name)
55   {
56     _objExpr = objExpr;
57
58     _name = name.intern();
59   }
60
61   /**
62    * Evaluates the expression.
63    *
64    * @param env the calling environment.
65    *
66    * @return the expression value.
67    */

68   public Value eval(Env env)
69   {
70     Value obj = _objExpr.eval(env);
71
72     return obj.getField(env, _name);
73   }
74
75   /**
76    * Evaluates the expression.
77    *
78    * @param env the calling environment.
79    *
80    * @return the expression value.
81    */

82   public Value evalArg(Env env)
83   {
84     Value value = _objExpr.evalArg(env);
85
86     return value.getFieldArg(env, _name);
87   }
88
89   /**
90    * Evaluates the expression.
91    *
92    * @param env the calling environment.
93    *
94    * @return the expression value.
95    */

96   public Value evalRef(Env env)
97   {
98     // quercus/0d1k
99
Value value = _objExpr.evalObject(env);
100
101     return value.getFieldRef(env, _name);
102   }
103
104   /**
105    * Evaluates the expression as a copyable value.
106    *
107    * @param env the calling environment.
108    *
109    * @return the expression value.
110    */

111   public Value evalCopy(Env env)
112   {
113     Value obj = _objExpr.eval(env);
114
115     return obj.getField(env, _name).copy();
116   }
117
118   /**
119    * Evaluates the expression.
120    *
121    * @param env the calling environment.
122    *
123    * @return the expression value.
124    */

125   public void evalAssign(Env env, Value value)
126   {
127     Value obj = _objExpr.evalObject(env);
128
129     obj.putField(env, _name, value);
130   }
131
132   /**
133    * Evaluates the expression, creating an array if the field is unset.
134    *
135    * @param env the calling environment.
136    *
137    * @return the expression value.
138    */

139   public Value evalArray(Env env)
140   {
141     Value obj = _objExpr.evalObject(env);
142
143     return obj.getFieldArray(env, _name);
144   }
145
146   /**
147    * Evaluates the expression, creating an object if the field is unset.
148    *
149    * @param env the calling environment.
150    *
151    * @return the expression value.
152    */

153   public Value evalObject(Env env)
154   {
155     Value obj = _objExpr.evalObject(env);
156
157     // php/0a6f
158
return obj.getFieldObject(env, _name);
159   }
160
161   /**
162    * Evaluates the expression.
163    *
164    * @param env the calling environment.
165    *
166    * @return the expression value.
167    */

168   public void evalUnset(Env env)
169   {
170     Value obj = _objExpr.eval(env);
171
172     obj.removeField(_name);
173   }
174
175   public String JavaDoc toString()
176   {
177     return _objExpr + "->" + _name;
178   }
179 }
180
181
Popular Tags