1 package gnu.kawa.xml; 2 import gnu.mapping.*; 3 import java.io.*; 4 import gnu.xml.NamespaceBinding; 5 6 public class XmlNamespace extends Namespace 7 implements Externalizable 8 { 9 public static final String XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml"; 10 public static final XmlNamespace HTML = getInstance("", XHTML_NAMESPACE); 11 public static final NamespaceBinding HTML_BINDINGS = 12 new NamespaceBinding(null, XHTML_NAMESPACE, 13 NamespaceBinding.predefinedXML); 14 15 public static XmlNamespace getInstance (String prefix, String uri) 16 { 17 String xname = prefix + " -> "+ uri; 18 synchronized (nsTable) 19 { 20 Object old = nsTable.get(xname); 21 if (old instanceof XmlNamespace) 22 return (XmlNamespace) old; 23 XmlNamespace ns = new XmlNamespace(); 24 ns.setName(uri); 25 ns.prefix = prefix; 26 nsTable.put(xname, ns); 27 return ns; 28 } 29 } 30 31 public Object get (String name) 32 { 33 ElementType type = ElementType.make(getSymbol(name)); 34 if (this == XmlNamespace.HTML) 35 type.setNamespaceNodes(XmlNamespace.HTML_BINDINGS); 36 return type; 37 } 38 39 public boolean isConstant (String key) 40 { 41 return true; 42 } 43 44 public void writeExternal(ObjectOutput out) throws IOException 45 { 46 out.writeObject(getName()); 47 out.writeObject(prefix); 48 } 49 50 public void readExternal(ObjectInput in) 51 throws IOException, ClassNotFoundException 52 { 53 setName((String ) in.readObject()); 54 prefix = (String ) in.readObject(); 55 } 56 57 public Object readResolve() throws ObjectStreamException 58 { 59 String xname = prefix + " -> "+ getName(); 60 Namespace ns = (Namespace) nsTable.get(xname); 61 if (ns instanceof XmlNamespace) 62 return ns; 63 nsTable.put(xname, this); 64 return this; 65 } 66 } 67 | Popular Tags |