getMetaDataFromObject (metaDataKey, defaultValue)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. list-table::
:widths: 20 80
:header-rows: 0
:class: tight-table
* - Category
- metadata functions
* - Signature
- getMetaDataFromObject(String metadataKey, String defaultValue) : String
* - Description
- Gets metadata from the model object in the context with a certain metadata key.
* - Arguments
- - metaDataKey: key of metadata to get from the model object
- defaultValue: value to return when model the object does not have metadata with metadata key
* - Returns
- - metadata value of the model object in the context if it has the metadata key
- the provided default value if the model object in the context does not have the metadata key.
.. note::
When the model object in the context does not have the metadata key,
CodeComposer will add the metadata key to the model object with the default value.
* - 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, with a Java
field named serialVersionUID.
Given the input shown in the input section below CodeComposer will generate the field with value *1*
for *ExampleObject1* and value *0* (default value) for *ExampleObject2* as shown in the output section below.
**Input**
.. code-block:: xml
:caption: src/codeinstruction/examples/example-code-instruction-simple-entity-foreach-object-and-get-meta-data-from-object.xml
:name: GetMetaDataFromObject_CodeInstruction
:linenos:
:emphasize-lines: 13
Long
${getMetaDataFromObject(serialVersionUID,0)}L
.. code-block:: xml
:caption: src/model/model.xml
:name: GetMetaDataFromObject_Model
:linenos:
:emphasize-lines: 8, 12, 13, 17, 18
**Output**
.. code-block:: java
:caption: src/main/java/io/metafactory/codecomposer_reference/entities/simple/ExampleObject1SimpleEntity.java
:name: GetMetaDataFromObject_Output1
:linenos:
:emphasize-lines: 6
package io.metafactory.codecomposer_reference.entities.simple;
public class ExampleObject1SimpleEntity
{
private Long serialVersionUID = 1L;
}
.. code-block:: java
:caption: src/main/java/io/metafactory/codecomposer_reference/entities/simple/ExampleObject2SimpleEntity.java
:name: GetMetaDataFromObject_Output2
:linenos:
:emphasize-lines: 6
package io.metafactory.codecomposer_reference.entities.simple;
public class ExampleObject2SimpleEntity
{
private Long serialVersionUID = 2L;
}
.. code-block:: java
:caption: src/main/java/io/metafactory/codecomposer_reference/entities/simple/ExampleObject3SimpleEntity.java
:name: GetMetaDataFromObject_Output3
:linenos:
:emphasize-lines: 6
package io.metafactory.codecomposer_reference.entities.simple;
public class ExampleObject3SimpleEntity
{
private Long serialVersionUID = 0L;
}