Author: ngn
Date: Sun Oct  5 14:55:21 2008
New Revision: 701891

URL: http://svn.apache.org/viewvc?rev=701891&view=rev
Log:
Make command factory immutable (FTPSERVER-187)

Added:
    
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CommandFactoryFactory.java
   (with props)
Modified:
    
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/DefaultFtpServerContext.java
    
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/DefaultCommandFactory.java
    
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java
    
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java
    
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/nio/FtpHandlerAdapter.java
    
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/DefaultCommandFactoryTest.java
    
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/config/spring/SpringConfigTest.java

Modified: 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/DefaultFtpServerContext.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/DefaultFtpServerContext.java?rev=701891&r1=701890&r2=701891&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/DefaultFtpServerContext.java
 (original)
+++ 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/DefaultFtpServerContext.java
 Sun Oct  5 14:55:21 2008
@@ -24,7 +24,7 @@
 import java.util.Map;
 
 import org.apache.ftpserver.command.CommandFactory;
-import org.apache.ftpserver.command.impl.DefaultCommandFactory;
+import org.apache.ftpserver.command.CommandFactoryFactory;
 import org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory;
 import org.apache.ftpserver.ftplet.Authority;
 import org.apache.ftpserver.ftplet.FileSystemFactory;
@@ -67,7 +67,7 @@
 
     private FtpStatistics statistics = new DefaultFtpStatistics();
 
-    private CommandFactory commandFactory = new DefaultCommandFactory();
+    private CommandFactory commandFactory = new 
CommandFactoryFactory().createCommandFactory();
 
     private ConnectionConfig connectionConfig = new DefaultConnectionConfig();
 

Added: 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CommandFactoryFactory.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CommandFactoryFactory.java?rev=701891&view=auto
==============================================================================
--- 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CommandFactoryFactory.java
 (added)
+++ 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CommandFactoryFactory.java
 Sun Oct  5 14:55:21 2008
@@ -0,0 +1,212 @@
+/*
+ * 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.ftpserver.command;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.ftpserver.command.impl.ABOR;
+import org.apache.ftpserver.command.impl.ACCT;
+import org.apache.ftpserver.command.impl.APPE;
+import org.apache.ftpserver.command.impl.AUTH;
+import org.apache.ftpserver.command.impl.CDUP;
+import org.apache.ftpserver.command.impl.CWD;
+import org.apache.ftpserver.command.impl.DELE;
+import org.apache.ftpserver.command.impl.DefaultCommandFactory;
+import org.apache.ftpserver.command.impl.EPRT;
+import org.apache.ftpserver.command.impl.EPSV;
+import org.apache.ftpserver.command.impl.FEAT;
+import org.apache.ftpserver.command.impl.HELP;
+import org.apache.ftpserver.command.impl.LANG;
+import org.apache.ftpserver.command.impl.LIST;
+import org.apache.ftpserver.command.impl.MD5;
+import org.apache.ftpserver.command.impl.MDTM;
+import org.apache.ftpserver.command.impl.MKD;
+import org.apache.ftpserver.command.impl.MLSD;
+import org.apache.ftpserver.command.impl.MLST;
+import org.apache.ftpserver.command.impl.MODE;
+import org.apache.ftpserver.command.impl.NLST;
+import org.apache.ftpserver.command.impl.NOOP;
+import org.apache.ftpserver.command.impl.OPTS;
+import org.apache.ftpserver.command.impl.PASS;
+import org.apache.ftpserver.command.impl.PASV;
+import org.apache.ftpserver.command.impl.PBSZ;
+import org.apache.ftpserver.command.impl.PORT;
+import org.apache.ftpserver.command.impl.PROT;
+import org.apache.ftpserver.command.impl.PWD;
+import org.apache.ftpserver.command.impl.QUIT;
+import org.apache.ftpserver.command.impl.REIN;
+import org.apache.ftpserver.command.impl.REST;
+import org.apache.ftpserver.command.impl.RETR;
+import org.apache.ftpserver.command.impl.RMD;
+import org.apache.ftpserver.command.impl.RNFR;
+import org.apache.ftpserver.command.impl.RNTO;
+import org.apache.ftpserver.command.impl.SITE;
+import org.apache.ftpserver.command.impl.SIZE;
+import org.apache.ftpserver.command.impl.STAT;
+import org.apache.ftpserver.command.impl.STOR;
+import org.apache.ftpserver.command.impl.STOU;
+import org.apache.ftpserver.command.impl.STRU;
+import org.apache.ftpserver.command.impl.SYST;
+import org.apache.ftpserver.command.impl.TYPE;
+import org.apache.ftpserver.command.impl.USER;
+
+/**
+ * Factory for [EMAIL PROTECTED] CommandFactory} instances
+ *
+ * @author The Apache MINA Project ([EMAIL PROTECTED])
+ * @version $Rev$, $Date$
+ */
+public class CommandFactoryFactory {
+
+    private static final HashMap<String, Command> DEFAULT_COMMAND_MAP = new 
HashMap<String, Command>();
+
+    static {
+        // first populate the default command list
+        DEFAULT_COMMAND_MAP.put("ABOR", new ABOR());
+        DEFAULT_COMMAND_MAP.put("ACCT", new ACCT());
+        DEFAULT_COMMAND_MAP.put("APPE", new APPE());
+        DEFAULT_COMMAND_MAP.put("AUTH", new AUTH());
+        DEFAULT_COMMAND_MAP.put("CDUP", new CDUP());
+        DEFAULT_COMMAND_MAP.put("CWD", new CWD());
+        DEFAULT_COMMAND_MAP.put("DELE", new DELE());
+        DEFAULT_COMMAND_MAP.put("EPRT", new EPRT());
+        DEFAULT_COMMAND_MAP.put("EPSV", new EPSV());
+        DEFAULT_COMMAND_MAP.put("FEAT", new FEAT());
+        DEFAULT_COMMAND_MAP.put("HELP", new HELP());
+        DEFAULT_COMMAND_MAP.put("LANG", new LANG());
+        DEFAULT_COMMAND_MAP.put("LIST", new LIST());
+        DEFAULT_COMMAND_MAP.put("MD5", new MD5());
+        DEFAULT_COMMAND_MAP.put("MMD5", new MD5());
+        DEFAULT_COMMAND_MAP.put("MDTM", new MDTM());
+        DEFAULT_COMMAND_MAP.put("MLST", new MLST());
+        DEFAULT_COMMAND_MAP.put("MKD", new MKD());
+        DEFAULT_COMMAND_MAP.put("MLSD", new MLSD());
+        DEFAULT_COMMAND_MAP.put("MODE", new MODE());
+        DEFAULT_COMMAND_MAP.put("NLST", new NLST());
+        DEFAULT_COMMAND_MAP.put("NOOP", new NOOP());
+        DEFAULT_COMMAND_MAP.put("OPTS", new OPTS());
+        DEFAULT_COMMAND_MAP.put("PASS", new PASS());
+        DEFAULT_COMMAND_MAP.put("PASV", new PASV());
+        DEFAULT_COMMAND_MAP.put("PBSZ", new PBSZ());
+        DEFAULT_COMMAND_MAP.put("PORT", new PORT());
+        DEFAULT_COMMAND_MAP.put("PROT", new PROT());
+        DEFAULT_COMMAND_MAP.put("PWD", new PWD());
+        DEFAULT_COMMAND_MAP.put("QUIT", new QUIT());
+        DEFAULT_COMMAND_MAP.put("REIN", new REIN());
+        DEFAULT_COMMAND_MAP.put("REST", new REST());
+        DEFAULT_COMMAND_MAP.put("RETR", new RETR());
+        DEFAULT_COMMAND_MAP.put("RMD", new RMD());
+        DEFAULT_COMMAND_MAP.put("RNFR", new RNFR());
+        DEFAULT_COMMAND_MAP.put("RNTO", new RNTO());
+        DEFAULT_COMMAND_MAP.put("SITE", new SITE());
+        DEFAULT_COMMAND_MAP.put("SIZE", new SIZE());
+        DEFAULT_COMMAND_MAP.put("STAT", new STAT());
+        DEFAULT_COMMAND_MAP.put("STOR", new STOR());
+        DEFAULT_COMMAND_MAP.put("STOU", new STOU());
+        DEFAULT_COMMAND_MAP.put("STRU", new STRU());
+        DEFAULT_COMMAND_MAP.put("SYST", new SYST());
+        DEFAULT_COMMAND_MAP.put("TYPE", new TYPE());
+        DEFAULT_COMMAND_MAP.put("USER", new USER());
+    }
+
+    private Map<String, Command> commandMap = new HashMap<String, Command>();
+
+    private boolean useDefaultCommands = true;
+
+    /**
+     * Create an [EMAIL PROTECTED] CommandFactory} based on the configuration 
on the factory.
+     * @return The [EMAIL PROTECTED] CommandFactory}
+     */
+    public CommandFactory createCommandFactory() {
+        
+        Map<String, Command> mergedCommands = new HashMap<String, Command>();
+        if(useDefaultCommands) {
+            mergedCommands.putAll(DEFAULT_COMMAND_MAP);
+        }
+        
+        mergedCommands.putAll(commandMap);
+        
+        return new DefaultCommandFactory(mergedCommands);
+    }
+    
+    /**
+     * Are default commands used?
+     * 
+     * @return true if default commands are used
+     */
+    public boolean isUseDefaultCommands() {
+        return useDefaultCommands;
+    }
+
+    /**
+     * Sets whether the default commands will be used.
+     * 
+     * @param useDefaultCommands
+     *            true if default commands should be used
+     */
+    public void setUseDefaultCommands(final boolean useDefaultCommands) {
+        this.useDefaultCommands = useDefaultCommands;
+    }
+
+    /**
+     * Get the installed commands
+     * 
+     * @return The installed commands
+     */
+    public Map<String, Command> getCommandMap() {
+        return commandMap;
+    }
+
+    /**
+     * Add or override a command.
+     * @param commandName The command name, e.g. STOR
+     * @param command The command
+     */
+    public void addCommand(String commandName, Command command) {
+        if(commandName == null) {
+            throw new NullPointerException("commandName can not be null");
+        }
+        if(command == null) {
+            throw new NullPointerException("command can not be null");
+        }
+        
+        commandMap.put(commandName.toUpperCase(), command);
+    }
+    
+    /**
+     * Set commands to add or override to the default commands
+     * 
+     * @param commandMap
+     *            The map of commands, the key will be used to map to requests.
+     */
+    public void setCommandMap(final Map<String, Command> commandMap) {
+        if (commandMap == null) {
+            throw new NullPointerException("commandMap can not be null");
+        }
+
+        this.commandMap.clear();
+
+        for (Entry<String, Command> entry : commandMap.entrySet()) {
+            this.commandMap.put(entry.getKey().toUpperCase(), 
entry.getValue());
+        }
+    }
+}

Propchange: 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CommandFactoryFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/DefaultCommandFactory.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/DefaultCommandFactory.java?rev=701891&r1=701890&r2=701891&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/DefaultCommandFactory.java
 (original)
+++ 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/DefaultCommandFactory.java
 Sun Oct  5 14:55:21 2008
@@ -21,123 +21,30 @@
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Map.Entry;
 
 import org.apache.ftpserver.command.Command;
 import org.apache.ftpserver.command.CommandFactory;
+import org.apache.ftpserver.command.CommandFactoryFactory;
 
 /**
  * Command factory to return appropriate command implementation depending on 
the
  * FTP request command string.
- * 
- * Used a default setup of commands which can be appended or overriden using
- * [EMAIL PROTECTED] #setCommandMap(HashMap)}.
+ *
+ * <strong>Internal class, do not use directly</strong>
  *
  * @author The Apache MINA Project ([EMAIL PROTECTED])
  * @version $Rev$, $Date$
  */
 public class DefaultCommandFactory implements CommandFactory {
 
-    private static final HashMap<String, Command> DEFAULT_COMMAND_MAP = new 
HashMap<String, Command>();
-
-    static {
-        // first populate the default command list
-        DEFAULT_COMMAND_MAP.put("ABOR", new ABOR());
-        DEFAULT_COMMAND_MAP.put("ACCT", new ACCT());
-        DEFAULT_COMMAND_MAP.put("APPE", new APPE());
-        DEFAULT_COMMAND_MAP.put("AUTH", new AUTH());
-        DEFAULT_COMMAND_MAP.put("CDUP", new CDUP());
-        DEFAULT_COMMAND_MAP.put("CWD", new CWD());
-        DEFAULT_COMMAND_MAP.put("DELE", new DELE());
-        DEFAULT_COMMAND_MAP.put("EPRT", new EPRT());
-        DEFAULT_COMMAND_MAP.put("EPSV", new EPSV());
-        DEFAULT_COMMAND_MAP.put("FEAT", new FEAT());
-        DEFAULT_COMMAND_MAP.put("HELP", new HELP());
-        DEFAULT_COMMAND_MAP.put("LANG", new LANG());
-        DEFAULT_COMMAND_MAP.put("LIST", new LIST());
-        DEFAULT_COMMAND_MAP.put("MD5", new MD5());
-        DEFAULT_COMMAND_MAP.put("MMD5", new MD5());
-        DEFAULT_COMMAND_MAP.put("MDTM", new MDTM());
-        DEFAULT_COMMAND_MAP.put("MLST", new MLST());
-        DEFAULT_COMMAND_MAP.put("MKD", new MKD());
-        DEFAULT_COMMAND_MAP.put("MLSD", new MLSD());
-        DEFAULT_COMMAND_MAP.put("MODE", new MODE());
-        DEFAULT_COMMAND_MAP.put("NLST", new NLST());
-        DEFAULT_COMMAND_MAP.put("NOOP", new NOOP());
-        DEFAULT_COMMAND_MAP.put("OPTS", new OPTS());
-        DEFAULT_COMMAND_MAP.put("PASS", new PASS());
-        DEFAULT_COMMAND_MAP.put("PASV", new PASV());
-        DEFAULT_COMMAND_MAP.put("PBSZ", new PBSZ());
-        DEFAULT_COMMAND_MAP.put("PORT", new PORT());
-        DEFAULT_COMMAND_MAP.put("PROT", new PROT());
-        DEFAULT_COMMAND_MAP.put("PWD", new PWD());
-        DEFAULT_COMMAND_MAP.put("QUIT", new QUIT());
-        DEFAULT_COMMAND_MAP.put("REIN", new REIN());
-        DEFAULT_COMMAND_MAP.put("REST", new REST());
-        DEFAULT_COMMAND_MAP.put("RETR", new RETR());
-        DEFAULT_COMMAND_MAP.put("RMD", new RMD());
-        DEFAULT_COMMAND_MAP.put("RNFR", new RNFR());
-        DEFAULT_COMMAND_MAP.put("RNTO", new RNTO());
-        DEFAULT_COMMAND_MAP.put("SITE", new SITE());
-        DEFAULT_COMMAND_MAP.put("SIZE", new SIZE());
-        DEFAULT_COMMAND_MAP.put("STAT", new STAT());
-        DEFAULT_COMMAND_MAP.put("STOR", new STOR());
-        DEFAULT_COMMAND_MAP.put("STOU", new STOU());
-        DEFAULT_COMMAND_MAP.put("STRU", new STRU());
-        DEFAULT_COMMAND_MAP.put("SYST", new SYST());
-        DEFAULT_COMMAND_MAP.put("TYPE", new TYPE());
-        DEFAULT_COMMAND_MAP.put("USER", new USER());
-    }
-
-    private Map<String, Command> commandMap = new HashMap<String, Command>();
-
-    private boolean useDefaultCommands = true;
-
-    /**
-     * Are default commands used?
-     * 
-     * @return true if default commands are used
-     */
-    public boolean isUseDefaultCommands() {
-        return useDefaultCommands;
-    }
-
-    /**
-     * Sets whether the default commands will be used.
-     * 
-     * @param useDefaultCommands
-     *            true if default commands should be used
-     */
-    public void setUseDefaultCommands(final boolean useDefaultCommands) {
-        this.useDefaultCommands = useDefaultCommands;
-    }
-
     /**
-     * Get the installed commands
-     * 
-     * @return The installed commands
+     * Internal constructor, use [EMAIL PROTECTED] CommandFactoryFactory} 
instead
      */
-    public Map<String, Command> getCommandMap() {
-        return commandMap;
+    public DefaultCommandFactory(Map<String, Command> commandMap) {
+        this.commandMap = commandMap;
     }
 
-    /**
-     * Set commands to add or override to the default commands
-     * 
-     * @param commandMap
-     *            The map of commands, the key will be used to map to requests.
-     */
-    public synchronized void setCommandMap(final Map<String, Command> 
commandMap) {
-        if (commandMap == null) {
-            throw new NullPointerException("commandMap can not be null");
-        }
-
-        this.commandMap.clear();
-
-        for (Entry<String, Command> entry : commandMap.entrySet()) {
-            this.commandMap.put(entry.getKey().toUpperCase(), 
entry.getValue());
-        }
-    }
+    private Map<String, Command> commandMap = new HashMap<String, Command>();
 
     /**
      * Get command. Returns null if not found.
@@ -147,12 +54,6 @@
             return null;
         }
         String upperCaseCmdName = cmdName.toUpperCase();
-        Command command = commandMap.get(upperCaseCmdName);
-
-        if (command == null && useDefaultCommands) {
-            command = DEFAULT_COMMAND_MAP.get(upperCaseCmdName);
-        }
-
-        return command;
+        return commandMap.get(upperCaseCmdName);
     }
 }

Modified: 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java?rev=701891&r1=701890&r2=701891&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java
 (original)
+++ 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/CommandFactoryBeanDefinitionParser.java
 Sun Oct  5 14:55:21 2008
@@ -22,7 +22,9 @@
 import java.util.List;
 
 import org.apache.ftpserver.command.CommandFactory;
-import org.apache.ftpserver.command.impl.DefaultCommandFactory;
+import org.apache.ftpserver.command.CommandFactoryFactory;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinitionHolder;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 import org.springframework.beans.factory.support.ManagedMap;
 import 
org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
@@ -44,7 +46,7 @@
      */
     @Override
     protected Class<? extends CommandFactory> getBeanClass(final Element 
element) {
-        return DefaultCommandFactory.class;
+        return null;
     }
 
     /**
@@ -54,6 +56,9 @@
     protected void doParse(final Element element,
             final ParserContext parserContext,
             final BeanDefinitionBuilder builder) {
+        
+        BeanDefinitionBuilder factoryBuilder = 
BeanDefinitionBuilder.genericBeanDefinition(CommandFactoryFactory.class);
+        
         ManagedMap commands = new ManagedMap();
 
         List<Element> childs = SpringUtil.getChildElements(element);
@@ -65,11 +70,22 @@
             commands.put(name, bean);
         }
 
-        builder.addPropertyValue("commandMap", commands);
+        factoryBuilder.addPropertyValue("commandMap", commands);
 
         if (StringUtils.hasText(element.getAttribute("use-default"))) {
-            builder.addPropertyValue("useDefaultCommands", Boolean
+            factoryBuilder.addPropertyValue("useDefaultCommands", Boolean
                     .parseBoolean(element.getAttribute("use-default")));
         }
+        
+        BeanDefinition factoryDefinition = factoryBuilder.getBeanDefinition();
+        String factoryId = 
parserContext.getReaderContext().generateBeanName(factoryDefinition);
+        
+        BeanDefinitionHolder factoryHolder = new 
BeanDefinitionHolder(factoryBuilder.getBeanDefinition(), factoryId);
+        registerBeanDefinition(factoryHolder, parserContext.getRegistry());
+
+        // set the factory on the listener bean
+        builder.getRawBeanDefinition().setFactoryBeanName(factoryId);
+        
builder.getRawBeanDefinition().setFactoryMethodName("createCommandFactory");
+
     }
 }

Modified: 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java?rev=701891&r1=701890&r2=701891&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java
 (original)
+++ 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/config/spring/ListenerBeanDefinitionParser.java
 Sun Oct  5 14:55:21 2008
@@ -152,12 +152,15 @@
             factoryBuilder.addPropertyValue("blockedSubnets", subnets);
         }
         
+        String listenerName = element.getAttribute("name");
+        // TODO Investigate how to make unique
+        String listenerFactoryName = listenerName + "-factory";
         
-        BeanDefinitionHolder factoryHolder = new 
BeanDefinitionHolder(factoryBuilder.getBeanDefinition(), "listener-factory");
+        BeanDefinitionHolder factoryHolder = new 
BeanDefinitionHolder(factoryBuilder.getBeanDefinition(), listenerFactoryName);
         registerBeanDefinition(factoryHolder, parserContext.getRegistry());
 
         // set the factory on the listener bean
-        builder.getRawBeanDefinition().setFactoryBeanName("listener-factory");
+        builder.getRawBeanDefinition().setFactoryBeanName(listenerFactoryName);
         builder.getRawBeanDefinition().setFactoryMethodName("createListener");
     }
 

Modified: 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/nio/FtpHandlerAdapter.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/nio/FtpHandlerAdapter.java?rev=701891&r1=701890&r2=701891&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/nio/FtpHandlerAdapter.java
 (original)
+++ 
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/nio/FtpHandlerAdapter.java
 Sun Oct  5 14:55:21 2008
@@ -23,8 +23,8 @@
 import org.apache.ftpserver.FtpServerContext;
 import org.apache.ftpserver.ftplet.FtpReply;
 import org.apache.ftpserver.ftplet.FtpRequest;
-import org.apache.ftpserver.impl.FtpIoSession;
 import org.apache.ftpserver.impl.DefaultFtpRequest;
+import org.apache.ftpserver.impl.FtpIoSession;
 import org.apache.mina.core.service.IoHandler;
 import org.apache.mina.core.session.IdleStatus;
 import org.apache.mina.core.session.IoSession;

Modified: 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/DefaultCommandFactoryTest.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/DefaultCommandFactoryTest.java?rev=701891&r1=701890&r2=701891&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/DefaultCommandFactoryTest.java
 (original)
+++ 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/DefaultCommandFactoryTest.java
 Sun Oct  5 14:55:21 2008
@@ -19,13 +19,11 @@
 
 package org.apache.ftpserver.commands.impl;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import junit.framework.TestCase;
 
 import org.apache.ftpserver.command.Command;
-import org.apache.ftpserver.command.impl.DefaultCommandFactory;
+import org.apache.ftpserver.command.CommandFactory;
+import org.apache.ftpserver.command.CommandFactoryFactory;
 import org.apache.ftpserver.command.impl.NOOP;
 import org.apache.ftpserver.command.impl.STOR;
 
@@ -39,7 +37,7 @@
 public class DefaultCommandFactoryTest extends TestCase {
 
     public void testReturnFromDefaultUpper() {
-        DefaultCommandFactory factory = new DefaultCommandFactory();
+        CommandFactory factory = new 
CommandFactoryFactory().createCommandFactory();
         Command command = factory.getCommand("STOR");
 
         assertNotNull(command);
@@ -47,7 +45,7 @@
     }
 
     public void testReturnFromDefaultLower() {
-        DefaultCommandFactory factory = new DefaultCommandFactory();
+        CommandFactory factory = new 
CommandFactoryFactory().createCommandFactory();
         Command command = factory.getCommand("stor");
 
         assertNotNull(command);
@@ -55,17 +53,17 @@
     }
 
     public void testReturnFromDefaultUnknown() {
-        DefaultCommandFactory factory = new DefaultCommandFactory();
+        CommandFactory factory = new 
CommandFactoryFactory().createCommandFactory();
         Command command = factory.getCommand("dummy");
 
         assertNull(command);
     }
 
     public void testOverride() {
-        DefaultCommandFactory factory = new DefaultCommandFactory();
-        Map<String, Command> commands = new HashMap<String, Command>();
-        commands.put("stor", new NOOP());
-        factory.setCommandMap(commands);
+        CommandFactoryFactory factoryFactory = new CommandFactoryFactory();
+        factoryFactory.addCommand("stor", new NOOP());
+
+        CommandFactory factory = factoryFactory.createCommandFactory();
 
         Command command = factory.getCommand("Stor");
 
@@ -73,22 +71,22 @@
     }
 
     public void testAppend() {
-        DefaultCommandFactory factory = new DefaultCommandFactory();
-        Map<String, Command> commands = new HashMap<String, Command>();
-        commands.put("foo", new NOOP());
-        factory.setCommandMap(commands);
+        CommandFactoryFactory factoryFactory = new CommandFactoryFactory();
+        factoryFactory.addCommand("foo", new NOOP());
+
+        CommandFactory factory = factoryFactory.createCommandFactory();
 
         assertTrue(factory.getCommand("FOO") instanceof NOOP);
         assertTrue(factory.getCommand("stor") instanceof STOR);
     }
 
     public void testAppendWithoutDefault() {
-        DefaultCommandFactory factory = new DefaultCommandFactory();
-        factory.setUseDefaultCommands(false);
-        Map<String, Command> commands = new HashMap<String, Command>();
-        commands.put("foo", new NOOP());
-        factory.setCommandMap(commands);
+        CommandFactoryFactory factoryFactory = new CommandFactoryFactory();
+        factoryFactory.addCommand("foo", new NOOP());
+        factoryFactory.setUseDefaultCommands(false);
 
+        CommandFactory factory = factoryFactory.createCommandFactory();
+        
         assertTrue(factory.getCommand("FOO") instanceof NOOP);
         assertNull(factory.getCommand("stor"));
     }

Modified: 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/config/spring/SpringConfigTest.java
URL: 
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/config/spring/SpringConfigTest.java?rev=701891&r1=701890&r2=701891&view=diff
==============================================================================
--- 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/config/spring/SpringConfigTest.java
 (original)
+++ 
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/config/spring/SpringConfigTest.java
 Sun Oct  5 14:55:21 2008
@@ -26,7 +26,7 @@
 import junit.framework.TestCase;
 
 import org.apache.ftpserver.FtpServer;
-import org.apache.ftpserver.command.impl.DefaultCommandFactory;
+import org.apache.ftpserver.command.CommandFactory;
 import org.apache.ftpserver.command.impl.HELP;
 import org.apache.ftpserver.command.impl.STAT;
 import org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory;
@@ -93,9 +93,7 @@
         assertTrue(listener instanceof MyCustomListener);
         assertEquals(2224, listener.getPort());
 
-        DefaultCommandFactory cf = (DefaultCommandFactory) server
-                .getServerContext().getCommandFactory();
-        assertEquals(2, cf.getCommandMap().size());
+        CommandFactory cf = server.getCommandFactory();
         assertTrue(cf.getCommand("FOO") instanceof HELP);
         assertTrue(cf.getCommand("FOO2") instanceof STAT);
 


Reply via email to