Skip to content

Commit 5b97ca3

Browse files
committed
Use reflection to avoid Saxon version dependency
1 parent 7378615 commit 5b97ca3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/com/nwalsh/sinclude/utils/NamespaceUtils.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.lang.reflect.Constructor;
99
import java.lang.reflect.InvocationTargetException;
1010
import java.lang.reflect.Method;
11+
import java.lang.reflect.Field;
1112

1213
// This class uses reflection to handle construction of QNames and FingerprintedQNames in a way
1314
// that's compatible with Saxon 10, 11, or 12
@@ -54,8 +55,15 @@ public static FingerprintedQName fqName(String prefix, String nsuri, String loca
5455

5556
public static QName qName(QNameValue qname) {
5657
String nsString;
57-
Object ns = qname.getNamespaceURI();
58-
nsString = (ns instanceof String) ? (String) ns : ns.toString();
58+
59+
try {
60+
Method getns = qname.getClass().getMethod("getNamespaceURI");
61+
Object ns = getns.invoke(qname);
62+
nsString = (ns instanceof String) ? (String) ns : ns.toString();
63+
} catch (NoSuchMethodException|IllegalAccessException|InvocationTargetException err) {
64+
throw new XIncludeObjectModelException("Failed to getNamespaceURI on QNameValue", err);
65+
}
66+
5967
return new QName(qname.getPrefix(), nsString, qname.getLocalName());
6068
}
6169
}

0 commit comments

Comments
 (0)