From: <rb...@us...> - 2013-07-18 20:26:14
|
Revision: 8405 http://sourceforge.net/p/htmlunit/code/8405 Author: rbri Date: 2013-07-18 20:26:10 +0000 (Thu, 18 Jul 2013) Log Message: ----------- Fix the way we search for some java methods when creating a XMLDocument from ActiveXObject. This should work with all JavaVMs now. Issue 1521 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ActiveXObject.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-07-18 18:49:24 UTC (rev 8404) +++ trunk/htmlunit/src/changes/changes.xml 2013-07-18 20:26:10 UTC (rev 8405) @@ -8,7 +8,11 @@ <body> <release version="2.13" date="???" description="Bugfixes"> - <action type="update" dev="rbri" issue="1519, 1522" due-to="Chuck Dumont"> + <action type="fix" dev="rbri" issue="1521"> + Fix the way we search for some java methods when creating a XML document from ActiveXObject. + This should work with all JavaVMs now. + </action> + <action type="fix" dev="rbri" issue="1519, 1522" due-to="Chuck Dumont"> Improved namespace support for XPath expressions. </action> <action type="update" dev="rbri"> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ActiveXObject.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ActiveXObject.java 2013-07-18 18:49:24 UTC (rev 8404) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ActiveXObject.java 2013-07-18 20:26:10 UTC (rev 8405) @@ -16,6 +16,7 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; +import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Locale; import java.util.Map; @@ -37,6 +38,9 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; import com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocument; import com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequest; @@ -52,6 +56,7 @@ * @author <a href="mailto:bc...@es...">Ben Curren</a> * @author Ahmed Ashour * @author Chuck Dumont + * @author Ronald Brill */ @JsxClass(browsers = @WebBrowser(IE)) public class ActiveXObject extends SimpleScriptable { @@ -260,7 +265,7 @@ } private static void addFunction(final SimpleScriptable scriptable, final String methodName) { - final Method javaFunction = getMethod(scriptable.getClass(), methodName); + final Method javaFunction = getMethod(scriptable.getClass(), methodName, JsxFunction.class); final FunctionObject fo = new FunctionObject(null, javaFunction, scriptable); scriptable.defineProperty(methodName, fo, READONLY); } @@ -289,26 +294,37 @@ static void addProperty(final SimpleScriptable scriptable, final String propertyName, final String getterMethodName, final String setterMethodName) { scriptable.defineProperty(propertyName, null, - getMethod(scriptable.getClass(), getterMethodName), - getMethod(scriptable.getClass(), setterMethodName), PERMANENT); + getMethod(scriptable.getClass(), getterMethodName, JsxGetter.class), + getMethod(scriptable.getClass(), setterMethodName, JsxSetter.class), PERMANENT); } /** * Gets the first method found of the class with the given name + * and the correct annotation * @param clazz the class to search on * @param name the name of the searched method + * @param annotationClass the class of the annotation required * @return <code>null</code> if not found */ - static Method getMethod(final Class<? extends SimpleScriptable> clazz, final String name) { + static Method getMethod(final Class<? extends SimpleScriptable> clazz, + final String name, final Class<? extends Annotation> annotationClass) { if (name == null) { return null; } + Method foundByNameOnly = null; for (final Method method : clazz.getMethods()) { if (method.getName().equals(name)) { - return method; + if (null != method.getAnnotation(annotationClass)) { + return method; + } + if (null != foundByNameOnly) { + throw new IllegalArgumentException("Found at least two methods for name '" + + name + "' in class '" + clazz + "'."); + } + foundByNameOnly = method; } } - return null; + return foundByNameOnly; } /** |