On Mar 23, 9:12 am, Martin Blom <[email protected]> wrote:
> > Thanks for the reply Mark. I tried various versions of this but
> > couldn't get them to work. I'll post code if this is working for
> > everyone else. What I see is that my wrap factory gets invoked if I do
> > like:
>
> > var s = request.getParameter("s");
> > s = String(s);
>
> > But I don't want to force callers to remember that Java strings need
> > to be explicitly converted.
>
> Here's the WrapFactory I use in ESXX:
>
> // Provide a better mapping for primitive types on this context
> WrapFactory wf = new WrapFactory() {
>     �...@override public Object wrap(Context cx, Scriptable scope,
>                                   Object obj, Class<?> static_type) {
>        if (obj instanceof char[]) {
>          return new String((char[]) obj);
>        }
>        else {
>          return super.wrap(cx, scope, obj, static_type);
>        }
>      }
>    };
> wf.setJavaPrimitiveWrap(false);
> cx.setWrapFactory(wf);
>
> I convert char[] into JavaScript strings because of
> java.io.Console.readPassword(). And here's how it behaves:
>
> esxx> javastring=new java.lang.String("A string")
> -> NativeJavaObject:
> -> `A string´
> esxx> typeof javastring
> -> `object´
> esxx> javastring.getClass()
> -> NativeJavaObject:
> -> java.lang.cl...@12452e8:
> -> class java.lang.String
> esxx> javastring.toString()
> -> `A string´
> esxx> typeof javastring.toString()
> -> `string´
>
> Isn't this what you want?
>
> --
> ---- Martin Blom --------------------------- [email protected] ----
> Eccl 1:18                                http://martin.blom.org/

Definitely what I want, it's just not working that way for me. Maybe
I'm not passing my custom wrap factory everywhere I need it. I'll keep
investigating. Thanks for the help,
Adam
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to