KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > program > CompiledClassDef


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.program;
31
32 import com.caucho.quercus.QuercusRuntimeException;
33 import com.caucho.quercus.env.ArrayValue;
34 import com.caucho.quercus.env.ArrayValueImpl;
35 import com.caucho.quercus.env.Env;
36 import com.caucho.quercus.env.QuercusClass;
37 import com.caucho.quercus.env.Value;
38 import com.caucho.quercus.expr.Expr;
39 import com.caucho.util.IdentityIntMap;
40
41 import java.lang.reflect.Method JavaDoc;
42 import java.util.ArrayList JavaDoc;
43
44 /**
45  * Represents a PHP class value.
46  */

47 public class CompiledClassDef extends ClassDef {
48   private final Class JavaDoc _compiledClass;
49   private final Method JavaDoc _init;
50   
51   private final ArrayList JavaDoc<String JavaDoc> _fieldNames
52     = new ArrayList JavaDoc<String JavaDoc>();
53   
54   private final IdentityIntMap _fieldMap
55     = new IdentityIntMap();
56   
57   protected ArrayValue _extFields = new ArrayValueImpl();
58   protected Value _parent;
59   
60   public CompiledClassDef(String JavaDoc name, String JavaDoc parent, String JavaDoc []ifaceList,
61               Class JavaDoc compiledClass)
62   {
63     super(name, parent, ifaceList);
64
65     _compiledClass = compiledClass;
66     try {
67       _init = compiledClass.getMethod("init",
68                       new Class JavaDoc[] { QuercusClass.class });
69     } catch (Exception JavaDoc e) {
70       throw new QuercusRuntimeException(e);
71     }
72   }
73
74   /**
75    * Initialize the quercus class.
76    */

77   public void initClass(QuercusClass cl)
78   {
79     try {
80       _init.invoke(null, cl);
81     } catch (Exception JavaDoc e) {
82       throw new QuercusRuntimeException(e);
83     }
84   }
85
86   /**
87    * Returns the field index.
88    */

89   public int findFieldIndex(String JavaDoc name)
90   {
91     return _fieldMap.get(name);
92   }
93
94   /**
95    * Returns the key set.
96    */

97   public ArrayList JavaDoc<String JavaDoc> getFieldNames()
98   {
99     return _fieldNames;
100   }
101
102   /**
103    * Returns the field index.
104    */

105   protected void addFieldIndex(String JavaDoc name, int id)
106   {
107     _fieldMap.put(name, id);
108     _fieldNames.add(name);
109   }
110
111   /**
112    * Returns the constructor
113    */

114   public AbstractFunction findConstructor()
115   {
116     return null;
117   }
118
119   /**
120    * Creates a new instance.
121    */

122   public void initInstance(Env env, Value value)
123   {
124   }
125
126   /**
127    * Adds a value.
128    */

129   public Value get(Value name)
130   {
131     throw new UnsupportedOperationException JavaDoc();
132     /*
133     if (_extFields != null) {
134       Value value = _extFields.get(name);
135       return value;
136     }
137     else
138       return NullValue.NULL;
139     */

140   }
141
142   /**
143    * Returns a reference to the field
144    */

145   public Value getRef(Value name)
146   {
147     throw new UnsupportedOperationException JavaDoc();
148     /*
149     if (_extFields == null)
150       _extFields = new ArrayValue();
151
152     Value ref = _extFields.getRef(name);
153
154     return ref;
155     */

156   }
157
158   /**
159    * Returns a reference to the field
160    */

161   public Value getArgRef(Value name)
162   {
163     throw new UnsupportedOperationException JavaDoc();
164     /*
165     if (_extFields == null)
166       _extFields = new ArrayValue();
167     
168     return _extFields.getArgRef(name);
169     */

170   }
171
172   /**
173    * Returns the field value, if unset, creates an array.
174    */

175   public Value getArray(Value name)
176   {
177     throw new UnsupportedOperationException JavaDoc();
178     
179     /*
180     Value value = get(name);
181
182     if (! value.isset()) {
183       value = new ArrayValue();
184       
185       put(name, value);
186     }
187
188     return value;
189     */

190   }
191
192   /**
193    * Returns the field value, if unset, creates an object.
194    */

195   public Value getObject(Env env, Value name)
196   {
197     throw new UnsupportedOperationException JavaDoc();
198     /*
199     Value value = get(name);
200
201     if (! value.isset()) {
202       value = env.createObject();
203       
204       put(name, value);
205     }
206
207     return value;
208     */

209   }
210
211   /**
212    * Returns the field value, if unset, creates an ArgGetValue.
213    */

214   public Value getArg(Value name)
215   {
216     throw new UnsupportedOperationException JavaDoc();
217     
218     /*
219     Value value = get(name);
220
221     if (value.isset()) {
222       return value;
223     }
224     else {
225       // quercus/3d55
226       return new ArgGetValue(this, name);
227     }
228
229     return null;
230     */

231   }
232
233   /**
234    * Adds a value.
235    */

236   public Value put(Value name, Value value)
237   {
238     throw new UnsupportedOperationException JavaDoc();
239
240     /*
241     if (_extFields == null)
242       _extFields = new ArrayValue();
243
244     _extFields.put(name, value);
245
246     return value;
247     */

248   }
249
250   /**
251    * Adds a value.
252    */

253   public Value put(Value value)
254   {
255     throw new UnsupportedOperationException JavaDoc();
256
257     /*
258     if (_extFields == null)
259       _extFields = new ArrayValue();
260
261     _extFields.put(value);
262
263     return value;
264     */

265   }
266
267   /**
268    * Adds a value.
269    */

270   public Value putRef()
271   {
272     throw new UnsupportedOperationException JavaDoc();
273
274     /*
275     // quercus/3d8i
276     
277     if (_extFields == null)
278       _extFields = new ArrayValue();
279
280     return _extFields.putRef();
281     */

282   }
283
284   /**
285    * Removes a value.
286    */

287   public Value remove(Value name)
288   {
289     throw new UnsupportedOperationException JavaDoc();
290     /*
291     // quercus/3d91
292     
293     if (_extFields != null) {
294       Value value = _extFields.remove(name);
295       return value;
296     }
297     else
298       return NullValue.NULL;
299     */

300   }
301
302   /**
303    * Creates a new instance.
304    */

305   public Value newInstance()
306   {
307     /*
308     try {
309       return getClass().newInstance();
310     } catch (Exception e) {
311       throw new QuercusRuntimeException(e);
312     }
313     */

314     throw new UnsupportedOperationException JavaDoc();
315   }
316
317   /**
318    * Eval new
319    */

320   public Value callNew(Env env, Expr []args)
321   {
322     return null;
323   }
324
325   /**
326    * Eval new
327    */

328   public Value callNew(Env env, Value []args)
329   {
330     return null;
331   }
332 }
333
334
Popular Tags