[jboss-cvs] jboss-seam/src/mail/org/jboss/seam/mail ...

Gavin King gavin.king at jboss.com
Sun Jan 28 20:11:07 EST 2007


  User: gavin   
  Date: 07/01/28 20:11:07

  Modified:    src/mail/org/jboss/seam/mail  MailSession.java
  Log:
  simplify the logic
  
  Revision  Changes    Path
  1.4       +62 -123   jboss-seam/src/mail/org/jboss/seam/mail/MailSession.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MailSession.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/MailSession.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- MailSession.java	28 Jan 2007 21:58:55 -0000	1.3
  +++ MailSession.java	29 Jan 2007 01:11:07 -0000	1.4
  @@ -27,7 +27,6 @@
   /**
    * Manager component for a javax.mail.Session
    */
  -
   @Name("org.jboss.seam.mail.mailSession")
   @Install(precedence=BUILT_IN)
   @Scope(APPLICATION)
  @@ -35,8 +34,6 @@
   public class MailSession extends AbstractMutable implements Serializable
   {
      
  -   public static final String SERVICE_NAME = "java:/Mail";
  -   
      private static final LogProvider log = Logging.getLogProvider(MailSession.class);
   
   	private Session session;
  @@ -46,18 +43,16 @@
   	private String username;
   	private String password;
   	private boolean debug = false;
  -   private String serviceName ;
  -   private Boolean lookupService;
  -   private boolean doJndi = false;
  +   private String sessionJndiName;
   
      @Unwrap
      public Session getSession() throws NamingException
      {
  -      if (doJndi) 
  +      if ( session==null ) 
         {
            // TODO Is this the best way to do this?
            // This simulates an EVENT scope component
  -         return  (Session) Naming.getInitialContext().lookup(getServiceName());
  +         return  (Session) Naming.getInitialContext().lookup( getSessionJndiName() );
         }
         else 
         {
  @@ -75,13 +70,15 @@
      @Create
   	public void create()
   	{
  -     
  -      if (isDoJndi()) {
  -         doJndi = true;
  +      if ( getSessionJndiName()==null ) 
  +      {
  +         createSession();
          }
  -      else
  +	}
  +
  +   private void createSession()
         {
  -         log.info("Using Seam managed mail session (" + getHost() + ':' + getPort() + ")");
  +      log.info("Creating JavaMail Session (" + getHost() + ':' + getPort() + ")");
            
      		Properties properties = new Properties();
      
  @@ -122,7 +119,6 @@
      			};
      		}
            
  -         
            // Use TLS (if supported) by default.
            properties.put("mail.smtp.starttls.enable", "true");
            properties.put("mail.imap.starttls.enable", "true");
  @@ -132,44 +128,6 @@
            
            log.info("connected to mail server");
         }
  -	}
  -   
  -   private boolean isDoJndi() {
  -      if (getLookupService() != null && !getLookupService()) 
  -      {
  -         return false;
  -      }
  -      else 
  -      {
  -         Session s = null;
  -         try
  -         {
  -            s = (Session) Naming.getInitialContext().lookup(getServiceName());
  -         }
  -         catch (NamingException e)
  -         { 
  -            // Swallow
  -         }
  -         
  -         if (lookupService == null && serviceName == null  && s == null) 
  -         {
  -            log.debug("Unable to get Session from JNDI: " + getServiceName());
  -            return false;
  -         }
  -         else if (s == null)
  -         {
  -            // The user has explicitly set a property that suggests they want a 
  -            // session from JNDI.  Log this at a high level as a result.
  -            log.warn("Unable to get Session from JNDI: " + getServiceName());
  -            return false;
  -         }
  -         else
  -         {
  -            log.info("Using Session from JNDI: " + getServiceName());
  -            return true;
  -         }
  -      }
  -   }
   
   	public String getPassword()
   	{
  @@ -243,37 +201,18 @@
   		return port;
   	}
      
  -   public String getServiceName()
  -   {
  -      if (serviceName == null) 
  -      {
  -         return SERVICE_NAME;
  -      }
  -      else
  -      {
  -         return serviceName;
  -      }
  -   }
  -
  -   public void setServiceName(String jndiName)
  +   public String getSessionJndiName()
      {
  -      this.serviceName = jndiName;
  +      return sessionJndiName;
      }
   
  -   public Boolean getLookupService()
  +   public void setSessionJndiName(String jndiName)
      {
  -      return lookupService;
  -   }
  -
  -   public void setLookupService(Boolean useJndi)
  -   {
  -      this.lookupService = useJndi;
  +      this.sessionJndiName = jndiName;
      }
   
      public static Session instance() {
         return (Session) Component.getInstance(MailSession.class);
      }
      
  -   
  -
   }
  
  
  



More information about the jboss-cvs-commits mailing list