objectHasMetaData (metaDataKey)

objectHasMetaData (metaDataKey)

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

src/codeinstruction/examples/example-code-instruction-simple-service-object-has-meta-data.xml
 1<java_package xmlns="https://metafactory.io/xsd/v1/java-codeinstruction"
 2              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3              xsi:schemaLocation="https://metafactory.io/xsd/v1/java-codeinstruction https://metafactory.io/xsd/v1/java-codeinstruction.xsd"
 4              name="${pattern.property.java.package.base}.services.simple"
 5              path="${pattern.property.java.main.directory}"
 6              package="domain_model"
 7>
 8  <class  name="${createSimpleServiceClassName(${object.name})}"
 9          foreach="object"
10          condition="${objectHasMetaData(createSimpleService)}">
11  </class>
12</java_package>
src/model/model.xml
 1<?xml version="1.0" encoding="UTF-8"?>
 2<model xmlns="https://metafactory.io/xsd/v1/model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://metafactory.io/xsd/v1/model https://metafactory.io/xsd/v1/model.xsd">
 3  <package name="domain_model">
 4        <object name="ExampleObject1">
 5          <metadata>
 6                        <createSimpleService></createSimpleService>
 7          </metadata>
 8        </object>
 9        <object name="ExampleObject2">
10          <metadata>
11                        <createSimpleService>false</createSimpleService>
12          </metadata>
13        </object>
14        <object name="ExampleObject3">
15          <metadata>
16                        <createSimpleService>true</createSimpleService>
17          </metadata>
18        </object>
19</model>

Output

src/main/java/io/metafactory/codecomposer_reference/services/simple/ExampleObject1SimpleService.java
1package io.metafactory.codecomposer_reference.services.simple;
2
3public class ExampleObject1SimpleService {
4
5}
src/main/java/io/metafactory/codecomposer_reference/services/simple/ExampleObject2SimpleService.java
1package io.metafactory.codecomposer_reference.services.simple;
2
3public class ExampleObject2SimpleService {
4
5}
src/main/java/io/metafactory/codecomposer_reference/services/simple/ExampleObject3SimpleService.java
1package io.metafactory.codecomposer_reference.services.simple;
2
3public class ExampleObject3SimpleService {
4
5}