/** * Attaches this file object to its file resource. This method is called before any of the doBlah() or onBlah() * methods. Sub-classes can use this method to perform lazy initialisation. * <p/> * This implementation does nothing. */ protected void doAttach() throws Exception { super.doAttach(); }
/** * Detaches this file, invalidating all cached info. This will force a call to {@link #doAttach} next time this file * is used. * * @throws Exception if an error occurs. */ private void detach() throws Exception { synchronized (monitorLock) { if (isAttached()) { try { doDetach(); } finally { setAttached(false); injectType(null); parent = null; // fs.fileDetached(this); removeChildrenCache(); // children = null; } } } }
/** * Returns the file's type. * * @return The FileType. * @throws FileSystemException if an error occurs. */ @Override public FileType getType() throws FileSystemException { synchronized (fs) { attach(); // VFS-210: get the type only if requested for try { if (type == null) { setFileType(doGetType()); } if (type == null) { setFileType(FileType.IMAGINARY); } } catch (final Exception e) { throw new FileSystemException("vfs.provider/get-type.error", e, fileName); } return type; } }
/** * Checks if this fileObject is the same file as {@code destFile} just with a different name. E.g. for case * insensitive filesystems like windows. * * @param destFile The file to compare to. * @return true if the FileObjects are the same. * @throws FileSystemException if an error occurs. */ protected boolean isSameFile(final FileObject destFile) throws FileSystemException { attach(); return doIsSameFile(destFile); }
/** * Returns the file's content. * * @return the FileContent for this FileObject. * @throws FileSystemException if an error occurs. */ @Override public FileContent getContent() throws FileSystemException { synchronized (fs) { attach(); if (content == null) { content = doCreateFileContent(); } return content; } }
/** * Detaches this file, invalidating all cached info. This will force a call to {@link #doAttach} next time this file * is used. * * @throws Exception if an error occurs. */ private void detach() throws Exception { synchronized (fs) { if (attached) { try { doDetach(); } finally { attached = false; setFileType(null); parent = null; // fs.fileDetached(this); removeChildrenCache(); // children = null; } } } }
if (canRenameTo(destFile)) { if (!getParent().isWriteable()) { throw new FileSystemException("vfs.provider/rename-parent-read-only.error", getName(), getParent().getName()); if (!isWriteable()) { throw new FileSystemException("vfs.provider/rename-read-only.error", getName()); if (destFile.exists() && !isSameFile(destFile)) { destFile.deleteAll(); if (canRenameTo(destFile)) { attach(); final FileType srcType = getType(); doRename(destFile); FileObjectUtils.getAbstractFileObject(destFile).handleCreate(srcType); handleDelete(); // fire delete-events. This file-object (src) is like deleted. } catch (final RuntimeException re) { throw re; } catch (final Exception exc) { throw new FileSystemException("vfs.provider/rename.error", exc, getName(), destFile.getName()); && destFile.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER)) && fs.hasCapability(Capability.GET_LAST_MODIFIED)) {
attach(); return resolveFiles(children); childrenObjects = doListChildrenResolved(); children = extractNames(childrenObjects); } catch (final FileSystemException exc) { files = doListChildren(); } catch (final FileSystemException exc) { return resolveFiles(children);
findFiles(selector, true, files); if (file.getType().hasChildren() && file.getChildren().length != 0) { if (file.deleteSelf()) { nuofDeleted++;
FileType type = getType(); final FileObject parent = getParent(); if (parent != null) { parent.createFolder(); attach(); doCreateFolder(); handleCreate(FileType.FOLDER); } catch (final RuntimeException re) { throw re;
/** * Returns the file's type. * * @return The FileType. * @throws FileSystemException if an error occurs. */ @Override public FileType getType() throws FileSystemException { synchronized (monitorLock) { attach(); // VFS-210: get the type only if requested for try { if (type == null) { injectType(doGetType()); } if (type == null) { injectType(FileType.IMAGINARY); } } catch (final Exception e) { throw new FileSystemException("vfs.provider/get-type.error", e, fileName); } return type; } }
/** * Attaches to the file. * * @throws FileSystemException if an error occurs. */ private void attach() throws FileSystemException { synchronized (monitorLock) { if (isAttached()) { return; } try { // Attach and determine the file type doAttach(); setAttached(true); // now the type could already be injected by doAttach (e.g from parent to child) /* * VFS-210: determine the type when really asked fore if (type == null) { setFileType(doGetType()); } if * (type == null) { setFileType(FileType.IMAGINARY); } */ } catch (final Exception exc) { throw new FileSystemException("vfs.provider/get-type.error", exc, fileName); } // fs.fileAttached(this); } }
/** * Deletes this file. * <p> * TODO - This will not fail if this is a non-empty folder. * * @return true if this object has been deleted * @throws FileSystemException if an error occurs. */ @Override public boolean delete() throws FileSystemException { return delete(Selectors.SELECT_SELF) > 0; }
/** * This will prepare the fileObject to get resynchronized with the underlying filesystem if required. * * @throws FileSystemException if an error occurs. */ @Override public void refresh() throws FileSystemException { // Detach from the file try { detach(); } catch (final Exception e) { throw new FileSystemException("vfs.provider/resync.error", fileName, e); } }
/** * Close the delegated file. * * @throws FileSystemException if an error occurs. */ @Override public void close() throws FileSystemException { super.close(); if (file != null) { file.close(); } }
/** * Notify the parent of a change to its children, when a child is created or deleted. * * @param childName The name of the child. * @param newType The type of the child. * @throws Exception if an error occurs. */ private void notifyParent(final FileName childName, final FileType newType) throws Exception { if (parent == null) { final FileName parentName = fileName.getParent(); if (parentName != null) { // Locate the parent, if it is cached parent = fs.getFileFromCache(parentName); } } if (parent != null) { FileObjectUtils.getAbstractFileObject(parent).childrenChanged(childName, newType); } }
protected void doDetach() throws Exception { super.doDetach(); attrs = null; }
if (canRenameTo(destFile)) { if (!getParent().isWriteable()) { throw new FileSystemException("vfs.provider/rename-parent-read-only.error", getName(), getParent().getName()); if (!isWriteable()) { throw new FileSystemException("vfs.provider/rename-read-only.error", getName()); if (destFile.exists() && !isSameFile(destFile)) { destFile.deleteAll(); if (canRenameTo(destFile)) { attach(); final FileType srcType = getType(); doRename(destFile); FileObjectUtils.getAbstractFileObject(destFile).handleCreate(srcType); handleDelete(); // fire delete-events. This file-object (src) is like deleted. } catch (final RuntimeException re) { throw re; } catch (final Exception exc) { throw new FileSystemException("vfs.provider/rename.error", exc, getName(), destFile.getName()); && destFile.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER)) && fs.hasCapability(Capability.GET_LAST_MODIFIED)) {
attach(); return resolveFiles(children); childrenObjects = doListChildrenResolved(); children = extractNames(childrenObjects); } catch (final FileSystemException exc) { files = doListChildren(); } catch (final FileSystemException exc) { return resolveFiles(children);
findFiles(selector, true, files); if (file.getType().hasChildren() && file.getChildren().length != 0) { if (file.deleteSelf()) { nuofDeleted++;