| 1 | |
package org.webslinger.commons.vfs.virtual; |
| 2 | |
|
| 3 | |
import java.net.URL; |
| 4 | |
import java.util.ArrayList; |
| 5 | |
import java.util.Arrays; |
| 6 | |
import java.util.Collection; |
| 7 | |
import java.util.Collections; |
| 8 | |
|
| 9 | |
import org.apache.commons.vfs.FileName; |
| 10 | |
import org.apache.commons.vfs.FileSystemException; |
| 11 | |
|
| 12 | |
import org.webslinger.commons.vfs.operations.COWStateOperation; |
| 13 | |
import org.webslinger.commons.vfs.operations.AllFilesOperation; |
| 14 | |
|
| 15 | |
public class VirtualCOWStateOperation implements AllFilesOperation, COWStateOperation { |
| 16 | |
protected final VirtualFileSystem fs; |
| 17 | |
protected final FileName name; |
| 18 | |
|
| 19 | 151 | protected VirtualCOWStateOperation(VirtualFileObject file) { |
| 20 | 151 | fs = file.getFileSystem(); |
| 21 | 151 | name = file.getName(); |
| 22 | 151 | } |
| 23 | |
|
| 24 | |
public final void process() throws FileSystemException { |
| 25 | 0 | throw new UnsupportedOperationException(); |
| 26 | |
} |
| 27 | |
|
| 28 | |
public void clear() throws FileSystemException { |
| 29 | 50 | fs.clear(name); |
| 30 | 50 | } |
| 31 | |
|
| 32 | |
public Collection<String> getBases() throws FileSystemException { |
| 33 | 24 | VirtualFileSystem.MountPoint point = fs.getMounts(name); |
| 34 | 24 | if (point == null) return Collections.emptyList(); |
| 35 | 18 | FileName parent = name.getParent(); |
| 36 | 18 | String[] bases = new String[point.bases.length]; |
| 37 | 24 | for (int i = 0; i < bases.length; i++) { |
| 38 | 6 | bases[i] = parent.getRelativeName(point.bases[i].lookupFile().getName()); |
| 39 | |
} |
| 40 | 18 | return Arrays.asList(bases); |
| 41 | |
} |
| 42 | |
|
| 43 | |
public boolean addBase(String relative) throws FileSystemException { |
| 44 | 118 | return fs.addBase(name, relative); |
| 45 | |
} |
| 46 | |
|
| 47 | |
public boolean removeBase(String relative) throws FileSystemException { |
| 48 | 6 | return fs.removeBase(name, relative); |
| 49 | |
} |
| 50 | |
|
| 51 | |
public boolean isDeleted() throws FileSystemException { |
| 52 | 0 | VirtualFileSystem.MountPoint point = fs.getMounts(name); |
| 53 | 0 | if (point == null) return false; |
| 54 | 0 | return point.isDeleted; |
| 55 | |
} |
| 56 | |
|
| 57 | |
public void setDeleted(boolean deleted) throws FileSystemException { |
| 58 | 0 | fs.setDeleted(name, deleted, true); |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
public Collection<URL> getAllURLs() throws FileSystemException { |
| 62 | 0 | return fs.resolveFile(name).getResolution().getAllURLs(); |
| 63 | |
} |
| 64 | |
} |