1
|
|
/*
|
2
|
|
* JBind
|
3
|
|
*
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
5
|
|
*
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
8
|
|
* 'Apache Software License V 1.1'.
|
9
|
|
*/
|
10
|
|
package org.jbind.xml.dom3.core;
|
11
|
|
|
12
|
|
import java.util.Iterator;
|
13
|
|
|
14
|
|
import org.jbind.xml.base.IRef;
|
15
|
|
import org.jbind.xml.base.ISymbolspaces;
|
16
|
|
import org.jbind.xml.base.Ref;
|
17
|
|
import org.jbind.xml.core.bridge.IDefaultAttrCreator;
|
18
|
|
import org.jbind.xml.dom3.types.IDomAttr;
|
19
|
|
import org.jbind.xml.dom3.types.IDomAttrsMap;
|
20
|
|
import org.jbind.xml.dom3.types.IDomDocument;
|
21
|
|
import org.jbind.xml.dom3.types.IDomElement;
|
22
|
|
import org.jbind.xml.msg.XmlException;
|
23
|
|
import org.w3c.dom.Node;
|
24
|
|
|
25
|
|
public class DomAttrsMap extends DomNamedNodeMap implements IDomAttrsMap {
|
26
|
|
|
27
|
|
private IDomElement myOwnerElement = null;
|
28
|
|
|
29
|
|
private IDefaultAttrCreator myDefaultAttrCreator = null;
|
30
|
|
|
31
|
0
|
public DomAttrsMap(IDomElement anOwnerElement) {
|
32
|
0
|
super((IDomDocument)anOwnerElement.getOwnerDocument());
|
33
|
0
|
myOwnerElement = anOwnerElement;
|
34
|
|
}
|
35
|
|
|
36
|
0
|
public void setDefaultAttrCreator(IDefaultAttrCreator aCreator) {
|
37
|
0
|
myDefaultAttrCreator = aCreator;
|
38
|
|
}
|
39
|
|
|
40
|
|
/**
|
41
|
|
* Creates a deep copy of the specified attributes map.
|
42
|
|
*/
|
43
|
0
|
public DomAttrsMap(IDomAttrsMap aMap, IDomElement anOwnerElement) {
|
44
|
0
|
super(aMap, true);
|
45
|
0
|
myOwnerElement = anOwnerElement;
|
46
|
|
// Attribute maps are always cloned deeply because the contained attributes
|
47
|
|
// belong to a new owner map.
|
48
|
0
|
for (Iterator i = iterNodes(); i.hasNext(); ) {
|
49
|
0
|
IDomAttr a = (IDomAttr)i.next();
|
50
|
0
|
a.setOwnerMap(this);
|
51
|
|
}
|
52
|
|
}
|
53
|
|
|
54
|
0
|
protected Node doGetDefault(String aNamespace, String aName) {
|
55
|
0
|
Node res = null;
|
56
|
0
|
if (null != myDefaultAttrCreator) {
|
57
|
0
|
IRef ref = new Ref(aNamespace, ISymbolspaces.ATTRIBUTE, aName);
|
58
|
0
|
res = (Node)myDefaultAttrCreator.createDefaultAttr(myOwnerElement, ref);
|
59
|
|
}
|
60
|
0
|
return res;
|
61
|
|
}
|
62
|
|
|
63
|
0
|
protected void doAfterSet(Node aNode) {
|
64
|
0
|
IDomAttr a = (IDomAttr)aNode;
|
65
|
0
|
if (null != a.getOwnerMap()) {
|
66
|
0
|
throw new DomException(DomException.INUSE_ATTRIBUTE_ERR);
|
67
|
|
}
|
68
|
0
|
a.setOwnerMap(this);
|
69
|
|
}
|
70
|
|
|
71
|
0
|
protected void doSetDefaults() {
|
72
|
0
|
if (null != myDefaultAttrCreator) {
|
73
|
0
|
for (Iterator i = myDefaultAttrCreator.iterDefaultAttrRefs();
|
74
|
0
|
i.hasNext(); ) {
|
75
|
0
|
IRef ref = (IRef)i.next();
|
76
|
0
|
if (null == getNamedItemNS(ref.getNamespace(), ref.getLocalPart())) {
|
77
|
0
|
Node node = (Node)myDefaultAttrCreator.createDefaultAttr(myOwnerElement, ref);
|
78
|
0
|
setNamedItemNS(node);
|
79
|
|
}
|
80
|
|
}
|
81
|
|
}
|
82
|
|
}
|
83
|
|
|
84
|
0
|
public IDomElement getOwnerElement() {
|
85
|
0
|
return myOwnerElement;
|
86
|
|
}
|
87
|
|
|
88
|
0
|
public void removeAttribute(String aNamespace, String aName) throws XmlException {
|
89
|
0
|
removeNamedItemNS(aNamespace, aName);
|
90
|
|
}
|
91
|
|
|
92
|
|
}
|
93
|
|
|