From: <Web...@St...> - 2004-04-05 17:41:15
|
On Sun, 4 Apr 2004, Eric Ridge wrote: | On Apr 4, 2004, at 8:58 PM, Endre St=F8lsvik wrote: | > It=B4s getting clearer.. | > | > When I make a Macro, and shove this thing into the context as "Rock", | > when | > I do $Rock, or $Rock.roll, what happens?? This is, I assume, the most | > used way to use Macro? | | If you initially called Template.write(out, context), then the .write() | method is getting called in your $Rock Macro. And that method calls | it's .evaluate() method to get the value to write: | | public Object evaluate(Context c) { return "Rock"; } | public void write(FastWriter fw, Context c) { | fw.write(this.evaluate(c).toString()); } | | That's how it works. This is getting clearer - but why is "evaluate" there in the first place, then? Macro is an iface, right? Why are there two methods, if the write method is the only method called -from the framework- in any case? It seems like evaluate is just there as a "guide" to how -I- should implemen= t write()?? "You should invoke evaluate(...)" - why? I can evaluate -and- write to the writer in one go, that=B4s how brilliant I am..! ;-) | | If you call $Rock.roll, then you're simply asking for the "roll" | property of the Rock macro (which could be a field, a method, or a | generic .get() method)... whose .toString() value gets output to the | template. That=B4s what I expected - it then just falls back to "normal property traversal" stuff, as with any Object put in the context, right? Thanks for shedding light on this.. Endre. |