From: <st...@us...> - 2011-04-03 22:16:14
|
Revision: 8558 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8558&view=rev Author: steve_l Date: 2011-04-03 22:16:08 +0000 (Sun, 03 Apr 2011) Log Message: ----------- SFOS-1542 add rmdir component to delete a directory or files on deployment Added Paths: ----------- trunk/core/smartfrog/src/org/smartfrog/services/filesystem/RmdirImpl.java trunk/core/smartfrog/src/org/smartfrog/services/filesystem/rmdir.sf Copied: trunk/core/smartfrog/src/org/smartfrog/services/filesystem/RmdirImpl.java (from rev 8530, trunk/core/smartfrog/src/org/smartfrog/services/filesystem/MkdirImpl.java) =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/filesystem/RmdirImpl.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/filesystem/RmdirImpl.java 2011-04-03 22:16:08 UTC (rev 8558) @@ -0,0 +1,94 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.services.filesystem; + +import org.smartfrog.sfcore.common.SmartFrogDeploymentException; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.prim.TerminationRecord; + +import java.io.File; +import java.rmi.RemoteException; + +/** + * Component to delete directoreis + */ + +public class RmdirImpl extends FileUsingComponentImpl implements Mkdir { + + /** + * Constructor. + * @throws RemoteException In case of network/rmi error + */ + public RmdirImpl() throws RemoteException { + } + + /** + * read in the directory settings and bind the file attributes. + * + * @throws SmartFrogException failure while starting + * @throws RemoteException In case of network/rmi error + */ + @Override + public synchronized void sfDeploy() throws SmartFrogException, RemoteException { + super.sfDeploy(); + + String dir; + File parentDir = null; + String parent; + parent = FileSystem.lookupAbsolutePath(this, + ATTR_PARENT, + null, + null, + false, + null); + if (parent != null) { + parentDir = new File(parent); + } + + dir = FileSystem.lookupAbsolutePath(this, Mkdir.ATTR_DIR, null, parentDir, true, null); + File directory = new File(dir); + bind(directory); + } + + /** + * we only create the directory at startup time, even though we bond at deploy time. + * @throws SmartFrogException failure in starting + * @throws RemoteException In case of network/rmi error + */ + @Override + public synchronized void sfStart() throws SmartFrogException, + RemoteException { + super.sfStart(); + File directory = getFile(); + try { + if (directory.exists()) { + FileSystem.recursiveDelete(directory); + } + } catch (SecurityException e) { + //failure is turned into a security problem; we catch it and make it meaningful + throw new SmartFrogDeploymentException( + "Security blocked the deletion of the directory " + directory, + e, + this); + } + + maybeStartTerminator("Rmdir"); + } +} Copied: trunk/core/smartfrog/src/org/smartfrog/services/filesystem/rmdir.sf (from rev 8530, trunk/core/smartfrog/src/org/smartfrog/services/filesystem/mkdir.sf) =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/filesystem/rmdir.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/filesystem/rmdir.sf 2011-04-03 22:16:08 UTC (rev 8558) @@ -0,0 +1,41 @@ +/** (C) Copyright 1998-2005 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ + +#include "org/smartfrog/services/filesystem/filesystemtemplate.sf" + + +RmdirSchema extends Schema { + //file is a file or a string. + dir extends Compulsory; + + //parent dir may not be needed. + parentDir extends Optional; + +} + +/** + * Deletes a directory, and all its children on startup. + * This operation can be slow, hence the operation is + * Asynchronous. + */ +Rmdir extends WorkflowPrim { + mkdirSchema extends MkdirSchema; + sfClass "org.smartfrog.services.filesystem.RmdirImpl"; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |