Java Reference
In-Depth Information
« IMPORT mindmap»
« IMPORT topic»
« IMPORT relationship»
« DEFINE Main FOR Map»
« EXPAND topic::csv FOR this »
« EXPAND relationship::csvFile FOR this »
« ENDDEFINE »
Note that each «EXPAND» statement explicitly includes FOR this , meaning
that the context of the enclosing «DEFINE» is passed along. Technically, we
could have eliminated FOR this altogether. An alternative is to pass another ele-
ment, such as a list of Topic or Relationship elements. In the following exam-
ple, the Relationship elements are filtered out and passed to a «DEFINE» that
takes a list.
« DEFINE Main FOR Map»
« EXPAND topic::csv»
« FILE title + "-relations.csv"-»
« EXPAND relationship::csv FOR elements.typeSelect(Relationship)-»
« ENDFILE »
« ENDDEFINE »
« DEFINE csv FOR List[mindmap::Relationship]»
« FOREACH this AS relation-»
«relation.name»,«relation.type.toString()»,«relation.source.name»,
«relation.target.name»
« ENDFOREACH »
« ENDDEFINE »
Another option would be to have a «DEFINE» that accepts a single
Relationship element, enabling us to use a FOREACH clause in the «EXPAND»
to iterate over the collection:
« EXPAND relationship::csv FOREACH elements.typeSelect(Relationship)»
« DEFINE csv FOR Relationship»
«relation.name»,«relation.type.toString()»,«relation.source.name»,
«relation.target.name»
« ENDDEFINE »
As you can see, we can accomplish the same result in many ways using
Xpand, as is the case for most languages. Before we describe how to accomplish
this using polymorphism, let's look at the final feature of our «EXPAND» state-
ment: the SEPARATOR .
Search WWH ::




Custom Search