![JAR search and dependency download from the Maven repository](/logo.png)
com.innoq.codeyourmodel.core.dsl.RelationshipSpec.groovy Maven / Gradle / Ivy
package com.innoq.codeyourmodel.core.dsl
import com.innoq.codeyourmodel.core.meta2.Element
import com.innoq.codeyourmodel.core.meta2.Relationship
import groovy.util.logging.Log
@Log
class RelationshipSpec {
String name
String reverseName
ElementSpec from
ElementSpec to
Map attributes = [:]
Map attributeDefinitions = [:]
Relationship init() {
new Relationship(name: name, from: from.element, to: to.element, attributes: attributes)
}
Relationship initReverse() {
new Relationship(name: reverseName, from: to.element, to: from.element, attributes: attributes)
}
RelationshipSpec apply(Closure initClosure) {
log.fine("apply()")
this.with(true, initClosure)
}
void set(String name, Object value) {
log.fine("set('${name}', ${value})")
if (!isAttributeDefined(name, value.class)) {
log.warning("no attribute with name '${name}' and type '${value.class.simpleName}' defined for relationship '${this.from?.elementType?.simpleName}.${this.name}' -> skipped")
return
}
attributes[name] = value
}
private boolean isAttributeDefined(String name, Class type) {
return attributeDefinitions[name] == type
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy