FileDocCategorySizeDatePackage
MailConfiguration.javaAPI DocGlassfish v2 API15392Fri May 04 22:31:22 BST 2007com.sun.enterprise.deployment

MailConfiguration

public class MailConfiguration extends Object implements Serializable
This class represent the configuration information of the JavaMail Session object within J2EE.

Fields Summary
private static String
PROTOCOL_TYPE_IMAP
private static String
PROTOCOL_TYPE_POP3
private static String
PROTOCOL_TYPE_SMTP
private static String
PROP_NAME_PREFIX
private static String
PROP_NAME_SUFFIX_HOST
private static String
PROP_NAME_SUFFIX_USER
private static char
PROP_NAME_DELIM
private static String
DEF_VAL_STORE_PROTOCOL
private static String
DEF_VAL_STORE_PROTOCOL_CLASS
private static String
DEF_VAL_TRANSPORT_PROTOCOL
private static String
DEF_VAL_TRANSPORT_PROTOCOL_CLASS
private static String
DEF_VAL_HOST
private static String
DEF_VAL_USER
private static String
DEF_VAL_FROM
private static boolean
DEF_VAL_DEBUG
private static String
MAIL_STORE_PROTOCOL
private static String
MAIL_TRANSPORT_PROTOCOL
private static String
MAIL_HOST
private static String
MAIL_USER
private static String
MAIL_FROM
private static String
MAIL_DEBUG
private static String
MAIL_PREFIX
private static String
MAIL_SUFFIX_CLASS
private static String
MAIL_SUFFIX_HOST
private static String
MAIL_SUFFIX_USER
private static char
MAIL_DELIM
private String
description
Mail resource attributes
private String
jndiName
private boolean
enabled
private String
storeProtocol
private String
storeProtocolClass
private String
transportProtocol
private String
transportProtocolClass
private String
mailHost
private String
username
private String
mailFrom
private boolean
debug
private Properties
mailProperties
static Logger
_logger
Constructors Summary
public MailConfiguration(String username, String mailFrom)
This constructs the mail configuration based on the username and the from address. This constructor is deprecated.

param
the username
param
the from address
deprecated

    
                                    
         
	this.username = username;
	this.mailFrom = mailFrom;
	this.mailHost = "";

        mailProperties.put(MAIL_FROM, this.getMailFrom());
        mailProperties.put(MAIL_USER, this.getUsername());
        mailProperties.put(MAIL_HOST, this.getMailHost());
    
public MailConfiguration(String username, String mailFrom, String mailHost)
Construct a specification of mail configuration with the given username, Mail From Address and mail hostname.

param
the username.
param
the from address.
param
the mail hostname.

	this.username = username;
	this.mailFrom = mailFrom;
	this.mailHost = mailHost;

        mailProperties.put(MAIL_FROM, this.getMailFrom());
        mailProperties.put(MAIL_USER, this.getUsername());
        mailProperties.put(MAIL_HOST, this.getMailHost());
    
public MailConfiguration(com.sun.enterprise.deployment.interfaces.MailResourceIntf mailRes)
Construct a specification of mail configuration.

        try {
            loadMailResources(mailRes);
        }
        catch (Exception ce) {
            //ce.printStackTrace();
            _logger.log(Level.INFO,"enterprise.deployment_mail_cfgexcp",ce);

        }
    
Methods Summary
public java.lang.StringgetDescription()
Get the mail description for the mail session the server will provide.

return
the description of the mail server.

        return this.description;
    
public booleangetEnabled()
Get the mail enable flag for the mail session the server will provide.

return
the enable flag of the mail server.

        return this.enabled;
    
public java.lang.StringgetJndiName()
Get the mail JNDI name for the mail session the server will provide.

return
the JNDI name of the mail server.

        return this.jndiName;
    
public booleangetMailDebug()
Get the mail debug flag for the mail session the server will provide.

return
the debug flag of the mail server.

        return this.debug;
    
public java.lang.StringgetMailFrom()
Get the mail from address for the mail session the server will provide.

return
the from address.

	return this.mailFrom;
    
public java.lang.StringgetMailHost()
Get the mail hostname for the mail session the server will provide.

return
the hostname of the mail server.

	return this.mailHost;
    
public java.util.PropertiesgetMailProperties()
Get the mail session properties as per JavaMail.

return
the mail session properties.

        /* IASRI 4629057
        Properties mailProperties = new Properties();
        mailProperties.put(MAIL_FROM, this.getMailFrom());
        mailProperties.put(MAIL_USER, this.getUsername());
        mailProperties.put(MAIL_HOST, this.getMailHost());
        */

        return mailProperties;
    
public java.lang.StringgetMailStoreProtocol()
Get the default Message Access Protocol for the mail session the server will provide.

return
the store protocol of the mail server.

        return this.storeProtocol;
    
public java.lang.StringgetMailStoreProtocolClass()
Get the default Message Access Protocol class for the mail session the server will provide.

return
the store protocol of the mail server.

        return this.storeProtocolClass;
    
public java.lang.StringgetMailTransportProtocol()
Get the default Transport Protocol for the mail session the server will provide.

return
the transport protocol of the mail server.

        return this.transportProtocol;
    
public java.lang.StringgetMailTransportProtocolClass()
Get the default Transport Protocol class for the mail session the server will provide.

return
the transport protocol of the mail server.

        return this.transportProtocolClass;
    
public java.lang.StringgetUsername()
Get the username for the mail session the server will provide.

return
the username.

	return this.username;
    
private voidloadMailResources(com.sun.enterprise.deployment.interfaces.MailResourceIntf mailResource)
Load all configuration information from the mail resource node in server.xml for the JavaMail Session object within J2EE.


        if (mailResource == null) {
            _logger.log(Level.FINE,
                "MailConfiguration: no MailResource object. mailResource=" +
                mailResource);
            return;
        }
        
        jndiName = mailResource.getName();
        description = mailResource.getDescription();
        enabled = mailResource.isEnabled();

        storeProtocol = mailResource.getStoreProtocol();
        storeProtocolClass = mailResource.getStoreProtocolClass();
        transportProtocol = mailResource.getTransportProtocol();
        transportProtocolClass = mailResource.getTransportProtocolClass();
        mailHost = mailResource.getMailHost();
        username = mailResource.getUsername();
        mailFrom = mailResource.getMailFrom();
        debug = mailResource.isDebug();

        // Save to Property list
        String storeProtocolClassName = MAIL_PREFIX + storeProtocol +
            MAIL_SUFFIX_CLASS;
        String transportProtocolClassName = MAIL_PREFIX + transportProtocol +
            MAIL_SUFFIX_CLASS;

        mailProperties.put(MAIL_STORE_PROTOCOL, storeProtocol);
        mailProperties.put(MAIL_TRANSPORT_PROTOCOL, transportProtocol);
        mailProperties.put(storeProtocolClassName, storeProtocolClass);
        mailProperties.put(transportProtocolClassName, transportProtocolClass);
        mailProperties.put(MAIL_FROM, mailFrom);
        mailProperties.put(MAIL_DEBUG, (debug ? "true" : "false"));

        // Get the properties and save to Property list
        Set properties = mailResource.getProperties();
        ResourceProperty property = null;
        String name = null;
        String value = null;

        String protRelatedHostPropName = PROP_NAME_PREFIX + storeProtocol +
            PROP_NAME_SUFFIX_HOST;
        String protRelatedUserPropName = PROP_NAME_PREFIX + storeProtocol +
            PROP_NAME_SUFFIX_USER;
        String protRelatedHostName = MAIL_PREFIX + storeProtocol +
                        MAIL_SUFFIX_HOST;
        String protRelatedUserName = MAIL_PREFIX + storeProtocol +
                        MAIL_SUFFIX_USER;

        for (Iterator it = properties.iterator(); it.hasNext();) {
            property = (ResourceProperty)it.next();
            name = property.getName();
            value = (String)property.getValue();

            if (name.startsWith(PROP_NAME_PREFIX)) {
                if (name.equals(protRelatedHostPropName)) {
                    mailHost = value;
                    mailProperties.put(protRelatedHostName, value);
                }
                else if (name.equals(protRelatedUserPropName)) {
                    username = value;
                    mailProperties.put(protRelatedUserName, value);
                }
                else {
                    name = name.replace(PROP_NAME_DELIM, MAIL_DELIM);
                    mailProperties.put(name, value);
                }
            }
        }

        // Save mail.host and mail.user to Property list
        mailProperties.put(MAIL_HOST, mailHost);
        mailProperties.put(MAIL_USER, username);
    
public voidprint(java.lang.StringBuffer toStringBuffer)
A formatted representation of my state.

	/* IASRI 4629057
	return "MailConfiguration: [" + username + "," + mailFrom + "," + 
		mailHost + "]";
	*/

        // START OF IASRI 4629057
        toStringBuffer.append("MailConfiguration: [");
        toStringBuffer.append("description=").append(description);
        toStringBuffer.append( ", jndiName=").append(jndiName);
        toStringBuffer.append( ", enabled=").append(enabled);

        toStringBuffer.append( ", storeProtocol=").append(storeProtocol);
        toStringBuffer.append( ", transportProtocol=").append(transportProtocol);
        toStringBuffer.append( ", storeProtocolClass=").append(storeProtocolClass);
        toStringBuffer.append( ", transportProtocolClass=").append(transportProtocolClass);
        toStringBuffer.append( ", mailHost=").append(mailHost);
        toStringBuffer.append( ", username=").append(username);
        toStringBuffer.append( ", mailFrom=").append(mailFrom);
        toStringBuffer.append( ", debug=").append(debug);
        toStringBuffer.append( ", mailProperties: [");

        Enumeration e = mailProperties.propertyNames();
        String name;
        String value;
        boolean isFirst = true;

        while (e.hasMoreElements()) {
            name = (String)e.nextElement();
            value = mailProperties.getProperty(name);
            if (isFirst) {
                toStringBuffer.append(name).append("=").append(value);
                isFirst = false;
            }
            else {
                toStringBuffer.append( ", ").append(name).append("=").append(value);
            }
        }
        toStringBuffer.append( "]]");

        // END OF IASRI 4629057