You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by pg...@apache.org on 2002/08/08 02:47:45 UTC

cvs commit: jakarta-james/src/java/org/apache/james James.java

pgoldstein    2002/08/07 17:47:45

  Modified:    src/java/org/apache/james James.java
  Log:
  Part of the String=>StringBuffer changes.  Includes some additional
  commenting, formatting fixes, and wrapping of logging calls in log
  level checks.  Also converted equalsIgnoreCase paradigm as discussed on
  mailing list.  Locale issue for both toUpperCase() and toLowerCase() was
  addressed as well.  Additionally, some finally clauses were added to ensure
  resources are closed in the case of exception.
  
  Revision  Changes    Path
  1.24      +71 -31    jakarta-james/src/java/org/apache/james/James.java
  
  Index: James.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/James.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- James.java	3 Jun 2002 16:07:05 -0000	1.23
  +++ James.java	8 Aug 2002 00:47:45 -0000	1.24
  @@ -18,7 +18,6 @@
   import org.apache.avalon.framework.context.DefaultContext;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.logger.Logger;
  -import org.apache.avalon.phoenix.BlockContext;
   import org.apache.james.core.MailHeaders;
   import org.apache.james.core.MailImpl;
   import org.apache.james.services.*;
  @@ -90,11 +89,10 @@
       private Map mailboxes; //Not to be shared!
       private Hashtable attributes = new Hashtable();
   
  -    protected BlockContext           blockContext;
  -
  +    protected Context           myContext;
   
       public void contextualize(final Context context) {
  -        this.blockContext = (BlockContext)context;
  +        this.myContext = context;
       }
   
       public void configure(Configuration conf) {
  @@ -102,8 +100,7 @@
       }
   
       /**
  -     * Override compose method of AbstractBlock to create new
  -     * ComponentManager object
  +     *
        */
       public void compose(ComponentManager comp) {
           compMgr = new DefaultComponentManager(comp);
  @@ -115,20 +112,27 @@
           getLogger().info("JAMES init...");
   
           // TODO: This should retrieve a more specific named thread pool from
  -        // BlockContext that is set up in server.xml
  -        // workerPool = blockContext.getThreadPool( "default" );
  +        // Context that is set up in server.xml
           try {
               mailstore = (MailStore) compMgr.lookup( MailStore.ROLE );
           } catch (Exception e) {
  -            getLogger().warn("Can't get Store: " + e);
  +            if (getLogger().isWarnEnabled()) {
  +                getLogger().warn("Can't get Store: " + e);
  +            }
  +        }
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("Using MailStore: " + mailstore.toString());
           }
  -        getLogger().debug("Using MailStore: " + mailstore.toString());
           try {
               usersStore = (UsersStore) compMgr.lookup( UsersStore.ROLE );
           } catch (Exception e) {
  -            getLogger().warn("Can't get Store: " + e);
  +            if (getLogger().isWarnEnabled()) {
  +                getLogger().warn("Can't get Store: " + e);
  +            }
  +        }
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("Using UsersStore: " + usersStore.toString());
           }
  -        getLogger().debug("Using UsersStore: " + usersStore.toString());
           context = new DefaultContext();
   
           String hostName = null;
  @@ -144,7 +148,7 @@
           serverNames = new Vector();
           Configuration serverConf = conf.getChild("servernames");
           if (serverConf.getAttributeAsBoolean("autodetect") && (!hostName.equals("localhost"))) {
  -            serverNames.add(hostName.toLowerCase());
  +            serverNames.add(hostName.toLowerCase(Locale.US));
           }
   
           final Configuration[] serverNameConfs =
  @@ -156,8 +160,10 @@
               throw new ConfigurationException( "Fatal configuration error: no servernames specified!");
           }
   
  -        for (Iterator i = serverNames.iterator(); i.hasNext(); ) {
  -            getLogger().info("Handling mail for: " + i.next());
  +        if (getLogger().isInfoEnabled()) {
  +            for (Iterator i = serverNames.iterator(); i.hasNext(); ) {
  +                getLogger().info("Handling mail for: " + i.next());
  +            }
           }
           context.put(Constants.SERVER_NAMES, this.serverNames);
           attributes.put(Constants.SERVER_NAMES, this.serverNames);
  @@ -200,7 +206,9 @@
           compMgr.put( MailServer.ROLE, this);
   
           spool = mailstore.getInboundSpool();
  -        if (DEEP_DEBUG) getLogger().debug("Got spool");
  +        if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
  +            getLogger().debug("Got spool");
  +        }
   
           // For mailet engine provide MailetContext
           //compMgr.put("org.apache.mailet.MailetContext", this);
  @@ -258,7 +266,14 @@
               }
               throw new MessagingException("Exception spooling message: " + e.getMessage(), e);
           }
  -        getLogger().info("Mail " + mailimpl.getName() + " pushed in spool");
  +        if (getLogger().isInfoEnabled()) {
  +            StringBuffer logBuffer = 
  +                new StringBuffer(64)
  +                        .append("Mail ")
  +                        .append(mailimpl.getName())
  +                        .append(" pushed in spool");
  +            getLogger().info(logBuffer.toString());
  +        }
       }
   
       /**
  @@ -278,7 +293,12 @@
           } else {
               // need mailbox object
               getLogger().info("Need inbox for " + userName );
  -            String destination = inboxRootURL + userName + "/";
  +            StringBuffer destinationBuffer =
  +                new StringBuffer(192)
  +                        .append(inboxRootURL)
  +                        .append(userName)
  +                        .append("/");
  +            String destination = destinationBuffer.toString();
               DefaultConfiguration mboxConf
                   = new DefaultConfiguration("repository", "generated:AvalonFileRepository.compose()");
               mboxConf.setAttribute("destinationURL", destination);
  @@ -288,7 +308,10 @@
                   mailboxes.put(userName, userInbox);
               } catch (Exception e) {
                   e.printStackTrace();
  -                getLogger().error("Cannot open user Mailbox" + e);
  +                if (getLogger().isErrorEnabled())
  +                {
  +                    getLogger().error("Cannot open user Mailbox" + e);
  +                }
                   throw new RuntimeException("Error in getUserInbox." + e);
               }
               return userInbox;
  @@ -296,7 +319,13 @@
       }
   
       public String getId() {
  -        return "Mail" + System.currentTimeMillis() + "-" + count++;
  +        StringBuffer idBuffer = 
  +            new StringBuffer(64)
  +                    .append("Mail")
  +                    .append(System.currentTimeMillis())
  +                    .append("-")
  +                    .append(count++);
  +        return idBuffer.toString();
       }
   
       public static void main(String[] args) {
  @@ -415,7 +444,8 @@
           return postmaster;
       }
   
  -    public void storeMail(MailAddress sender, MailAddress recipient, MimeMessage message) {
  +    public void storeMail(MailAddress sender, MailAddress recipient, MimeMessage message)
  +        throws MessagingException {
           String username;
           if (ignoreCase) {
               username = localusers.getRealName(recipient.getUser());
  @@ -434,13 +464,23 @@
                   recipients.add(forwardTo);
                   try {
                       sendMail(sender, recipients, message);
  -                    getLogger().info("Mail for " + username + " forwarded to "
  -                                         +  forwardTo.toString());
  +                    StringBuffer logBuffer =
  +                        new StringBuffer(128)
  +                                .append("Mail for ")
  +                                .append(username)
  +                                .append(" forwarded to ")
  +                                .append(forwardTo.toString());
  +                    getLogger().info(logBuffer.toString());
                       return;
                   } catch (MessagingException me) {
  -                    getLogger().error("Error forwarding mail to "
  -                              + forwardTo.toString()
  -                              + "attempting local delivery");
  +                    if (getLogger().isErrorEnabled()) {
  +                        StringBuffer logBuffer = 
  +                            new StringBuffer(128)
  +                                    .append("Error forwarding mail to ")
  +                                    .append(forwardTo.toString())
  +                                    .append("attempting local delivery");
  +                        getLogger().error(logBuffer.toString());
  +                    }
                   }
               }
           }
  @@ -452,15 +492,15 @@
       }
   
       public int getMajorVersion() {
  -        return 1;
  +        return 2;
       }
   
       public int getMinorVersion() {
  -        return 3;
  +        return 1;
       }
   
       public boolean isLocalServer( final String serverName ) {
  -        return serverNames.contains(serverName.toLowerCase());
  +        return serverNames.contains(serverName.toLowerCase(Locale.US));
       }
   
       public String getServerInfo() {
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>