On Tue, Dec 29, 2009 at 2:08 PM, Daryl Stultz <[email protected]> wrote:

> That's similar to what I want to do. My host object would be generic with
> no properties, just the inner POJO delegate. A call to get/put would cause
> the host object to use reflection to access the appropriate getter/setter in
> the delegate (or in a subclass of the host object).
>

I'm currently experimenting with the idea of putting my domain object into
the prototype. Consider this:

// my java domain class
public class DomainEntity {

public void save() {
System.out.println("DomainEntity.save()");
}
 public void delete() {
System.out.println("DomainEntity.delete()");
}
}

// my Java Host object wrapper
public class HostEntity extends ScriptableObject {
 public HostEntity() {
super();
DomainEntity proto = new DomainEntity();
NativeJavaObject jsproto = new NativeJavaObject(scope, proto, null);
setPrototype(jsproto);
}
 public void jsFunction_save() {
System.out.println("HostEntity.save()");
}
}

The idea is that methods found in HostEntity will be executed before those
found in DomainEntity.
So this JS code:

var obj = new HostEntity();
obj.save();
obj.delete();

will produce this output:

HostEntity.save()
DomainEntity.delete()

The obvious problem is that "scope" is not available at this line:
NativeJavaObject jsproto = new NativeJavaObject(scope, proto, null);

I don't see any way of getting the "current scope" as one might get the
current context. Am on the right track with what I want to accomplish or is
there a better way. I'm open to hearing how anyone else handles an "API"
layer between their Java domain classes and what is exposed to Javascript.

Thanks.

-- 
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:[email protected]
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to