KickJava   Java API By Example, From Geeks To Geeks.

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


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 FieldVarGetExpr extends AbstractVarExpr {
41   private static final L10N L = new L10N(FieldVarGetExpr.class);
42
43   protected final Expr _objExpr;
44   protected final Expr _nameExpr;
45
46   public FieldVarGetExpr(Location location, Expr objExpr, Expr nameExpr)
47   {
48     super(location);
49     _objExpr = objExpr;
50     
51     _nameExpr = nameExpr;
52   }
53
54   public FieldVarGetExpr(Expr objExpr, Expr nameExpr)
55   {
56     _objExpr = objExpr;
57     
58     _nameExpr = nameExpr;
59   }
60
61   /**
62    * Evaluates the expression.
63    *
64    * @param env the calling environment.
65    *
66    * @return the expression value.
67    */

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

82   public Value evalRef(Env env)
83   {
84     // quercus/0d1k
85
Value value = _objExpr.evalObject(env);
86
87     return value.getFieldRef(env, _nameExpr.evalString(env).intern());
88   }
89   
90   /**
91    * Evaluates the expression.
92    *
93    * @param env the calling environment.
94    *
95    * @return the expression value.
96    */

97   public Value eval(Env env)
98   {
99     Value obj = _objExpr.eval(env);
100
101     return obj.getField(env, _nameExpr.evalString(env).intern());
102   }
103   
104   /**
105    * Evaluates the expression.
106    *
107    * @param env the calling environment.
108    *
109    * @return the expression value.
110    */

111   public void evalAssign(Env env, Value value)
112   {
113     Value obj = _objExpr.evalObject(env);
114
115     obj.putField(env, _nameExpr.evalString(env).intern(), value);
116   }
117
118   /**
119    * Evaluates the expression, creating an array if the field is unset.
120    *
121    * @param env the calling environment.
122    *
123    * @return the expression value.
124    */

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

139   public Value evalObject(Env env)
140   {
141     Value obj = _objExpr.evalObject(env);
142
143     return obj.getFieldObject(env, _nameExpr.evalString(env).intern());
144   }
145   
146   /**
147    * Evaluates the expression.
148    *
149    * @param env the calling environment.
150    *
151    * @return the expression value.
152    */

153   public void evalUnset(Env env)
154   {
155     Value obj = _objExpr.eval(env);
156
157     obj.removeField(_nameExpr.evalString(env).intern());
158   }
159   
160   public String JavaDoc toString()
161   {
162     return _objExpr + "->{" + _nameExpr + "}";
163   }
164 }
165
166
Popular Tags