objectHasMetaData (metaDataKey)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. list-table:: objectHasMetaData (metaDataKey)
:widths: 20 80
:header-rows: 0
:class: tight-table
* - Category
- metadata functions
* - Signature
- objectHasMetaData(String metadataKey) : boolean
* - Description
- check if an object has a certain metadata key
* - Arguments
- metaDataKey: key of metadata to check for existence
* - Returns
- - true if the model object in the context has the metadata key
- false if the model object in the context does not have the metadata key
* - Exceptions
- .. error::
This function raises a *No model object in context* exception when the context does not contain a model object
* - Example
- The following example shows parts of a code instruction that generates a Java class for each object
that has metadata *createSimpleService*.
Given the input shown in the input section below CodeComposer will generate this class for object *ExampleObject1*, *ExampleObject2* and *ExampleObject3* as shown in the output section below.
.. note::
CodeComposer will generate the class for ExampleObject2 even though the createSimpleService metadata value is false in the model.
**Input**
.. code-block:: xml
:caption: src/codeinstruction/examples/example-code-instruction-simple-service-object-has-meta-data.xml
:name: ObjectHasMetaData_CodeInstruction
:linenos:
:emphasize-lines: 10
.. code-block:: xml
:caption: src/model/model.xml
:name: ObjectHasMetaData_Model
:linenos:
:emphasize-lines: 6, 11, 16
**Output**
.. code-block:: java
:caption: src/main/java/io/metafactory/codecomposer_reference/services/simple/ExampleObject1SimpleService.java
:name: ObjectHasMetaData_Output1
:linenos:
:emphasize-lines: 3
package io.metafactory.codecomposer_reference.services.simple;
public class ExampleObject1SimpleService {
}
.. code-block:: java
:caption: src/main/java/io/metafactory/codecomposer_reference/services/simple/ExampleObject2SimpleService.java
:name: ObjectHasMetaData_Output2
:linenos:
:emphasize-lines: 3
package io.metafactory.codecomposer_reference.services.simple;
public class ExampleObject2SimpleService {
}
.. code-block:: java
:caption: src/main/java/io/metafactory/codecomposer_reference/services/simple/ExampleObject3SimpleService.java
:name: ObjectHasMetaData_Output3
:linenos:
:emphasize-lines: 3
package io.metafactory.codecomposer_reference.services.simple;
public class ExampleObject3SimpleService {
}