objectHasMetaData (metadataKey, metadataValue)

Category

metadata functions

Signature

objectHasMetaData(String metadataKey, String metadataValue) : boolean

Description

checks if an object 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 object in the context has the metadata key with the given metadata value

  • false if the model object 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 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 createSpecialService with value true.

Given the input shown in the input section below CodeComposer will generate this class only for object ExampleObject3 as shown in the output section below.

Input

src/codeinstruction/examples/example-code-instruction-special-service-object-has-meta-data-with-value.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.special"
 5              path="${pattern.property.java.main.directory}"
 6              package="domain_model">
 7        <class  name="${createSpecialServiceClassName(${object.name})}"
 8                foreach="object"
 9                condition="${objectHasMetaData(createSpecialService,true)}">
10        </class>
11</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                                <createSpecialService></createSpecialService>
 7                        </metadata>
 8                </object>
 9                <object name="ExampleObject2">
10                        <metadata>
11                                <createSpecialService>false</createSpecialService>
12                        </metadata>
13                </object>
14                <object name="ExampleObject3">
15                        <metadata>
16                                <createSpecialService>true</createSpecialService>
17                        </metadata>
18                </object>
19        </package>
20</model>

Output

src/main/java/io/metafactory/codecomposer_reference/services/special/ExampleObject3SpecialService.java
1package io.metafactory.codecomposer_reference.services.special;
2
3public class ExampleObject3SpecialService {
4
5}