Search in sources :

Example 6 with DslEntityField

use of io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityField 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 DslEntityField

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

the class DslDefinitionBuilder method addPropertyValue.

/**
 * @param fieldName Name of the field
 * @param value Valeur de la propriété
 * @return this builder
 */
public DslDefinitionBuilder addPropertyValue(final String fieldName, final Object value) {
    final DslEntityField dslEntityField = entity.getField(fieldName);
    Assertion.checkState(dslEntityField.getType().isProperty(), "expected a property on {0}", fieldName);
    // ----
    entity.getPropertyType(fieldName).checkValue(value);
    propertyValueByFieldName.put(dslEntityField, value);
    return this;
}
Also used : DslEntityField(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityField)

Aggregations

DslEntityField (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityField)7 PegChoice (io.vertigo.commons.peg.PegChoice)1 PegRule (io.vertigo.commons.peg.PegRule)1 DslEntity (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity)1 DslEntityLink (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityLink)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1