From: Marc P. <ma...@an...> - 2003-04-20 12:12:28
|
Hiya, Does anybody know the best way to enforce that an "RValue" directive arg is a Variable? In my (now working) #newobject directive I have the following optional syntax: #newobject $newobj inherits $baseobj (Which makes $newobj return properties from $baseobj if the property is not defined on $newobj). Anyway, $baseobject has to be a compatible object type - an RValue but also a WebMacroObject or perhaps a java.util.Map. I can enforce this at evaluation time with instanceof but at build time, can how do I force that it is a Variable and not a literal or inline array? As separate issue, writing this has made me realising something interesting - that I probably shouldn't do... I could make it "inherit" from -any- Variable even application-supplied custom objects. This would be a weird kind of "runtime inheritance" but only for properties, not method calls. This would just require that if the property X is not defined on the referenced WebMacroObject, it will use introspection to read the property from the "ancestor" object if any. i.e. ...using #bean to demonstrate custom class in context...: #bean $mybaseObj "com.mycompany.MyObject" #set $mybaseObject.SomeProperty = "something" #newobject $wmObj inherits $mybaseObj The value is: $wmObj.SomeProperty ......Which would show "something" of course. Not rocket science, but it might be a useful facility... effectively applying a property "decorator" pattern to objects already in the context, such as adding name properties. -- Marc Palmer (Wangjammer5) http://www.wangjammers.org Java Consultants |