/** 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); }
public void rename(FileLock lock, String name, String ext) throws IOException { MultiFileSystem fs = getMultiFileSystem(); getFileSystem().beginAtomicAction(); MfLock l = testLock(lock); if (isData() && ext != null && ext.trim().length() > 0) { newFullName += (EXT_SEP + ext); String oldFullName = getPath(); if (isReadOnly()) { throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_CannotRenameFromTo", getPath(), getMultiFileSystem().getDisplayName(), newFullName)); if (getFileSystem().isReadOnly()) { throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_FSisRO", getMultiFileSystem().getDisplayName())); String on = getName(); String oe = getExt(); getMultiFileSystem().unmaskFileOnAll(single, newFullName); copyContent(this, leader); } else { if (isData()) { FileObject folder = FileUtil.createFolder(root(single), getParent().getPath());
public final void refresh(boolean expected) { if (!isInitialized() && isFolder()) { return; } Enumeration<FileObject> en = delegates(); while (en.hasMoreElements()) { FileObject fo = en.nextElement(); fo.refresh(expected); } super.refresh(expected); }
/** 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(); } }
getFileSystem().beginAtomicAction(); MultiFileSystem fs = getMultiFileSystem(); if (isReadOnly()) { throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_FisRO", name, fs.getDisplayName())); if (!isFolder()) { throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_FoNotFolder", n, getPath(), fs.getDisplayName())); if (this.getFileObject(name, ext) != null) { throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_DataAlreadyExist", n, fs.getDisplayName(), getPath())); String fullName = getPath() + PATH_SEP + n; FileUtil.createData(root(simple), fullName); getMultiFileSystem().unmaskFileOnAll(simple, fullName); refresh(n, null, true, false); fo = getMultiChild(n); throw new FileStateInvalidException(NbBundle.getMessage(MultiFileObject.class, "EXC_ApplicationCreateError", getPath(), n)); if (hasListeners()) { fileCreated0(new FileEvent(this, fo), true); getFileSystem().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(); } }
MultiFileSystem mfs = getMultiFileSystem(); FileSystem[] arr = mfs.getDelegates(); FileObject led = null; String name = getPath(); FileSystem writable = mfs.writableLayer(name); fo.isRoot() && !mfs.canHaveRootAttributeOnReadOnlyFS(WEIGHT_ATTRIBUTE) ? 0 : weightOf(fo, writable); if (led == null || weight.doubleValue() > maxWeight.doubleValue()) { led = fo; if (isData() && isValid()) { fileChanged0(new FileEvent(this)); getMultiFileSystem().notifyMigration(this);
String path = getPath(); FileSystem fs = getMultiFileSystem().createWritableOn(path); FileObject fo = getMultiFileSystem().findResourceOn(fs, path); Object oldValue = null; String attrToSet = attrName; oldValue = getAttribute(attrName); if (oldValue == value) { return; getAttributeCache().setDelegate(fo); getAttributeCache().setAttributeName(attrToSet); fire = setAttributeOnFO(fo, attrToSet, null, fire); if (fo.getAttribute(attrToSet) != null) { fire = setAttributeOnFO(fo, attrToSet, voidify(null), fire); fire = setAttributeOnFO(fo, attrToSet, voidify(value), fire); if (fire && (oldValue != value) && hasAtLeastOneListeners()) { fileAttributeChanged0(new FileAttributeEvent(this, attrName, oldValue, value));
String path = getPath (); FileSystem fs = getMultiFileSystem ().createWritableOn (path); FileObject fo = getMultiFileSystem ().findResourceOn (fs,path); Object oldValue = null; String attrToSet = attrName; oldValue = getAttribute (attrName); ((AbstractFolder)fo).setAttribute(attrToSet, voidify (value), false); else { fo.setAttribute (attrToSet, voidify (value)); if (fire && oldValue != value && hasAtLeastOneListeners () ) fileAttributeChanged0 (new FileAttributeEvent (this,attrName,oldValue,value));
/** Update all existing subobjects. */ void updateAll () { FileSystem mfs = getMultiFileSystem (); try { mfs.beginAtomicAction (); // enumeration of all existing objects Enumeration en = existingSubFiles(true); while (en.hasMoreElements()) { MultiFileObject mfo = (MultiFileObject)en.nextElement(); if (mfo.isFolder() && !mfo.isInitialized ()) continue; mfo.freeLastAttrCache (); mfo.superRefresh(true); } } finally { mfs.finishAtomicAction (); } }
if ( !(foFs instanceof XMLFileSystem)) { localFo = foFs.getRoot (); oPerf = getAttribute (localFo,prefixattr, ""); // NOI18N if (oPerf != null) return devoidify ( oPerf); oPerf = getAttribute (localFo,attrName, localFo.getPath()); if (oPerf != null) return devoidify ( oPerf); FileSystem[] systems = getMultiFileSystem ().getDelegates (); FileSystem leaderfs; try { leaderfs = getLeaderFileSystem (); } catch (FileStateInvalidException fsie) { FileObject fo = getMultiFileSystem ().findResourceOn (systems[i], path); if (fo != null) { Object o = getAttribute (fo,attrName, fo.getPath());// Performance tricks: if (o != null) return devoidify (o); Object o = getAttribute (fo,prefixattr, ""); // NOI18N if (o != null) return devoidify (o);
FileObject localFo = getAttributeCache().getDelegate(); String cachedAttrName = getAttributeCache().getAttributeName(); try { FileSystem foFs = localFo.getFileSystem(); if (!foFs.isReadOnly() || getMultiFileSystem().canHaveRootAttributeOnReadOnlyFS(prefixattr)) { localFo = foFs.getRoot(); oPerf = getAttribute(localFo, prefixattr, ""); // NOI18N return devoidify(oPerf); oPerf = getAttribute(localFo, attrName, localFo.getPath()); return devoidify(oPerf); FileSystem[] systems = getMultiFileSystem().getDelegates(); FileSystem writable = getMultiFileSystem().writableLayer(path); boolean revealEntries = isFolder() && "revealEntries".equals(attrName) && writable != null && !writable.isReadOnly(); //NOI18N return collectRevealedFiles(); FileObject fo = getMultiFileSystem().findResourceOn(systems[i], path); Object o = getAttribute(fo, attrName, fo.getPath()); // Performance tricks: return devoidify(o);
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; }
/** Fired when a file is changed. * @param fe the event describing context where action has taken place */ public void fileChanged(FileEvent fe) { FileObject changedFile = this; if (fe.getSource().equals(leader) && hasAtLeastOneListeners() && !fe.firedFrom(markAtomicAction)) { /**There should not dissapear information about source and changed file*/ if (!fe.getFile().equals(fe.getSource())) { changedFile = getFileObject(fe.getFile().getName(), fe.getFile().getExt()); } /**fileChanged1 - should not fire event for this.getParent (). * I think that already bottom layer forked event.*/ /** [PENDING] fix of #16926, #16895. But there should be investigated * why this MFO doesn`t know about child ?*/ if (changedFile != null) { fileChanged1(new FileEvent(this, changedFile, fe.getTime())); } } }
if (!hasAtLeastOneListeners() || (leader == null)) { return; !fe.getNewValue().equals(getAttribute(fe.getName())) ) { return; try { ev.inheritPostNotify(fe); fileAttributeChanged0(ev); } finally { ev.setPostNotify(null);
@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); } }
/** Copies content of one folder into another. * @param source source folder * @param target target folder * @exception IOException if it fails */ private static void copyContent(FileObject source, FileObject target) throws IOException { FileObject[] srcArr = source.getChildren(); copyAttrs(source, target); //added for (int i = 0; i < srcArr.length; i++) { FileObject child = srcArr[i]; if (MultiFileSystem.isMaskFile(child)) { continue; } if (target.getFileObject(child.getName(), child.getExt()) == null) { if (child.isData()) { FileObject fo = FileUtil.copyFile(child, target, child.getName(), child.getExt()); if (fo != null) { copyAttrs(child, fo); } } else { FileObject targetChild = target.createFolder(child.getName()); copyContent(child, targetChild); } } } }
/** * Actually implements contract of FileSystem.refresh(). */ public @Override void refresh(boolean expected) { Enumeration<AbstractFolder> en = getMultiRoot().existingSubFiles(true); while (en.hasMoreElements()) { FileObject fo = en.nextElement(); fo.refresh(expected); } }
/** * @return the root of the filesystem */ private MultiFileObject getMultiRoot() { MultiFileObject retval = null; synchronized (MultiFileSystem.class) { if (root != null) { retval = root; } } if (retval == null) { retval = new MultiFileObject(this); } synchronized (MultiFileSystem.class) { if (root == null) { root = retval; } } return root; }
getFileSystem().beginAtomicAction(); MultiFileSystem fs = getMultiFileSystem(); if (isReadOnly()) { IOException ex = new IOException("Read only: " + leader + " delegates: " + delegates); // NOI18N Exceptions.attachLocalizedMessage(ex, NbBundle.getMessage(MultiFileObject.class, "EXC_FisRO", name, fs.getDisplayName())); String fullName = getPath() + PATH_SEP + name; if (!isFolder()) { throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_FoNotFolder", name, getPath(), fs.getDisplayName())); if (this.getFileObject(name) != null) { throw new FSException(NbBundle.getMessage(MultiFileObject.class, "EXC_FolderAlreadyExist", name, fs.getDisplayName(), getPath())); FileUtil.createFolder(root(simple), fullName); getMultiFileSystem().unmaskFileOnAll(simple, fullName); refresh(name, null, true, false); fo = getMultiChild(name); throw new FileStateInvalidException(NbBundle.getMessage(MultiFileObject.class, "EXC_ApplicationCreateError", getPath(), name)); FileObject[] chlds = fo.getChildren(); getMultiFileSystem().maskFile(simple, chlds[i].getPath());