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

org.cricketmsf.config.AdapterConfiguration Maven / Gradle / Ivy

/*
 * Copyright 2016 Grzegorz Skorupa .
 *
 * 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.cricketmsf.config;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.cricketmsf.Adapter;
import org.cricketmsf.in.InboundAdapter;
import org.cricketmsf.out.OutboundAdapter;

/**
 *
 * @author greg
 */
public class AdapterConfiguration {

    private String name;
    private String interfaceName;
    private String classFullName;
    private String adapterClassName;
    private HashMap properties;

    public AdapterConfiguration() {
        properties = new HashMap<>();
    }

    public AdapterConfiguration(String name, String interfaceName, String className, HashMap properties) {
        this.properties = properties;
        this.name = name;
        this.interfaceName = interfaceName;
        this.classFullName = className;
    }

    public AdapterConfiguration(Adapter adapter) {
        name = adapter.getName();
        classFullName = adapter.getClass().getName();
        if (adapter instanceof InboundAdapter) {
            setProperties(((InboundAdapter) adapter).properties);
        } else if (adapter instanceof OutboundAdapter) {
            setProperties(((OutboundAdapter) adapter).properties);
        }
    }

    public String getProperty(String name) {
        return properties.get(name);
    }

    public void putProperty(String name, String value) {
        properties.put(name, value);
    }

    /*
    public String getInterfaceName() {
        return interfaceName;
    }

    public void setInterfaceName(String interfaceName) {
        this.interfaceName = interfaceName;
    }
     */
    /**
     * @return the classFullName
     */
    public String getClassFullName() {
        return classFullName;
    }

    /**
     * @param classFullName the classFullName to set
     */
    public void setClassFullName(String classFullName) {
        this.classFullName = classFullName;
    }

    /**
     * @return the properties
     */
    public HashMap getProperties() {
        return properties;
    }

    /**
     * @param properties the properties to set
     */
    public void setProperties(HashMap properties) {
        this.properties = properties;
    }

    /**
     * @return the name
     */
    public String getName() {
        if (name == null || name.isEmpty()) {
            //return getInterfaceName();
            return "";
        } else {
            return name;
        }
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    public void joinProps() {
        HashMap newProperties = new HashMap<>();
        Iterator> it = properties.entrySet().iterator();
        String key;
        String value;
        String tmpValue;
        String tmpKey;
        int i;
        while (it.hasNext()) {
            Map.Entry pair = it.next();
            tmpKey = pair.getKey();
            if (tmpKey.endsWith(".0")) {
                value = properties.get(tmpKey);
                key = tmpKey.substring(0, tmpKey.length() - 2);
                i = 1;
                tmpValue = properties.get(key + "." + i);
                while (tmpValue != null) {
                    value = value.concat(tmpValue);
                    i++;
                    tmpValue = properties.get(key + "." + i);
                }
                newProperties.put(key, value);
            } else if (tmpKey.indexOf(".") > 0) {
                // do nothing
            } else if (tmpKey.indexOf(".") == 0) {
                // do nothing - property name starting from "."
            } else {
                newProperties.put(tmpKey, properties.get(tmpKey));
            }
        }
        properties = newProperties;
    }

    /**
     * @return the interfaceName
     */
    public String getInterfaceName() {
        return interfaceName;
    }

    /**
     * @param interfaceName the interfaceName to set
     */
    public void setInterfaceName(String interfaceName) {
        this.interfaceName = interfaceName;
    }

    /**
     * @return the adapterClassName
     */
    public String getAdapterClassName() {
        if(null==adapterClassName){
            return getClassFullName();
        }
        return adapterClassName;
    }

    /**
     * @param adapterClassName the adapterClassName to set
     */
    public void setAdapterClassName(String adapterClassName) {
        this.adapterClassName = adapterClassName;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy