Created
January 22, 2015 15:20
-
-
Save yokolet/27b0c90caaefb61c3dd0 to your computer and use it in GitHub Desktop.
Makes XPath faster on some JDK imples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private JAXPExtensionsProvider getProviderInstance() throws ClassNotFoundException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { | |
Class<?> clazz = Class.forName("com.sun.org.apache.xpath.internal.jaxp.JAXPExtensionsProvider"); | |
Constructor[] constructors = clazz.getDeclaredConstructors(); | |
for (int i = 0; i < constructors.length; i++) { | |
Class[] parameterTypes = constructors[i].getParameterTypes(); | |
if (parameterTypes.length == 2) { | |
return (JAXPExtensionsProvider) constructors[i].newInstance(functionResolver, false); | |
} else if (parameterTypes.length == 1) { | |
return (JAXPExtensionsProvider) constructors[i].newInstance(functionResolver); | |
} | |
} | |
return null; | |
} | |
.... | |
Node doc = node.getNode().getOwnerDocument(); | |
if (doc == null) { | |
doc = node.getNode(); | |
} | |
xpathSupport = (XPathContext) doc.getUserData(XPATH_CONTEXT); | |
if (xpathSupport == null) { | |
JAXPExtensionsProvider jep = getProviderInstance(); | |
xpathSupport = new XPathContext(jep); | |
xpathSupport.setVarStack(new JAXPVariableStack(variableResolver)); | |
doc.setUserData(XPATH_CONTEXT, xpathSupport, null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment