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