KickJava   Java API By Example, From Geeks To Geeks.

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


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 static field reference.
39  */

40 public class StaticFieldGetExpr extends AbstractVarExpr {
41   private static final L10N L = new L10N(StaticFieldGetExpr.class);
42
43   protected final String JavaDoc _className;
44   protected final String JavaDoc _varName;
45   protected final String JavaDoc _envName;
46
47   public StaticFieldGetExpr(Location location, String JavaDoc className, String JavaDoc varName)
48   {
49     super(location);
50     _className = className;
51     
52     _varName = varName;
53
54     _envName = className + "::" + varName;
55   }
56
57   public StaticFieldGetExpr(String JavaDoc className, String JavaDoc varName)
58   {
59     _className = className;
60     
61     _varName = varName;
62
63     _envName = className + "::" + varName;
64   }
65   
66   /**
67    * Evaluates the expression.
68    *
69    * @param env the calling environment.
70    *
71    * @return the expression value.
72    */

73   public Value eval(Env env)
74   {
75     return env.getGlobalValue(_envName);
76   }
77
78   /**
79    * Evaluates the expression.
80    *
81    * @param env the calling environment.
82    *
83    * @return the expression value.
84    */

85   public Value evalArg(Env env)
86   {
87     return env.getGlobalRef(_envName);
88   }
89
90   /**
91    * Evaluates the expression.
92    *
93    * @param env the calling environment.
94    *
95    * @return the expression value.
96    */

97   public Value evalRef(Env env)
98   {
99     return env.getGlobalVar(_envName);
100   }
101   
102   /**
103    * Evaluates the expression.
104    *
105    * @param env the calling environment.
106    *
107    * @return the expression value.
108    */

109   public void evalAssign(Env env, Value value)
110   {
111     env.setGlobalValue(_envName, value);
112   }
113   
114   /**
115    * Evaluates the expression.
116    *
117    * @param env the calling environment.
118    *
119    * @return the expression value.
120    */

121   public void evalUnset(Env env)
122   {
123     // env.removeGlobal(_envName);
124
}
125   
126   public String JavaDoc toString()
127   {
128     return _className + "::$" + _varName;
129   }
130 }
131
132
Popular Tags