|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Best way of extending HopObject functionsHi list,
first of all: feels good to be back (for those who still remember me) (-: I am looking for the best way of extending predefined HopObject functions like get(), getById(), and so on. I need to extend these functions because I want to implement a security layer, which should control access to HopObjects and properties. Yes, even getting and setting properties. This is important to me, as with lots of generic macros, the allow or not allow macro paradigm of Helma is not enough anymore, and implementing security checks in each macro is a no go too. I have two working solutions, but I feel like there are better ways to do it. Approach 1: I changed the helma source and added calls to JS callback functions (HopObject.canGet(), HopObject.canAdd(), HopObject.canWrite(), HopObject.canRead(), ...). This way the predefined HopObject functions are not overridden, but extended in their Java implementation. Works fine, even for getting and setting generic properties, but touches the helma source. Approach2: My second approach is JS based only and does not touch the helma source. I simplified things below. -----global/functions.js----- function get(id) { // do some security checks and eventually return something // ... return this._get(id); } -----Test/functions.js----- function Test() { this._get = this.get; this.get = get; } The overriding get() function is defined in the global space as I only need it once for all prototypes. The constructor of Test does only set one new reference variable per instance. I would however prefer to set the function reference on the prototype, but I did not find a way to do this for Helma prototypes. I also failed to implement generic getter / setter functions in JS. I managed to implement specific ones, but not generic ones. Anyone aware of how to improve the second approach? Kind regards, Daniel _______________________________________________ Helma-user mailing list Helma-user@... http://helma.org/mailman/listinfo/helma-user |
|
|
Re: Best way of extending HopObject functionsGeneric getter/setters are not possible in standard javascript, but I
think support for JSAdapter is built into recent versions that should make it possible for you (not sure, haven't experimented with it). To override the built-ins, what I have ended up doing is just using another type as my base type from which to inherit. Then I don't have to move any existing functions (which I've found is prone to unexpected interactions with the cache) and it's still easy to call the built-ins. HopObject.get.apply(this,arguments) -Joshua _______________________________________________ Helma-user mailing list Helma-user@... http://helma.org/mailman/listinfo/helma-user |
| Free embeddable forum powered by Nabble | Forum Help |