KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > env > ArgGetValue


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.env;
31
32 import java.io.Serializable JavaDoc;
33
34 /**
35  * Represents an array-get argument which might be a call to a reference.
36  *
37  * foo($a[0]), where is not known if foo is defined as foo($a) or foo(&$a)
38  */

39 public class ArgGetValue extends Value
40   implements Serializable JavaDoc
41 {
42   private final Value _obj;
43   private final Value _index;
44
45   public ArgGetValue(Value obj, Value index)
46   {
47     _obj = obj;
48     _index = index;
49   }
50
51   /**
52    * Returns the arg object for a field reference, e.g.
53    * foo($a[0][1])
54    */

55   public Value getArg(Value index)
56   {
57     return new ArgGetValue(this, index); // php/3d1p
58
}
59
60   /**
61    * Returns the arg object for a field reference, e.g.
62    * foo($a[0]->x)
63    */

64   public Value getFieldArg(Env env, String JavaDoc index)
65   {
66     return new ArgGetFieldValue(env, this, index); // php/3d2p
67
}
68
69   /**
70    * Converts to a reference variable.
71    */

72   @Override JavaDoc
73   public Var toRefVar()
74   {
75     // php/3d55, php/3d49
76
return _obj.getArgRef(_index).toRefVar();
77   }
78
79   /**
80    * Converts to a reference variable.
81    */

82   @Override JavaDoc
83   public Value toRefValue()
84   {
85     // php/3a57
86
return _obj.getArgRef(_index);
87   }
88
89   /**
90    * Converts to a value.
91    */

92   @Override JavaDoc
93   public Value toValue()
94   {
95     return _obj.get(_index);
96   }
97
98   /**
99    * Converts to a read-only value.
100    */

101   @Override JavaDoc
102   public Value toArgValueReadOnly()
103   {
104     return _obj.get(_index);
105   }
106
107   /**
108    * Converts to a value.
109    */

110   @Override JavaDoc
111   public Value toArgValue()
112   {
113     return toValue();
114   }
115
116   /**
117    * Converts to a variable.
118    */

119   public Var toVar()
120   {
121     // quercus/3d56
122
return new Var();
123   }
124
125   /**
126    * Returns the reference.
127    */

128   public Value getArgRef(Value index)
129   {
130     return _obj.getArray(_index).getRef(index); // php/3d1p
131
}
132
133   /**
134    * Converts to a reference variable.
135    */

136   public Value getFieldObject(Env env, String JavaDoc index)
137   {
138     return _obj.getObject(env, _index).getFieldObject(env, index);
139   }
140
141   /**
142    * Converts to a reference variable.
143    */

144   public Value getFieldRef(Env env, String JavaDoc index)
145   {
146     // php/3d2p
147
return _obj.getObject(env, _index).getFieldRef(env, index);
148   }
149   
150   //
151
// Java Serialization
152
//
153

154   public Object JavaDoc writeReplace()
155   {
156     return toValue();
157   }
158 }
159
160
Popular Tags