referenceHasMetaData (metaDataKey, metadataValue)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. list-table::
:widths: 20 80
:header-rows: 0
:class: tight-table
* - Category
- metadata functions
* - Signature
- referenceHasMetaData(String metadataKey, String metadataValue) : boolean
* - Description
- Checks if the model reference in the context has a certain metadata key with a certain metadata value.
* - Arguments
- - metadataKey: key of metadata to check for existence
- metadataValue: value of metadata to check for existence
* - Returns
- - true if the model reference in the context has the metadata key with the given metadata value
- false if the model reference in the context does not have the metadata key or has the metadata
key with a metadata value different from the given metadata value.
* - Exceptions
- .. error::
This function raises a *No model reference in context* exception when the context does not contain a model reference.
* - Example
- The following example shows a code instruction that generates a Java class for each object,
and conditionally generates a comment for a Java field for each reference that has metadata *bar* with value *baz*.
Given the input in the input section below CodeComposer will generate the file(s) as shown in the output section below.
**Input**
.. code-block:: xml
:caption: src/codeinstruction/examples/example-code-instruction-simple-entity-foreach-reference-and-reference-has-meta-data-with-value.xml
:name: ReferenceHasMetaDataWithValue_CodeInstruction
:linenos:
:emphasize-lines: 13, 15
${fmsnippet.examples.exampleCommentForReferenceThatHasMetaDataBarWithValueBaz}
.. code-block::
:caption: src/snippet/examples/exampleCommentForReferenceThatHasMetaDataBarWithValueBaz.ftl
:name: ReferenceHasMetaDataWithValue_Snippet1
:linenos:
:emphasize-lines: 3
<#if !(modelReference)??> <#stop "modelReference not found in context" >#if>
This is an example comment for a reference with meta data bar with value baz: ${modelReference.type} ${modelReference.name}.
.. code-block:: xml
:caption: src/model/model.xml
:name: ReferenceHasMetaDataWithValue_Model
:linenos:
:emphasize-lines: 20
**Output**
.. code-block:: java
:caption: src/main/java/io/metafactory/codecomposer_reference/entities/simple/ExampleObject4SimpleEntity.java
:name: ReferenceHasMetaDataWithValue_Output1
:linenos:
:emphasize-lines: 22
package io.metafactory.codecomposer_reference.entities.simple;
/**
* This is an example comment for a reference with any multiplicity: ExampleObject1 exampleObject1.
* This is an example comment for a reference with multiplicity 0..1 or 1..1: ExampleObject1 exampleObject1.
*/
private ExampleObject1SimpleEntity exampleObject1;
/**
* This is an example comment for a reference with any multiplicity: ExampleObject2 exampleObject2.
* This is an example comment for a reference with multiplicity 0..1 or 1..1: ExampleObject2 exampleObject2.
* This is an example comment for a reference with meta data bar: ExampleObject2 exampleObject2.
*/
private ExampleObject2SimpleEntity exampleObject2;
/**
* This is an example comment for a reference with any multiplicity: ExampleObject3 exampleObject3.
* This is an example comment for a reference with multiplicity 0..1 or 1..1: ExampleObject3 exampleObject3.
* This is an example comment for a reference with meta data bar: ExampleObject3 exampleObject3.
* This is an example comment for a reference with meta data bar with value baz: ExampleObject3 exampleObject3.
*/
private ExampleObject3SimpleEntity exampleObject3;