KickJava   Java API By Example, From Geeks To Geeks.

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


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 Nam Nguyen
28  */

29
30 package com.caucho.quercus.env;
31
32 import java.io.IOException JavaDoc;
33 import java.net.URL JavaDoc;
34
35 import java.util.*;
36
37 import com.caucho.vfs.WriteStream;
38
39 import com.caucho.quercus.expr.Expr;
40
41 import com.caucho.quercus.program.AbstractFunction;
42
43 /**
44  * Represents a PHP variable value.
45  */

46 public class JavaAdapterVar extends Var
47 {
48   
49   private JavaAdapter _adapter;
50   private Value _key;
51
52   public JavaAdapterVar(JavaAdapter adapter, Value key)
53   {
54     _adapter = adapter;
55     _key = key;
56   }
57
58   public Value getValue()
59   {
60     return _adapter.get(_key);
61   }
62   
63   public void setValue(Value value)
64   {
65     _adapter.putImpl(_key, value);
66   }
67   
68   /**
69    * Sets the value.
70    */

71   public Value set(Value value)
72   {
73     setRaw(getValue());
74     
75     value = super.set(value);
76     
77     setValue(getRawValue());
78     
79     return value;
80   }
81
82   /**
83    * Returns the type.
84    */

85   public String JavaDoc getType()
86   {
87     return getValue().getType();
88   }
89
90   /**
91    * Returns true for a set type.
92    */

93   public boolean isset()
94   {
95     return getValue().isset();
96   }
97
98   /**
99    * Returns true for an implementation of a class
100    */

101   public boolean isA(String JavaDoc name)
102   {
103     return getValue().isA(name);
104   }
105
106   /**
107    * True for a number
108    */

109   public boolean isNull()
110   {
111     return getValue().isNull();
112   }
113
114   /**
115    * True for a long
116    */

117   public boolean isLongConvertible()
118   {
119     return getValue().isLongConvertible();
120   }
121
122   /**
123    * True to a double.
124    */

125   public boolean isDoubleConvertible()
126   {
127     return getValue().isDoubleConvertible();
128   }
129
130   /**
131    * True for a number
132    */

133   public boolean isNumberConvertible()
134   {
135     return getValue().isNumberConvertible();
136   }
137
138   /**
139    * Returns true for is_numeric
140    */

141   @Override JavaDoc
142   public boolean isNumeric()
143   {
144     return getValue().isNumeric();
145   }
146
147   /**
148    * Returns true for a scalar
149    */

150   /*
151   public boolean isScalar()
152   {
153     return getValue().isScalar();
154   }
155   */

156
157   /**
158    * Returns true for a StringValue.
159    */

160   public boolean isString()
161   {
162     return getValue().isString();
163   }
164
165   /**
166    * Returns true for a BinaryValue.
167    */

168   public boolean isBinary()
169   {
170     return getValue().isBinary();
171   }
172
173   /**
174    * Returns true for a UnicodeValue.
175    */

176   public boolean isUnicode()
177   {
178     return getValue().isUnicode();
179   }
180
181   //
182
// Conversions
183
//
184

185   public String JavaDoc toString()
186   {
187     return getValue().toString();
188   }
189
190   /**
191    * Converts to a boolean.
192    */

193   public boolean toBoolean()
194   {
195     return getValue().toBoolean();
196   }
197
198   /**
199    * Converts to a long.
200    */

201   public long toLong()
202   {
203     return getValue().toLong();
204   }
205
206   /**
207    * Converts to a double.
208    */

209   public double toDouble()
210   {
211     return getValue().toDouble();
212   }
213
214   /**
215    * Converts to a string.
216    * @param env
217    */

218   public StringValue toString(Env env)
219   {
220     return getValue().toString(env);
221   }
222
223   /**
224    * Converts to an object.
225    */

226   public Object JavaDoc toJavaObject()
227   {
228     return getValue().toJavaObject();
229   }
230
231   /**
232    * Converts to an object.
233    */

234   @Override JavaDoc
235   public Object JavaDoc toJavaObject(Env env, Class JavaDoc type)
236   {
237     return getValue().toJavaObject(env, type);
238   }
239
240   /**
241    * Converts to an object.
242    */

243   @Override JavaDoc
244   public Object JavaDoc toJavaObjectNotNull(Env env, Class JavaDoc type)
245   {
246     return getValue().toJavaObjectNotNull(env, type);
247   }
248
249   /**
250    * Converts to a java Collection object.
251    */

252   public Collection toJavaCollection(Env env, Class JavaDoc type)
253   {
254     return getValue().toJavaCollection(env, type);
255   }
256   
257   /**
258    * Converts to a java List object.
259    */

260   public List toJavaList(Env env, Class JavaDoc type)
261   {
262     return getValue().toJavaList(env, type);
263   }
264   
265   /**
266    * Converts to a java Map object.
267    */

268   public Map toJavaMap(Env env, Class JavaDoc type)
269   {
270     return getValue().toJavaMap(env, type);
271   }
272
273
274   /**
275    * Converts to an array
276    */

277   public Value toArray()
278   {
279     return getValue().toArray();
280   }
281
282   /**
283    * Converts to an array
284    */

285   @Override JavaDoc
286   public ArrayValue toArrayValue(Env env)
287   {
288     return getValue().toArrayValue(env);
289   }
290
291   /**
292    * Converts to an array
293    */

294   public Value toAutoArray()
295   {
296     setRaw(getValue());
297     
298     Value value = super.toAutoArray();
299     
300     setValue(getRawValue());
301     
302     return value;
303   }
304
305   /**
306    * Converts to an object.
307    */

308   public Value toObject(Env env)
309   {
310     return getValue().toObject(env);
311   }
312
313   /**
314    * Converts to a Java Calendar.
315    */

316   @Override JavaDoc
317   public Calendar toJavaCalendar()
318   {
319     return getValue().toJavaCalendar();
320   }
321   
322   /**
323    * Converts to a Java Date.
324    */

325   @Override JavaDoc
326   public Date toJavaDate()
327   {
328     return getValue().toJavaDate();
329   }
330   
331   /**
332    * Converts to a Java URL.
333    */

334   @Override JavaDoc
335   public URL JavaDoc toJavaURL(Env env)
336   {
337     return getValue().toJavaURL(env);
338   }
339   
340   /**
341    * Append to a string builder.
342    */

343   public void appendTo(StringBuilderValue sb)
344   {
345     getValue().appendTo(sb);
346   }
347
348   /**
349    * Append to a string builder.
350    */

351   public void appendTo(BinaryBuilderValue sb)
352   {
353     getValue().appendTo(sb);
354   }
355
356   /**
357    * Converts to a raw value.
358    */

359   public Value toValue()
360   {
361     return getValue();
362   }
363
364   /**
365    * Converts to a function argument value that is never assigned or modified.
366    */

367   @Override JavaDoc
368   public Value toArgValueReadOnly()
369   {
370     return getValue();
371   }
372
373   /**
374    * Converts to a raw value.
375    */

376   @Override JavaDoc
377   public Value toArgValue()
378   {
379     return getValue().toArgValue();
380   }
381
382   /**
383    * Converts to a function argument ref value, i.e. an argument
384    * declared as a reference, but not assigned
385    */

386   @Override JavaDoc
387   public Value toRefValue()
388   {
389     setRaw(getValue());
390     
391     Value value = super.toRefValue();
392     
393     setValue(getRawValue());
394     
395     return value;
396   }
397
398   /**
399    * Converts to a variable
400    */

401   @Override JavaDoc
402   public Var toVar()
403   {
404     setRaw(getValue());
405     
406     Var value = super.toVar();
407     
408     setValue(getRawValue());
409     
410     return value;
411   }
412
413   /**
414    * Converts to a key.
415    */

416   public Value toKey()
417   {
418     return getValue().toKey();
419   }
420
421   @Override JavaDoc
422   public StringValue toStringValue()
423   {
424     return getValue().toStringValue();
425   }
426
427   @Override JavaDoc
428   public BinaryValue toBinaryValue(Env env)
429   {
430     return getValue().toBinaryValue(env);
431   }
432
433   @Override JavaDoc
434   public UnicodeValue toUnicodeValue(Env env)
435   {
436     return getValue().toUnicodeValue(env);
437   }
438
439   @Override JavaDoc
440   public StringValue toStringBuilder()
441   {
442     return getValue().toStringBuilder();
443   }
444
445   //
446
// Operations
447
//
448

449   /**
450    * Copy the value.
451    */

452   public Value copy()
453   {
454     setRaw(getValue());
455     
456     Value value = super.copy();
457     
458     setValue(getRawValue());
459     
460     return value;
461   }
462
463   /**
464    * Copy the value as a return value.
465    */

466   public Value copyReturn()
467   {
468     setRaw(getValue());
469     
470     Value value = super.copyReturn();
471     
472     setValue(getRawValue());
473     
474     return value;
475   }
476
477   /**
478    * Converts to a variable reference (for function arguments)
479    */

480   public Value toRef()
481   {
482     setRaw(getValue());
483     
484     Value value = super.toRef();
485     
486     setValue(getRawValue());
487     
488     return value;
489   }
490
491   /**
492    * Returns true for an array.
493    */

494   public boolean isArray()
495   {
496     return getValue().isArray();
497   }
498
499   /**
500    * Negates the value.
501    */

502   public Value neg()
503   {
504     return getValue().neg();
505   }
506
507   /**
508    * Adds to the following value.
509    */

510   public Value add(Value rValue)
511   {
512     return getValue().add(rValue);
513   }
514
515   /**
516    * Adds to the following value.
517    */

518   @Override JavaDoc
519   public Value add(long rValue)
520   {
521     return getValue().add(rValue);
522   }
523
524   /**
525    * Pre-increment the following value.
526    */

527   public Value preincr(int incr)
528   {
529     setRaw(getValue());
530     
531     Value value = super.preincr(incr);
532     
533     setValue(getRawValue());
534     
535     return value;
536   }
537
538   /**
539    * Post-increment the following value.
540    */

541   public Value postincr(int incr)
542   {
543     setRaw(getValue());
544     
545     Value value = super.postincr(incr);
546     
547     setValue(getRawValue());
548     
549     return value;
550   }
551
552   /**
553    * Subtracts to the following value.
554    */

555   public Value sub(Value rValue)
556   {
557     return getValue().sub(rValue);
558   }
559
560   /**
561    * Multiplies to the following value.
562    */

563   public Value mul(Value rValue)
564   {
565     return getValue().mul(rValue);
566   }
567
568   /**
569    * Multiplies to the following value.
570    */

571   public Value mul(long lValue)
572   {
573     return getValue().mul(lValue);
574   }
575
576   /**
577    * Divides the following value.
578    */

579   public Value div(Value rValue)
580   {
581     return getValue().div(rValue);
582   }
583
584   /**
585    * Shifts left by the value.
586    */

587   public Value lshift(Value rValue)
588   {
589     return getValue().lshift(rValue);
590   }
591
592   /**
593    * Shifts right by the value.
594    */

595   public Value rshift(Value rValue)
596   {
597     return getValue().rshift(rValue);
598   }
599
600   /**
601    * Returns true for equality
602    */

603   public boolean eq(Value rValue)
604   {
605     return getValue().eq(rValue);
606   }
607
608   /**
609    * Returns true for equality
610    */

611   public boolean eql(Value rValue)
612   {
613     return getValue().eql(rValue);
614   }
615
616   /**
617    * Compares the two values
618    */

619   public int cmp(Value rValue)
620   {
621     return getValue().cmp(rValue);
622   }
623
624   /**
625    * Returns the array/object size
626    */

627   public int getSize()
628   {
629     return getValue().getSize();
630   }
631
632   /**
633    * Returns the field values.
634    */

635   public Collection<Value> getIndices()
636   {
637     return getValue().getIndices();
638   }
639
640   /**
641    * Returns the array keys.
642    */

643   public Value []getKeyArray()
644   {
645     return getValue().getKeyArray();
646   }
647
648   /**
649    * Returns the array values.
650    */

651   public Value []getValueArray(Env env)
652   {
653     return getValue().getValueArray(env);
654   }
655
656   /**
657    * Returns the array ref.
658    */

659   public Value getArray()
660   {
661     setRaw(getValue());
662     
663     Value value = super.getArray();
664     
665     setValue(getRawValue());
666     
667     return value;
668   }
669
670   /**
671    * Returns the value, creating an object if unset.
672    */

673   public Value getObject(Env env)
674   {
675     setRaw(getValue());
676     
677     Value value = super.getObject(env);
678     
679     setValue(getRawValue());
680     
681     return value;
682   }
683
684   /**
685    * Returns the array ref.
686    */

687   public Value get(Value index)
688   {
689     return getValue().get(index);
690   }
691
692   /**
693    * Returns the array ref.
694    */

695   public Value getRef(Value index)
696   {
697     setRaw(getValue());
698     
699     Value value = super.getRef(index);
700     
701     setValue(getRawValue());
702     
703     return value;
704   }
705
706   /**
707    * Returns the array ref.
708    */

709   public Value getArg(Value index)
710   {
711     setRaw(getValue());
712     
713     Value value = super.getArg(index);
714     
715     setValue(getRawValue());
716     
717     return value;
718   }
719
720   /**
721    * Returns the array ref.
722    */

723   public Value getArgRef(Value index)
724   {
725     setRaw(getValue());
726     
727     Value value = super.getArgRef(index);
728     
729     setValue(getRawValue());
730     
731     return value;
732   }
733
734   /**
735    * Returns the value, creating an object if unset.
736    */

737   public Value getArray(Value index)
738   {
739     setRaw(getValue());
740     
741     Value value = super.getArray(index);
742     
743     setValue(getRawValue());
744     
745     return value;
746   }
747
748   /**
749    * Returns the value, doing a copy-on-write if needed.
750    */

751   public Value getDirty(Value index)
752   {
753     return getValue().getDirty(index);
754   }
755
756   /**
757    * Returns the value, creating an object if unset.
758    */

759   public Value getObject(Env env, Value index)
760   {
761     setRaw(getValue());
762     
763     Value value = super.getObject(env, index);
764     
765     setValue(getRawValue());
766     
767     return value;
768   }
769
770   /**
771    * Returns the array ref.
772    */

773   public Value put(Value index, Value value)
774   {
775     setRaw(getValue());
776     
777     Value retValue = super.put(index, value);
778     
779     setValue(getRawValue());
780     
781     return retValue;
782   }
783
784   /**
785    * Returns the array ref.
786    */

787   public Value put(Value value)
788   {
789     setRaw(getValue());
790     
791     Value retValue = super.put(value);
792     
793     setValue(getRawValue());
794     
795     return retValue;
796   }
797
798   /**
799    * Returns the array ref.
800    */

801   public Value putRef()
802   {
803     setRaw(getValue());
804     
805     Value retValue = super.putRef();
806     
807     setValue(getRawValue());
808     
809     return retValue;
810   }
811
812   /**
813    * Return unset the value.
814    */

815   public Value remove(Value index)
816   {
817     return getValue().remove(index);
818   }
819
820   /**
821    * Returns the field ref.
822    */

823   @Override JavaDoc
824   public Value getField(Env env, String JavaDoc index)
825   {
826     return getValue().getField(env, index);
827   }
828
829   /**
830    * Returns the field ref.
831    */

832   public Value getFieldRef(Env env, String JavaDoc index)
833   {
834     setRaw(getValue());
835     
836     Value retValue = super.getFieldRef(env, index);
837     
838     setValue(getRawValue());
839     
840     return retValue;
841   }
842
843   /**
844    * Returns the array ref.
845    */

846   public Value getFieldArg(Env env, String JavaDoc index)
847   {
848     setRaw(getValue());
849     
850     Value retValue = super.getFieldArg(env, index);
851     
852     setValue(getRawValue());
853     
854     return retValue;
855   }
856
857   /**
858    * Returns the field value as an array
859    */

860   public Value getFieldArray(Env env, String JavaDoc index)
861   {
862     setRaw(getValue());
863     
864     Value retValue = super.getFieldArray(env, index);
865     
866     setValue(getRawValue());
867     
868     return retValue;
869   }
870
871   /**
872    * Returns the field value as an object
873    */

874   public Value getFieldObject(Env env, String JavaDoc index)
875   {
876     setRaw(getValue());
877     
878     Value retValue = super.getFieldObject(env, index);
879     
880     setValue(getRawValue());
881     
882     return retValue;
883   }
884
885   /**
886    * Sets the field.
887    */

888   public Value putField(Env env, String JavaDoc index, Value value)
889   {
890     setRaw(getValue());
891     
892     Value retValue = super.putField(env, index, value);
893     
894     setValue(getRawValue());
895     
896     return retValue;
897   }
898
899   /**
900    * Unsets the field.
901    */

902   public void removeField(String JavaDoc index)
903   {
904     getValue().removeField(index);
905   }
906
907   /**
908    * Takes the values of this array, unmarshalls them to objects of type
909    * <i>elementType</i>, and puts them in a java array.
910    */

911   public Object JavaDoc valuesToArray(Env env, Class JavaDoc elementType)
912   {
913     return getValue().valuesToArray(env, elementType);
914   }
915   
916   /**
917    * Returns the character at an index
918    */

919   @Override JavaDoc
920   public Value charValueAt(long index)
921   {
922     return getValue().charValueAt(index);
923   }
924
925   /**
926    * Sets the character at an index
927    */

928   @Override JavaDoc
929   public Value setCharValueAt(long index, String JavaDoc value)
930   {
931     return getValue().setCharValueAt(index, value);
932   }
933
934   /**
935    * Returns true if there are more elements.
936    */

937   public boolean hasCurrent()
938   {
939     return getValue().hasCurrent();
940   }
941
942   /**
943    * Returns the current key
944    */

945   public Value key()
946   {
947     return getValue().key();
948   }
949
950   /**
951    * Returns the current value
952    */

953   public Value current()
954   {
955     return getValue().current();
956   }
957
958   /**
959    * Returns the current value
960    */

961   public Value next()
962   {
963     return getValue().next();
964   }
965
966   /**
967    * Evaluates a method.
968    */

969   public Value callMethod(Env env, String JavaDoc methodName, Expr []args)
970   {
971     return getValue().callMethod(env, methodName, args);
972   }
973
974   /**
975    * Evaluates a method.
976    */

977   public Value callMethod(Env env, String JavaDoc methodName, Value []args)
978   {
979     return getValue().callMethod(env, methodName, args);
980   }
981
982   /**
983    * Evaluates a method.
984    */

985   public Value callMethod(Env env, String JavaDoc methodName)
986   {
987     return getValue().callMethod(env, methodName);
988   }
989
990   /**
991    * Evaluates a method.
992    */

993   public Value callMethod(Env env, String JavaDoc methodName, Value a0)
994   {
995     return getValue().callMethod(env, methodName, a0);
996   }
997
998   /**
999    * Evaluates a method.
1000   */

1001  public Value callMethod(Env env, String JavaDoc methodName, Value a0, Value a1)
1002  {
1003    return getValue().callMethod(env, methodName, a0, a1);
1004  }
1005
1006  /**
1007   * Evaluates a method with 3 args.
1008   */

1009  public Value callMethod(Env env, String JavaDoc methodName,
1010              Value a0, Value a1, Value a2)
1011  {
1012    return getValue().callMethod(env, methodName, a0, a1, a2);
1013  }
1014
1015  /**
1016   * Evaluates a method with 4 args.
1017   */

1018  public Value callMethod(Env env, String JavaDoc methodName,
1019              Value a0, Value a1, Value a2, Value a3)
1020  {
1021    return getValue().callMethod(env, methodName, a0, a1, a2, a3);
1022  }
1023
1024  /**
1025   * Evaluates a method with 5 args.
1026   */

1027  public Value callMethod(Env env, String JavaDoc methodName,
1028              Value a0, Value a1, Value a2, Value a3, Value a4)
1029  {
1030    return getValue().callMethod(env, methodName, a0, a1, a2, a3, a4);
1031  }
1032
1033  /**
1034   * Evaluates a method.
1035   */

1036  public Value callMethodRef(Env env, String JavaDoc methodName, Expr []args)
1037  {
1038    return getValue().callMethodRef(env, methodName, args);
1039  }
1040
1041  /**
1042   * Evaluates a method.
1043   */

1044  public Value callMethodRef(Env env, String JavaDoc methodName, Value []args)
1045  {
1046    return getValue().callMethodRef(env, methodName, args);
1047  }
1048
1049  /**
1050   * Evaluates a method.
1051   */

1052  public Value callMethodRef(Env env, String JavaDoc methodName)
1053  {
1054    return getValue().callMethodRef(env, methodName);
1055  }
1056
1057  /**
1058   * Evaluates a method.
1059   */

1060  public Value callMethodRef(Env env, String JavaDoc methodName, Value a0)
1061  {
1062    return getValue().callMethodRef(env, methodName, a0);
1063  }
1064
1065  /**
1066   * Evaluates a method.
1067   */

1068  public Value callMethodRef(Env env, String JavaDoc methodName, Value a0, Value a1)
1069  {
1070    return getValue().callMethodRef(env, methodName, a0, a1);
1071  }
1072
1073  /**
1074   * Evaluates a method with 3 args.
1075   */

1076  public Value callMethodRef(Env env, String JavaDoc methodName,
1077              Value a0, Value a1, Value a2)
1078  {
1079    return getValue().callMethodRef(env, methodName, a0, a1, a2);
1080  }
1081
1082  /**
1083   * Evaluates a method with 4 args.
1084   */

1085  public Value callMethodRef(Env env, String JavaDoc methodName,
1086              Value a0, Value a1, Value a2, Value a3)
1087  {
1088    return getValue().callMethodRef(env, methodName, a0, a1, a2, a3);
1089  }
1090
1091  /**
1092   * Evaluates a method with 5 args.
1093   */

1094  public Value callMethodRef(Env env, String JavaDoc methodName,
1095              Value a0, Value a1, Value a2, Value a3, Value a4)
1096  {
1097    return getValue().callMethodRef(env, methodName, a0, a1, a2, a3, a4);
1098  }
1099
1100  /**
1101   * Evaluates a method.
1102   */

1103  public Value callClassMethod(Env env, AbstractFunction fun, Value []args)
1104  {
1105    return getValue().callClassMethod(env, fun, args);
1106  }
1107
1108  /**
1109   * Prints the value.
1110   * @param env
1111   */

1112  public void print(Env env)
1113  {
1114    getValue().print(env);
1115  }
1116
1117  /**
1118   * Serializes the value.
1119   */

1120  public void serialize(StringBuilder JavaDoc sb)
1121  {
1122    getValue().serialize(sb);
1123  }
1124
1125  public void varDumpImpl(Env env,
1126                          WriteStream out,
1127                          int depth,
1128                          IdentityHashMap<Value, String JavaDoc> valueSet)
1129    throws IOException JavaDoc
1130  {
1131    out.print("&");
1132    getValue().varDump(env, out, depth, valueSet);
1133  }
1134  
1135  //
1136
// Java Serialization
1137
//
1138

1139  public Object JavaDoc writeReplace()
1140  {
1141    return getValue();
1142  }
1143}
1144
1145
Popular Tags