    001    package org.nanocontainer.deployer;
    002
    003    import org.apache.commons.vfs.FileObject;
    004    import org.apache.commons.vfs.FileSystemException;
    005    import org.picocontainer.Startable;
    006
    007    /**
    008     * @author Aslak Helles&oslash;y
    009     * @version $Revision: 2343 $
    010     */
    011    public class DeployingFolderListener implements FolderListener, Startable {
    012        private final Deployer deployer;
    013        private final DifferenceAnalysingFolderContentHandler handler;
    014
    015        public DeployingFolderListener(Deployer deployer, DifferenceAnalysingFolderContentHandler handler) {
    016            this.deployer = deployer;
    017            this.handler = handler;
    018        }
    019
    020        public void folderAdded(FileObject folder) {
    021            try {
    022                deployer.deploy(folder, getClass().getClassLoader(), null);
    023            } catch (FileSystemException e) {
    024                throw new DeploymentException(e);
    025            } catch (ClassNotFoundException e) {
    026                throw new DeploymentException(e);
    027            }
    028        }
    029
    030        public void folderRemoved(FileObject fileObject) {
    031
    032        }
    033
    034        public void start() {
    035            handler.addFolderListener(this);
    036        }
    037
    038        public void stop() {
    039            handler.removeFolderListener(this);
    040        }
    041    }