Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-10-23 10:45:33 -0400
committerEike Stepper2010-10-23 10:45:33 -0400
commit8e02069af25dfb99bffec3eca5f75b44c15588a1 (patch)
treee3e72c2a9e961aaf14fe577434b438f594452afc /plugins/org.eclipse.emf.cdo.workspace.efs
parentb17e18c5fbe00acf61ee191693d0b586f0e230ec (diff)
downloadcdo-8e02069af25dfb99bffec3eca5f75b44c15588a1.tar.gz
cdo-8e02069af25dfb99bffec3eca5f75b44c15588a1.tar.xz
cdo-8e02069af25dfb99bffec3eca5f75b44c15588a1.zip
[327405] Provide an offline CDOWorkspace with Checkout/Update/Commit workflows
https://bugs.eclipse.org/bugs/show_bug.cgi?id=327405
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.workspace.efs')
-rw-r--r--plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOResourceNodeStore.java126
1 files changed, 87 insertions, 39 deletions
diff --git a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOResourceNodeStore.java b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOResourceNodeStore.java
index e3cfb60e35..260b3a1ac9 100644
--- a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOResourceNodeStore.java
+++ b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOResourceNodeStore.java
@@ -10,10 +10,14 @@
*/
package org.eclipse.emf.cdo.workspace.internal.efs;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.cdo.workspace.internal.efs.bundle.OM;
+import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.core.filesystem.EFS;
@@ -23,9 +27,12 @@ import org.eclipse.core.filesystem.provider.FileInfo;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
/**
* @author Eike Stepper
@@ -38,6 +45,8 @@ public final class CDOResourceNodeStore extends AbstractFileStore
private String name;
+ private AtomicReference<CDOID> resourceNodeID = new AtomicReference<CDOID>();
+
public CDOResourceNodeStore(CDOWorkspaceStore workspaceStore, IFileStore parent, String name)
{
this.workspaceStore = workspaceStore;
@@ -75,29 +84,24 @@ public final class CDOResourceNodeStore extends AbstractFileStore
@Override
public String[] childNames(int options, IProgressMonitor monitor) throws CoreException
{
- List<String> childNames = new ArrayList<String>();
- CDOView view = null;
-
- try
+ return new ResourceNodeRunnable<String[]>()
{
- view = workspaceStore.getWorkspace().openView();
- CDOResourceNode node = view.getResourceNode(getPath());
- if (node instanceof CDOResourceFolder)
+ @Override
+ protected String[] run(CDOResourceNode node)
{
- CDOResourceFolder folder = (CDOResourceFolder)node;
-
- for (CDOResourceNode child : folder.getNodes())
+ List<String> childNames = new ArrayList<String>();
+ if (node instanceof CDOResourceFolder)
{
- childNames.add(child.getName());
+ CDOResourceFolder folder = (CDOResourceFolder)node;
+
+ for (CDOResourceNode child : folder.getNodes())
+ {
+ childNames.add(child.getName());
+ }
}
+ return childNames.toArray(new String[childNames.size()]);
}
- }
- finally
- {
- IOUtil.close(view);
- }
-
- return childNames.toArray(new String[childNames.size()]);
+ }.run();
}
@Override
@@ -109,32 +113,76 @@ public final class CDOResourceNodeStore extends AbstractFileStore
@Override
public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException
{
- CDOView view = null;
-
- try
+ return new ResourceNodeRunnable<IFileInfo>()
{
- view = workspaceStore.getWorkspace().openView();
- CDOResourceNode node = view.getResourceNode(getPath());
-
- FileInfo info = new FileInfo(getName());
- info.setExists(true);
- info.setLength(EFS.NONE);
- info.setLastModified(EFS.NONE);
- info.setDirectory(node instanceof CDOResourceFolder);
- info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, false);
- info.setAttribute(EFS.ATTRIBUTE_HIDDEN, false);
- return info;
- }
- finally
- {
- IOUtil.close(view);
- }
+ @Override
+ protected IFileInfo run(CDOResourceNode node)
+ {
+ FileInfo info = new FileInfo(getName());
+ info.setExists(true);
+ info.setLength(EFS.NONE);
+ info.setLastModified(EFS.NONE);
+ info.setDirectory(node instanceof CDOResourceFolder);
+ info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, false);
+ info.setAttribute(EFS.ATTRIBUTE_HIDDEN, false);
+ return info;
+ }
+ }.run();
}
@Override
public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException
{
- // TODO: implement CDOWorkspaceNodeStore.openInputStream(options, monitor)
- throw new UnsupportedOperationException();
+ return new ResourceNodeRunnable<InputStream>()
+ {
+ @Override
+ protected InputStream run(CDOResourceNode node)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ CDOResource resource = (CDOResource)node;
+ // resource.cdoPrefetch(CDORevision.DEPTH_INFINITE);
+
+ try
+ {
+ resource.save(baos, null);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ throw WrappedException.wrap(ex);
+ }
+
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+ }.run();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private abstract class ResourceNodeRunnable<RESULT>
+ {
+ public ResourceNodeRunnable()
+ {
+ }
+
+ public RESULT run()
+ {
+ CDOView view = null;
+
+ try
+ {
+ view = workspaceStore.getWorkspace().openView();
+ CDOResourceNode node = view.getResourceNode(getPath());
+ resourceNodeID.compareAndSet(null, node.cdoID());
+ return run(node);
+ }
+ finally
+ {
+ IOUtil.close(view);
+ }
+ }
+
+ protected abstract RESULT run(CDOResourceNode node);
}
}

Back to the top