From 8246e38dcd5585df0f9c767000ce4d5a5858ad36 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Mon, 14 Aug 2006 15:11:41 +0000 Subject: [PATCH] ScriptableHashMap fixed to support integer indexing as an associative javascript array - AR-712 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3496 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/jscript/ScriptableHashMap.java | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/source/java/org/alfresco/repo/jscript/ScriptableHashMap.java b/source/java/org/alfresco/repo/jscript/ScriptableHashMap.java index 95b2a72d6d..3f3f76766b 100644 --- a/source/java/org/alfresco/repo/jscript/ScriptableHashMap.java +++ b/source/java/org/alfresco/repo/jscript/ScriptableHashMap.java @@ -16,17 +16,19 @@ */ package org.alfresco.repo.jscript; -import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; -import org.alfresco.service.namespace.NamespacePrefixResolver; -import org.alfresco.service.namespace.QNameMap; import org.mozilla.javascript.Scriptable; /** * @author Kevin Roast */ -public class ScriptableHashMap extends HashMap implements Scriptable +public class ScriptableHashMap extends LinkedHashMap implements Scriptable { + private Scriptable parentScope; + private Scriptable prototype; + /** * @see org.mozilla.javascript.Scriptable#getClassName() */ @@ -56,7 +58,14 @@ public class ScriptableHashMap extends HashMap implements Scriptable */ public Object get(int index, Scriptable start) { - return null; + Object value = null; + int i=0; + Iterator itrValues = this.values().iterator(); + while (i++ <= index && itrValues.hasNext()) + { + value = itrValues.next(); + } + return value; } /** @@ -73,7 +82,7 @@ public class ScriptableHashMap extends HashMap implements Scriptable */ public boolean has(int index, Scriptable start) { - return false; + return (index >= 0 && this.values().size() > index); } /** @@ -90,6 +99,7 @@ public class ScriptableHashMap extends HashMap implements Scriptable */ public void put(int index, Scriptable start, Object value) { + // TODO: implement? } /** @@ -106,6 +116,17 @@ public class ScriptableHashMap extends HashMap implements Scriptable */ public void delete(int index) { + int i=0; + Iterator itrKeys = this.keySet().iterator(); + while (i <= index && itrKeys.hasNext()) + { + Object key = itrKeys.next(); + if (i == index) + { + remove(key); + break; + } + } } /** @@ -113,7 +134,7 @@ public class ScriptableHashMap extends HashMap implements Scriptable */ public Scriptable getPrototype() { - return null; + return this.prototype; } /** @@ -121,6 +142,7 @@ public class ScriptableHashMap extends HashMap implements Scriptable */ public void setPrototype(Scriptable prototype) { + this.prototype = prototype; } /** @@ -128,7 +150,7 @@ public class ScriptableHashMap extends HashMap implements Scriptable */ public Scriptable getParentScope() { - return null; + return this.parentScope; } /** @@ -136,6 +158,7 @@ public class ScriptableHashMap extends HashMap implements Scriptable */ public void setParentScope(Scriptable parent) { + this.parentScope = parent; } /** @@ -143,7 +166,7 @@ public class ScriptableHashMap extends HashMap implements Scriptable */ public Object[] getIds() { - return null; + return keySet().toArray(); } /**