This function combines the functionality of checkElementMap()
,
createElementMap()
and putElementsByKeys()
functions at once.
It works the following way:
If the map with the identifier specified in elementMapId
parameter already exists, the function does nothing and just returns the number
of the key/element associations contained in that map.
If the map with such an identifier is not found, the function creates a new one according the following steps.
sourceElements
parameter subquery is executed and the source
element enumeration produced.
keysQuery
parameter
is executed, which produces one or several keys.
elementsQuery
subquery is specified, it is executed as well.
This produces the elements that are actually put in the map:
each newly generated element will be associated with every key generated on the step (4).
elementsQuery
subquery is absent, the currently iterated
source element is put in the map together with every key generated on the step (4).
elementMapId
FlexDoc generator is able to maintain unlimited number of element maps. So, they themselves are stored in a hashtable and accessed using map identifiers as hash keys.
Therefore, any object representing a map identifier should be good enough
to be used as a hashkey. That is, it should have appropriately implemented method
Object.hashCode()
in the implementing Java class.
The simple data types (like String
and Number
) do satisfy this.
However, in certain situations, it might be tricky to find how to express a hashmap
identifier in the form of a simple data type object. (Normally, this would involve
writing some complicated expression that converts everything that identifies a hashmap
into a single long string.)
The HashKey()
function provides a way to solve this problem.
Using it, you can create a compound hashkey object which encloses several
simple ones.
For example, suppose you need to maintain lots of element maps each of which is connected with a certain element and identified with the element's ID plus a "some-methods" string (that's because you may also have a similar set of element maps connected with the same elements but representing "some-fields" instead). Then, you can create identifiers for those element maps using the following call:
HashKey(element.id, "some-methods")
sourceElements
elementsQuery
parameter for more details).
That element enumeration may be produced by a certain "heavy" query, exactly the one whose repeating the entire element map is supposed to avoid. However, note the following.
FlexQuery processor treats each parameter in a function call as a separate subexpression. Those parameter subexpressions are compiled into separate subqueries. When a function is called, the parameter subqueries are not automatically executed before the call. Instead, they are passed to the function implementation. So, it is the function implementation where the parameter subqueries are actually executed and the parameter values are obtained.
Given this, the prepareElementMap()
function is implemented the following way:
elementMapId
parameter and searches
the corresponding element map in the generator table.sourceElements
parameter subquery is executed and a new map
is created.sourceElements
enumeration should be specified
entirely within the parameter subexpression.
For example, the call
prepareElementMap (element.id,
element.findElementsByLPath("Field"), ...)
e = element.findElementsByLPath("Field");
prepareElementMap(element.id, e, ...)
This feature allows you to specify the creation of necessary element maps not only in the initialization expression of the main template (see Template Properties Dialog | Processing | Init/Finish | Template Init Expression), but also in any other location within templates, where an element map may be used to improve performance.
keysQuery
sourceElements
parameter.
The keys subquery should be created using FlexQuery()
function.
It should generate one or many keys for the source element passed as the
generator context element.
The result returned by the subquery may be one of the following:
Object[]
containing keysVector
containing keysnull
value returned by the subquery is interpreted as no keys.
That means, the given source element will not be represented in the element map.
elementsQuery
keysQuery
subquery will be put to
the element map.
The object returned by this query may be:
Enumeration
of elementsnull
value will be treated as no elements.
That is, nothing will be put in the element map on the given iteration.
createElementMap(), checkElementMap(), putElementsByKeys(),
HashKey(), FlexQuery()