Subj : Re: Rhino - general method in JS To : Yossi Bener From : Igor Bukanov Date : Tue Sep 16 2003 06:52 pm Yossi Bener wrote: > I managed to run the method and the last thing (hopefully) I need is to use > a member in the JS > That the method doesn't know about: > > ...... > parametersHash = java.util.HashMap(); > parametersHash.put("host","hover") > parametersHash.put("port","8888") > root = Packages.com.mercury.topaz.fm.execution.DataCollectorsAPI > SS = root.getSiteScopeInstance(); > host = GetMapParam("host","hover","Enter Host Name") > ...... > > Can I use parametersHash inside the GetMapParam() ??? You can make GetMapParam non-static but for that to work to extend the class where you defined GetMapParam from ScriptableObject and use its instance as a scope. When Rhino calls the method, it will try to convert JS this to Java this. Since for global functions JS this == scope you need to have scope that can be cast to you class. The modifid example will be then: ClassThatDefinesFunctions scope = new ClassThatDefinesFunctions(); Context.initStandardObjects(scope, false); // Export the following function to JS String[] names = { "print", "anotherFunction", "GetMapParam" }; try { scope.defineFunctionProperties(names, ClassThatDefinesFunctions.class, ScriptableObject.DONTENUM); } catch (PropertyException e) { throw RuntimeException("Unexpected"); } .... class ClassThatDefinesFunctions extends ScriptableObject { Hashtable hash; public String getClassName() { return "global"; } .... public Object GetMapParam(String paramName) { return hash.get(paramName); } } Regards, Igor .