Search in sources :

Example 6 with FormatterDefinition

use of io.vertigo.dynamo.domain.metamodel.FormatterDefinition 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

FormatterDefinition (io.vertigo.dynamo.domain.metamodel.FormatterDefinition)6 Test (org.junit.Test)5 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)3 FormatterDefault (io.vertigo.dynamox.domain.formatter.FormatterDefault)3 FormatterNumber (io.vertigo.dynamox.domain.formatter.FormatterNumber)2 DataType (io.vertigo.dynamo.domain.metamodel.DataType)1 DomainBuilder (io.vertigo.dynamo.domain.metamodel.DomainBuilder)1 Properties (io.vertigo.dynamo.domain.metamodel.Properties)1