KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > lib > simplexml > SimpleXMLElementArray


1 /*
2  * Copyright (c) 1998-2004 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 Charles Reich
28  */

29
30 package com.caucho.quercus.lib.simplexml;
31
32 import com.caucho.quercus.env.ArrayValueImpl;
33 import com.caucho.quercus.env.Env;
34 import com.caucho.quercus.env.LongValue;
35 import com.caucho.quercus.env.StringValue;
36 import com.caucho.quercus.env.Value;
37
38 public class SimpleXMLElementArray extends ArrayValueImpl {
39
40   /**
41    * This class exists solely because in PHP
42    * $xml->bar[0]['attrName'] is equiv. to $xml->bar['attrName']
43    *
44    * In other words, without an offset, 0 is the assumed offset
45    *
46    * @param key
47    * @return appropriate attribute
48    */

49   @Override JavaDoc
50   public Value get(Value key)
51   {
52     Value value;
53     
54     if (key instanceof StringValue) {
55       value = super.get(LongValue.ZERO).get(key);
56     } else {
57       value = super.get(key);
58     }
59
60     return value;
61   }
62
63   /**
64    * This is a field getter for the 0th entry in this array
65    * This is created to allow for:
66    * $foo->bar[0] and
67    * $foo->bar->someTag
68    */

69   @Override JavaDoc
70   public Value getField(Env env, String JavaDoc index)
71   {
72     return super.get(LongValue.ZERO).getField(env, index);
73   }
74
75  /**
76   * Returns the field ref.
77   */

78  @Override JavaDoc
79  public Value putField(Env env, String JavaDoc index, Value object)
80  {
81    return super.get(LongValue.ZERO).putField(env, index, object);
82  }
83
84   /**
85    * Prints the value.
86    * @param env
87    */

88   @Override JavaDoc
89   public void print(Env env)
90   {
91     super.get(LongValue.ZERO).print(env);
92   }
93
94   @Override JavaDoc
95   public Value toValue()
96   {
97     return super.get(LongValue.ZERO).toValue();
98   }
99
100   public Value copy()
101   {
102     return this;
103   }
104
105   public String JavaDoc toString()
106   {
107     Value value = super.get(LongValue.ZERO);
108
109     return value.toString();
110   }
111
112 }
113
Popular Tags