/*-
 * ~~~~~~licensing~~~~~~
 * template
 * ==========
 * Copyright (C) 2020 - 2021 EmDev LLC
 * ==========
 * 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.
 * ~~~~~~/licensing~~~~~~
 */
package ru.entaxy.esb.system.core.template;

import org.osgi.framework.BundleContext;

import java.net.URL;
import java.util.Map;

public class TemplateImpl implements Template {

    //    необходим для создания нескольких разных типов коннекторов на основе одного шаблона
    private String templateName;
    private String templateFileName;
    private URL templateLocation;
    private Map<String, String> params;
    private BundleContext bundleContext;

    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }

    public void setParams(Map<String, String> params) {
        this.params = params;
    }

    public void setTemplateFileName(String templateFileName) {
        this.templateFileName = templateFileName;
    }

    @Override
    public String getTemplateName() {
        return templateName;
    }

    @Override
    public URL getTemplateLocation() {
        return templateLocation;
    }

    @Override
    public Map<String, String> getParams() {
        return params;
    }

    @Override
    public String getTemplateFileName() {
        return templateFileName == null || templateFileName.isEmpty() ? templateName : templateFileName;
    }

    @Override
    public void setBundleContext(BundleContext bundleContext) {
        this.bundleContext = bundleContext;
        this.templateLocation = bundleContext.getBundle().getEntry("/template/");
    }
}
