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 rd...@apache.org on 2007/02/10 14:02:51 UTC

svn commit: r505685 - in /james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver: ./ commands/

Author: rdonkin
Date: Sat Feb 10 05:02:49 2007
New Revision: 505685

URL: http://svn.apache.org/viewvc?view=rev&rev=505685
Log:
Moved decoding code into parser classes.

Added:
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseResponseMessage.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommandMessage.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UidCommandParser.java
Modified:
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/ImapRequestHandler.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AppendCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AuthenticateCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CapabilityCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CheckCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommandMessage.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandParser.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandTemplate.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CopyCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CreateCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/DeleteCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/FetchCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ListCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LoginCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LsubCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/NoopCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/RenameCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SearchCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SelectCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StatusCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StoreCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UidCommand.java
    james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/ImapRequestHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/ImapRequestHandler.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/ImapRequestHandler.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/ImapRequestHandler.java Sat Feb 10 05:02:49 2007
@@ -35,7 +35,6 @@
 public final class ImapRequestHandler extends AbstractLogEnabled {
     
     private final ImapCommandFactory imapCommands = new ImapCommandFactory();
-    private CommandParser parser = new CommandParser();
     private static final String REQUEST_SYNTAX = "Protocol Error: Was expecting <tag SPACE command [arguments]>";
 
     /**
@@ -92,7 +91,7 @@
         String commandName = null;
 
         try {
-            tag = parser.tag( request );
+            tag = CommandParser.tag( request );
         }
         catch ( ProtocolException e ) {
             getLogger().debug("error parsing request", e);
@@ -106,7 +105,7 @@
         }
         
         try {
-            commandName = parser.atom( request );
+            commandName = CommandParser.atom( request );
         }
         catch ( ProtocolException e ) {
             getLogger().debug("error parsing request", e);            

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AppendCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AppendCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AppendCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AppendCommand.java Sat Feb 10 05:02:49 2007
@@ -41,23 +41,10 @@
     public static final String NAME = "APPEND";
     public static final String ARGS = "<mailbox> [<flag_list>] [<date_time>] literal";
 
-    private AppendCommandParser parser = new AppendCommandParser();
+    private AppendCommandParser parser = new AppendCommandParser(this);
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        String mailboxName = parser.mailbox( request );
-        Flags flags = parser.optionalAppendFlags( request );
-        if ( flags == null ) {
-            flags = new Flags();
-        }
-        Date datetime = parser.optionalDateTime( request );
-        if ( datetime == null ) {
-            datetime = new Date();
-        }
-        MimeMessage message = parser.mimeMessage( request );
-        parser.endLine( request );
-        // TODO: use an object pool
-        final AppendCommandMessage result = new AppendCommandMessage(this, mailboxName, 
-                flags, datetime, message, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
         return result;
     }
 
@@ -75,6 +62,11 @@
 
     private static class AppendCommandParser extends CommandParser
     {        
+
+        public AppendCommandParser(ImapCommand command) {
+            super(command);
+        }
+
         /**
          * If the next character in the request is a '(', tries to read
          * a "flag_list" argument from the request. If not, returns a
@@ -132,6 +124,24 @@
 
             }
             return mm;
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            String mailboxName = mailbox( request );
+            Flags flags = optionalAppendFlags( request );
+            if ( flags == null ) {
+                flags = new Flags();
+            }
+            Date datetime = optionalDateTime( request );
+            if ( datetime == null ) {
+                datetime = new Date();
+            }
+            MimeMessage message = mimeMessage( request );
+            endLine( request );
+            // TODO: use an object pool
+            final AppendCommandMessage result = new AppendCommandMessage(command, mailboxName, 
+                    flags, datetime, message, tag);
+            return result;
         }
     }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AuthenticateCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AuthenticateCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AuthenticateCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/AuthenticateCommand.java Sat Feb 10 05:02:49 2007
@@ -32,10 +32,10 @@
     public static final String NAME = "AUTHENTICATE";
     public static final String ARGS = "<auth_type> *(CRLF base64)";
     
+    private final AuthenticateCommandParser parser = new AuthenticateCommandParser(this);
+    
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        String authType = parser.astring( request );
-        parser.endLine( request );        
-        final AuthenticateCommandMessage result = new AuthenticateCommandMessage(this, authType, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
         return result;
     }
 
@@ -49,6 +49,21 @@
     public String getArgSyntax()
     {
         return ARGS;
+    }
+    
+    private static class AuthenticateCommandParser extends CommandParser {
+
+        public AuthenticateCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            String authType = astring( request );
+            endLine( request );        
+            final AuthenticateCommandMessage result = new AuthenticateCommandMessage(command, authType, tag);
+            return result;
+        }
+        
     }
 }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CapabilityCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CapabilityCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CapabilityCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CapabilityCommand.java Sat Feb 10 05:02:49 2007
@@ -34,9 +34,10 @@
 
     public static final String CAPABILITY_RESPONSE = NAME + SP + VERSION + SP + CAPABILITIES;
 
+    private final CapabilityCommandParser parser = new CapabilityCommandParser(this);
+    
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        parser.endLine( request );
-        final CapabilityCommandMessage result = new CapabilityCommandMessage(this, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
         return result;
     }
 
@@ -50,6 +51,20 @@
     public String getArgSyntax()
     {
         return ARGS;
+    }
+    
+    private static class CapabilityCommandParser extends CommandParser {
+
+        public CapabilityCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            endLine( request );
+            final CapabilityCommandMessage result = new CapabilityCommandMessage(command, tag);
+            return result;
+        }
+        
     }
 }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CheckCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CheckCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CheckCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CheckCommand.java Sat Feb 10 05:02:49 2007
@@ -32,9 +32,11 @@
     public static final String NAME = "CHECK";
     public static final String ARGS = null;
 
+    private final CheckCommandParser parser = new CheckCommandParser(this);
+    
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        parser.endLine( request );
-        return new CompleteCommandMessage(this, false, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
+        return result;
     }
 
     /** @see ImapCommand#getName */
@@ -47,6 +49,20 @@
     public String getArgSyntax()
     {
         return ARGS;
+    }
+    
+    private static class CheckCommandParser extends CommandParser {
+
+        public CheckCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            endLine( request );
+            final CompleteCommandMessage result = new CompleteCommandMessage(command, false, tag);
+            return result;
+        }
+        
     }
 }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommand.java Sat Feb 10 05:02:49 2007
@@ -20,10 +20,7 @@
 package org.apache.james.imapserver.commands;
 
 import org.apache.james.imapserver.ImapRequestLineReader;
-import org.apache.james.imapserver.ImapResponse;
-import org.apache.james.imapserver.ImapSession;
 import org.apache.james.imapserver.ProtocolException;
-import org.apache.james.imapserver.store.MailboxException;
 
 /**
  * Handles processeing for the CHECK imap command.
@@ -34,25 +31,12 @@
 {
     public static final String NAME = "CLOSE";
     public static final String ARGS = null;
-
-    static class CloseResponseMessage extends AbstractCommandResponseMessage {
-        public CloseResponseMessage(ImapCommand command, String tag) {
-            super(command, tag);
-        }
-
-        void doEncode(ImapResponse response, ImapSession session, ImapCommand command, String tag) throws MailboxException {
-            //TODO: the following comment was present in the code before refactoring
-            //TODO: doesn't seem to match the implementation
-            //TODO: check that implementation is correct
-//          Don't send unsolicited responses on close.
-            session.unsolicitedResponses( response, false );
-            response.commandComplete( command , tag);
-        }
-    }
     
+    private final CloseCommandParser parser = new CloseCommandParser(this);
+
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        parser.endLine( request );
-        return new CloseCommandMessage(this, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
+        return result;
     }
 
     /** @see ImapCommand#getName */
@@ -65,6 +49,20 @@
     public String getArgSyntax()
     {
         return ARGS;
+    }
+    
+    private static class CloseCommandParser extends CommandParser {
+
+        public CloseCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            endLine( request );
+            final CloseCommandMessage result = new CloseCommandMessage(command, tag);
+            return result;
+        }
+        
     }
 }
 /*

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommandMessage.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommandMessage.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommandMessage.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseCommandMessage.java Sat Feb 10 05:02:49 2007
@@ -21,7 +21,6 @@
 import org.apache.james.imapserver.AuthorizationException;
 import org.apache.james.imapserver.ImapSession;
 import org.apache.james.imapserver.ProtocolException;
-import org.apache.james.imapserver.commands.CloseCommand.CloseResponseMessage;
 import org.apache.james.imapserver.store.MailboxException;
 import org.apache.james.mailboxmanager.MailboxManagerException;
 import org.apache.james.mailboxmanager.MessageResult;

Added: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseResponseMessage.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseResponseMessage.java?view=auto&rev=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseResponseMessage.java (added)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CloseResponseMessage.java Sat Feb 10 05:02:49 2007
@@ -0,0 +1,38 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imapserver.commands;
+
+import org.apache.james.imapserver.ImapResponse;
+import org.apache.james.imapserver.ImapSession;
+import org.apache.james.imapserver.store.MailboxException;
+
+class CloseResponseMessage extends AbstractCommandResponseMessage {
+        public CloseResponseMessage(ImapCommand command, String tag) {
+            super(command, tag);
+        }
+
+        void doEncode(ImapResponse response, ImapSession session, ImapCommand command, String tag) throws MailboxException {
+            //TODO: the following comment was present in the code before refactoring
+            //TODO: doesn't seem to match the implementation
+            //TODO: check that implementation is correct
+//          Don't send unsolicited responses on close.
+            session.unsolicitedResponses( response, false );
+            response.commandComplete( command , tag);
+        }
+    }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandParser.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandParser.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandParser.java Sat Feb 10 05:02:49 2007
@@ -36,14 +36,46 @@
  *
  * @version $Revision: 109034 $
  */
-public class CommandParser
+public abstract class CommandParser
 {
-    private static final char[] EMPTY_CHAR_ARRAY = new char[0];
+    private final ImapCommand command;
+    
+    
+    public CommandParser(final ImapCommand command) {
+        super();
+        this.command = command;
+    }
 
     /**
+     * Parses a request into a command message
+     * for later processing.
+     * @param request <code>ImapRequestLineReader</code>, not null
+     * @param tag TODO
+     * @return <code>ImapCommandMessage</code>, not null
+     * @throws ProtocolException if the request cannot be parsed
+     */
+    public final AbstractImapCommandMessage decode( ImapRequestLineReader request, String tag ) 
+        throws ProtocolException {
+        final AbstractImapCommandMessage result = decode(command, request, tag);
+        return result;
+    }
+    
+    /**
+     * Parses a request into a command message
+     * for later processing.
+     * @param request <code>ImapRequestLineReader</code>, not null
+     * @param tag TODO
+     * @param command <code>ImapCommand</code> to be parsed, not null
+     * @return <code>ImapCommandMessage</code>, not null
+     * @throws ProtocolException if the request cannot be parsed
+     */
+    protected abstract AbstractImapCommandMessage decode( ImapCommand command, ImapRequestLineReader request, String tag ) 
+        throws ProtocolException;
+    
+    /**
      * Reads an argument of type "atom" from the request.
      */
-    public String atom( ImapRequestLineReader request ) throws ProtocolException
+    public static String atom( ImapRequestLineReader request ) throws ProtocolException
     {
         return consumeWord( request, new ATOM_CHARValidator() );
     }
@@ -51,7 +83,7 @@
     /**
      * Reads a command "tag" from the request.
      */
-    public String tag(ImapRequestLineReader request) throws ProtocolException
+    public static String tag(ImapRequestLineReader request) throws ProtocolException
     {
         CharacterValidator validator = new TagCharValidator();
         return consumeWord( request, validator );
@@ -169,7 +201,7 @@
      * Characters are tested by the supplied CharacterValidator, and an exception is thrown
      * if invalid characters are encountered.
      */
-    protected String consumeWord( ImapRequestLineReader request,
+    protected static String consumeWord( ImapRequestLineReader request,
                                   CharacterValidator validator )
             throws ProtocolException
     {
@@ -190,7 +222,7 @@
         return atom.toString();
     }
 
-    private boolean isWhitespace( char next )
+    private static boolean isWhitespace( char next )
     {
         return ( next == ' ' || next == '\n' || next == '\r' || next == '\t' );
     }
@@ -304,6 +336,8 @@
      */
     public byte[] base64( ImapRequestLineReader request ) throws ProtocolException
     {
+        // TODO: throw unsupported exception?
+        // TODO: log
         return null;
     }
 
@@ -375,7 +409,7 @@
         return number;
     }
 
-    private boolean isCHAR( char chr )
+    private static boolean isCHAR( char chr )
     {
         return ( chr >= 0x01 && chr <= 0x7f );
     }
@@ -385,12 +419,12 @@
         return ( chr >= 0x01 && chr <= 0xff );
     }
 
-    protected boolean isListWildcard( char chr )
+    protected static boolean isListWildcard( char chr )
     {
         return ( chr == '*' || chr == '%' );
     }
 
-    private boolean isQuotedSpecial( char chr )
+    private static boolean isQuotedSpecial( char chr )
     {
         return ( chr == '"' || chr == '\\' );
     }
@@ -473,7 +507,7 @@
         boolean isValid( char chr );
     }
 
-    protected class NoopCharValidator implements CharacterValidator
+    protected static class NoopCharValidator implements CharacterValidator
     {
         public boolean isValid( char chr )
         {
@@ -481,7 +515,7 @@
         }
     }
 
-    protected class ATOM_CHARValidator implements CharacterValidator
+    protected static class ATOM_CHARValidator implements CharacterValidator
     {
         public boolean isValid( char chr )
         {
@@ -499,7 +533,7 @@
         }
     }
 
-    protected class DigitCharValidator implements CharacterValidator
+    protected static class DigitCharValidator implements CharacterValidator
     {
         public boolean isValid( char chr )
         {
@@ -508,7 +542,7 @@
         }
     }
 
-    private class TagCharValidator extends ATOM_CHARValidator
+    private static class TagCharValidator extends ATOM_CHARValidator
     {
         public boolean isValid( char chr )
         {
@@ -517,7 +551,7 @@
         }
     }
 
-    private class MessageSetCharValidator implements CharacterValidator
+    private static class MessageSetCharValidator implements CharacterValidator
     {
         public boolean isValid( char chr )
         {

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandTemplate.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandTemplate.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandTemplate.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CommandTemplate.java Sat Feb 10 05:02:49 2007
@@ -40,8 +40,6 @@
         extends AbstractLogEnabled
         implements ImapCommand, ImapConstants, ImapCommandParser
 {
-    protected CommandParser parser = new CommandParser();
-
     /**
      * By default, valid in any state (unless overridden by subclass.
      * @see org.apache.james.imapserver.commands.ImapCommand#validForState
@@ -177,10 +175,4 @@
      *         commands without arguments.
      */
     public abstract String getArgSyntax();
-
-
-    public CommandParser getParser()
-    {
-        return parser;
-    }
 }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CopyCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CopyCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CopyCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CopyCommand.java Sat Feb 10 05:02:49 2007
@@ -32,6 +32,8 @@
     public static final String NAME = "COPY";
     public static final String ARGS = "<message-set> <mailbox>";
 
+    private final CopyCommandParser parser = new CopyCommandParser(this);
+    
     /** @see ImapCommand#getName */
     public String getName()
     {
@@ -49,12 +51,24 @@
     }
     
     public AbstractImapCommandMessage decode(final ImapRequestLineReader request, final boolean useUids, String tag) throws ProtocolException {
-        IdRange[] idSet = parser.parseIdRange( request );
-        String mailboxName = parser.mailbox( request );
-        parser.endLine( request );
-        final CopyCommandMessage result = 
-            new CopyCommandMessage(this, idSet, mailboxName, useUids, tag);
-        return result;
+        return parser.decode(request, tag, useUids);
+    }
+    
+    private static class CopyCommandParser extends UidCommandParser {
+
+        public CopyCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, boolean useUids) throws ProtocolException {
+            IdRange[] idSet = parseIdRange( request );
+            String mailboxName = mailbox( request );
+            endLine( request );
+            final CopyCommandMessage result = 
+                new CopyCommandMessage(command, idSet, mailboxName, useUids, tag);
+            return result;
+        }
+        
     }
 }
 /*

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CreateCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CreateCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CreateCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/CreateCommand.java Sat Feb 10 05:02:49 2007
@@ -32,6 +32,8 @@
     public static final String NAME = "CREATE";
     public static final String ARGS = "<mailbox>";
 
+    private final CreateCommandParser parser = new CreateCommandParser(this);
+    
     /** @see ImapCommand#getName */
     public String getName()
     {
@@ -45,10 +47,23 @@
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        String mailboxName = parser.mailbox( request );
-        parser.endLine( request );
-        final CreateCommandMessage result = new CreateCommandMessage(this, mailboxName, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
         return result;
+    }
+    
+    private static class CreateCommandParser extends CommandParser {
+
+        public CreateCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            String mailboxName = mailbox( request );
+            endLine( request );
+            final CreateCommandMessage result = new CreateCommandMessage(command, mailboxName, tag);
+            return result;
+        }
+        
     }
 }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/DeleteCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/DeleteCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/DeleteCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/DeleteCommand.java Sat Feb 10 05:02:49 2007
@@ -31,6 +31,8 @@
 {
     public static final String NAME = "DELETE";
     public static final String ARGS = "<mailbox>";
+    
+    private final DeleteCommandParser parser = new DeleteCommandParser(this);
 
     /** @see ImapCommand#getName */
     public String getName()
@@ -45,11 +47,24 @@
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        String mailboxName = parser.mailbox( request );
-        parser.endLine( request );
-        final DeleteCommandMessage result = 
-            new DeleteCommandMessage( this, mailboxName, tag );
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
         return result;
+    }
+    
+    private static class DeleteCommandParser extends CommandParser {
+
+        public DeleteCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            String mailboxName = mailbox( request );
+            endLine( request );
+            final DeleteCommandMessage result = 
+                new DeleteCommandMessage( command, mailboxName, tag );
+            return result;
+        }
+        
     }
 }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java Sat Feb 10 05:02:49 2007
@@ -32,6 +32,8 @@
     public static final String NAME = "EXPUNGE";
     public static final String ARGS = null;
     
+    private final ExpungeCommandParser parser = new ExpungeCommandParser(this);
+    
     /** @see ImapCommand#getName */
     public String getName()
     {
@@ -45,9 +47,22 @@
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        parser.endLine( request );
-        final ExpungeCommandMessage result = new ExpungeCommandMessage(this, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
         return result;
+    }
+    
+    private static class ExpungeCommandParser extends CommandParser {
+
+        public ExpungeCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            endLine( request );
+            final ExpungeCommandMessage result = new ExpungeCommandMessage(command, tag);
+            return result;
+        }
+        
     }
 }
 /*

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/FetchCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/FetchCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/FetchCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/FetchCommand.java Sat Feb 10 05:02:49 2007
@@ -35,7 +35,7 @@
     public static final String NAME = "FETCH";
     public static final String ARGS = "<message-set> <fetch-profile>";
 
-    private FetchCommandParser parser = new FetchCommandParser();
+    private FetchCommandParser parser = new FetchCommandParser(this);
 
     /** @see ImapCommand#getName */
     public String getName()
@@ -49,9 +49,11 @@
         return ARGS;
     }
 
-    private static class FetchCommandParser extends CommandParser
+    private static class FetchCommandParser extends UidCommandParser
     {
-
+        public FetchCommandParser(ImapCommand command) {
+            super(command);
+        }
 
         public FetchRequest fetchRequest( ImapRequestLineReader request )
                 throws ProtocolException
@@ -182,6 +184,16 @@
             return next;
         }
 
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, boolean useUids) throws ProtocolException {
+            IdRange[] idSet = parseIdRange( request );
+            FetchRequest fetch = fetchRequest( request );
+            endLine( request );
+            
+            final FetchCommandMessage result 
+                = new FetchCommandMessage(command, useUids, idSet, fetch, tag);
+            return result;
+        }
+
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
@@ -190,11 +202,7 @@
     }
 
     public AbstractImapCommandMessage decode(ImapRequestLineReader request, boolean useUids, String tag) throws ProtocolException {
-        IdRange[] idSet = parser.parseIdRange( request );
-        FetchRequest fetch = parser.fetchRequest( request );
-        parser.endLine( request );
-        
-        final FetchCommandMessage result = new FetchCommandMessage(this, useUids, idSet, fetch, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag, useUids);
         return result;
     }
 }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ListCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ListCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ListCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/ListCommand.java Sat Feb 10 05:02:49 2007
@@ -25,7 +25,7 @@
 
 /**
  * Handles processeing for the LIST imap command.
- *
+ * TODO: inheritance tree seems wrong to me
  * @version $Revision: 109034 $
  */
 class ListCommand extends AuthenticatedStateCommand
@@ -33,7 +33,7 @@
     public static final String NAME = "LIST";
     public static final String ARGS = "<reference-name> <mailbox-name-with-wildcards>";
 
-    private ListCommandParser parser = new ListCommandParser();
+    private final ListCommandParser parser = new ListCommandParser(this);
 
     /** @see ImapCommand#getName */
     public String getName()
@@ -47,8 +47,12 @@
         return ARGS;
     }
 
-    private static class ListCommandParser extends CommandParser
+    protected static class ListCommandParser extends UidCommandParser
     {
+        public ListCommandParser(ImapCommand command) {
+            super(command);
+        }
+
         /**
          * Reads an argument of type "list_mailbox" from the request, which is
          * the second argument for a LIST or LSUB command. Valid values are a "string"
@@ -78,22 +82,29 @@
                 return super.isValid( chr );
             }
         }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, boolean useUids) throws ProtocolException {
+            String referenceName = mailbox( request );
+            String mailboxPattern = listMailbox( request );
+            endLine( request );
+            final ListCommandMessage result = createMessage(command, referenceName, mailboxPattern, tag);
+            return result;
+        }
+        
+        protected ListCommandMessage createMessage(ImapCommand command, final String referenceName, final String mailboxPattern, final String tag) 
+        {
+            final ListCommandMessage result = new ListCommandMessage(command, referenceName, mailboxPattern, tag);
+            return result;
+        }
     }
 
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        String referenceName = parser.mailbox( request );
-        String mailboxPattern = parser.listMailbox( request );
-        parser.endLine( request );
-        final ListCommandMessage result = createMessage(referenceName, mailboxPattern, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
         return result;
     }
     
-    protected ListCommandMessage createMessage(final String referenceName, final String mailboxPattern, final String tag) 
-    {
-        final ListCommandMessage result = new ListCommandMessage(this, referenceName, mailboxPattern, tag);
-        return result;
-    }
+
 }
 
 /*

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LoginCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LoginCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LoginCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LoginCommand.java Sat Feb 10 05:02:49 2007
@@ -33,6 +33,8 @@
     public static final String NAME = "LOGIN";
     public static final String ARGS = "<userid> <password>";
 
+    private final LoginCommandParser parser = new LoginCommandParser(this);
+     
     /** @see ImapCommand#getName */
     public String getName()
     {
@@ -46,10 +48,24 @@
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        final String userid = parser.astring( request );
-        final String password = parser.astring( request );
-        parser.endLine( request );
-        return new LoginCommandMessage(this, userid, password, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
+        return result;
+    }
+    
+    private static class LoginCommandParser extends CommandParser {
+
+        public LoginCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            final String userid = astring( request );
+            final String password = astring( request );
+            endLine( request );
+            final LoginCommandMessage result = new LoginCommandMessage(command, userid, password, tag);
+            return result;
+        }
+        
     }
 }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommand.java Sat Feb 10 05:02:49 2007
@@ -19,11 +19,8 @@
 
 package org.apache.james.imapserver.commands;
 
-import org.apache.james.imapserver.AuthorizationException;
 import org.apache.james.imapserver.ImapRequestLineReader;
-import org.apache.james.imapserver.ImapSession;
 import org.apache.james.imapserver.ProtocolException;
-import org.apache.james.imapserver.store.MailboxException;
 
 /**
  * Handles processeing for the LOGOUT imap command.
@@ -36,6 +33,8 @@
     public static final String ARGS = null;
     public static final String BYE_MESSAGE = VERSION + SP + "Server logging out";
 
+    private final LoginCommandParser parser = new LoginCommandParser(this);
+    
     /** @see ImapCommand#getName */
     public String getName()
     {
@@ -49,18 +48,19 @@
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        parser.endLine( request );
-        return new LogoutCommandMessage(this, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
+        return result;
     }
     
-    private static class LogoutCommandMessage extends AbstractImapCommandMessage {
+    private static class LoginCommandParser extends CommandParser {
 
-        public LogoutCommandMessage(final ImapCommand command, final String tag) {
-            super(tag, command);
+        public LoginCommandParser(ImapCommand command) {
+            super(command);
         }
-        
-        protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
-            final LogoutResponseMessage result = new LogoutResponseMessage(command, tag);
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            endLine( request );
+            final LogoutCommandMessage result = new LogoutCommandMessage(command, tag);
             return result;
         }
         

Added: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommandMessage.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommandMessage.java?view=auto&rev=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommandMessage.java (added)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LogoutCommandMessage.java Sat Feb 10 05:02:49 2007
@@ -0,0 +1,37 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imapserver.commands;
+
+import org.apache.james.imapserver.AuthorizationException;
+import org.apache.james.imapserver.ImapSession;
+import org.apache.james.imapserver.ProtocolException;
+import org.apache.james.imapserver.store.MailboxException;
+
+class LogoutCommandMessage extends AbstractImapCommandMessage {
+
+    public LogoutCommandMessage(final ImapCommand command, final String tag) {
+        super(tag, command);
+    }
+    
+    protected ImapResponseMessage doProcess(ImapSession session, String tag, ImapCommand command) throws MailboxException, AuthorizationException, ProtocolException {
+        final LogoutResponseMessage result = new LogoutResponseMessage(command, tag);
+        return result;
+    }
+    
+}

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LsubCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LsubCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LsubCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/LsubCommand.java Sat Feb 10 05:02:49 2007
@@ -19,6 +19,9 @@
 
 package org.apache.james.imapserver.commands;
 
+import org.apache.james.imapserver.ImapRequestLineReader;
+import org.apache.james.imapserver.ProtocolException;
+
 
 /**
  * @version $Revision: 109034 $
@@ -27,7 +30,7 @@
 {
     public static final String NAME = "LSUB";
 
-
+    private final LsubCommandParser parser = new LsubCommandParser(this);
 
     /** @see ImapCommand#getName */
     public String getName()
@@ -35,9 +38,20 @@
         return NAME;
     }
     
-    
-    
-    protected ListCommandMessage createMessage(String referenceName, String mailboxPattern, String tag) {
-        return new LsubListCommandMessage(this, referenceName, mailboxPattern, tag);
+    protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
+        return result;
+    }
+
+    private class LsubCommandParser extends ListCommandParser {
+
+        public LsubCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected ListCommandMessage createMessage(ImapCommand command, String referenceName, String mailboxPattern, String tag) {
+            final LsubListCommandMessage result = new LsubListCommandMessage(command, referenceName, mailboxPattern, tag);
+            return result;
+        }
     }
 }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/NoopCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/NoopCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/NoopCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/NoopCommand.java Sat Feb 10 05:02:49 2007
@@ -32,6 +32,8 @@
     public static final String NAME = "NOOP";
     public static final String ARGS = null;
     
+    private final NoopCommandParser parser = new NoopCommandParser(this);
+    
     /** @see ImapCommand#getName */
     public String getName()
     {
@@ -45,8 +47,22 @@
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        parser.endLine( request );
-        return new CompleteCommandMessage(this, false, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
+        return result;
+    }
+    
+    private static class NoopCommandParser extends CommandParser {
+
+        public NoopCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            endLine( request );
+            final CompleteCommandMessage result = new CompleteCommandMessage(command, false, tag);
+            return result;
+        }
+        
     }
 }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/RenameCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/RenameCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/RenameCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/RenameCommand.java Sat Feb 10 05:02:49 2007
@@ -32,6 +32,8 @@
     public static final String NAME = "RENAME";
     public static final String ARGS = "existing-mailbox-name SPACE new-mailbox-name";
 
+    private final RenameCommandParser parser = new RenameCommandParser(this);
+    
     /** @see ImapCommand#getName */
     public String getName()
     {
@@ -45,10 +47,24 @@
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        final String existingName = parser.mailbox( request );
-        final String newName = parser.mailbox( request );
-        parser.endLine( request );
-        return new RenameCommandMessage(this, existingName, newName, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
+        return result;
+    }
+    
+    private static class RenameCommandParser extends CommandParser {
+
+        public RenameCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            final String existingName = mailbox( request );
+            final String newName = mailbox( request );
+            endLine( request );
+            final RenameCommandMessage result = new RenameCommandMessage(command, existingName, newName, tag);
+            return result;
+        }
+        
     }
 }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SearchCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SearchCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SearchCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SearchCommand.java Sat Feb 10 05:02:49 2007
@@ -35,7 +35,7 @@
     public static final String NAME = "SEARCH";
     public static final String ARGS = "<search term>";
 
-    private SearchCommandParser parser = new SearchCommandParser();
+    private SearchCommandParser parser = new SearchCommandParser(this);
 
     /** @see ImapCommand#getName */
     public String getName()
@@ -49,8 +49,12 @@
         return ARGS;
     }
 
-    private static class SearchCommandParser extends CommandParser
+    private static class SearchCommandParser extends UidCommandParser
     {
+        public SearchCommandParser(ImapCommand command) {
+            super(command);
+        }
+
         /**
          * Parses the request argument into a valid search term.
          * Not yet implemented - all searches will return everything for now.
@@ -79,6 +83,15 @@
             };
         }
 
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, boolean useUids) throws ProtocolException {
+            // Parse the search term from the request
+            final SearchTerm searchTerm = searchTerm( request );
+            endLine( request );
+            final SearchImapCommand result 
+                = new SearchImapCommand(command, searchTerm, useUids, tag);
+            return result;
+        }
+
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
@@ -86,11 +99,7 @@
     }
 
     public AbstractImapCommandMessage decode(ImapRequestLineReader request, boolean useUids, String tag) throws ProtocolException {
-        // Parse the search term from the request
-        final SearchTerm searchTerm = parser.searchTerm( request );
-        parser.endLine( request );
-        final SearchImapCommand result = new SearchImapCommand(this, searchTerm, useUids, tag);
-        return result;
+        return parser.decode(request, tag, useUids);
     }
 }
 /*

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SelectCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SelectCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SelectCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SelectCommand.java Sat Feb 10 05:02:49 2007
@@ -25,7 +25,7 @@
 
 /**
  * Handles processeing for the SELECT imap command.
- *
+ * TODO: the inheritance tree seems a little wrong.
  * @version $Revision: 109034 $
  */
 class SelectCommand extends AuthenticatedStateCommand
@@ -33,11 +33,10 @@
     public static final String NAME = "SELECT";
     public static final String ARGS = "mailbox";
     
-    // TODO: the inheritance tree seems a little wrong
-    private final boolean isExamine;
-    
+    private final SelectCommandParser parser;
+
     protected SelectCommand(boolean isExamine) {
-        this.isExamine = isExamine;
+        parser = new SelectCommandParser(this, isExamine);
     }
     
     public SelectCommand() {
@@ -57,10 +56,25 @@
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        final String mailboxName = parser.mailbox( request );
-        parser.endLine( request );
-        final SelectCommandMessage result = new SelectCommandMessage(this, mailboxName, isExamine, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
         return result;
+    }
+    
+    private static class SelectCommandParser extends CommandParser {
+        private final boolean isExamine;
+        
+        public SelectCommandParser(ImapCommand command, boolean isExamine) {
+            super(command);
+            this.isExamine = isExamine;
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            final String mailboxName = mailbox( request );
+            endLine( request );
+            final SelectCommandMessage result = new SelectCommandMessage(command, mailboxName, isExamine, tag);
+            return result;
+        }
+        
     }
 }
 

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StatusCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StatusCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StatusCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StatusCommand.java Sat Feb 10 05:02:49 2007
@@ -38,7 +38,7 @@
     static final String UIDVALIDITY = "UIDVALIDITY";
     static final String UNSEEN = "UNSEEN";
 
-    private StatusCommandParser parser = new StatusCommandParser();
+    private StatusCommandParser parser = new StatusCommandParser(this);
 
     /** @see ImapCommand#getName */
     public String getName()
@@ -54,6 +54,10 @@
 
     private static class StatusCommandParser extends CommandParser
     {
+        public StatusCommandParser(ImapCommand command) {
+            super(command);
+        }
+
         StatusDataItems statusDataItems( ImapRequestLineReader request )
                 throws ProtocolException
         {
@@ -97,14 +101,19 @@
                 throw new ProtocolException( "Unknown status item: '" + nextWord + "'" );
             }
         }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            final String mailboxName = mailbox( request );
+            final StatusDataItems statusDataItems = statusDataItems( request );
+            endLine( request );
+            final StatusCommandMessage result = 
+                new StatusCommandMessage(command, mailboxName, statusDataItems, tag);
+            return result;
+        }
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        final String mailboxName = parser.mailbox( request );
-        final StatusDataItems statusDataItems = parser.statusDataItems( request );
-        parser.endLine( request );
-        final StatusCommandMessage result = 
-            new StatusCommandMessage(this, mailboxName, statusDataItems, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
         return result;
     }
 }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StoreCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StoreCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StoreCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/StoreCommand.java Sat Feb 10 05:02:49 2007
@@ -34,7 +34,7 @@
     public static final String NAME = "STORE";
     public static final String ARGS = "<Message-set> ['+'|'-']FLAG[.SILENT] <flag-list>";
 
-    private StoreCommandParser parser = new StoreCommandParser();
+    private StoreCommandParser parser = new StoreCommandParser(this);
     
     /** @see ImapCommand#getName */
     public String getName()
@@ -48,8 +48,12 @@
         return ARGS;
     }
 
-    private static class StoreCommandParser extends CommandParser
+    private static class StoreCommandParser extends UidCommandParser
     {
+        public StoreCommandParser(ImapCommand command) {
+            super(command);
+        }
+
         StoreDirective storeDirective( ImapRequestLineReader request ) throws ProtocolException
         {
             int sign = 0;
@@ -80,6 +84,16 @@
             }
             return new StoreDirective( sign, silent );
         }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, boolean useUids) throws ProtocolException {
+            final IdRange[] idSet = parseIdRange( request );
+            final StoreDirective directive = storeDirective( request );
+            final Flags flags = flagList( request );
+            endLine( request );
+            final StoreCommandMessage result = 
+                new StoreCommandMessage(command, idSet, directive, flags, useUids, tag);
+            return result;
+        }
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
@@ -87,12 +101,8 @@
     }
 
     public AbstractImapCommandMessage decode(ImapRequestLineReader request, boolean useUids, String tag) throws ProtocolException {
-        
-        final IdRange[] idSet = parser.parseIdRange( request );
-        final StoreDirective directive = parser.storeDirective( request );
-        final Flags flags = parser.flagList( request );
-        parser.endLine( request );
-        return new StoreCommandMessage(this, idSet, directive, flags, useUids, tag);
+        final AbstractImapCommandMessage result = parser.decode(this, request, tag, useUids);
+        return result;
     }
 }
 /*

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java Sat Feb 10 05:02:49 2007
@@ -31,6 +31,8 @@
     public static final String NAME = "SUBSCRIBE";
     public static final String ARGS = "<mailbox>";
 
+    private final SubscribeCommandParser parser = new SubscribeCommandParser(this);
+    
     /** @see ImapCommand#getName */
     public String getName() {
         return NAME;
@@ -42,11 +44,24 @@
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        final String mailboxName = parser.mailbox( request );
-        parser.endLine( request );
-        
-        final SubscribeCommandMessage result = 
-            new SubscribeCommandMessage(this, mailboxName, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
         return result;
+    }
+    
+    private static class SubscribeCommandParser extends CommandParser {
+
+        public SubscribeCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            final String mailboxName = mailbox( request );
+            endLine( request );
+            
+            final SubscribeCommandMessage result = 
+                new SubscribeCommandMessage(command, mailboxName, tag);
+            return result;
+        }
+        
     }
 }

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UidCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UidCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UidCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UidCommand.java Sat Feb 10 05:02:49 2007
@@ -52,14 +52,35 @@
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        String commandName = parser.atom( request );
-        ImapCommand command = commandFactory.getCommand( commandName );
-        if ( command == null ||
-             ! (command instanceof UidEnabledCommand ) ) {
-            throw new ProtocolException("Invalid UID command: '" + commandName + "'" );
-        }
-        final UidEnabledCommand uidEnabled = (UidEnabledCommand) command;
-        final AbstractImapCommandMessage result = uidEnabled.decode( request, true, tag );
+        UidCommandParser parser = new UidCommandParser(this, commandFactory);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
         return result;
+    }
+    
+    private class UidCommandParser extends CommandParser {
+        private final ImapCommandFactory commandFactory;
+
+        public UidCommandParser(ImapCommand command, final ImapCommandFactory commandFactory) {
+            super(command);
+            this.commandFactory = commandFactory;
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            // TODO: check the logic against the specification:
+            // TODO: suspect that it is now bust
+            // TODO: the command written may be wrong
+            // TODO: this will be easier to fix a little later
+            // TODO: also not sure whether the old implementation shares this flaw 
+            String commandName = atom( request );
+            ImapCommand helperCommand = commandFactory.getCommand( commandName );
+            if ( helperCommand == null ||
+                 ! (helperCommand instanceof UidEnabledCommand ) ) {
+                throw new ProtocolException("Invalid UID command: '" + commandName + "'" );
+            }
+            final UidEnabledCommand uidEnabled = (UidEnabledCommand) helperCommand;
+            final AbstractImapCommandMessage result = uidEnabled.decode( request, true, tag );
+            return result;
+        }
+        
     }
 }

Added: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UidCommandParser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UidCommandParser.java?view=auto&rev=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UidCommandParser.java (added)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UidCommandParser.java Sat Feb 10 05:02:49 2007
@@ -0,0 +1,48 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imapserver.commands;
+
+import org.apache.james.imapserver.ImapRequestLineReader;
+import org.apache.james.imapserver.ProtocolException;
+
+abstract class UidCommandParser extends CommandParser {
+
+    private final ImapCommand command;
+    
+    public UidCommandParser(ImapCommand command) {
+        super(command);
+        this.command = command;
+    }
+
+    protected AbstractImapCommandMessage decode(ImapCommand command,
+            ImapRequestLineReader request, String tag) throws ProtocolException {
+        final AbstractImapCommandMessage result = decode(command, request, tag, false);
+        return result;
+    }
+    
+    public AbstractImapCommandMessage decode(ImapRequestLineReader request, 
+            String tag, boolean useUids) throws ProtocolException {
+        final AbstractImapCommandMessage result = decode(command, request, tag, useUids);
+        return result;
+    }
+
+    protected abstract AbstractImapCommandMessage decode(ImapCommand command,
+            ImapRequestLineReader request, String tag, boolean useUids) throws ProtocolException;
+}

Modified: james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java?view=diff&rev=505685&r1=505684&r2=505685
==============================================================================
--- james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java (original)
+++ james/server/sandbox/seda-imap/src/java/org/apache/james/imapserver/commands/UnsubscribeCommand.java Sat Feb 10 05:02:49 2007
@@ -32,6 +32,8 @@
     public static final String NAME = "UNSUBSCRIBE";
     public static final String ARGS = "<mailbox>";
 
+    private final UnsubscribeCommandParser parser = new UnsubscribeCommandParser(this);
+    
     /** @see ImapCommand#getName */
     public String getName() {
         return NAME;
@@ -43,8 +45,22 @@
     }
 
     protected AbstractImapCommandMessage decode(ImapRequestLineReader request, String tag) throws ProtocolException {
-        final String mailboxName = parser.mailbox( request );
-        parser.endLine( request );
-        return new UnsubscribeCommandMessage(this, mailboxName, tag);
+        final AbstractImapCommandMessage result = parser.decode(request, tag);
+        return result;
+    }
+    
+    private static class UnsubscribeCommandParser extends CommandParser {
+
+        public UnsubscribeCommandParser(ImapCommand command) {
+            super(command);
+        }
+
+        protected AbstractImapCommandMessage decode(ImapCommand command, ImapRequestLineReader request, String tag) throws ProtocolException {
+            final String mailboxName = mailbox( request );
+            endLine( request );
+            final UnsubscribeCommandMessage result = new UnsubscribeCommandMessage(command, mailboxName, tag);
+            return result;
+        }
+        
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org