@Override public Object getAttribute(String attrName) { // Performance optimization (avoid calling getPath() too many times): final String path = getPath(); if (path.isEmpty() && attrName.indexOf('\\') >= 0) { return null; } return getAttribute(attrName, path); }
public Enumeration<String> getAttributes() { return getAttributes(getPath()); }
/** 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; }
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; }
@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; }
/** * 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; }
String path = getPath(); FileSystem[] systems = getMultiFileSystem().getDelegates(); FileSystem writable = getMultiFileSystem().writableLayer(path);
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; }
FileObject led = null; String name = getPath(); FileSystem writable = mfs.writableLayer(name);
throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_FoNotFolder", n, getPath(), fs.getDisplayName())); throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_DataAlreadyExist", n, fs.getDisplayName(), getPath())); String fullName = getPath() + PATH_SEP + n; throw new FileStateInvalidException(NbBundle.getMessage(MultiFileObject.class, "EXC_ApplicationCreateError", getPath(), n));
String fullName = getPath() + PATH_SEP + name; throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_FoNotFolder", name, getPath(), fs.getDisplayName())); throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_FolderAlreadyExist", name, fs.getDisplayName(), getPath())); throw new FileStateInvalidException(NbBundle.getMessage(MultiFileObject.class, "EXC_ApplicationCreateError", getPath(), name));
/** 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; }
/** 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(); } }
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(); } }
String path = getPath(); FileSystem fs = getMultiFileSystem().createWritableOn(path); FileObject fo = getMultiFileSystem().findResourceOn(fs, path);
/** All objects that are beyond this one. * @return enumeration of FileObject */ private Enumeration 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) FSException.io ("EXC_InvalidLock", l, getPath (), getMultiFileSystem ().getDisplayName (), lock); // NOI18N if (lock.get () != l) FSException.io ("EXC_InvalidLock", l, getPath (), getMultiFileSystem ().getDisplayName (), lock.get ()); // NOI18N return (MfLock)l; }