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

com.anrisoftware.sscontrol.hosts.host.HostArgs Maven / Gradle / Ivy

There is a newer version: 1.0-alpha-4
Show newest version
/*
 * Copyright 2012-2015 Erwin Müller 
 *
 * This file is part of sscontrol-hosts.
 *
 * sscontrol-hosts is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * sscontrol-hosts is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with sscontrol-hosts. If not, see .
 */
package com.anrisoftware.sscontrol.hosts.host;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import com.anrisoftware.sscontrol.core.list.StringToListFactory;
import com.anrisoftware.sscontrol.hosts.api.HostsService;

/**
 * Parses host arguments.
 *
 * @author Erwin Mueller, [email protected]
 * @since 1.0
 */
class HostArgs {

    private static final String ALIAS = "alias";

    private static final String HOST = "host";

    @Inject
    private HostLogger log;

    @Inject
    private StringToListFactory toListFactory;

    String address(HostsService service, Map args) {
        Object address = args.get("address");
        log.checkAddress(service, address);
        return address.toString();
    }

    String hostname(HostsService service, Map args) {
        Object name = args.get(HOST);
        log.checkHostname(service, name);
        return name.toString();
    }

    boolean haveAliases(Map args) {
        return args.containsKey(ALIAS);
    }

    List aliases(HostsService service, Map args) {
        Object alias = args.get(ALIAS);
        log.checkAlias(service, alias);
        List list = toListFactory.create(alias).getList();
        List res = new ArrayList(list.size());
        for (Object o : list) {
            res.add(o.toString());
        }
        return res;
    }

}