comparison agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSMap.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
1 /*
2 * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 package sun.jvm.hotspot.utilities.soql;
26
27 import java.util.*;
28 import sun.jvm.hotspot.oops.*;
29
30 /**
31 This is JavaScript wrapper for a Map.
32 */
33
34 public class JSMap extends DefaultScriptObject {
35 public JSMap(Map map, JSJavaFactory fac) {
36 this.map = map;
37 this.factory = fac;
38 }
39
40 public Object get(String name) {
41 if (map.containsKey(name)) {
42 return wrapObject(map.get(name));
43 } else {
44 return super.get(name);
45 }
46 }
47
48 public Object[] getIds() {
49 Object[] superIds = super.getIds();
50 Object[] tmp = map.keySet().toArray();
51 Object[] res = new Object[superIds.length + tmp.length];
52 System.arraycopy(tmp, 0, res, 0, tmp.length);
53 System.arraycopy(superIds, 0, res, tmp.length, superIds.length);
54 return res;
55 }
56
57 public boolean has(String name) {
58 if (map.containsKey(name)) {
59 return true;
60 } else {
61 return super.has(name);
62 }
63 }
64
65 public void put(String name, Object value) {
66 if (! map.containsKey(name)) {
67 super.put(name, value);
68 }
69 }
70
71 public String toString() {
72 StringBuffer buf = new StringBuffer();
73 Set keys = map.keySet();
74 buf.append('{');
75 for (Iterator itr = keys.iterator(); itr.hasNext();) {
76 Object key = itr.next();
77 buf.append(key);
78 buf.append('=');
79 buf.append(wrapObject(map.get(key)));
80 if (itr.hasNext()) {
81 buf.append(", ");
82 }
83 }
84 buf.append('}');
85 return buf.toString();
86 }
87
88 private Object wrapObject(Object obj) {
89 return factory.newJSJavaWrapper(obj);
90 }
91
92 private final Map map;
93 private final JSJavaFactory factory;
94 }