/** Finds a root for given file system. It also counts with * redefined method findResourceOn. * * @param fs the filesystem to seach on * @return the root on the fs */ private FileObject root(FileSystem fs) { return getMultiFileSystem().findResourceOn(fs, ""); // NOI18N }
/** Method to create a file object for given subfile. * @param name of the subfile * @return the file object */ protected final AbstractFolder createFile(String name) { return new MultiFileObject(getMultiFileSystem(), this, name); }
@Deprecated // have to override for compat public void setImportant(boolean b) { Enumeration<FileObject> en = delegates(); while (en.hasMoreElements()) { FileObject fo = en.nextElement(); fo.setImportant(b); } if (!b) { getMultiFileSystem().markUnimportant(this); } }
/** All objects that are beyond this one. * @return enumeration of FileObject */ private Enumeration<FileObject> delegates() { return getMultiFileSystem().delegates(getPath()); }
/** Tests the lock if it is valid, if not throws exception. * @param l lock to test * @return the mf lock for this file object */ private MfLock testLock(FileLock l) throws java.io.IOException { if (lock == null) { throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_InvalidLock", l, getPath(), getMultiFileSystem().getDisplayName(), lock)); } if (lock.get() != l) { throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_InvalidLock", l, getPath(), getMultiFileSystem().getDisplayName(), lock.get())); } return (MfLock) l; }
private FileObject findLeader(FileSystem[] fs, String path) { MultiFileSystem mfs = getMultiFileSystem(); Number maxWeight = 0; FileObject _leader = null; FileSystem writable = mfs.writableLayer(path); for (FileSystem f : fs) { if (f == null) { continue; } FileObject fo = mfs.findResourceOn(f, path); if (fo != null) { Number weight = weightOf(fo, writable); if (_leader == null || weight.doubleValue() > maxWeight.doubleValue()) { _leader = fo; maxWeight = weight; } } } return _leader; }
private final Enumeration<String> getAttributes(String path) { Set<String> s = new HashSet<String>(); FileSystem[] systems = getMultiFileSystem().getDelegates(); final boolean empty = path.length() == 0; FileObject fo = getMultiFileSystem().findResourceOn(systems[i], path);
if (!getMultiFileSystem().getPropagateMasks()) { if (getMultiFileSystem().getPropagateMasks()) {
public synchronized FileLock lock() throws IOException { if (lock != null) { FileLock f = (FileLock) lock.get(); if (f != null) { FileAlreadyLockedException alreadyLockedException = new FileAlreadyLockedException(getPath()); alreadyLockedException.initCause(lockedBy); throw alreadyLockedException; } } Set<? extends FileSystem> set = getMultiFileSystem().createLocksOn(getPath()); MfLock l = new MfLock(leader, delegates(), set); lock = new WeakReference<MfLock>(l); assert (lockedBy = new Throwable("Locked by:")) != null; //NOI18N return l; }
/** * auxiliary method that returns true if mask is needed and deletes all delegates * on writable layers if deleteDelegates is true. * @param lock * @param deleteDelegates if true all delegates on writable layers will be deleted * @throws IOException is thrown if lock is not valid. * @return true if mask is necessary*/ private boolean needsMask(FileLock lock, boolean deleteDelegates) throws IOException { MfLock lck = testLock(lock); Enumeration<FileObject> e = getMultiFileSystem().delegates(getPath()); boolean needsMask = false; while (e.hasMoreElements()) { FileObject fo = e.nextElement(); FileLock lockForFo = lck.findLock(fo); if (lockForFo == null) { // we will need to create mask needsMask = true; } else { if (deleteDelegates) { fo.delete(lockForFo); } } } return needsMask; }
@Deprecated // have to override for compat public boolean isReadOnly() { MultiFileSystem fs = getMultiFileSystem(); if (fs.isReadOnly()) { return true; } if (leader.isReadOnly()) { // if we can make it writable then nothing try { FileSystem simple = fs.createWritableOn(getPath()); return simple == leader.getFileSystem(); } catch (IOException e) { return true; } } return false; }
/** Update all existing subobjects. */ void updateAll() { FileSystem mfs = getMultiFileSystem(); try { mfs.beginAtomicAction(); // enumeration of all existing objects Enumeration<AbstractFolder> en = existingSubFiles(true); while (en.hasMoreElements()) { MultiFileObject mfo = (MultiFileObject) en.nextElement(); if (mfo.isFolder() && !mfo.isInitialized()) { continue; } mfo.freeAttribCache(); mfo.superRefresh(true); } } finally { mfs.finishAtomicAction(); } }
/** This method was added to achieve firing events that attributes * were changed after setDelegates. Events are not fired reliable but this solution was * choosed because of performance reasons. Attributes name is set to null - what means * that one of attributes was probably changed. */ void updateAllAfterSetDelegates(FileSystem[] oldFileSystems) { try { getMultiFileSystem().beginAtomicAction(); FileSystem[] fileSystems = getMultiFileSystem().getDelegates(); Enumeration<AbstractFolder> en = existingSubFiles(true); while (en.hasMoreElements()) { MultiFileObject mfo = (MultiFileObject) en.nextElement(); if (mfo.isFolder() && !mfo.isInitialized()) { continue; } if (mfo.hasListeners()) { String path = mfo.getPath(); FileObject oldLeader = findLeader(oldFileSystems, path); FileObject newLeader = findLeader(fileSystems, path); if ((oldLeader != null) && (newLeader != null) && !oldLeader.equals(newLeader)) { mfo.fileAttributeChanged0(new FileAttributeEvent(mfo, null, null, null)); } } mfo.freeAttribCache(); mfo.refresh(true); } } finally { getMultiFileSystem().finishAtomicAction(); } }
public boolean canWrite() { MultiFileSystem fs = getMultiFileSystem(); if (fs.isReadOnly()) { return false; } if (!leader.canWrite()) { // if we can make it writable then nothing try { FileSystem simple = fs.createWritableOn(getPath()); return simple != leader.getFileSystem(); } catch (IOException e) { return false; } } return true; }
void handleDelete(FileLock lock) throws IOException { if (parent == null) { throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_CannotDeleteRoot", getMultiFileSystem().getDisplayName())); } MultiFileSystem fs = getMultiFileSystem(); try { getFileSystem().beginAtomicAction(); synchronized (parent) { String fullName = getPath(); FileSystem single = fs.createWritableOn(fullName); if (needsMask(lock, true)) { getMultiFileSystem().maskFile(single, fullName); updateFoldersLock(getParent()); } String n = name; validFlag = false; /** [PENDING] expected rename of some refresh method */ //parent.internalRefresh (null, n, true, false, null); parent.refresh(null, n, true, false); if (hasAtLeastOneListeners()) { fileDeleted0(new FileEvent(this)); } } } finally { getFileSystem().finishAtomicAction(); } }
MultiFileSystem fs = getMultiFileSystem(); getMultiFileSystem().unmaskFileOnAll(simple, fullName); getMultiFileSystem().maskFile(simple, chlds[i].getPath());
FileSystem fs = getMultiFileSystem().createWritableOn(path); FileObject fo = getMultiFileSystem().findResourceOn(fs, path); Object oldValue = null; String attrToSet = attrName;
MultiFileSystem fs = getMultiFileSystem(); getMultiFileSystem().unmaskFileOnAll(simple, fullName);
throw new FSException(NbBundle.getMessage(FileObject.class, "EXC_MoveChild", this, target)); // NOI18N MultiFileSystem fs = getMultiFileSystem(); getMultiFileSystem().maskFile(simple, getPath()); updateFoldersLock(getParent());
/** Converts the file to be writable. * The file has to be locked! * * @return file object (new leader) that is writable * @exception IOException if the object cannot be writable */ private FileObject writable(boolean copyContents) throws IOException { MultiFileSystem fs = getMultiFileSystem(); FileSystem single = fs.createWritableOn(getPath()); if (single != leader.getFileSystem()) { // if writing to a file that is not on writable fs => // copy it if (leader.isFolder()) { leader = FileUtil.createFolder(root(single), getPath()); } else { FileObject folder = FileUtil.createFolder(root(single), getParent().getPath()); if (copyContents) { leader = leader.copy(folder, leader.getName(), leader.getExt()); } else { leader = folder.createData(leader.getNameExt()); } } MfLock l = ((lock == null) ? null : lock.get()); if (l != null) { // update the lock l.addLock(leader); } } return leader; }