KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > es > ESArguments


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  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.es;
30
31 import com.caucho.util.IntMap;
32
33 import java.util.HashMap JavaDoc;
34
35 class ESArguments extends ESObject {
36   static ESId CALLEE = ESId.intern("callee");
37   static ESId ARGUMENTS = ESId.intern("arguments");
38   static ESId LENGTH = ESId.intern("length");
39
40   HashMap JavaDoc aliases = new HashMap JavaDoc();
41
42   private ESArguments(ESId []formals, Call eval, int length)
43     throws ESException
44   {
45     super("Arguments", Global.getGlobalProto().arrayProto);
46
47     for (int i = 0; i < length; i++)
48       super.put(ESString.create(i), eval.getArg(i, length), DONT_ENUM);
49     
50     for (int i = 0; i < formals.length; i++) {
51       super.put(formals[i], eval.getArg(i, length), DONT_ENUM|DONT_DELETE);
52       aliases.put(formals[i], ESString.create(i));
53       aliases.put(ESString.create(i), formals[i]);
54     }
55     
56     super.put(LENGTH, ESNumber.create(length), DONT_ENUM);
57     super.put(CALLEE, eval.callee, DONT_ENUM);
58   }
59
60   static ESObject create(ESId []formals, Call eval, int length)
61     throws ESException
62   {
63     ESArguments args = new ESArguments(formals, eval, length);
64     
65     args.put(ARGUMENTS, args, DONT_ENUM|DONT_DELETE);
66     
67     return args;
68   }
69
70   public ESString toSource(IntMap map, boolean isLoopPass) throws Throwable JavaDoc
71   {
72     return ESArray.arrayToSource(this, map, isLoopPass);
73   }
74
75   public void setProperty(ESString key, ESBase value) throws Throwable JavaDoc
76   {
77     ESId alias = (ESId) aliases.get(key);
78
79     super.setProperty(key, value);
80
81     if (alias != null)
82       super.setProperty(alias, value);
83   }
84
85   public void put(ESString key, ESBase value, int flags)
86   {
87     ESId alias = (ESId) aliases.get(key);
88
89     super.put(key, value, flags);
90
91     if (alias != null)
92       super.put(alias, value, flags);
93   }
94
95   public ESBase delete(ESString key) throws Throwable JavaDoc
96   {
97     ESId alias = (ESId) aliases.get(key);
98
99     if (alias == null)
100       return super.delete(key);
101     else {
102       return ESBoolean.FALSE;
103       // aliases.remove(key); // XXX: is this right? 10.1.8
104
}
105   }
106
107   protected ESArguments() {}
108   protected ESObject dup() { return new ESArguments(); }
109
110   protected void copy(HashMap JavaDoc refs, Object JavaDoc newObj)
111   {
112     ESArguments newArgs = (ESArguments) newObj;
113
114     newArgs.aliases = aliases;
115
116     super.copy(refs, newObj);
117   }
118 }
119
Popular Tags