public class WorkspaceDocumentManagerImpl extends Object implements WorkspaceDocumentManager
Modifier and Type | Class and Description |
---|---|
static class |
WorkspaceDocumentManagerImpl.DocumentPair
This class holds workspace document and its lock.
|
Modifier | Constructor and Description |
---|---|
protected |
WorkspaceDocumentManagerImpl() |
Modifier and Type | Method and Description |
---|---|
void |
clearAllFilePaths()
Clear all file paths.
|
void |
closeFile(Path filePath)
Close the given file in document manager.
|
Set<Path> |
getAllFilePaths()
Returns a list of all file paths.
|
String |
getFileContent(Path filePath)
Returns the content of the file.
|
static WorkspaceDocumentManagerImpl |
getInstance() |
boolean |
isFileOpen(Path filePath)
Checks whether the given file is open in workspace.
|
Optional<Lock> |
lockFile(Path filePath)
Acquire a file lock.
|
Optional<Lock> |
openFile(Path filePath,
String content)
Opens the given file in document manager.
|
Optional<Lock> |
updateFile(Path filePath,
String updatedContent)
Updates given file in document manager with new content.
|
public static WorkspaceDocumentManagerImpl getInstance()
public boolean isFileOpen(Path filePath)
isFileOpen
in interface WorkspaceDocumentManager
filePath
- Path of the filepublic Optional<Lock> openFile(Path filePath, String content) throws WorkspaceDocumentException
openFile
in interface WorkspaceDocumentManager
filePath
- Path of the filecontent
- Content of the fileLock
retrieving a lock for the file. You must call Lock.unlock() once you are done with the work.WorkspaceDocumentException
- when file cannot be opened.public Optional<Lock> updateFile(Path filePath, String updatedContent) throws WorkspaceDocumentException
Optional<Lock> lock = Optional.empty(); try { lock = documentManager.updateFile(filePath, ""); } finally { lock.ifPresent(Lock:unlock); }
updateFile
in interface WorkspaceDocumentManager
filePath
- Path of the fileupdatedContent
- New content of the fileLock
retrieving a lock for the file. You must call Lock.unlock() once you are done with the work.WorkspaceDocumentException
- when file cannot be updated.public void closeFile(Path filePath) throws WorkspaceDocumentException
closeFile
in interface WorkspaceDocumentManager
filePath
- Path of the fileWorkspaceDocumentException
- when file cannot be closed.public String getFileContent(Path filePath) throws WorkspaceDocumentException
getFileContent
in interface WorkspaceDocumentManager
filePath
- Path of the fileWorkspaceDocumentException
- when file cannot be read.public Optional<Lock> lockFile(Path filePath)
Optional<Lock> lock = documentManager.lockFile(filePath); try { //your code } finally { lock.ifPresent(Lock:unlock); }
lockFile
in interface WorkspaceDocumentManager
filePath
- Path of the fileLock
retrieving a lock for the file. You must call Lock.unlock() once you are done with the work.public Set<Path> getAllFilePaths()
getAllFilePaths
in interface WorkspaceDocumentManager
Path
public void clearAllFilePaths()
clearAllFilePaths
in interface WorkspaceDocumentManager
Copyright © 2019 WSO2. All rights reserved.