attributeHasMetaData (metaDataKey)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. list-table::
:widths: 20 80
:header-rows: 0
:class: tight-table
* - Category
- metadata functions
* - Signature
- attributeHasMetaData(String metadataKey) : boolean
* - Description
- Checks if the model attribute in the context has a certain metadata key.
* - Arguments
- metaDataKey: key of metadata to check for existence
* - Returns
- - true if the model attribute in the context has the metadata key,
- false if the model attribute in the context does not have the metadata key.
* - Exceptions
- .. error::
This function raises a *No model attribute in context* exception when the context does not contain a model attribute.
* - Example
- The following example shows a code instruction that generates a Java class for each object,
with a Java field that is transient for each attribute that has metadata *transient*.
Given the input shown in the input section below CodeComposer will generate the field only for attribute *exampleAttribute2* as shown in the output section below.
**Input**
.. code-block:: xml
:caption: src/codeinstruction/examples/example-code-instruction-simple-entity-foreach-attribute-and-attribute-has-meta-data.xml
:name: AttributeHasMetaData_CodeInstruction
:linenos:
:emphasize-lines: 12, 13
${attribute.type}
.. code-block:: xml
:caption: src/model/model.xml
:name: AttributeHasMetaData_Model
:linenos:
:emphasize-lines: 7, 8, 12
**Output**
.. code-block:: java
:caption: src/main/java/io/metafactory/codecomposer_reference/entities/simple/ExampleObject1SimpleEntity.java
:name: AttributeHasMetaData_Output1
:linenos:
:emphasize-lines: 6
package io.metafactory.codecomposer_reference.entities.simple;
public class ExampleObject1SimpleEntity
{
private String exampleAttribute1;
private transient Long exampleAttribute2;
}