Java Reference
In-Depth Information
« ENDFOREACH »
« ENDFILE »
« ENDDEFINE »
« DEFINE csvFile(String title) FOR List[mindmap::Relationship]»
« FILE title + "-relations.csv"-»
« FOREACH this AS relation-»
«relation.name»,«relation.type.toString()»,«relation.source.name»,
«relation.target.name»
« ENDFOREACH »
« ENDFILE »
« ENDDEFINE »
As you can see, this is not quite polymorphism at its best, but it is a working
example that illustrates the proper dispatching of «DEFINE» statements based on
type—in this case, a list of a particular type. This example also illustrates the use
of parameters: The title from the Map is passed to both MapElement subclass
«DEFINE» blocks for use in creating their output files.
Also note that an empty «DEFINE» for a list of MapElement types is pro-
vided. This seems to be an Xpand limitation; without a «DEFINE» for the super-
class, Xpand could not properly invoke the subclass «DEFINE» blocks.
Even better is the next example, where true polymorphism is used in place of
the explicit typeSelect() filtering. Notice that the FILE statements specify
outlets now. This is because it's possible to set an append attribute to an outlet;
otherwise, each invocation of csvFile would create a new file. Outlets are spec-
ified in the workflow file that invokes this template and are covered in detail
later.
« IMPORT mindmap»
« DEFINE Main FOR Map»
« EXPAND csvFile(title) FOREACH elements-»
« ENDDEFINE »
« DEFINE csvFile(String title) FOR MapElement»
« ENDDEFINE »
« DEFINE csvFile(String title) FOR Topic»
« FILE title + "-topics.csv" TOPIC_OUTLET-»
«name»,«start»,«end»
« ENDFILE »
« ENDDEFINE »
« DEFINE csvFile(String title) FOR Relationship»
« FILE title + "-relations.csv" RELATIONS_OUTLET-»
«name»,«type.toString()»,«source.name»,«target.name»
« ENDFILE »
« ENDDEFINE »
Search WWH ::




Custom Search