All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cattleframework.cloud.config.AbstractDataSource Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.cattleframework.cloud.config;

import org.cattleframework.cloud.config.property.PropertyDelegate;
import org.cattleframework.cloud.constants.RuleType;
import org.cattleframework.exception.CommonException;

/**
 * 数据源抽象
 * 
 * @author orange
 *
 * @param  类的类型
 */
public abstract class AbstractDataSource implements ReadableDataSource {

    private final String name;

    private final RuleType type;

    private final PropertyDelegate propertyDelegate;

    private final Converter converter;

    public AbstractDataSource(String name, RuleType type, PropertyDelegate propertyDelegate,
	    Converter converter) {
	this.name = name;
	this.type = type;
	this.propertyDelegate = propertyDelegate;
	this.converter = converter;
    }

    public String getName() {
	return name;
    }

    public RuleType getType() {
	return type;
    }

    @Override
    public T loadConfig() throws CommonException {
	return loadConfig(readSource());
    }

    @Override
    public PropertyDelegate getPropertyDelegate() {
	return propertyDelegate;
    }

    protected Converter getConverter() {
	return converter;
    }

    private T loadConfig(String config) {
	return converter.convert(config);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy