[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit/javascript JavaScript.java,1.7,1.8 JavaSc
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-08-08 20:47:26
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv16831/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java JavaScriptEngineFactory.java Log Message: Class renaming, added support for Option constructor and options property writing Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- JavaScript.java 7 Aug 2002 20:36:24 -0000 1.7 +++ JavaScript.java 8 Aug 2002 20:47:22 -0000 1.8 @@ -20,13 +20,15 @@ * *******************************************************************************************************************/ import com.meterware.httpunit.HTMLPage; -import com.meterware.httpunit.ScriptEngine; import com.meterware.httpunit.WebForm; import com.meterware.httpunit.WebResponse; import com.meterware.httpunit.WebLink; import com.meterware.httpunit.WebImage; -import com.meterware.httpunit.scripting.SelectionOptions; + +import com.meterware.httpunit.scripting.ScriptingEngine; +import com.meterware.httpunit.scripting.ScriptableDelegate; import com.meterware.httpunit.scripting.SelectionOption; +import com.meterware.httpunit.scripting.SelectionOptions; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; @@ -73,9 +75,9 @@ } - abstract static class JavaScriptEngine extends ScriptableObject implements ScriptEngine { + abstract static class JavaScriptEngine extends ScriptableObject implements ScriptingEngine { - protected com.meterware.httpunit.ScriptableObject _scriptable; + protected ScriptableDelegate _scriptable; public void executeScript( String script ) { @@ -100,7 +102,7 @@ } - void initialize( JavaScriptEngine parent, com.meterware.httpunit.ScriptableObject scriptable ) + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { _scriptable = scriptable; _scriptable.setScriptEngine( this ); @@ -135,10 +137,10 @@ private Object convertIfNeeded( final Object property ) { if (property == null) return NOT_FOUND; - if (!(property instanceof com.meterware.httpunit.ScriptableObject)) return property; + if (!(property instanceof ScriptableDelegate)) return property; try { - return toScriptable( (com.meterware.httpunit.ScriptableObject) property ); + return toScriptable( (ScriptableDelegate) property ); } catch (PropertyException e) { throw new RuntimeException( e.toString() ); } catch (NotAFunctionException e) { @@ -164,7 +166,7 @@ * Converts a scriptable delegate obtained from a subobject into the appropriate Rhino-compatible Scriptable. * This default implementation throws an exception. **/ - Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + Scriptable toScriptable( ScriptableDelegate delegate ) throws PropertyException, NotAFunctionException, JavaScriptException, SAXException { throw new UnsupportedOperationException(); } @@ -197,7 +199,7 @@ } - void initialize( JavaScriptEngine parent, com.meterware.httpunit.ScriptableObject scriptable ) + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { super.initialize( parent, scriptable ); _document = (Document) Context.getCurrentContext().newObject( this, "Document" ); @@ -212,7 +214,7 @@ } - Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) { + Scriptable toScriptable( ScriptableDelegate delegate ) { return null; } @@ -235,7 +237,7 @@ } - void initialize( JavaScriptEngine parent, com.meterware.httpunit.ScriptableObject scriptable ) + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { super.initialize( parent, scriptable ); initializeLinks(); @@ -294,7 +296,7 @@ } - Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + Scriptable toScriptable( com.meterware.httpunit.scripting.ScriptableDelegate delegate ) throws PropertyException, JavaScriptException, NotAFunctionException, SAXException { JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( delegate ) ); element.initialize( this, delegate ); @@ -302,7 +304,7 @@ } - private String getScriptableClassName( com.meterware.httpunit.ScriptableObject delegate ) { + private String getScriptableClassName( ScriptableDelegate delegate ) { if (delegate instanceof WebForm.Scriptable) { return "Form"; } else if (delegate instanceof WebLink.Scriptable) { @@ -310,7 +312,7 @@ } else if (delegate instanceof WebImage.Scriptable) { return "Image"; } else { - throw new IllegalArgumentException( "Unknown ScriptableObject class: " + delegate.getClass() ); + throw new IllegalArgumentException( "Unknown ScriptableDelegate class: " + delegate.getClass() ); } } @@ -332,7 +334,7 @@ } - void initialize( JavaScriptEngine parent, com.meterware.httpunit.ScriptableObject scriptable ) + void initialize( JavaScriptEngine parent, ScriptableDelegate scriptable ) throws JavaScriptException, NotAFunctionException, PropertyException, SAXException { super.initialize( parent, scriptable ); _document = (Document) parent; @@ -369,7 +371,7 @@ } - Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + Scriptable toScriptable( ScriptableDelegate delegate ) throws PropertyException, NotAFunctionException, JavaScriptException, SAXException { final Control control = (Control) Context.getCurrentContext().newObject( this, "Control" ); control.initialize( this, delegate ); @@ -402,7 +404,7 @@ } - Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + Scriptable toScriptable( ScriptableDelegate delegate ) throws PropertyException, JavaScriptException, NotAFunctionException, SAXException { JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( delegate ) ); element.initialize( this, delegate ); @@ -410,11 +412,11 @@ } - private String getScriptableClassName( com.meterware.httpunit.ScriptableObject delegate ) { + private String getScriptableClassName( ScriptableDelegate delegate ) { if (delegate instanceof SelectionOptions) { return "Options"; } else { - throw new IllegalArgumentException( "Unknown ScriptableObject class: " + delegate.getClass() ); + throw new IllegalArgumentException( "Unknown ScriptableDelegate class: " + delegate.getClass() ); } } @@ -433,18 +435,33 @@ } + public void jsSet_length( int length ) { + getDelegate().setLength( length ); + } + + + public void put( int i, Scriptable scriptable, Object object ) { + if (object == null) { + getDelegate().put( i, null ); + } else { + if (!(object instanceof Option)) throw new IllegalArgumentException( "May only add an Option to this array" ); + Option option = (Option) object; + getDelegate().put( i, option.getDelegate() ); + } + } + + private SelectionOptions getDelegate() { return (SelectionOptions) _scriptable; } - Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + Scriptable toScriptable( ScriptableDelegate delegate ) throws PropertyException, JavaScriptException, NotAFunctionException, SAXException { JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, "Option" ); element.initialize( this, delegate ); return element; } - } @@ -455,6 +472,12 @@ } + public void jsConstructor( String text, String value, boolean defaultSelected, boolean selected ) { + _scriptable = WebResponse.newDelegate( "Option" ); + getDelegate().initialize( text, value, defaultSelected, selected ); + } + + public int jsGet_index() { return getDelegate().getIndex(); } @@ -465,6 +488,11 @@ } + public void jsSet_text( String text ) { + getDelegate().setText( text ); + } + + public String jsGet_value() { return getDelegate().getValue(); } @@ -490,8 +518,9 @@ } - private SelectionOption getDelegate() { + SelectionOption getDelegate() { return (SelectionOption) _scriptable; } } + } Index: JavaScriptEngineFactory.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScriptEngineFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JavaScriptEngineFactory.java 5 Aug 2002 18:58:43 -0000 1.1 +++ JavaScriptEngineFactory.java 8 Aug 2002 20:47:22 -0000 1.2 @@ -19,7 +19,7 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ -import com.meterware.httpunit.ScriptingEngineFactory; +import com.meterware.httpunit.scripting.ScriptingEngineFactory; import com.meterware.httpunit.WebResponse; import java.lang.reflect.InvocationTargetException; |