diff options
author | nitind | 2004-11-23 19:23:00 +0000 |
---|---|---|
committer | nitind | 2004-11-23 19:23:00 +0000 |
commit | 958d79a852fed44e64fc5297402dd49f5f81d24c (patch) | |
tree | e548c626c38f28f0e538b875f82058cfefd6dcd8 /bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/contentmodel/chtml/CMNamedNodeMapImpl.java | |
parent | b0f7b2695ef3646cc3f23f6712d409ff46b2aa7a (diff) | |
download | webtools.sourceediting-958d79a852fed44e64fc5297402dd49f5f81d24c.tar.gz webtools.sourceediting-958d79a852fed44e64fc5297402dd49f5f81d24c.tar.xz webtools.sourceediting-958d79a852fed44e64fc5297402dd49f5f81d24c.zip |
initial check-in
Diffstat (limited to 'bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/contentmodel/chtml/CMNamedNodeMapImpl.java')
-rw-r--r-- | bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/contentmodel/chtml/CMNamedNodeMapImpl.java | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/contentmodel/chtml/CMNamedNodeMapImpl.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/contentmodel/chtml/CMNamedNodeMapImpl.java new file mode 100644 index 0000000000..39a7ba9a81 --- /dev/null +++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/contentmodel/chtml/CMNamedNodeMapImpl.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.html.core.contentmodel.chtml; + + + +import java.util.Iterator; + +import org.eclipse.wst.common.contentmodel.CMNode; + +/** + * An implementation of the CMNamedNodeMap interface. + * This class is intented to be used as a container of attribute declarations. + * If someone wants to use this class for other purpose, he must pay attention + * to the fact that this class is tolerant of the key name case. That is, this + * class does not distinguish "name", "NAME", and "Name" as a key name. + */ +class CMNamedNodeMapImpl implements org.eclipse.wst.common.contentmodel.CMNamedNodeMap { + + private java.util.Hashtable items = null; + + /** + */ + public CMNamedNodeMapImpl() { + super(); + items = new java.util.Hashtable(); + } + + /** + * getLength method + * @return int + */ + public int getLength() { + return items.size(); + } + + /** + * getNamedItem method + * @return CMNode <code>null</code> for unknown keys. + * @param name java.lang.String + */ + public CMNode getNamedItem(String name) { + String cookedName = makeCanonicalForm(name); + if (!items.containsKey(cookedName)) + return null; + return (CMNode) items.get(cookedName); + } + + /** + * item method + * @return CMNode + * @param index int + */ + public CMNode item(int index) { + Iterator iter = iterator(); + while (iter.hasNext()) { + CMNode node = (CMNode) iter.next(); + if (--index < 0) + return node; + } + return null; + } + + /** + * @return java.util.Iterator + */ + public Iterator iterator() { + return items.values().iterator(); + } + + /** + * @return java.lang.String + * @param rawForm java.lang.String + */ + private String makeCanonicalForm(String rawForm) { + return rawForm.toUpperCase(); + } + + /** + * @param key java.lang.String + * @param item java.lang.String + */ + void putNamedItem(String name, CMNode item) { + String cookedName = makeCanonicalForm(name); + if (items.containsKey(cookedName)) + return; // already registered. + items.put(cookedName, item); + } +}
\ No newline at end of file |