cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ricardo Rocha" <rica...@apache.org>
Subject Unwrapping native java objects in FOM session.setAttribute()
Date Sun, 23 Nov 2003 20:57:16 GMT
So far FOM session method setAttribute(name, value) stored the given value
directly:

    // FOM_Cocoon.FOM_Session
    public void jsFunction_setAttribute(String name, Object value) {
        session.setAttribute(name, value);
    }

Since this method is actually treated as a Javascript function, the value
passed by Rhino is always a Javascript object.

This works fine when the value is to be retrieved later by Flowscript code.

It's not fine, though, when the value being stored is actually a *Java*
object to be retrieved later by *Java* code.

An example is when -from Flowscript- you store an XMLizable object in the
session and then invoke a pipeline headed by a SessionAttributeGenerator. In
this case, the generator gets an instance of
org.mozilla.javascript.NativeJavaObject (which is rendered as text) instead
of the expected org.apache.excalibur.xml.sax.XMLizable.

I've changed this method so that is unwraps Java objects prior to storing
them in the "real" session object:

    public void jsFunction_setAttribute(String name, Object value) {
        if (value instanceof NativeJavaObject) {
            value = ((NativeJavaObject) value).unwrap();
        }
        session.setAttribute(name, value);
    }

If the attribute is later recalled from Flowscript code Rhino will wrap the
value back to a Javascript object representation.

I hope this doesn't break anything...

Ricardo




Mime
View raw message