手机程序在线投票的例子
源代码在线查看: prefixmap.java
package org.kxml; import java.util.*; /** Like Attribute, this class is immutable for similar reasons */ public class PrefixMap { Hashtable prefixMap; Hashtable namespaceMap; public PrefixMap () { prefixMap = new Hashtable (); namespaceMap = new Hashtable (); } public PrefixMap (PrefixMap base, String prefix, String namespace) { if (base == null) { prefixMap = new Hashtable (); namespaceMap = new Hashtable (); } else { prefixMap = clone (base.prefixMap); namespaceMap = clone (base.namespaceMap); } if (namespace == null) namespace = ""; String oldNS = (String) prefixMap.get (prefix); if (oldNS == null) oldNS = ""; if (!namespace.equals (oldNS)) { if (prefix.equals (namespaceMap.get (oldNS))) namespaceMap.remove (oldNS); prefixMap.put (prefix, namespace); namespaceMap.put (namespace, prefix); } } private static Hashtable clone (Hashtable original) { Hashtable copy = new Hashtable (original.size () + 1); for (Enumeration e = original.keys (); e.hasMoreElements ();) { Object key = e.nextElement (); copy.put (key, original.get (key)); } return copy; } /** returns the namespace associated with the given prefix, or null, if none is assigned */ public String getNamespace (String prefix) { return (String) prefixMap.get (prefix); // String namespace = (String) prefixMap.get (prefix); // return namespace == null ? Xml.NO_NAMESPACE : namespace; } public String getPrefix (String namespace) { return (String) namespaceMap.get (namespace == null ? "" : namespace); } public Enumeration prefixEnumeration () { return prefixMap.keys (); } }