I have a class MyResource which implements Resource and can be adapted to a ValueMap. A custom MyResourceProvider serves up the MyResources as requested. In my esp scripts, I had just been adapting the resource to a Map, then accessing the properties through that. But, I'd like to use MyResource.

If I try to adaptTo(MyResource), the adapt succeeds (I see debug from MyResource.adaptTo() and I have a non-null javascript object upon return), but it has no methods or properties.

So, I started writing some debug code to investigate what was going on.

This is the debugging pre-amble in my html.esp...

<%
log.debug("Original Resource: " + resource); // resource displayed as the resource path
        // this loop produces no output
        for (i in resource) {
                log.debug("\t" + i);
        }
log.debug("resource.getPath: " + resource.getPath()); // method call succeeds, resource path displayed
        
        var resourceObject = resource.getObject();
log.debug("resourceObject: " + resourceObject); // resourceObject displays as the resource path
        // this loop produces no output
        for (i in resourceObject) {
                log.debug("\t" + i);
        }
        
        var valueMap = resource.adaptTo(Packages.java.util.Map);
log.debug("ValueMap: " + valueMap); // valueMap displays as a java object instance
        // this loop shows all the expected methods and fields
        for (i in valueMap) {
                log.debug("\t" + i);
        }
log.debug("valueMap.name: " + valueMap.get("name")); // this succeeds, displaying the correct name value

var asString = resource.adaptTo(Packages.java.lang.String); // adapting to String produces MyResource's toString() log.debug("asString: " + asString); // produces the expected MyResource.toString() value
        // this loop produces no output
        for (i in asString) {
                log.debug("\t" + i);
        }

        var myResource = resource.adaptTo(Packages.example.MyResource);
log.debug("MyResource: " + myResource); // myResource displayed as resource path
        // this loop produces no output
        for (i in myResource) {
                log.debug("\t" + i);
        }
        
%>

It looks like MyResource is getting wrapped in a ScriptableResource instead of just being converted into a javascript object. Is that right? How can I get a javascript object equivalent of MyResource?

Confused,
Andreas

Reply via email to