In my Java application I'm using an object-oriented interpreted script language (specified using ANTLR) and would like to use that together with Velocity.
An object in my language is represented by an instance of DataObject, which looks like this (simplified):
public class DataObject {
protected Map<String, Object> properties;
public Map<String, DataEntity> getProperties() {
return properties;
}
public Object getProperty(String name) {
return properties.get(name);
}
}
and the properties of an object instance $foo could be accessed as $foo.bar
Now let's assume I have put $foo into my VelocityContext:
DataObject foo = new DataObject();
velocityContext.put("foo", foo);
As far as I know, I could then access the properties (which reside in DataObject.properties) in velocity in any of these ways:
<span>$foo.getProperties().get('bar')</span>
<span>$foo.getProperties()['bar']</span>
<span>$foo.getProperties().bar</span>
<span>$foo.properties.bar</span>
Now to my main question: Is there a way to change the behavior such that $foo.bar would not address the Java property dataObject.bar, but rather directly dataObject.properties.get("bar"), so that I could use $foo.bar inside Velociy just as I would in my own script language?