9.11.
The subgenerators ???_JavaFile??? (which is the same as in Fig. 9.10) and ???_Java??? take
care of the most critical part of the generation process: the generation of the state
machine implementations. To support the possibility to invoke a state machine from
within another state machine in a hierarchical fashion, a recursive structure was
implemented in the ???_JavaFile??? subgenerator. During the generation, when a
reference to a lower-level state machine is encountered, the ???_JavaFile??? subgenerator
will dive to that level and call itself from there.
The task of the ???_Java??? subgenerator is to generate the ?¬?nal Java implementation
for the Logical Watch and Watch Application state machines. An example of such
code can be found in Listing 9.4, which shows the implementation of the Stopwatch
application.
For a comprehensive understanding of the ???_Java??? subgenerator output, let us
study the generated code line by line. As before, a new concrete Watch Application
class is derived from the AbstractWatch Application class (line 1). From here
on, the responsibility for the generated code is distributed among the
???_Variables,??? ???_StateData,??? ???_TransitionData,??? ???_StateDisplayData,??? ???_Actions,???
and ???_DisplayFns??? subgenerators.
The ???_Variables??? and ???_getSet??? subgenerators are responsible for declaring
the identi?¬?ers for actions and display functions to be used later within the
switch??“case structure (lines 3??“7).
Pages:
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396