1 22 23 package org.xquark.util; 24 25 import java.util.HashMap ; 26 27 public class DefaultXMLNameFactory { 28 private static final String RCSRevision = "$Revision: 1.1 $"; 29 private static final String RCSName = "$Name: $"; 30 31 private HashMap namespaceMaps = new HashMap (); 32 private static DefaultXMLNameFactory instance = new DefaultXMLNameFactory(); 33 34 private DefaultXMLNameFactory() {} 35 36 public static DefaultXMLNameFactory getFactory() { return instance; } 37 38 public synchronized XMLName createXMLName(String namespace, String name) { 39 HashMap namespaceMap = getNamespaceMap(namespace); 40 XMLName result = (XMLName)namespaceMap.get(name); 41 if (result == null) { 42 result = new XMLNameImpl(namespace, name); 43 namespaceMap.put(name, result); 44 } 45 return result; 46 } 47 48 private HashMap getNamespaceMap(String namespace) { 49 HashMap result = (HashMap )namespaceMaps.get(namespace); 50 if (result == null) { 51 result = new HashMap (); 52 namespaceMaps.put(namespace, result); 53 } 54 return result; 55 } 56 57 private static class XMLNameImpl implements XMLName { 58 private static final String RCSRevision = "$Revision: 1.1 $"; 59 private static final String RCSName = "$Name: $"; 60 private String name; 61 private String namespace; 62 63 XMLNameImpl(String namespace, String name) { 64 this.namespace = namespace; 65 this.name = name; 66 } 67 68 public String getLocalName() { return name; } 69 70 public String getNamespaceURI() { return namespace; } 71 72 public boolean equals(Object name) { 73 if (!(name instanceof XMLNameImpl)) return false; 74 return equals((XMLNameImpl)name); 75 } 76 77 public boolean equals(XMLName name) { return this == name; } 78 } 79 } 80 81 | Popular Tags |