Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-10-24 01:00:09 -0400
committerEike Stepper2010-10-24 01:00:09 -0400
commit6ca1b6430519471e1c386ff2f236d72e920a41c1 (patch)
tree72cd92eb0c5f112c18b15d0502af7b8d9dd1a3f4 /plugins/org.eclipse.emf.cdo.workspace.efs
parent8ac928fe67b1496f78d248db03505366099e6342 (diff)
downloadcdo-6ca1b6430519471e1c386ff2f236d72e920a41c1.tar.gz
cdo-6ca1b6430519471e1c386ff2f236d72e920a41c1.tar.xz
cdo-6ca1b6430519471e1c386ff2f236d72e920a41c1.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/AbstractResourceNodeStore.java182
-rw-r--r--plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOResourceNodeStore.java136
-rw-r--r--plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceStore.java89
3 files changed, 261 insertions, 146 deletions
diff --git a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/AbstractResourceNodeStore.java b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/AbstractResourceNodeStore.java
new file mode 100644
index 0000000000..b471dac4c8
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/AbstractResourceNodeStore.java
@@ -0,0 +1,182 @@
+/**
+ * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.workspace.internal.efs;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.eresource.CDOResourceNode;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CommitException;
+import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.cdo.workspace.CDOWorkspace;
+
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.io.IOUtil;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileInfo;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.filesystem.provider.FileInfo;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class AbstractResourceNodeStore extends AbstractFileStore
+{
+ private CDOID resourceNodeID;
+
+ public AbstractResourceNodeStore()
+ {
+ }
+
+ @Override
+ public String[] childNames(int options, IProgressMonitor monitor) throws CoreException
+ {
+ return new ResourceNodeRunnable<String[]>()
+ {
+ @Override
+ protected String[] run(CDOResourceNode node)
+ {
+ List<String> childNames = new ArrayList<String>();
+ collectChildNames(node, childNames);
+ return childNames.toArray(new String[childNames.size()]);
+ }
+ }.run();
+ }
+
+ @Override
+ public IFileStore getChild(String name)
+ {
+ return new CDOResourceNodeStore(getWorkspaceStore(), this, name);
+ }
+
+ @Override
+ public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException
+ {
+ return new ResourceNodeRunnable<IFileInfo>()
+ {
+ @Override
+ protected IFileInfo run(CDOResourceNode node)
+ {
+ boolean exists = node != null;
+
+ FileInfo info = new FileInfo(getName());
+ info.setExists(exists);
+ info.setLength(EFS.NONE);
+ info.setLastModified(EFS.NONE);
+ info.setDirectory(exists && isDirectory(node));
+ info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, false);
+ info.setAttribute(EFS.ATTRIBUTE_HIDDEN, false);
+ return info;
+ }
+ }.run();
+ }
+
+ public abstract CDOWorkspaceStore getWorkspaceStore();
+
+ @Override
+ public abstract AbstractResourceNodeStore getParent();
+
+ protected abstract CDOResourceNode getResourceNode(CDOView view);
+
+ protected abstract boolean isDirectory(CDOResourceNode node);
+
+ protected abstract void collectChildNames(CDOResourceNode node, List<String> childNames);
+
+ /**
+ * @author Eike Stepper
+ */
+ protected abstract class ResourceNodeRunnable<RESULT>
+ {
+ public ResourceNodeRunnable()
+ {
+ }
+
+ public RESULT run()
+ {
+ return run(false);
+ }
+
+ public RESULT run(boolean transactional)
+ {
+ CDOView view = null;
+
+ try
+ {
+ view = openView(transactional);
+ RESULT result = run(view);
+ if (view instanceof CDOTransaction)
+ {
+ CDOTransaction transaction = (CDOTransaction)view;
+ transaction.commit();
+ }
+
+ return result;
+ }
+ catch (CommitException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ finally
+ {
+ IOUtil.close(view);
+ }
+ }
+
+ protected RESULT run(CDOView view)
+ {
+ CDOResourceNode node = getResourceNode(view);
+ RESULT result = run(node);
+ return result;
+ }
+
+ protected RESULT run(CDOResourceNode node)
+ {
+ return null;
+ }
+
+ private CDOView openView(boolean transactional)
+ {
+ CDOView view;
+ CDOWorkspace workspace = getWorkspaceStore().getWorkspace();
+ view = transactional ? workspace.openTransaction() : workspace.openView();
+ return view;
+ }
+
+ private CDOResourceNode getResourceNode(CDOView view)
+ {
+ CDOResourceNode node = null;
+
+ try
+ {
+ if (resourceNodeID == null)
+ {
+ node = AbstractResourceNodeStore.this.getResourceNode(view);
+ resourceNodeID = node.cdoID();
+ }
+ else
+ {
+ node = (CDOResourceNode)view.getObject(resourceNodeID);
+ }
+ }
+ catch (Exception ex)
+ {
+ //$FALL-THROUGH$
+ }
+
+ return node;
+ }
+ }
+}
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 5696b4b5a6..cf72c111af 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,56 +10,44 @@
*/
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.transaction.CDOTransaction;
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;
-import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
-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;
/**
* @author Eike Stepper
*/
-public final class CDOResourceNodeStore extends AbstractFileStore
+public final class CDOResourceNodeStore extends AbstractResourceNodeStore
{
private CDOWorkspaceStore workspaceStore;
- private IFileStore parent;
+ private AbstractResourceNodeStore parent;
private String name;
- private CDOID resourceNodeID;
-
- public CDOResourceNodeStore(CDOWorkspaceStore workspaceStore, IFileStore parent, String name)
+ public CDOResourceNodeStore(CDOWorkspaceStore workspaceStore, AbstractResourceNodeStore parent, String name)
{
this.workspaceStore = workspaceStore;
this.parent = parent;
this.name = name;
}
- public CDOWorkspaceStore getWorkspaceStore()
- {
- return workspaceStore;
- }
-
@Override
- public IFileStore getParent()
+ public AbstractResourceNodeStore getParent()
{
return parent;
}
@@ -81,56 +69,6 @@ public final class CDOResourceNodeStore extends AbstractFileStore
}
@Override
- public String[] childNames(int options, IProgressMonitor monitor) throws CoreException
- {
- return new ResourceNodeRunnable<String[]>()
- {
- @Override
- protected String[] run(CDOResourceNode node)
- {
- List<String> childNames = new ArrayList<String>();
- if (node instanceof CDOResourceFolder)
- {
- CDOResourceFolder folder = (CDOResourceFolder)node;
-
- for (CDOResourceNode child : folder.getNodes())
- {
- childNames.add(child.getName());
- }
- }
-
- return childNames.toArray(new String[childNames.size()]);
- }
- }.run();
- }
-
- @Override
- public IFileStore getChild(String name)
- {
- return new CDOResourceNodeStore(workspaceStore, this, name);
- }
-
- @Override
- public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException
- {
- return new ResourceNodeRunnable<IFileInfo>()
- {
- @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
{
return new ResourceNodeRunnable<InputStream>()
@@ -157,42 +95,50 @@ public final class CDOResourceNodeStore extends AbstractFileStore
}.run();
}
- /**
- * @author Eike Stepper
- */
- private abstract class ResourceNodeRunnable<RESULT>
+ @Override
+ public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException
{
- public ResourceNodeRunnable()
+ new ResourceNodeRunnable<CDOResourceFolder>()
{
- }
+ @Override
+ protected CDOResourceFolder run(CDOView view)
+ {
+ return ((CDOTransaction)view).createResourceFolder(getPath());
+ }
+ }.run(true);
- public RESULT run()
- {
- CDOView view = null;
+ return this;
+ }
- try
- {
- view = workspaceStore.getWorkspace().openView();
+ @Override
+ public CDOWorkspaceStore getWorkspaceStore()
+ {
+ return workspaceStore;
+ }
- CDOResourceNode node;
- if (resourceNodeID == null)
- {
- node = view.getResourceNode(getPath());
- resourceNodeID = node.cdoID();
- }
- else
- {
- node = (CDOResourceNode)view.getObject(resourceNodeID);
- }
+ @Override
+ protected CDOResourceNode getResourceNode(CDOView view)
+ {
+ return view.getResourceNode(getPath());
+ }
- return run(node);
- }
- finally
+ @Override
+ protected boolean isDirectory(CDOResourceNode node)
+ {
+ return node instanceof CDOResourceFolder;
+ }
+
+ @Override
+ protected void collectChildNames(CDOResourceNode node, List<String> childNames)
+ {
+ if (node instanceof CDOResourceFolder)
+ {
+ CDOResourceFolder folder = (CDOResourceFolder)node;
+
+ for (CDOResourceNode child : folder.getNodes())
{
- IOUtil.close(view);
+ childNames.add(child.getName());
}
}
-
- protected abstract RESULT run(CDOResourceNode node);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceStore.java b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceStore.java
index 514a1c2217..ec9b29f049 100644
--- a/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceStore.java
+++ b/plugins/org.eclipse.emf.cdo.workspace.efs/src/org/eclipse/emf/cdo/workspace/internal/efs/CDOWorkspaceStore.java
@@ -16,14 +16,10 @@ import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.cdo.workspace.CDOWorkspace;
import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.filesystem.provider.FileInfo;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -31,15 +27,14 @@ import java.io.File;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.ArrayList;
import java.util.List;
/**
* @author Eike Stepper
*/
-public final class CDOWorkspaceStore extends AbstractFileStore
+public final class CDOWorkspaceStore extends AbstractResourceNodeStore
{
- private static final IFileStore NO_PARENT = null;
+ private static final AbstractResourceNodeStore NO_PARENT = null;
private String name;
@@ -74,7 +69,7 @@ public final class CDOWorkspaceStore extends AbstractFileStore
}
@Override
- public IFileStore getParent()
+ public AbstractResourceNodeStore getParent()
{
return NO_PARENT;
}
@@ -99,35 +94,6 @@ public final class CDOWorkspaceStore extends AbstractFileStore
}
@Override
- public String[] childNames(int options, IProgressMonitor monitor) throws CoreException
- {
- List<String> childNames = new ArrayList<String>();
- childNames.add(CDOProjectDescriptionStore.DESCRIPTION_FILE_NAME);
-
- CDOView view = null;
-
- try
- {
- view = getWorkspace().openView();
- CDOResource rootResource = view.getRootResource();
- for (EObject content : rootResource.getContents())
- {
- if (content instanceof CDOResourceNode)
- {
- CDOResourceNode node = (CDOResourceNode)content;
- childNames.add(node.getName());
- }
- }
- }
- finally
- {
- IOUtil.close(view);
- }
-
- return childNames.toArray(new String[childNames.size()]);
- }
-
- @Override
public IFileStore getChild(String name)
{
if (CDOProjectDescriptionStore.DESCRIPTION_FILE_NAME.equals(name))
@@ -135,20 +101,7 @@ public final class CDOWorkspaceStore extends AbstractFileStore
return new CDOProjectDescriptionStore(this);
}
- return new CDOResourceNodeStore(this, this, name);
- }
-
- @Override
- public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException
- {
- FileInfo info = new FileInfo(getName());
- info.setExists(true);
- info.setLength(EFS.NONE);
- info.setLastModified(EFS.NONE);
- info.setDirectory(true);
- info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, false);
- info.setAttribute(EFS.ATTRIBUTE_HIDDEN, false);
- return info;
+ return super.getChild(name);
}
@Override
@@ -169,6 +122,40 @@ public final class CDOWorkspaceStore extends AbstractFileStore
throw new UnsupportedOperationException();
}
+ @Override
+ public CDOWorkspaceStore getWorkspaceStore()
+ {
+ return this;
+ }
+
+ @Override
+ protected CDOResourceNode getResourceNode(CDOView view)
+ {
+ return view.getRootResource();
+ }
+
+ @Override
+ protected boolean isDirectory(CDOResourceNode node)
+ {
+ return true;
+ }
+
+ @Override
+ protected void collectChildNames(CDOResourceNode node, List<String> childNames)
+ {
+ childNames.add(CDOProjectDescriptionStore.DESCRIPTION_FILE_NAME);
+
+ CDOResource rootResource = (CDOResource)node;
+ for (EObject content : rootResource.getContents())
+ {
+ if (content instanceof CDOResourceNode)
+ {
+ CDOResourceNode child = (CDOResourceNode)content;
+ childNames.add(child.getName());
+ }
+ }
+ }
+
private CDOWorkspace openWorkspace()
{
// TODO: implement CDOWorkspaceStore.openWorkspace()

Back to the top