Search in sources :

Example 1 with DomainBuilder

use of io.vertigo.dynamo.domain.metamodel.DomainBuilder in project vertigo by KleeGroup.

the class DomainDynamicRegistry method createDomain.

private static Domain createDomain(final DefinitionSpace definitionSpace, final DslDefinition xdomain) {
    final String domainName = xdomain.getName();
    final List<String> constraintNames = xdomain.getDefinitionLinkNames("constraint");
    final String type = xdomain.getDefinitionLinkName("dataType");
    final Boolean multiple = (Boolean) xdomain.getPropertyValue(KspProperty.MULTIPLE);
    final Properties properties = extractProperties(xdomain);
    final DomainBuilder domainBuilder;
    if ("DtObject".equals(type)) {
        domainBuilder = Domain.builder(domainName, properties.getValue(DtProperty.TYPE), false);
    } else if ("DtList".equals(type)) {
        domainBuilder = Domain.builder(domainName, properties.getValue(DtProperty.TYPE), true);
    } else {
        final DataType dataType = DataType.valueOf(type);
        domainBuilder = Domain.builder(domainName, dataType, multiple == null ? false : multiple);
        // only primitive can have a formatter
        final boolean hasFormatter = !xdomain.getDefinitionLinkNames("formatter").isEmpty();
        if (hasFormatter) {
            final String formatterName = xdomain.getDefinitionLinkName("formatter");
            final FormatterDefinition formatterDefinition = definitionSpace.resolve(formatterName, FormatterDefinition.class);
            // ---
            domainBuilder.withFormatter(formatterDefinition);
        }
    }
    return domainBuilder.withConstraints(createConstraints(definitionSpace, constraintNames)).withProperties(properties).build();
}
Also used : DomainBuilder(io.vertigo.dynamo.domain.metamodel.DomainBuilder) DataType(io.vertigo.dynamo.domain.metamodel.DataType) Properties(io.vertigo.dynamo.domain.metamodel.Properties) FormatterDefinition(io.vertigo.dynamo.domain.metamodel.FormatterDefinition)

Aggregations

DataType (io.vertigo.dynamo.domain.metamodel.DataType)1 DomainBuilder (io.vertigo.dynamo.domain.metamodel.DomainBuilder)1 FormatterDefinition (io.vertigo.dynamo.domain.metamodel.FormatterDefinition)1 Properties (io.vertigo.dynamo.domain.metamodel.Properties)1