/* * Component.java (Implements Composite Pattern File) * * Written by : Nitin Motgi (nmotgi@cs.ucf.edu) * * ASSUMPTIONS : * * 1. This program does not handle single line multi-level change * directory. (e.g. cd ... allowed, but * cd / ... not allowed. * * 2. All the operations that are done will be done in the * directory pointed by currentDir. * * 3. The file/directory to be deleted should be owned by "me". If * I don't own the file, then I cannot delete them. * * 4. The file or directory that you are thinking of deleting should * be present in the current directory. * * 5. During recursive deletion of directory if there is any file or * directory that is owned by some one else, the operation of * recursive deletion is aborted. * * * Portions copyright(c) 2001 to School of Electrical Engineering and * Computer Science, UCF, Orlando. * * Use and distribution of this source code are strictly governed by * terms and conditions set by the authors. * * $Id : Component.java, 03/26/2001. $ * * Revision History: * * 1. Created basic structure Nitin, v1.0.0 04/02/2001. * 2. Added Documentation. Nitin, v1.0.1 04/02/2001. */ import java.io.*; import java.util.*; /* This class implements Composite Pattern using abstract class.*/ abstract class Component extends Object{ public Component() { _next = null; } public abstract void operation(); public Component getchild() { return(_next); } public void setchild(Component next) {_next=next; } public int DirectoryDetect() { return(0); } public abstract boolean chown(String szNewOwn,String szName); public abstract boolean chmod(String szMode,String szName); public abstract String getOwner(); public abstract String getName(); public abstract String getPermissions(); /* Formats time.*/ public String formatTime(long lTime){ long LeftSec=0; long LeftMin=0; int nHour=0,nMin=0,nSec=0,nHundSec=0; String szTime = new String(); LeftSec = lTime/100; nHundSec = (int)(lTime%100); LeftMin = LeftSec/60; nSec = (int)(LeftSec%60); nMin = (int)(LeftMin%60); nHour = (int)(LeftMin/60); if(nHour == 0 && nMin == 0 && nSec == 0) szTime = "0."+nHundSec; else if(nHour == 0 && nMin == 0) szTime = nSec + "." + nHundSec; else if(nHour == 0) szTime = nMin + ":" + nSec + "." + nHundSec; else szTime = nHour/1000000 + ":" + nMin + ":" + nSec; return szTime; }/* End of formatTime.*/ private Component _next; }/* End of Abstract Component Pattern.*/