Search in sources :

Example 1 with ValueType

use of org.apache.servicecomb.config.kie.client.model.ValueType in project java-chassis by ServiceComb.

the class KieClient method processValueType.

private Map<String, Object> processValueType(KVDoc kvDoc) {
    ValueType valueType;
    try {
        valueType = ValueType.valueOf(kvDoc.getValueType());
    } catch (IllegalArgumentException e) {
        throw new OperationException("value type not support");
    }
    Properties properties = new Properties();
    Map<String, Object> kvMap = new HashMap<>();
    try {
        switch(valueType) {
            case yml:
            case yaml:
                YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
                yamlFactory.setResources(new ByteArrayResource(kvDoc.getValue().getBytes()));
                return toMap(yamlFactory.getObject());
            case properties:
                properties.load(new StringReader(kvDoc.getValue()));
                return toMap(properties);
            case text:
            case string:
            default:
                kvMap.put(kvDoc.getKey(), kvDoc.getValue());
                return kvMap;
        }
    } catch (Exception e) {
        LOGGER.error("read config failed");
    }
    return Collections.emptyMap();
}
Also used : ValueType(org.apache.servicecomb.config.kie.client.model.ValueType) HashMap(java.util.HashMap) StringReader(java.io.StringReader) YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Properties(java.util.Properties) OperationException(org.apache.servicecomb.config.kie.client.exception.OperationException) OperationException(org.apache.servicecomb.config.kie.client.exception.OperationException)

Aggregations

StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 OperationException (org.apache.servicecomb.config.kie.client.exception.OperationException)1 ValueType (org.apache.servicecomb.config.kie.client.model.ValueType)1 YamlPropertiesFactoryBean (org.springframework.beans.factory.config.YamlPropertiesFactoryBean)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1