KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.caucho.vfs.WriteStream;
33
34 import java.io.IOException JavaDoc;
35 import java.io.PrintWriter JavaDoc;
36 import java.io.Serializable JavaDoc;
37 import java.net.URL JavaDoc;
38 import java.util.IdentityHashMap JavaDoc;
39 import java.util.Calendar JavaDoc;
40 import java.util.Date JavaDoc;
41 import java.util.Map JavaDoc;
42
43 /**
44  * Represents a PHP null value.
45  */

46 public class NullValue extends Value
47   implements Serializable JavaDoc
48 {
49   public static final NullValue NULL = new NullValue();
50
51   protected NullValue()
52   {
53   }
54
55   /**
56    * Returns the null value singleton.
57    */

58   public static NullValue create()
59   {
60     return NULL;
61   }
62
63   /**
64    * Returns the type.
65    */

66   public String JavaDoc getType()
67   {
68     return "NULL";
69   }
70
71   /**
72    * Returns true for a set type.
73    */

74   public boolean isset()
75   {
76     return false;
77   }
78
79   /**
80    * Converts to a boolean.
81    */

82   public boolean toBoolean()
83   {
84     return false;
85   }
86
87   /**
88    * Returns true for a null.
89    */

90   public boolean isNull()
91   {
92     return true;
93   }
94
95   /**
96    * Converts to a long.
97    */

98   public long toLong()
99   {
100     return 0;
101   }
102
103   /**
104    * Converts to a double.
105    */

106   public double toDouble()
107   {
108     return 0;
109   }
110
111   /**
112    * Converts to a string.
113    * @param env
114    */

115   public String JavaDoc toString()
116   {
117     return "";
118   }
119
120   /**
121    * Converts to an object.
122    */

123   public Object JavaDoc toJavaObject()
124   {
125     return null;
126   }
127
128   /**
129    * Converts to a java object.
130    */

131   @Override JavaDoc
132   public Object JavaDoc toJavaObject(Env env, Class JavaDoc type)
133   {
134     return null;
135   }
136
137   /**
138    * Converts to a java object.
139    */

140   public Object JavaDoc toJavaObjectNotNull(Env env, Class JavaDoc type)
141   {
142     env.warning(L.l("null is an unexpected argument; expected '{0}'",
143             type.getName()));
144     
145     return null;
146   }
147
148   /**
149    * Converts to a java boolean object.
150    */

151   @Override JavaDoc
152   public Boolean JavaDoc toJavaBoolean()
153   {
154     return null;
155   }
156
157   /**
158    * Converts to a java Byte object.
159    */

160   @Override JavaDoc
161   public Byte JavaDoc toJavaByte()
162   {
163     return null;
164   }
165
166   /**
167    * Converts to a java Short object.
168    */

169   @Override JavaDoc
170   public Short JavaDoc toJavaShort()
171   {
172     return null;
173   }
174
175   /**
176    * Converts to a java Integer object.
177    */

178   @Override JavaDoc
179   public Integer JavaDoc toJavaInteger()
180   {
181     return null;
182   }
183
184   /**
185    * Converts to a java Long object.
186    */

187   @Override JavaDoc
188   public Long JavaDoc toJavaLong()
189   {
190     return null;
191   }
192
193   /**
194    * Converts to a java Float object.
195    */

196   @Override JavaDoc
197   public Float JavaDoc toJavaFloat()
198   {
199     return null;
200   }
201
202   /**
203    * Converts to a java Double object.
204    */

205   @Override JavaDoc
206   public Double JavaDoc toJavaDouble()
207   {
208     return null;
209   }
210
211   /**
212    * Converts to a java Character object.
213    */

214   @Override JavaDoc
215   public Character JavaDoc toJavaCharacter()
216   {
217     return null;
218   }
219
220   /**
221    * Converts to a java String object.
222    */

223   @Override JavaDoc
224   public String JavaDoc toJavaString()
225   {
226     return null;
227   }
228
229   /**
230    * Converts to a java object.
231    */

232   public Map JavaDoc toJavaMap(Env env, Class JavaDoc type)
233   {
234     return null;
235   }
236
237   /**
238    * Converts to a Java Calendar.
239    */

240   @Override JavaDoc
241   public Calendar JavaDoc toJavaCalendar()
242   {
243     return null;
244   }
245   
246   /**
247    * Converts to a Java Date.
248    */

249   @Override JavaDoc
250   public Date JavaDoc toJavaDate()
251   {
252     return null;
253   }
254   
255   /**
256    * Converts to a Java URL.
257    */

258   @Override JavaDoc
259   public URL JavaDoc toJavaURL(Env env)
260   {
261     return null;
262   }
263   
264   /**
265    * Takes the values of this array, unmarshalls them to objects of type
266    * <i>elementType</i>, and puts them in a java array.
267    */

268   public Object JavaDoc valuesToArray(Env env, Class JavaDoc elementType)
269   {
270     return null;
271   }
272   
273   /**
274    * Converts to an object.
275    */

276   public Value toObject(Env env)
277   {
278     return NullValue.NULL;
279   }
280
281   /**
282    * Converts to an array
283    */

284   public Value toArray()
285   {
286     return new ArrayValueImpl();
287   }
288
289   /**
290    * Converts to an array if null.
291    */

292   public Value toAutoArray()
293   {
294     return new ArrayValueImpl();
295   }
296
297   /**
298    * Casts to an array.
299    */

300   @Override JavaDoc
301   public ArrayValue toArrayValue(Env env)
302   {
303     return null;
304   }
305
306   /**
307    * Returns the array size.
308    */

309   public int getSize()
310   {
311     return 0;
312   }
313
314   /**
315    * Converts to an object if null.
316    */

317   public Value toAutoObject(Env env)
318   {
319     return env.createObject();
320   }
321
322   /**
323    * Converts to a key.
324    */

325   public Value toKey()
326   {
327     return StringValue.EMPTY;
328   }
329
330   /**
331    * Returns true for equality
332    */

333   public boolean eql(Value rValue)
334   {
335     return rValue.isNull();
336   }
337
338   /**
339    * Adds to the following value.
340    */

341   @Override JavaDoc
342   public Value add(long lLong)
343   {
344     return LongValue.create(lLong);
345   }
346
347   /**
348    * Subtracts the following value.
349    */

350   public Value sub(long rLong)
351   {
352     return LongValue.create( - rLong);
353   }
354
355   /**
356    * Returns true for equality
357    */

358   @Override JavaDoc
359   public int cmp(Value rValue)
360   {
361     rValue = rValue.toValue();
362
363     if (! (rValue instanceof StringValue)) {
364       int l = 0;
365       int r = rValue.toBoolean() ? 1 : 0;
366
367       return l - r;
368     }
369     else if (rValue.isNumberConvertible()) {
370       double l = 0;
371       double r = rValue.toDouble();
372
373       if (l == r)
374     return 0;
375       else if (l < r)
376     return -1;
377       else
378     return 1;
379     }
380     else
381       return "".compareTo(rValue.toString());
382   }
383
384   /**
385    * Prints the value.
386    * @param env
387    */

388   public void print(Env env)
389   {
390   }
391
392   /**
393    * Serializes the value.
394    */

395   public void serialize(StringBuilder JavaDoc sb)
396   {
397     sb.append("N;");
398   }
399
400   /**
401    * Exports the value.
402    */

403   public void varExport(StringBuilder JavaDoc sb)
404   {
405     sb.append("null");
406   }
407
408   /**
409    * Returns a new array.
410    */

411   public Value getArray()
412   {
413     return new ArrayValueImpl();
414   }
415
416   /**
417    * Append to a binary builder.
418    */

419   public void appendTo(BinaryBuilderValue sb)
420   {
421   }
422
423   //
424
// Java generator code
425
//
426

427   /**
428    * Generates code to recreate the expression.
429    *
430    * @param out the writer to the Java source code.
431    */

432   public void generate(PrintWriter JavaDoc out)
433     throws IOException JavaDoc
434   {
435     out.print("NullValue.NULL");
436   }
437
438   /**
439    * Returns a new object.
440    */

441   public Value getObject(Env env)
442   {
443     return env.createObject();
444   }
445
446   public String JavaDoc toDebugString()
447   {
448     return "null";
449   }
450
451   public void varDumpImpl(Env env,
452                           WriteStream out,
453                           int depth,
454                           IdentityHashMap JavaDoc<Value, String JavaDoc> valueSet)
455     throws IOException JavaDoc
456   {
457     out.print("NULL");
458   }
459   
460   //
461
// Java Serialization
462
//
463

464   private Object JavaDoc readResolve()
465   {
466     return NULL;
467   }
468 }
469
470
Popular Tags