Search in sources :

Example 6 with DslEntity

use of io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity in project vertigo by KleeGroup.

the class DslDefinitionBodyRule method createMainRule.

private static PegRule<List<Object>> createMainRule(final DslEntity entity) {
    Assertion.checkNotNull(entity);
    final List<String> attributeNames = new ArrayList<>();
    final List<PegRule<?>> innerDefinitionRules = new ArrayList<>();
    for (final DslEntityField dslEntityField : entity.getFields()) {
        attributeNames.add(dslEntityField.getName());
        final DslEntity dslEntity;
        if (dslEntityField.getType() instanceof DslEntity) {
            dslEntity = DslEntity.class.cast(dslEntityField.getType());
        } else if (dslEntityField.getType() instanceof DslEntityLink) {
            dslEntity = DslEntityLink.class.cast(dslEntityField.getType()).getEntity();
        } else {
            // case property
            dslEntity = null;
        }
        if (dslEntity != null) {
            innerDefinitionRules.add(new DslInnerDefinitionRule(dslEntityField.getName(), dslEntity));
        }
    }
    final DslPropertyDeclarationRule propertyDeclarationRule = new DslPropertyDeclarationRule(entity.getPropertyNames());
    final DslDefinitionEntryRule xDefinitionEntryRule = new DslDefinitionEntryRule(attributeNames);
    final PegRule<PegChoice> firstOfRule = PegRules.choice(// 0
    propertyDeclarationRule, // 1
    xDefinitionEntryRule, // 2,
    PegRules.choice(innerDefinitionRules), SPACES);
    final PegRule<List<PegChoice>> manyRule = PegRules.zeroOrMore(firstOfRule, false);
    return PegRules.sequence(OBJECT_START, SPACES, // 2
    manyRule, SPACES, OBJECT_END);
}
Also used : DslEntityLink(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityLink) ArrayList(java.util.ArrayList) PegChoice(io.vertigo.commons.peg.PegChoice) PegRule(io.vertigo.commons.peg.PegRule) DslEntity(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity) DslEntityField(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityField) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with DslEntity

use of io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity in project vertigo by KleeGroup.

the class DsValidator method check.

static void check(final DslDefinition definition) {
    Assertion.checkNotNull(definition);
    // -----
    final DslEntity myEntity = definition.getEntity();
    // 1.On vérifie la définition par rapport à la métadéfinition
    // 1.1 on vérifie les propriétés.
    final Set<String> propertyNames = definition.getPropertyNames();
    final Set<String> entityPropertyNames = myEntity.getPropertyNames();
    // 1.1.1 on vérifie que toutes les propriétés sont déclarées sur le
    // métamodèle
    checkProperties(definition, propertyNames, entityPropertyNames);
    // 1.1.2 on vérifie les propriétés obligatoires
    checkMandatoryProperties(definition, myEntity, propertyNames, entityPropertyNames);
    // 1.1.3 on vérifie les types des propriétés déclarées
    for (final String propertyName : propertyNames) {
        myEntity.getPropertyType(propertyName).checkValue(definition.getPropertyValue(propertyName));
    }
    // 1.2 on vérifie les définitions composites (sous définitions).
    for (final DslDefinition child : definition.getAllChildDefinitions()) {
        check(child);
    }
// 1.3 on vérifie les définitions références.
// TODO vérifier les définitions références
}
Also used : DslEntity(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity)

Aggregations

DslEntity (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity)7 DslDefinitionBodyRule (io.vertigo.dynamo.plugins.environment.loaders.kpr.rules.DslDefinitionBodyRule)3 Test (org.junit.Test)3 DslDefinitionBuilder (io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinitionBuilder)2 DslDefinitionBody (io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody)2 PegChoice (io.vertigo.commons.peg.PegChoice)1 PegNoMatchFoundException (io.vertigo.commons.peg.PegNoMatchFoundException)1 PegRule (io.vertigo.commons.peg.PegRule)1 DslDefinition (io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition)1 DslEntityField (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityField)1 DslEntityLink (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityLink)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1