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

com.exactpro.sf.configuration.netdumper.NetDumperOptions Maven / Gradle / Ivy

There is a newer version: 3.4.260
Show newest version
/******************************************************************************
 * Copyright 2009-2018 Exactpro (Exactpro Systems Limited)
 *
 * 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 com.exactpro.sf.configuration.netdumper;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.beanutils.BeanUtils;

public class NetDumperOptions implements Cloneable {

    private static final String STORAGE_PREFIX = "netdumper.";
	
    private String rootHost = "0.0.0.0";
    private int rootPort = 6000;
	private boolean enabled;

	public void fillFromMap(Map options) throws Exception {
        for(Entry entry : options.entrySet()) {
            if (entry.getKey().startsWith(STORAGE_PREFIX)) {
				BeanUtils.setProperty(this, entry.getKey().replace(STORAGE_PREFIX, ""), entry.getValue());
			}
		}
	}
	
    @SuppressWarnings("unchecked")
	public Map toMap() throws Exception {

		Map description = BeanUtils.describe(this);
        Map result = new HashMap<>();

        for(Entry entry : description.entrySet()) {
            if(!"class".equals(entry.getKey())) {
				result.put(STORAGE_PREFIX + entry.getKey(), entry.getValue());
			}
		}
		
		return result;
	}
	
    public String getRootUrl() {

        StringBuilder builder = new StringBuilder();

        builder.append("http://")
                .append(rootHost)
                .append(":")
                .append(rootPort);

        return builder.toString();
	}

    public NetDumperOptions clone() {

        NetDumperOptions options = new NetDumperOptions();

        options.setEnabled(enabled);
        options.setRootHost(rootHost);
        options.setRootPort(rootPort);

        return options;
    }

    public String getRootHost() {
        return rootHost;
    }

    public void setRootHost(String rootHost) {
        this.rootHost = rootHost;
    }

    public int getRootPort() {
        return rootPort;
    }

    public void setRootPort(int rootPort) {
        this.rootPort = rootPort;
    }

    public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy