incubator-ftpserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r487976 - in /incubator/ftpserver/trunk/core/src: java/org/apache/ftpserver/ java/org/apache/ftpserver/ftplet/ test/org/apache/ftpserver/ftplet/
Date Sun, 17 Dec 2006 12:29:14 GMT
Author: ngn
Date: Sun Dec 17 04:29:14 2006
New Revision: 487976

URL: http://svn.apache.org/viewvc?view=rev&rev=487976
Log:
Refactored out an explicit FtpletContainer and added tests for it (more to come)

Added:
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/DefaultFtpletContainer.java
  (with props)
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/FtpletContainer.java
  (with props)
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ftplet/DefaultFtpLetContainerTest.java
  (with props)
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ftplet/FtpLetContainerTestTemplate.java
  (with props)
Removed:
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpletContainer.java
Modified:
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpConfigImpl.java

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpConfigImpl.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpConfigImpl.java?view=diff&rev=487976&r1=487975&r2=487976
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpConfigImpl.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpConfigImpl.java Sun Dec
17 04:29:14 2006
@@ -20,22 +20,26 @@
 package org.apache.ftpserver;
 
 import java.net.InetAddress;
+import java.util.StringTokenizer;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ftpserver.ftplet.Component;
 import org.apache.ftpserver.ftplet.Configuration;
+import org.apache.ftpserver.ftplet.DefaultFtpletContainer;
 import org.apache.ftpserver.ftplet.FileSystemManager;
+import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.FtpStatistics;
 import org.apache.ftpserver.ftplet.Ftplet;
+import org.apache.ftpserver.ftplet.FtpletContainer;
 import org.apache.ftpserver.ftplet.UserManager;
 import org.apache.ftpserver.interfaces.CommandFactory;
 import org.apache.ftpserver.interfaces.ConnectionManager;
 import org.apache.ftpserver.interfaces.DataConnectionConfig;
-import org.apache.ftpserver.interfaces.ServerFtpConfig;
-import org.apache.ftpserver.interfaces.ServerFtpStatistics;
 import org.apache.ftpserver.interfaces.IpRestrictor;
 import org.apache.ftpserver.interfaces.MessageResource;
+import org.apache.ftpserver.interfaces.ServerFtpConfig;
+import org.apache.ftpserver.interfaces.ServerFtpStatistics;
 import org.apache.ftpserver.interfaces.SocketFactory;
 import org.apache.ftpserver.usermanager.BaseUser;
 
@@ -92,11 +96,9 @@
                 createDefaultUsers();
             }
             
-            // create and initialize ftlets
-            ftpletContainer = new FtpletContainer();
-            String ftpletNames = conf.getString("ftplets", null);
-            Configuration ftpletConf = conf.subset("ftplet");
-            ftpletContainer.init(this, ftpletNames, ftpletConf);        
+            ftpletContainer    = (FtpletContainer) createComponent(conf, "ftplet-container",
    DefaultFtpletContainer.class.getName());
+       
+            initFtplets(ftpletContainer, conf);
         }
         catch(Exception ex) {
             dispose();
@@ -105,6 +107,49 @@
     }
 
     /**
+     * create and initialize ftlets
+     * @param container
+     * @param conf
+     * @throws FtpException
+     */
+    private void initFtplets(FtpletContainer container, Configuration conf) throws FtpException
{
+        String ftpletNames = conf.getString("ftplets", null);
+        Configuration ftpletConf = conf.subset("ftplet");
+                
+        if(ftpletNames == null) {
+            return;
+        }
+        
+        //log = ftpConfig.getLogFactory().getInstance(getClass());
+        StringTokenizer st = new StringTokenizer(ftpletNames, " ,;\r\n\t");
+        try {
+            while(st.hasMoreTokens()) {
+                String ftpletName = st.nextToken();
+                log.info("Configuring ftplet : " + ftpletName);
+                
+                // get ftplet specific configuration
+                Configuration subConfig = ftpletConf.subset(ftpletName);
+                String className = subConfig.getString("class", null);
+                if(className == null) {
+                    continue;
+                }
+                Ftplet ftplet = (Ftplet)Class.forName(className).newInstance();
+                ftplet.init(this, subConfig);
+                container.addFtplet(ftpletName, ftplet);
+            }
+        }
+        catch(FtpException ex) {
+            container.destroy();
+            throw ex;
+        }
+        catch(Exception ex) {
+            container.destroy();
+            log.fatal("FtpletContainer.init()", ex);
+            throw new FtpException("FtpletContainer.init()", ex);
+        }
+    }
+    
+    /**
      * Create component. 
      */
     private Component createComponent(Configuration parentConfig, String configName, String
defaultClass) throws Exception {
@@ -276,7 +321,9 @@
         }
         
         if(ftpletContainer != null) {
-            ftpletContainer.destroy();
+            if(ftpletContainer instanceof Component) {
+                ((Component)ftpletContainer).dispose();
+            }
             ftpletContainer = null;
         }
         

Added: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/DefaultFtpletContainer.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/DefaultFtpletContainer.java?view=auto&rev=487976
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/DefaultFtpletContainer.java
(added)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/DefaultFtpletContainer.java
Sun Dec 17 04:29:14 2006
@@ -0,0 +1,552 @@
+/*
+ * 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.ftplet;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This ftplet calls other ftplet methods and returns appropriate return value.
+ * 
+ * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
+ */
+public 
+class DefaultFtpletContainer implements Component, FtpletContainer {
+    
+    private Log log;
+    private List ftplets = new ArrayList();
+    
+    private static class FtpletEntry {
+        public FtpletEntry(String name, Ftplet ftplet) {
+            this.name = name;
+            this.ftplet = ftplet;
+        }
+        final String name;
+        final Ftplet ftplet;
+    }
+    
+    public void configure(Configuration config) throws FtpException {
+        // do nothing
+    }
+
+    public void dispose() {
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            try {
+                ftpletEnt.ftplet.destroy();
+            }
+            catch(Exception ex) {
+                log.error(ftpletEnt.name + " :: FtpletHandler.destroy()", ex);
+            }
+        }
+        ftplets.clear();
+        
+    }
+
+    public void setLogFactory(LogFactory logFact) {
+        log = logFact.getInstance(DefaultFtpletContainer.class);
+        
+    }
+    
+    public void addFtplet(String name, Ftplet ftplet) {
+        if(getFtplet(name) != null) {
+            throw new IllegalArgumentException("Ftplet with name \"" + name + "\" already
registred with container");
+        }
+        
+        ftplets.add(new FtpletEntry(name, ftplet));
+    }
+
+    public Ftplet removeFtplet(String name) {
+        int sz = ftplets.size();
+        Ftplet removedFtplet = null;
+        for (int i=0; i<sz; i++) {
+            FtpletEntry entry = (FtpletEntry) ftplets.get(i);
+            
+            if(name.equals(entry.name)) {
+                ftplets.remove(i);
+                removedFtplet = entry.ftplet;
+                break;
+            }
+            
+        }
+        
+        return removedFtplet;
+        
+    }
+    
+    /**
+     * Get Ftplet for the given name.
+     */
+    public Ftplet getFtplet(String name) {
+        if(name == null) {
+            return null;
+        }
+        
+        Ftplet ftplet = null;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            if(ftpletEnt.name.equals(name)) {
+                ftplet = ftpletEnt.ftplet;
+                break;
+            }
+        }
+        return ftplet;
+    }
+    
+    /**
+     * Destroy all ftplets.
+     */
+    public void destroy() {
+        dispose();
+    }
+    
+    /**
+     * Call ftplet onConnect.
+     */
+    public FtpletEnum onConnect(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onConnect(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /**
+     * Call ftplet onDisconnect.
+     */
+    public FtpletEnum onDisconnect(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onDisconnect(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+    
+    /**
+     * Call ftplet onLogin.
+     */
+    public FtpletEnum onLogin(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onLogin(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /** 
+     * Call ftplet onDeleteStart.
+     */
+    public FtpletEnum onDeleteStart(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onDeleteStart(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    
+    /**
+     * Call ftplet onDeleteEnd.
+     */
+    public FtpletEnum onDeleteEnd(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onDeleteEnd(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /**
+     * Call ftplet onUploadStart.
+     */
+    public FtpletEnum onUploadStart(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onUploadStart(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /**
+     * Call ftplet onUploadEnd.
+     */
+    public FtpletEnum onUploadEnd(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onUploadEnd(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /**
+     * Call ftplet onDownloadStart.
+     */
+    public FtpletEnum onDownloadStart(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onDownloadStart(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /**
+     * Call ftplet onDownloadEnd.
+     */
+    public FtpletEnum onDownloadEnd(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onDownloadEnd(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /**
+     * Call ftplet onRmdirStart.
+     */
+    public FtpletEnum onRmdirStart(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onRmdirStart(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /**
+     * Call ftplet onRmdirEnd.
+     */
+    public FtpletEnum onRmdirEnd(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onRmdirEnd(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /**
+     * Call ftplet onMkdirStart.
+     */
+    public FtpletEnum onMkdirStart(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onMkdirStart(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /** 
+     * Call ftplet onMkdirEnd.
+     */
+    public FtpletEnum onMkdirEnd(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onMkdirEnd(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+    
+    /**
+     * Call ftplet onAppendStart.
+     */
+    public FtpletEnum onAppendStart(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onAppendStart(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /**
+     * Call ftplet onAppendEnd.
+     */
+    public FtpletEnum onAppendEnd(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onAppendEnd(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /**
+     * Call ftplet onUploadUniqueStart.
+     */
+    public FtpletEnum onUploadUniqueStart(FtpRequest request, FtpResponse response) throws
FtpException, IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onUploadUniqueStart(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+    
+    /**
+     * Call ftplet onUploadUniqueEnd.
+     */
+    public FtpletEnum onUploadUniqueEnd(FtpRequest request, FtpResponse response) throws
FtpException, IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onUploadUniqueEnd(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    /**
+     * Call ftplet onRenameStart.
+     */
+    public FtpletEnum onRenameStart(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onRenameStart(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+    
+    /**
+     * Call ftplet onRenameEnd.
+     */
+    public FtpletEnum onRenameEnd(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onRenameEnd(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+    
+    /**
+     * Call ftplet onSite.
+     */
+    public FtpletEnum onSite(FtpRequest request, FtpResponse response) throws FtpException,
IOException {
+        FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
+        int sz = ftplets.size();
+        for(int i=0; i<sz; ++i) {
+            FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
+            retVal = ftpletEnt.ftplet.onSite(request, response);
+            if(retVal == null) {
+                retVal = FtpletEnum.RET_DEFAULT;
+            }
+            
+            // proceed only if the return value is FtpletEnum.RET_DEFAULT
+            if(retVal != FtpletEnum.RET_DEFAULT) {
+                break;
+            }
+        }
+        return retVal;
+    }
+
+    public void init(FtpConfig ftpConfig, Configuration config) throws FtpException {
+        // dummy, forces by Ftplet API       
+    }
+
+
+}

Propchange: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/DefaultFtpletContainer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/FtpletContainer.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/FtpletContainer.java?view=auto&rev=487976
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/FtpletContainer.java
(added)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/FtpletContainer.java
Sun Dec 17 04:29:14 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.ftplet;
+
+/**
+ * Interface describing an Ftplet container. 
+ * Ftplet containers extend the {@link Ftplet} interface and 
+ * forward any events to the Ftplets hosted by the container.
+ */
+public interface FtpletContainer extends Ftplet {
+
+    /**
+     * Add an {@link Ftplet} to the container.
+     * 
+     * @param name The name of the Ftplet to be added
+     * @param ftplet The Ftplet
+     * @throws IllegalArgumentException If an Ftplet with the same
+     *   name already exist within the container
+     */
+    void addFtplet(String name, Ftplet ftplet);
+
+    /**
+     * Remove the {@link Ftplet} identified by the name (as
+     * provided in the {@link #addFtplet(String, Ftplet)} method.
+     * 
+     * @param name The name of the Ftplet to be removed
+     * @return The removed Ftplet if found, or null if the name is
+     *   unknown to the container.
+     */
+    Ftplet removeFtplet(String name);
+    
+    /**
+     * Retrive the {@link Ftplet} identified by the name (as
+     * provided in the {@link #addFtplet(String, Ftplet)} method.
+     * @param name The name of the Ftplet to retrive
+     * @return The Ftplet if found, or null if the name is
+     *   unknown to the container.
+     */
+    Ftplet getFtplet(String name);
+}
\ No newline at end of file

Propchange: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/ftplet/FtpletContainer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ftplet/DefaultFtpLetContainerTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ftplet/DefaultFtpLetContainerTest.java?view=auto&rev=487976
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ftplet/DefaultFtpLetContainerTest.java
(added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ftplet/DefaultFtpLetContainerTest.java
Sun Dec 17 04:29:14 2006
@@ -0,0 +1,31 @@
+/*
+ * 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.ftplet;
+
+
+
+public class DefaultFtpLetContainerTest extends FtpLetContainerTestTemplate {
+
+
+    protected FtpletContainer createFtpletContainer() {
+        return new DefaultFtpletContainer();
+    }
+
+}

Propchange: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ftplet/DefaultFtpLetContainerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ftplet/FtpLetContainerTestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ftplet/FtpLetContainerTestTemplate.java?view=auto&rev=487976
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ftplet/FtpLetContainerTestTemplate.java
(added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ftplet/FtpLetContainerTestTemplate.java
Sun Dec 17 04:29:14 2006
@@ -0,0 +1,81 @@
+/*
+ * 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.ftplet;
+
+import junit.framework.TestCase;
+
+
+public abstract class FtpLetContainerTestTemplate extends TestCase {
+
+    private FtpletContainer container = createFtpletContainer();
+    
+    public void testAddAndGetFtplet() {
+        MockFtplet ftplet1 = new MockFtplet();
+        MockFtplet ftplet2 = new MockFtplet();
+        
+        assertNull(container.getFtplet("ftplet1"));
+        assertNull(container.getFtplet("ftplet2"));
+        
+        container.addFtplet("ftplet1", ftplet1);
+        container.addFtplet("ftplet2", ftplet2);
+        
+        assertSame(ftplet1, container.getFtplet("ftplet1"));
+        assertSame(ftplet2, container.getFtplet("ftplet2"));
+    }
+    
+    public void testAddFtpletWithDuplicateName() {
+        MockFtplet ftplet1 = new MockFtplet();
+        MockFtplet ftplet2 = new MockFtplet();
+        
+        assertNull(container.getFtplet("ftplet1"));
+        
+        container.addFtplet("ftplet1", ftplet1);
+        
+        try {
+            container.addFtplet("ftplet1", ftplet2);
+            fail("IllegalArgumentException must be thrown");
+        } catch(IllegalArgumentException e) {
+            // ok
+        }
+        
+        assertSame(ftplet1, container.getFtplet("ftplet1"));
+    }
+
+    public void testRemoveFtplet() {
+        MockFtplet ftplet1 = new MockFtplet();
+        MockFtplet ftplet2 = new MockFtplet();
+        
+        container.addFtplet("ftplet1", ftplet1);
+        container.addFtplet("ftplet2", ftplet2);
+        
+        assertSame(ftplet1, container.getFtplet("ftplet1"));
+        assertSame(ftplet2, container.getFtplet("ftplet2"));
+        
+        assertSame(ftplet1, container.removeFtplet("ftplet1"));
+        
+        assertNull(container.getFtplet("ftplet1"));
+        assertSame(ftplet2, container.getFtplet("ftplet2"));
+        
+        assertNull(container.removeFtplet("ftplet1"));
+    }
+    
+    protected abstract FtpletContainer createFtpletContainer();
+
+}

Propchange: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/ftplet/FtpLetContainerTestTemplate.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message