/**
 * Copyright (c) 2016, 2017 Bosch Software Innovations GmbH.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Bosch Software Innovations GmbH - initial creation
 */

package org.eclipse.hono.config;

import java.util.Objects;

import org.eclipse.hono.util.Constants;

/**
 * Common configuration properties required for accessing an AMQP 1.0 container.
 */
public final class ClientConfigProperties extends AbstractConfig {

    private String name;
    private String host = "localhost";
    private int port = Constants.PORT_AMQPS;
    private String username;
    private char[] password;
    private String amqpHostname;

    /**
     * Gets the name or literal IP address of the host that the client is configured to connect to.
     * 
     * @return The host name.
     */
    public String getHost() {
        return host;
    }

    /**
     * Sets the name or literal IP address of the host that the client should connect to.
     * 
     * @param host The host name or IP address.
     * @throws NullPointerException if host is {@code null}.
     */
    public void setHost(final String host) {
        this.host = Objects.requireNonNull(host);
    }

    /**
     * Gets the TCP port of the server that this client is configured to connect to.
     * <p>
     * The default value of this property is {@link Constants#PORT_AMQPS}.
     * 
     * @return The port number.
     */
    public int getPort() {
        return port;
    }

    /**
     * Sets the TCP port of the server that this client should connect to.
     * <p>
     * The default value of this property is {@link Constants#PORT_AMQPS}.
     * 
     * @param port The port number.
     * @throws IllegalArgumentException if port &lt; 1000 or port &gt; 65535.
     */
    public void setPort(final int port) {
        if (isValidPort(port)) {
            this.port = port;
        } else {
            throw new IllegalArgumentException("invalid port number");
        }
    }

    /**
     * Gets the user name that is used when authenticating to the Hono server.
     * 
     * @return The user name or {@code null} if not set.
     */
    public String getUsername() {
        return username;
    }

    /**
     * Sets the user name to use when authenticating to the Hono server.
     * <p>
     * If not set then this client will not try to authenticate to the server.
     * 
     * @param username The user name.
     */
    public void setUsername(final String username) {
        this.username = username;
    }

    /**
     * Gets the password that is used when authenticating to the Hono server.
     * 
     * @return The password or {@code null} if not set.
     */
    public String getPassword() {
        if (password == null) {
            return null;
        } else {
            return String.valueOf(password);
        }
    }

    /**
     * Sets the password to use in conjunction with the user name when authenticating to the Hono server.
     * <p>
     * If not set then this client will not try to authenticate to the server.
     * 
     * @param password The password.
     */
    public void setPassword(final String password) {
        if (password != null) {
            this.password = password.toCharArray();
        } else {
            this.password = null;
        }
    }

    /**
     * Gets the name being indicated as the <em>container-id</em> in the client's AMQP <em>Open</em> frame.
     * 
     * @return The name or {@code null} if no name has been set.
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name to indicate as the <em>container-id</em> in the client's AMQP <em>Open</em> frame.
     * 
     * @param name The name to set.
     */
    public void setName(final String name) {
        this.name = name;
    }

    /**
     * Gets the name being indicated as the <em>hostname</em> in the client's AMQP <em>Open</em> frame.
     * 
     * @return The host name or {@code null} if no host name has been set.
     */
    public String getAmqpHostname() {
        return amqpHostname;
    }

    /**
     * Sets the name to indicate as the <em>hostname</em> in the client's AMQP <em>Open</em> frame.
     * 
     * @param amqpHostname The host name to set.
     */
    public void setAmqpHostname(String amqpHostname) {
        this.amqpHostname = amqpHostname;
    }
}

@@ -587,22 +587,16 @@
 %0Apublic 
-final 
 class Cl
@@ -641,16 +641,16 @@
 onfig %7B%0A
+
 %0A    pri
@@ -1000,32 +1000,38 @@
   */%0A    public 
+final 
 String getHost()
@@ -1287,32 +1287,38 @@
   */%0A    public 
+final 
 void setHost(fin
@@ -1630,16 +1630,22 @@
  public 
+final 
 int getP
@@ -1982,32 +1982,38 @@
   */%0A    public 
+final 
 void setPort(fin
@@ -2358,32 +2358,38 @@
   */%0A    public 
+final 
 String getUserna
@@ -2655,32 +2655,38 @@
   */%0A    public 
+final 
 void setUsername
@@ -2913,32 +2913,38 @@
   */%0A    public 
+final 
 String getPasswo
@@ -3346,32 +3346,38 @@
   */%0A    public 
+final 
 void setPassword
@@ -3754,32 +3754,38 @@
   */%0A    public 
+final 
 String getName()
@@ -3982,32 +3982,38 @@
   */%0A    public 
+final 
 void setName(fin
@@ -4277,16 +4277,22 @@
  public 
+final 
 String g
@@ -4511,32 +4511,32 @@
 to set.%0A     */%0A
-
     public void 
@@ -4530,16 +4530,22 @@
  public 
+final 
 void set

Allow ClientConfigProperties to be extended.