public Object visitAttribute()

in data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/parser/ModelConvertingLogstashVisitor.java [84:135]


    public Object visitAttribute(final LogstashParser.AttributeContext attributeContext) {
        LogstashValueType logstashValueType = null;
        Object value = null;

        if(attributeContext.value() == null)
            return null;

        if (attributeContext.value().getChild(0) instanceof LogstashParser.ArrayContext) {
            logstashValueType = LogstashValueType.ARRAY;
            value = visitArray(attributeContext.value().array());
        }
        else if (attributeContext.value().getChild(0) instanceof LogstashParser.HashContext) {
            logstashValueType = LogstashValueType.HASH;
            value = visitHash(attributeContext.value().hash());
        }
        else if (attributeContext.value().getChild(0) instanceof LogstashParser.PluginContext) {
            throw new LogstashParsingException("plugins are not supported in an attribute");
        }
        else if (attributeContext.value().NUMBER() != null && attributeContext.value().getText().equals(attributeContext.value().NUMBER().toString())) {
            logstashValueType = LogstashValueType.NUMBER;
            try {
                value = Integer.parseInt(attributeContext.value().getText());
            } catch (NumberFormatException e) {
                try {
                    value = Double.parseDouble(attributeContext.value().getText());
                } catch (NumberFormatException exception) {
                    throw new LogstashParsingException("NUMBER types must be either Integer or Double");
                }
            }
        }
        else if (attributeContext.value().BAREWORD() != null && attributeContext.value().getText().equals(attributeContext.value().BAREWORD().toString())) {
            logstashValueType = LogstashValueType.BAREWORD;
            value = attributeContext.value().getText();
            if (value.toString().equals("true") || value.toString().equals("false")) {
                value = Boolean.parseBoolean(value.toString());
            }
        }
        else if (attributeContext.value().STRING() != null && attributeContext.value().getText().equals(attributeContext.value().STRING().toString())) {
            logstashValueType = LogstashValueType.STRING;
            value = normalizeText(attributeContext.value().getText());
        }

        final LogstashAttributeValue logstashAttributeValue =  LogstashAttributeValue.builder()
                .attributeValueType(logstashValueType)
                .value(value)
                .build();

        return LogstashAttribute.builder()
                .attributeName(normalizeText(attributeContext.name().getText()))
                .attributeValue(logstashAttributeValue)
                .build();
    }