Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2009-04-08 11:42:46 +0000
committerEike Stepper2009-04-08 11:42:46 +0000
commit378235b8a6619204e09f89ef429a2dcc6fa5c8ac (patch)
tree3dca2e459b76b2005345eb4e7b6b48fe20c67c72 /plugins/org.eclipse.emf.cdo/src/org
parent4291a9706f0ec67380fe19bbfd65f27ed36c3077 (diff)
downloadcdo-378235b8a6619204e09f89ef429a2dcc6fa5c8ac.tar.gz
cdo-378235b8a6619204e09f89ef429a2dcc6fa5c8ac.tar.xz
cdo-378235b8a6619204e09f89ef429a2dcc6fa5c8ac.zip
[247873] Getting information of a CDO URI (URIHandler/Converter)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=247873
Diffstat (limited to 'plugins/org.eclipse.emf.cdo/src/org')
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceInputStream.java58
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOURIHandler.java77
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java2
3 files changed, 71 insertions, 66 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceInputStream.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceInputStream.java
deleted file mode 100644
index d4407fe8a0..0000000000
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceInputStream.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Copyright (c) 2004 - 2009 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.eresource;
-
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.emf.common.util.URI;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.MessageFormat;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public final class CDOResourceInputStream extends InputStream
-{
- private CDOView view;
-
- private URI uri;
-
- public CDOResourceInputStream(CDOView view, URI uri)
- {
- this.view = view;
- this.uri = uri;
- }
-
- public CDOView getView()
- {
- return view;
- }
-
- public URI getURI()
- {
- return uri;
- }
-
- @Override
- public int read() throws IOException
- {
- throw new IOException("read not supported");
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("CDOInputStream[{0}]", uri);
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOURIHandler.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOURIHandler.java
index e9556085f7..debb677ffb 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOURIHandler.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOURIHandler.java
@@ -7,19 +7,31 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Victor Roldan Betancort - maintenance
*/
package org.eclipse.emf.internal.cdo;
-import org.eclipse.emf.cdo.eresource.CDOResourceInputStream;
+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.util.CDOURIUtil;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ContentHandler;
+import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.URIHandler;
import org.eclipse.emf.spi.cdo.InternalCDOView;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
/**
* @author Eike Stepper
@@ -27,6 +39,8 @@ import java.util.Map;
*/
public class CDOURIHandler implements URIHandler
{
+ private static final String CDO_URI_SCHEME = "cdo";
+
private InternalCDOView view;
public CDOURIHandler(InternalCDOView view)
@@ -41,39 +55,88 @@ public class CDOURIHandler implements URIHandler
public boolean canHandle(URI uri)
{
- return false;
+ return CDO_URI_SCHEME.equals(uri.scheme())
+ && view.getSession().repository().getUUID().equals(CDOURIUtil.extractRepositoryUUID(uri));
}
public boolean exists(URI uri, Map<?, ?> options)
{
- return false;
+ return view.hasResource(CDOURIUtil.extractResourcePath(uri));
}
public void delete(URI uri, Map<?, ?> options) throws IOException
{
+ String path = CDOURIUtil.extractResourcePath(uri);
+ CDOTransaction transaction = null;
+
+ try
+ {
+ transaction = view.getSession().openTransaction();
+ CDOResourceNode node = transaction.getResourceNode(path);
+ node.delete(options);
+ transaction.commit();
+ }
+ catch (Exception ex)
+ {
+ IOException ioException = new IOException(ex.getMessage());
+ ioException.initCause(ex);
+ throw ioException;
+ }
+ finally
+ {
+ IOUtil.closeSilent(transaction);
+ }
}
public InputStream createInputStream(URI uri, Map<?, ?> options) throws IOException
{
- return new CDOResourceInputStream(view, uri);
+ throw new UnsupportedOperationException();
}
public OutputStream createOutputStream(URI uri, Map<?, ?> options) throws IOException
{
- return null;
+ throw new UnsupportedOperationException();
}
public Map<String, ?> contentDescription(URI uri, Map<?, ?> options) throws IOException
{
- return null;
+ // ViK: I hardly find this useful for CDO. ContentHandler defines, for instance, VALIDITY_PROPERTY
+ // It might make sense in CDO... We could also introduce some CDO-Specific information here...
+ return ContentHandler.INVALID_CONTENT_DESCRIPTION;
}
+ @SuppressWarnings("unchecked")
public Map<String, ?> getAttributes(URI uri, Map<?, ?> options)
{
- return null;
+ Map<String, Object> result = new HashMap<String, Object>();
+ String path = CDOURIUtil.extractResourcePath(uri);
+ CDOResourceNode node = view.getResourceNode(path);
+ if (node != null)
+ {
+ Set<String> requestedAttributes = (Set<String>)options.get(URIConverter.OPTION_REQUESTED_ATTRIBUTES);
+ if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_TIME_STAMP))
+ {
+ long stamp = node instanceof CDOResource ? ((CDOResource)node).getTimeStamp() : URIConverter.NULL_TIME_STAMP;
+ result.put(URIConverter.ATTRIBUTE_TIME_STAMP, stamp);
+ }
+
+ if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_DIRECTORY))
+ {
+ result.put(URIConverter.ATTRIBUTE_DIRECTORY, node instanceof CDOResourceFolder);
+ }
+
+ if (requestedAttributes == null || requestedAttributes.contains(URIConverter.ATTRIBUTE_READ_ONLY))
+ {
+ result.put(URIConverter.ATTRIBUTE_READ_ONLY, view.getViewType() != CDOView.Type.TRANSACTION);
+ }
+ }
+
+ return result;
}
public void setAttributes(URI uri, Map<String, ?> attributes, Map<?, ?> options) throws IOException
{
+ // ViK: We can't change any of the proposed attributes. Only TIME_STAMP, and I believe we are not
+ // storing that attribute in the server. Due to CDOResouce distributed nature, changing it wouldn't make much sense.
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
index 8dd5764dc2..7acb5279ce 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
@@ -196,7 +196,7 @@ public class CDOViewImpl extends Lifecycle implements InternalCDOView
this.viewSet = viewSet;
if (viewSet != null)
{
- viewSet.getResourceSet().getURIConverter().getURIHandlers().add(getURIHandler());
+ viewSet.getResourceSet().getURIConverter().getURIHandlers().add(0, getURIHandler());
}
}

Back to the top