Subj : RE: Integrating Java Maps in Rhino To : netscape.public.mozilla.jseng From : Jan Grant Date : Wed May 11 2005 03:57 pm On Wed, 11 May 2005, Rod Macpherson wrote: > Here is another way of stating the problem. > > > > We can dynamically add properties to a JavaScript object at will. How > can we translate the key/value pairs in a Java Map to a set of > properties on a JavaScript Object? The objective being the ability to > use foo.bar syntax in JavaScript versus foo.get( "bar" ). This is reasonably doable. Look at org.mozilla.javascript.WrapFactory: in particular, wrapAsJavaObject. This is called to wrap java objects that don't fall into other categories that are already special-cased, and just slaps a NativeJavaObject around. You can subclass the WrapFactory and override this method; then install the result using org.mozilla.javascript.Context #setWrapFactory(WrapFactory) A NativeJavaMap implementation is pretty straightforward: see NativeJavaObject for hints, and the Rhino documentation on java host objects: there are only a few methods you need to implement, since a java Map is very close indeed to a javascript object. (The trick is to remember to wrap objects on the way out of the map, and to unwrap them on the way back in.) Hope this is a sufficient pointer (don't have time to write the code right now) - Cheers, jan -- jan grant, ILRT, University of Bristol. http://www.ilrt.bris.ac.uk/ Tel +44 (0)117 9287088 (with luck) http://ioctl.org/jan/ It's a sad fact that the word "semantics" seems to have lost all meaning. .