From: Steve L. <st...@us...> - 2004-05-27 15:12:51
|
Update of /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/services/filesystem In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18319/smartfrog/src/org/smartfrog/services/filesystem Modified Files: components.sf TempFileImpl.java Added Files: FileIntf.java FileImpl.java Log Message: Portability of filenames 1. conversion class 2. a file class with attributes 3. patches into RunJava --- NEW FILE: FileIntf.java --- /** (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 java.rmi.Remote; import java.rmi.RemoteException; /** * created 27-May-2004 10:43:10 */ public interface FileIntf extends Remote { /* filename extends OptionalString; dir extends OptionalString; mustExist extends OptionalBoolean; exists: Boolean absolutePath: String URI: String */ String varFilename="filename"; String varDir="dir"; String varExists="exists"; String varAbsolutePath="absolutePath"; String varIsDirectory="isDirectory"; String varIsFile = "isFile"; String varIsHidden = "isHidden"; String varTimestamp = "timestamp"; String varLength = "length"; String varIsEmpty = "isEmpty"; String varURI = "uri"; String varShortname="shortname"; String varMustExist = "mustExist"; String varMustRead = "mustRead"; String varMustWrite = "mustWrite"; /** * get the absolute path of this file * @return * @throws RemoteException */ public String getAbsolutePath() throws RemoteException; } Index: TempFileImpl.java =================================================================== RCS file: /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/services/filesystem/TempFileImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TempFileImpl.java 18 May 2004 16:31:09 -0000 1.1 --- TempFileImpl.java 27 May 2004 15:12:39 -0000 1.2 *************** *** 36,40 **** */ ! public class TempFileImpl extends PrimImpl implements Prim, TempFile { /** --- 36,40 ---- */ ! public class TempFileImpl extends PrimImpl implements Prim, TempFile, FileIntf { /** *************** *** 78,82 **** --- 78,85 ---- } + sfReplaceAttribute(ATTR_FILENAME, tempFile.toString()); + sfReplaceAttribute(varAbsolutePath,tempFile.getAbsolutePath()); sfContext().put(ATTR_FILENAME, tempFile.toString()); + } *************** *** 122,124 **** --- 125,131 ---- } + public String getAbsolutePath() throws RemoteException { + return tempFile.getAbsolutePath(); + } + } Index: components.sf =================================================================== RCS file: /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/services/filesystem/components.sf,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** components.sf 18 May 2004 16:31:09 -0000 1.3 --- components.sf 27 May 2004 15:12:39 -0000 1.4 *************** *** 21,28 **** #include "/org/smartfrog/predicates.sf" TouchFileSchema extends Schema { //filename; this must be in a platform-specific format ! filename extends String; //age of file, seconds since 1970-01-01; a value of -1 indicates //current timestamp, as does omitting the value --- 21,73 ---- #include "/org/smartfrog/predicates.sf" + /** + * platform independent file + * set the name and optionally the dir; get the absolute path in a + * platform independent manner + * + * The mustXXX attributes are characteristics of the files which must always hold + */ + + + FileSchema extends Schema { + + filename extends OptionalString; + dir extends OptionalString; + + //file must always exist + mustExist extends OptionalBoolean; + //the process must have read access + mustRead extends OptionalBoolean; + //the file must be writeable + mustWrite extends OptionalBoolean; + + /* added at deploy time + exists: Boolean + absolutePath: String + URI: String + isFile + isDirectory + isHidden + timestamp: long + length: long + isEmpty: bool + + */ + + } + + File extends Prim { + fileSchema extends Schema; + sfClass "org.smartfrog.services.filesystem.FileImpl"; + } + TouchFileSchema extends Schema { //filename; this must be in a platform-specific format ! filename extends OptionalString; ! ! //file is a file instance ! file extends OptionalCD; ! //age of file, seconds since 1970-01-01; a value of -1 indicates //current timestamp, as does omitting the value *************** *** 39,42 **** --- 84,90 ---- } + /** + * tempfile + */ TempFileSchema extends Schema { //prefix should be three or more characters long *************** *** 53,56 **** --- 101,108 ---- /** * the temp file component creates a temporary file on deployment. + * this interface also implements the same interface as File, so that the + * getAbsolutePath() call works on it to give an absolute path. + * and absolutePath is set to the absolute path. None of the other + * attributes of File are set */ TempFile extends Prim { --- NEW FILE: FileImpl.java --- /** (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.prim.Prim; import org.smartfrog.sfcore.prim.PrimImpl; import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.common.SmartFrogResolutionException; import org.smartfrog.sfcore.common.SmartFrogRuntimeException; import org.smartfrog.sfcore.common.SmartFrogLivenessException; import org.smartfrog.sfcore.utils.PlatformHelper; import java.rmi.RemoteException; import java.io.File; /** * created 27-May-2004 10:47:34 */ public class FileImpl extends PrimImpl implements FileIntf { private File file; private boolean mustExist; private boolean mustRead; private boolean mustWrite; private boolean exists; public FileImpl() throws RemoteException { } public String getAbsolutePath() throws RemoteException { return file.getAbsolutePath(); } /** * all our binding stuff. reads attributes, builds the filename, checks it, updates attributes * * @throws RemoteException * @throws SmartFrogRuntimeException */ public void bind() throws RemoteException, SmartFrogRuntimeException { PlatformHelper platform= PlatformHelper.getLocalPlatform(); String filename = sfResolve(varFilename,(String)null,true); filename=platform.convertFilename(filename); String dir= sfResolve(varDir, (String) null, false); if(dir!=null) { dir= platform.convertFilename(dir); File parent=new File(dir); file=new File(parent,filename); } else { file=new File(filename); } mustExist =getBool(varMustExist,false,false); mustRead = getBool(varMustWrite, false, false); mustWrite = getBool(varMustRead, false, false); exists = file.exists(); boolean isDirectory; boolean isFile; boolean isEmpty; long timestamp; long length; if(exists) { isDirectory = file.isDirectory(); isFile = file.isFile(); timestamp = file.lastModified(); length = file.length(); } else { isDirectory=isFile=false; timestamp=-1; length=0; } isEmpty = length == 0; setAttribute(varExists, exists); setAttribute(varIsDirectory,isDirectory); setAttribute(varIsFile,isFile); setAttribute(varIsEmpty,isEmpty); setAttribute(varTimestamp, timestamp); setAttribute(varLength, length); String path= getAbsolutePath(); sfReplaceAttribute(varAbsolutePath,path); String uri=file.toURI().toString(); sfReplaceAttribute(varURI, uri); String name=file.getName(); sfReplaceAttribute(varShortname,name); } private void setAttribute(String attr, boolean flag) throws SmartFrogRuntimeException, RemoteException { sfReplaceAttribute(attr,new Boolean(flag)); } private boolean getBool(String attr,boolean value,boolean mandatory) throws SmartFrogResolutionException, RemoteException { Boolean b=(Boolean) sfResolve(attr,Boolean.valueOf(value),mandatory); return b.booleanValue(); } private void setAttribute(String attr, long value) throws SmartFrogRuntimeException, RemoteException { sfReplaceAttribute(attr, new Long(value)); } /** * Called after instantiation for deployment purposed. Heart monitor is * started and if there is a parent the deployed component is added to the * heartbeat. Subclasses can override to provide additional deployment * behavior. * * @throws org.smartfrog.sfcore.common.SmartFrogException * error while deploying * @throws java.rmi.RemoteException In case of network/rmi error */ public synchronized void sfDeploy() throws SmartFrogException, RemoteException { super.sfDeploy(); bind(); } /** * Returns the string of the remote reference if this primitive was * exported, the superclass toString if not. * * @return string form for this component */ public String toString() { return file!=null?file.getAbsolutePath() : "uninitialized file"; } /** * Liveness call in to check if this component is still alive. * * @param source source of call * @throws org.smartfrog.sfcore.common.SmartFrogLivenessException * component is terminated * @throws java.rmi.RemoteException for consistency with the {@link org.smartfrog.sfcore.prim.Liveness} interface */ public void sfPing(Object source) throws SmartFrogLivenessException, RemoteException { super.sfPing(source); if(mustExist && !file.exists()) { throw new SmartFrogLivenessException("File "+file.getAbsolutePath()+" does not exist"); } if(mustRead && !file.canRead()) { throw new SmartFrogLivenessException("File " + file.getAbsolutePath() + " is not readable"); } if (mustWrite && !file.canWrite()) { throw new SmartFrogLivenessException("File " + file.getAbsolutePath() + " is not writeable"); } } } |