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.instance.impl;
|
11
|
|
|
12
|
|
import java.util.Collections;
|
13
|
|
import java.util.Iterator;
|
14
|
|
|
15
|
|
import org.jaxen.BaseXPath;
|
16
|
|
import org.jaxen.DefaultNavigator;
|
17
|
|
import org.jaxen.Navigator;
|
18
|
|
import org.jaxen.UnsupportedAxisException;
|
19
|
|
import org.jaxen.XPath;
|
20
|
|
import org.jaxen.saxpath.SAXPathException;
|
21
|
|
import org.jbind.xml.core.bridge.IImplChild;
|
22
|
|
import org.jbind.xml.core.bridge.IImplContainer;
|
23
|
|
|
24
|
|
public class ImplNavigator extends DefaultNavigator implements Navigator {
|
25
|
|
|
26
|
|
public static ImplNavigator ourImplNavigator = new ImplNavigator();
|
27
|
|
|
28
|
2
|
public ImplNavigator() {}
|
29
|
|
|
30
|
11149
|
public Iterator getChildAxisIterator(Object contextNode) throws UnsupportedAxisException {
|
31
|
11149
|
Iterator res = null;
|
32
|
11149
|
if (contextNode instanceof IImplContainer) {
|
33
|
8985
|
res = ((IImplContainer)contextNode).iterChildren();
|
34
|
|
} else {
|
35
|
2164
|
res = Collections.EMPTY_LIST.iterator();
|
36
|
|
}
|
37
|
11149
|
return res;
|
38
|
|
}
|
39
|
|
|
40
|
4
|
public Iterator getParentAxisIterator(Object contextNode) throws UnsupportedAxisException {
|
41
|
4
|
Iterator res = null;
|
42
|
4
|
if (contextNode instanceof AttributeImpl) {
|
43
|
0
|
res = Collections.singletonList(((AttributeImpl)contextNode).getParentImpl()).iterator();
|
44
|
4
|
} else if ((contextNode instanceof ElementImpl) && ((ElementImpl)contextNode).getParentImpl() != null) {
|
45
|
4
|
res = Collections.singletonList(((ElementImpl)contextNode).getParentImpl()).iterator();
|
46
|
|
} else {
|
47
|
0
|
res = Collections.EMPTY_LIST.iterator();
|
48
|
|
}
|
49
|
4
|
return res;
|
50
|
|
}
|
51
|
|
|
52
|
287
|
public Iterator getAttributeAxisIterator(Object contextNode) throws UnsupportedAxisException {
|
53
|
287
|
Iterator res = null;
|
54
|
287
|
if (contextNode instanceof ElementImpl) {
|
55
|
287
|
res = ((ElementImpl)contextNode).iterAttributeImpls();
|
56
|
|
} else {
|
57
|
0
|
res = Collections.EMPTY_LIST.iterator();
|
58
|
|
}
|
59
|
287
|
return res;
|
60
|
|
}
|
61
|
|
|
62
|
4
|
public Object getDocumentNode(Object contextNode) {
|
63
|
4
|
Object res = contextNode;
|
64
|
4
|
while (res instanceof IImplChild) {
|
65
|
8
|
res = ((IImplChild)res).getParentImpl();
|
66
|
|
}
|
67
|
4
|
return res;
|
68
|
|
}
|
69
|
|
|
70
|
592
|
public String getAttributeName(Object attr) {
|
71
|
592
|
AttributeImpl a = (AttributeImpl)attr;
|
72
|
592
|
return a.getPartName();
|
73
|
|
}
|
74
|
|
|
75
|
592
|
public String getAttributeNamespaceUri(Object attr) {
|
76
|
592
|
AttributeImpl a = (AttributeImpl)attr;
|
77
|
592
|
return a.getNamespace();
|
78
|
|
}
|
79
|
|
|
80
|
0
|
public String getAttributeQName(Object attr) {
|
81
|
0
|
AttributeImpl a = (AttributeImpl)attr;
|
82
|
0
|
String prefix = (String)a.getPrefixToNamespaceMapping().get(a.getNamespace());
|
83
|
0
|
return ((prefix != null) ? prefix + ":" : "") + a.getPartName();
|
84
|
|
}
|
85
|
|
|
86
|
21
|
public String getAttributeStringValue(Object attr) {
|
87
|
21
|
AttributeImpl a = (AttributeImpl)attr;
|
88
|
21
|
return a.getTextContent();
|
89
|
|
}
|
90
|
|
|
91
|
0
|
public String getCommentStringValue(Object comment) {
|
92
|
0
|
return null;
|
93
|
|
}
|
94
|
|
|
95
|
5758
|
public String getElementName(Object element) {
|
96
|
5758
|
ElementImpl e = (ElementImpl)element;
|
97
|
5758
|
return e.getPartName();
|
98
|
|
}
|
99
|
|
|
100
|
5758
|
public String getElementNamespaceUri(Object element) {
|
101
|
5758
|
ElementImpl e = (ElementImpl)element;
|
102
|
5758
|
return e.getNamespace();
|
103
|
|
}
|
104
|
|
|
105
|
0
|
public String getElementQName(Object element) {
|
106
|
0
|
ElementImpl e = (ElementImpl)element;
|
107
|
0
|
String prefix = e.getPrefixForNamespace(e.getNamespace(), false);
|
108
|
0
|
return ((prefix != null) ? prefix + ":" : "") + e.getPartName();
|
109
|
|
}
|
110
|
|
|
111
|
0
|
public String getElementStringValue(Object element) {
|
112
|
0
|
ElementImpl e = (ElementImpl)element;
|
113
|
0
|
return e.getTextContent();
|
114
|
|
}
|
115
|
|
|
116
|
0
|
public String getNamespacePrefix(Object ns) {
|
117
|
0
|
return null;
|
118
|
|
}
|
119
|
|
|
120
|
0
|
public String getNamespaceStringValue(Object ns) {
|
121
|
0
|
return null;
|
122
|
|
}
|
123
|
|
|
124
|
0
|
public String getTextStringValue(Object txt) {
|
125
|
0
|
TextImpl t = (TextImpl)txt;
|
126
|
0
|
return t.getTextContent();
|
127
|
|
}
|
128
|
|
|
129
|
1738
|
public boolean isAttribute(Object object) {
|
130
|
1738
|
return object instanceof AttributeImpl;
|
131
|
|
}
|
132
|
|
|
133
|
1
|
public boolean isComment(Object object) {
|
134
|
1
|
return false;
|
135
|
|
}
|
136
|
|
|
137
|
1103
|
public boolean isDocument(Object object) {
|
138
|
1103
|
return (object instanceof ElementImpl) && ((ElementImpl)object).getParentImpl() == null;
|
139
|
|
}
|
140
|
|
|
141
|
7496
|
public boolean isElement(Object object) {
|
142
|
7496
|
return object instanceof ElementImpl;
|
143
|
|
}
|
144
|
|
|
145
|
1104
|
public boolean isNamespace(Object object) {
|
146
|
1104
|
return false;
|
147
|
|
}
|
148
|
|
|
149
|
1
|
public boolean isProcessingInstruction(Object object) {
|
150
|
1
|
return false;
|
151
|
|
}
|
152
|
|
|
153
|
1
|
public boolean isText(Object object) {
|
154
|
1
|
return object instanceof TextImpl;
|
155
|
|
}
|
156
|
|
|
157
|
0
|
public XPath parseXPath(String xpath) throws SAXPathException {
|
158
|
0
|
return new BaseXPath(xpath, ourImplNavigator);
|
159
|
|
}
|
160
|
|
|
161
|
|
}
|
162
|
|
|