/*
 * Copyright 2009-2010 The MICE Project Team.
 * Licensed under the MICE s.r.l.
 * End User License Agreement
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.micegroup.it/voila/license.html
 */
package it.mice.voila.runtime.mail.beans;

import java.util.ArrayList;
import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Server di posta definiti.
 */
public class MailConfig extends MailBaseBean {
	/**
	 * Serial version UID.
	 */
	private static final long serialVersionUID = 2798621741L;
	/**
	 * Default logger.
	 */
	@SuppressWarnings("unused")
	private static Log logger = LogFactory.getLog(MailConfig.class);
	//
	// Declare entity attributes with accessor methods
	//
	/**
	 * String data type.
	 */
	private String mailConfigId;
	/**
	 * String data type.
	 */
	private String mailConfigDescription;
	/**
	 * String data type.
	 */
	private boolean enabled = true;
	/**
	 * String data type.
	 */
	private String mailNomeHost;
	/**
	 * Code data type.
	 */
	private Integer mailPort;
	/**
	 * String data type. I possibili valori ammessi per la proprietà sono:
	 * <dl>
	 * <dt></dt>
	 * <dd>- Nessuna</dd>
	 * <dt>SSL</dt>
	 * <dd>- SSL</dd>
	 * <dt>TLS</dt>
	 * <dd>- TLS</dd>
	 * <dt>AUTO</dt>
	 * <dd>- Automatica</dd>
	 * </dl>
	 */
	private String mailCrypto;
	/**
	 * Flag data type.
	 */
	private String mailSPA;
	/**
	 * String data type.
	 */
	private String mailUsername;
	/**
	 * String data type.
	 */
	private String mailPassword;
	/**
	 * String data type.
	 */
	private String mailDefaultSubject;
	/**
	 * String data type.
	 */
	private String mailFromAddress;
	/**
	 * String data type.
	 */
	private String mailCcAddress;
	/**
	 * String data type.
	 */
	private String mailBccAddress;
	//
	// entity child attribute declarations
	//
	/**
	 * Riferimento all'entity list: MailTemplate. Ogni occorrenza in questa
	 * entity rappresenta una mail inviabile tramite il sistema SkyCon.
	 */
	private Collection<MailTemplate> theMailTemplate = new ArrayList<MailTemplate>();

	//
	// Constructor declaration
	//
	/**
	 * Costruttore vuoto per MailConfig. Istanzia un nuovo MailConfig
	 * completamente vuoto.
	 */
	public MailConfig() {
		super();
	}

	//
	// getters and setters
	//

	/**
	 * @return the mailConfigId
	 */
	public String getMailConfigId() {
		return mailConfigId;
	}

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

	/**
	 * @return the mailConfigDescription
	 */
	public String getMailConfigDescription() {
		return mailConfigDescription;
	}

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

	/**
	 * @return the enabled
	 */
	public boolean isEnabled() {
		return enabled;
	}

	/**
	 * @param enabled the enabled to set
	 */
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	/**
	 * @return the mailNomeHost
	 */
	public String getMailNomeHost() {
		return mailNomeHost;
	}

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

	/**
	 * @return the mailPort
	 */
	public Integer getMailPort() {
		return mailPort;
	}

	/**
	 * @param mailPort the mailPort to set
	 */
	public void setMailPort(Integer mailPort) {
		this.mailPort = mailPort;
	}

	/**
	 * @return the mailCrypto
	 */
	public String getMailCrypto() {
		return mailCrypto;
	}

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

	/**
	 * @return the mailSPA
	 */
	public String getMailSPA() {
		return mailSPA;
	}

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

	/**
	 * @return the mailUsername
	 */
	public String getMailUsername() {
		return mailUsername;
	}

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

	/**
	 * @return the mailPassword
	 */
	public String getMailPassword() {
		return mailPassword;
	}

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

	/**
	 * @return the mailDefaultSubject
	 */
	public String getMailDefaultSubject() {
		return mailDefaultSubject;
	}

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

	/**
	 * @return the mailFromAddress
	 */
	public String getMailFromAddress() {
		return mailFromAddress;
	}

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

	/**
	 * @return the mailCcAddress
	 */
	public String getMailCcAddress() {
		return mailCcAddress;
	}

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

	/**
	 * @return the mailBccAddress
	 */
	public String getMailBccAddress() {
		return mailBccAddress;
	}

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

	/**
	 * @return the theMailTemplate
	 */
	public Collection<MailTemplate> getTheMailTemplate() {
		return theMailTemplate;
	}

	/**
	 * @param theMailTemplate the theMailTemplate to set
	 */
	public void setTheMailTemplate(Collection<MailTemplate> theMailTemplate) {
		this.theMailTemplate = theMailTemplate;
	}
	
	//
	// other methods
	//

	public void afterPropertiesSet() throws Exception {
		setMailConfigId(getBeanName());
		if (logger.isInfoEnabled()) {
			logger.info("Defined mail config: " + this);
		}
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "MailConfig [mailConfigId=" + mailConfigId
				+ ", mailConfigDescription=" + mailConfigDescription
				+ ", enabled=" + enabled + ", mailNomeHost=" + mailNomeHost
				+ ", mailPort=" + mailPort + ", mailCrypto=" + mailCrypto
				+ ", mailSPA=" + mailSPA + ", mailUsername=" + mailUsername
				+ ", mailPassword=********" + ", mailDefaultSubject="
				+ mailDefaultSubject + ", mailFromAddress=" + mailFromAddress
				+ ", mailCcAddress=" + mailCcAddress + ", mailBccAddress="
				+ mailBccAddress + "]";
	}

}
