1 17 18 package org.apache.james.imapserver.commands; 19 20 import org.apache.avalon.framework.CascadingRuntimeException; 21 import org.apache.avalon.framework.logger.AbstractLogEnabled; 22 import org.apache.avalon.framework.logger.LogEnabled; 23 import org.apache.james.imapserver.CommandFetch; 24 import org.apache.james.imapserver.CommandStore; 25 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 34 public final class ImapCommandFactory 35 extends AbstractLogEnabled 36 { 37 private Map _imapCommands; 38 private ImapCommand _invalidCommand; 39 40 public ImapCommandFactory() 41 { 42 _invalidCommand = new InvalidCommand(); 43 44 _imapCommands = new HashMap (); 45 _imapCommands.put( "CAPABILITY", CapabilityCommand.class ); 48 _imapCommands.put( "NOOP", NoopCommand.class ); 49 _imapCommands.put( "LOGOUT", LogoutCommand.class ); 50 51 _imapCommands.put( "AUTHENTICATE", AuthenticateCommand.class ); 54 _imapCommands.put( "LOGIN", LoginCommand.class ); 55 56 _imapCommands.put( "SELECT", SelectCommand.class ); 59 _imapCommands.put( "EXAMINE", ExamineCommand.class ); 60 _imapCommands.put( "CREATE", CreateCommand.class ); 61 _imapCommands.put( "DELETE", DeleteCommand.class ); 62 _imapCommands.put( "RENAME", RenameCommand.class ); 63 _imapCommands.put( "SUBSCRIBE", SubscribeCommand.class ); 64 _imapCommands.put( "UNSUBSCRIBE", UnsubscribeCommand.class ); 65 _imapCommands.put( "LIST", ListCommand.class ); 66 _imapCommands.put( "LSUB", LsubCommand.class ); 67 _imapCommands.put( "STATUS", StatusCommand.class ); 68 _imapCommands.put( "APPEND", AppendCommand.class ); 69 _imapCommands.put( "NAMESPACE", NamespaceCommand.class ); 71 _imapCommands.put( "GETACL", GetAclCommand.class ); 73 _imapCommands.put( "SETACL", SetAclCommand.class ); 74 _imapCommands.put( "DELETEACL", DeleteAclCommand.class ); 75 _imapCommands.put( "LISTRIGHTS", ListRightsCommand.class ); 76 _imapCommands.put( "MYRIGHTS", MyRightsCommand.class ); 77 78 79 _imapCommands.put( "CHECK", CheckCommand.class ); 82 _imapCommands.put( "CLOSE", CloseCommand.class ); 83 _imapCommands.put( "COPY", CopyCommand.class ); 84 _imapCommands.put( "EXPUNGE", ExpungeCommand.class ); 85 _imapCommands.put( "SEARCH", SearchCommand.class ); 86 _imapCommands.put( "FETCH", CommandFetch.class ); 87 _imapCommands.put( "STORE", CommandStore.class ); 88 _imapCommands.put( "UID", UidCommand.class ); 89 } 90 91 public ImapCommand getCommand( String commandName ) 92 { 93 Class cmdClass = (Class )_imapCommands.get( commandName.toUpperCase() ); 94 95 if ( cmdClass == null ) { 96 return _invalidCommand; 97 } 98 else { 99 return createCommand( cmdClass ); 100 } 101 } 102 103 private ImapCommand createCommand( Class commandClass ) 104 { 105 try { 106 ImapCommand cmd = (ImapCommand) commandClass.newInstance(); 107 if ( cmd instanceof LogEnabled ) { 108 ((LogEnabled) cmd).enableLogging( getLogger() ); 109 } 110 return cmd; 111 } 112 catch ( Exception e ) { 113 throw new CascadingRuntimeException( "Could not create command instance: " + commandClass.getName(), e ); 114 } 115 } 116 117 118 } 119 | Popular Tags |