Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-06-05 11:19:15 +0000
committerEike Stepper2012-06-05 11:19:15 +0000
commite5bc42789a5fa73d5f2c9a2dac4f0d0c177f9b63 (patch)
treefa7ac6f5500431fd69a4f27d61fe6ec64a39e335 /plugins/org.eclipse.emf.cdo
parente2fa7de2e0249c3d4b6c603a1694197453e45c38 (diff)
downloadcdo-e5bc42789a5fa73d5f2c9a2dac4f0d0c177f9b63.tar.gz
cdo-e5bc42789a5fa73d5f2c9a2dac4f0d0c177f9b63.tar.xz
cdo-e5bc42789a5fa73d5f2c9a2dac4f0d0c177f9b63.zip
[381356] Support prefetching through CDO URI formats
https://bugs.eclipse.org/bugs/show_bug.cgi?id=381356
Diffstat (limited to 'plugins/org.eclipse.emf.cdo')
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResource.java542
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceFactory.java73
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java3352
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIData.java78
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIUtil.java492
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewProvider.java112
6 files changed, 2382 insertions, 2267 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResource.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResource.java
index be88740b64..685e878842 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResource.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResource.java
@@ -1,274 +1,268 @@
-/*
- * Copyright (c) 2004 - 2012 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.transaction.CDOTransaction;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-/**
- * <!-- begin-user-doc --> A representation of the model object '<em><b>CDO Resource</b></em>'.
- *
- * @extends Resource
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @apiviz.landmark <!-- end-user-doc -->
- * <p>
- * The following features are supported:
- * <ul>
- * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#getResourceSet <em>Resource Set</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#getURI <em>URI</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#getContents <em>Contents</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#isModified <em>Modified</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#isLoaded <em>Loaded</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#isTrackingModification <em>Tracking
- * Modification</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#getErrors <em>Errors</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#getWarnings <em>Warnings</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#getTimeStamp <em>Time Stamp</em>}</li>
- * </ul>
- * </p>
- * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource()
- * @model
- * @generated
- */
-public interface CDOResource extends CDOResourceLeaf, Resource
-{
- /**
- * @ADDED
- * @since 2.0
- */
- public static final String OPTION_SAVE_PROGRESS_MONITOR = IProgressMonitor.class.getName();
-
- /**
- * @ADDED
- * @since 3.0
- */
- public static final String OPTION_SAVE_OVERRIDE_TRANSACTION = CDOTransaction.class.getName();
-
- /**
- * @ADDED
- * @since 4.0
- */
- public static final String OPTION_SAVE_BASE_URI = "OPTION_SAVE_BASE_URI";
-
- /**
- * Returns the value of the '<em><b>Resource Set</b></em>' attribute. <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Resource Set</em>' attribute isn't clear, there really should be more of a description
- * here...
- * </p>
- * <!-- end-user-doc -->
- *
- * @return the value of the '<em>Resource Set</em>' attribute.
- * @see #setResourceSet(ResourceSet)
- * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_ResourceSet()
- * @model dataType="org.eclipse.emf.cdo.eresource.ResourceSet" transient="true"
- * @generated
- */
- ResourceSet getResourceSet();
-
- /**
- * Sets the value of the '{@link org.eclipse.emf.cdo.eresource.CDOResource#getResourceSet <em>Resource Set</em>}'
- * attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @param value
- * the new value of the '<em>Resource Set</em>' attribute.
- * @see #getResourceSet()
- * @generated
- */
- void setResourceSet(ResourceSet value);
-
- /**
- * Returns the value of the '<em><b>URI</b></em>' attribute. <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>URI</em>' attribute isn't clear, there really should be more of a description here...
- * </p>
- * <!-- end-user-doc -->
- *
- * @return the value of the '<em>URI</em>' attribute.
- * @see #setURI(URI)
- * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_URI()
- * @model dataType="org.eclipse.emf.cdo.eresource.URI" transient="true" volatile="true" derived="true"
- * @generated
- */
- URI getURI();
-
- /**
- * Sets the value of the '{@link org.eclipse.emf.cdo.eresource.CDOResource#getURI <em>URI</em>}' attribute. <!--
- * begin-user-doc --> <!-- end-user-doc -->
- *
- * @param value
- * the new value of the '<em>URI</em>' attribute.
- * @see #getURI()
- * @generated
- */
- void setURI(URI value);
-
- /**
- * Returns the value of the '<em><b>Contents</b></em>' containment reference list. The list contents are of type
- * {@link org.eclipse.emf.ecore.EObject}. <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Contents</em>' containment reference list isn't clear, there really should be more of a
- * description here...
- * </p>
- * <!-- end-user-doc -->
- *
- * @return the value of the '<em>Contents</em>' containment reference list.
- * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_Contents()
- * @model containment="true"
- * @generated
- */
- EList<EObject> getContents();
-
- /**
- * Returns the value of the '<em><b>Modified</b></em>' attribute. <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Modified</em>' attribute isn't clear, there really should be more of a description
- * here...
- * </p>
- * <!-- end-user-doc -->
- *
- * @return the value of the '<em>Modified</em>' attribute.
- * @see #setModified(boolean)
- * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_Modified()
- * @model transient="true"
- * @generated
- */
- boolean isModified();
-
- /**
- * Sets the value of the '{@link org.eclipse.emf.cdo.eresource.CDOResource#isModified <em>Modified</em>}' attribute.
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @param value
- * the new value of the '<em>Modified</em>' attribute.
- * @see #isModified()
- * @generated
- */
- void setModified(boolean value);
-
- /**
- * Returns the value of the '<em><b>Loaded</b></em>' attribute. The default value is <code>"true"</code>. <!--
- * begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Loaded</em>' attribute isn't clear, there really should be more of a description here...
- * </p>
- * <!-- end-user-doc -->
- *
- * @return the value of the '<em>Loaded</em>' attribute.
- * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_Loaded()
- * @model default="true" transient="true" suppressedSetVisibility="true"
- * @generated
- */
- boolean isLoaded();
-
- /**
- * Returns the value of the '<em><b>Tracking Modification</b></em>' attribute. <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Tracking Modification</em>' attribute isn't clear, there really should be more of a
- * description here...
- * </p>
- * <!-- end-user-doc -->
- *
- * @return the value of the '<em>Tracking Modification</em>' attribute.
- * @see #setTrackingModification(boolean)
- * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_TrackingModification()
- * @model transient="true"
- * @generated
- */
- boolean isTrackingModification();
-
- /**
- * Sets the value of the '{@link org.eclipse.emf.cdo.eresource.CDOResource#isTrackingModification
- * <em>Tracking Modification</em>}' attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @param value
- * the new value of the '<em>Tracking Modification</em>' attribute.
- * @see #isTrackingModification()
- * @generated
- */
- void setTrackingModification(boolean value);
-
- /**
- * Returns the value of the '<em><b>Errors</b></em>' attribute list. The list contents are of type
- * {@link org.eclipse.emf.ecore.resource.Resource.Diagnostic}. <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Errors</em>' attribute list isn't clear, there really should be more of a description
- * here...
- * </p>
- * <!-- end-user-doc -->
- *
- * @return the value of the '<em>Errors</em>' attribute list.
- * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_Errors()
- * @model dataType="org.eclipse.emf.cdo.eresource.Diagnostic" transient="true" changeable="false" volatile="true"
- * derived="true"
- * @generated
- */
- EList<Diagnostic> getErrors();
-
- /**
- * Returns the value of the '<em><b>Warnings</b></em>' attribute list. The list contents are of type
- * {@link org.eclipse.emf.ecore.resource.Resource.Diagnostic}. <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Warnings</em>' attribute list isn't clear, there really should be more of a description
- * here...
- * </p>
- * <!-- end-user-doc -->
- *
- * @return the value of the '<em>Warnings</em>' attribute list.
- * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_Warnings()
- * @model dataType="org.eclipse.emf.cdo.eresource.Diagnostic" transient="true" changeable="false" volatile="true"
- * derived="true"
- * @generated
- */
- EList<Diagnostic> getWarnings();
-
- /**
- * Returns the value of the '<em><b>Time Stamp</b></em>' attribute. <!-- begin-user-doc -->
- * <p>
- * If the meaning of the '<em>Time Stamp</em>' attribute isn't clear, there really should be more of a description
- * here...
- * </p>
- * <!-- end-user-doc -->
- *
- * @return the value of the '<em>Time Stamp</em>' attribute.
- * @see #setTimeStamp(long)
- * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_TimeStamp()
- * @model transient="true"
- * @generated
- */
- long getTimeStamp();
-
- /**
- * Sets the value of the '{@link org.eclipse.emf.cdo.eresource.CDOResource#getTimeStamp <em>Time Stamp</em>}'
- * attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @param value
- * the new value of the '<em>Time Stamp</em>' attribute.
- * @see #getTimeStamp()
- * @generated
- */
- void setTimeStamp(long value);
-
- /**
- * @ADDED
- * @since 2.0
- */
- public boolean isExisting();
-
-} // CDOResource
+/*
+ * Copyright (c) 2004 - 2012 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.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOURIData;
+import org.eclipse.emf.cdo.util.CDOURIUtil;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * <!-- begin-user-doc -->
+ * A representation of the model object '<em><b>CDO Resource</b></em>'.
+ *
+ * @extends Resource
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @apiviz.landmark
+ * <!-- end-user-doc -->
+ * <p>
+ * The following features are supported:
+ * <ul>
+ * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#getResourceSet <em>Resource Set</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#getURI <em>URI</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#getContents <em>Contents</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#isModified <em>Modified</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#isLoaded <em>Loaded</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#isTrackingModification <em>Tracking
+ * Modification</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#getErrors <em>Errors</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#getWarnings <em>Warnings</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.CDOResource#getTimeStamp <em>Time Stamp</em>}</li>
+ * </ul>
+ * </p>
+ * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource()
+ * @model
+ * @generated
+ */
+public interface CDOResource extends CDOResourceLeaf, Resource
+{
+ /**
+ * @ADDED
+ * @since 2.0
+ */
+ public static final String OPTION_SAVE_PROGRESS_MONITOR = IProgressMonitor.class.getName();
+
+ /**
+ * @ADDED
+ * @since 3.0
+ */
+ public static final String OPTION_SAVE_OVERRIDE_TRANSACTION = CDOTransaction.class.getName();
+
+ /**
+ * @ADDED
+ * @since 4.0
+ */
+ public static final String OPTION_SAVE_BASE_URI = "OPTION_SAVE_BASE_URI";
+
+ /**
+ * @ADDED
+ * @since 4.1
+ */
+ public static final String PREFETCH_PARAMETER = "prefetch";
+
+ /**
+ * Returns the value of the '<em><b>Resource Set</b></em>' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @return the value of the '<em>Resource Set</em>' attribute.
+ * @see #setResourceSet(ResourceSet)
+ * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_ResourceSet()
+ * @model dataType="org.eclipse.emf.cdo.eresource.ResourceSet" transient="true"
+ * @generated
+ */
+ ResourceSet getResourceSet();
+
+ /**
+ * Sets the value of the '{@link org.eclipse.emf.cdo.eresource.CDOResource#getResourceSet <em>Resource Set</em>}'
+ * attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @param value
+ * the new value of the '<em>Resource Set</em>' attribute.
+ * @see #getResourceSet()
+ * @generated
+ */
+ void setResourceSet(ResourceSet value);
+
+ /**
+ * Returns the value of the '<em><b>URI</b></em>' attribute.
+ * <!-- begin-user-doc -->
+ * The URI format is explained in {@link CDOURIUtil} and {@link CDOURIData}.
+ * <!-- end-user-doc -->
+ *
+ * @return the value of the '<em>URI</em>' attribute.
+ * @see #setURI(URI)
+ * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_URI()
+ * @model dataType="org.eclipse.emf.cdo.eresource.URI" transient="true" volatile="true" derived="true"
+ * @generated
+ */
+ URI getURI();
+
+ /**
+ * Sets the value of the '{@link org.eclipse.emf.cdo.eresource.CDOResource#getURI <em>URI</em>}' attribute.
+ * <!-- begin-user-doc -->
+ * The URI format is explained in {@link CDOURIUtil} and {@link CDOURIData}.
+ * <!-- end-user-doc -->
+ *
+ * @param value
+ * the new value of the '<em>URI</em>' attribute.
+ * @see #getURI()
+ * @generated
+ */
+ void setURI(URI value);
+
+ /**
+ * Returns the value of the '<em><b>Contents</b></em>' containment reference list. The list contents are of type
+ * {@link org.eclipse.emf.ecore.EObject}.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @return the value of the '<em>Contents</em>' containment reference list.
+ * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_Contents()
+ * @model containment="true"
+ * @generated
+ */
+ EList<EObject> getContents();
+
+ /**
+ * Returns the value of the '<em><b>Modified</b></em>' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @return the value of the '<em>Modified</em>' attribute.
+ * @see #setModified(boolean)
+ * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_Modified()
+ * @model transient="true"
+ * @generated
+ */
+ boolean isModified();
+
+ /**
+ * Sets the value of the '{@link org.eclipse.emf.cdo.eresource.CDOResource#isModified <em>Modified</em>}' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @param value
+ * the new value of the '<em>Modified</em>' attribute.
+ * @see #isModified()
+ * @generated
+ */
+ void setModified(boolean value);
+
+ /**
+ * Returns the value of the '<em><b>Loaded</b></em>' attribute. The default value is <code>"true"</code>.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @return the value of the '<em>Loaded</em>' attribute.
+ * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_Loaded()
+ * @model default="true" transient="true" suppressedSetVisibility="true"
+ * @generated
+ */
+ boolean isLoaded();
+
+ /**
+ * Returns the value of the '<em><b>Tracking Modification</b></em>' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @return the value of the '<em>Tracking Modification</em>' attribute.
+ * @see #setTrackingModification(boolean)
+ * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_TrackingModification()
+ * @model transient="true"
+ * @generated
+ */
+ boolean isTrackingModification();
+
+ /**
+ * Sets the value of the '{@link org.eclipse.emf.cdo.eresource.CDOResource#isTrackingModification
+ * <em>Tracking Modification</em>}' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @param value
+ * the new value of the '<em>Tracking Modification</em>' attribute.
+ * @see #isTrackingModification()
+ * @generated
+ */
+ void setTrackingModification(boolean value);
+
+ /**
+ * Returns the value of the '<em><b>Errors</b></em>' attribute list. The list contents are of type
+ * {@link org.eclipse.emf.ecore.resource.Resource.Diagnostic}.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @return the value of the '<em>Errors</em>' attribute list.
+ * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_Errors()
+ * @model dataType="org.eclipse.emf.cdo.eresource.Diagnostic" transient="true" changeable="false" volatile="true"
+ * derived="true"
+ * @generated
+ */
+ EList<Diagnostic> getErrors();
+
+ /**
+ * Returns the value of the '<em><b>Warnings</b></em>' attribute list. The list contents are of type
+ * {@link org.eclipse.emf.ecore.resource.Resource.Diagnostic}.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @return the value of the '<em>Warnings</em>' attribute list.
+ * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_Warnings()
+ * @model dataType="org.eclipse.emf.cdo.eresource.Diagnostic" transient="true" changeable="false" volatile="true"
+ * derived="true"
+ * @generated
+ */
+ EList<Diagnostic> getWarnings();
+
+ /**
+ * Returns the value of the '<em><b>Time Stamp</b></em>' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @return the value of the '<em>Time Stamp</em>' attribute.
+ * @see #setTimeStamp(long)
+ * @see org.eclipse.emf.cdo.eresource.EresourcePackage#getCDOResource_TimeStamp()
+ * @model transient="true"
+ * @generated
+ */
+ long getTimeStamp();
+
+ /**
+ * Sets the value of the '{@link org.eclipse.emf.cdo.eresource.CDOResource#getTimeStamp <em>Time Stamp</em>}'
+ * attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ *
+ * @param value
+ * the new value of the '<em>Time Stamp</em>' attribute.
+ * @see #getTimeStamp()
+ * @generated
+ */
+ void setTimeStamp(long value);
+
+ /**
+ * @ADDED
+ * @since 2.0
+ */
+ public boolean isExisting();
+
+} // CDOResource
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceFactory.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceFactory.java
index 1c1311fff1..dcc3a883fa 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceFactory.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/CDOResourceFactory.java
@@ -1,32 +1,41 @@
-/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - bug 213402
- */
-package org.eclipse.emf.cdo.eresource;
-
-import org.eclipse.emf.cdo.eresource.impl.CDOResourceFactoryImpl;
-
-import org.eclipse.emf.ecore.resource.Resource;
-
-/**
- * Creates {@link CDOResource} instances.
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- * @apiviz.uses {@link CDOResource} - - creates
- */
-public interface CDOResourceFactory extends Resource.Factory
-{
- /**
- * @since 4.0
- */
- public static final CDOResourceFactory INSTANCE = CDOResourceFactoryImpl.INSTANCE;
-}
+/*
+ * Copyright (c) 2004 - 2012 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
+ * Simon McDuff - bug 213402
+ */
+package org.eclipse.emf.cdo.eresource;
+
+import org.eclipse.emf.cdo.eresource.impl.CDOResourceFactoryImpl;
+import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
+import org.eclipse.emf.cdo.util.CDOURIData;
+import org.eclipse.emf.cdo.util.CDOURIUtil;
+
+import org.eclipse.emf.ecore.resource.Resource;
+
+/**
+ * Creates {@link CDOResource} instances.
+ * <p>
+ * Note that the only important task of this factory is to instantiate a {@link CDOResourceImpl} and mark it
+ * {@link CDOResource#isExisting() existing} or not. All further {@link CDOResource#getURI() URI} processing
+ * is done later on in the registration process, especially in {@link CDOResourceImpl#basicSetResourceSet(org.eclipse.emf.ecore.resource.ResourceSet, org.eclipse.emf.common.notify.NotificationChain) CDOResourceImpl.basicSetResourceSet()}.
+ * <p>
+ * The recognized URI formats are explained in {@link CDOURIUtil} and {@link CDOURIData}.
+ *
+ * @author Eike Stepper
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @apiviz.uses {@link CDOResource} - - creates
+ */
+public interface CDOResourceFactory extends Resource.Factory
+{
+ /**
+ * @since 4.0
+ */
+ public static final CDOResourceFactory INSTANCE = CDOResourceFactoryImpl.INSTANCE;
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
index 467c6f872a..f7f4dc4112 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
@@ -1,1668 +1,1684 @@
-/*
- * Copyright (c) 2004 - 2012 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
- * Simon McDuff - maintenance
- */
-package org.eclipse.emf.cdo.eresource.impl;
-
-import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.CDOState;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.eresource.CDOResource;
-import org.eclipse.emf.cdo.eresource.EresourcePackage;
-import org.eclipse.emf.cdo.transaction.CDOTransaction;
-import org.eclipse.emf.cdo.util.CDOModificationTrackingAdapter;
-import org.eclipse.emf.cdo.util.CDOURIUtil;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.util.CommitException;
-import org.eclipse.emf.cdo.util.ReadOnlyException;
-import org.eclipse.emf.cdo.view.CDOView;
-import org.eclipse.emf.cdo.view.CDOViewProvider;
-import org.eclipse.emf.cdo.view.CDOViewProviderRegistry;
-
-import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.view.CDOStateMachine;
-
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.collection.Pair;
-import org.eclipse.net4j.util.transaction.TransactionException;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.NotificationChain;
-import org.eclipse.emf.common.notify.impl.NotificationChainImpl;
-import org.eclipse.emf.common.notify.impl.NotificationImpl;
-import org.eclipse.emf.common.notify.impl.NotifyingListImpl;
-import org.eclipse.emf.common.util.AbstractTreeIterator;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.InternalEObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.URIConverter;
-import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
-import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
-import org.eclipse.emf.ecore.util.InternalEList;
-import org.eclipse.emf.ecore.xmi.XMIResource;
-import org.eclipse.emf.ecore.xmi.XMLHelper;
-import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
-import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
-import org.eclipse.emf.spi.cdo.FSMUtil;
-import org.eclipse.emf.spi.cdo.InternalCDOObject;
-import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
-import org.eclipse.emf.spi.cdo.InternalCDOView;
-import org.eclipse.emf.spi.cdo.InternalCDOViewSet;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Callable;
-
-/**
- * <!-- begin-user-doc --> An implementation of the model object '<em><b>CDO Resource</b></em>'.
- *
- * @extends Resource.Internal
- * @noextend This interface is not intended to be extended by clients. <!-- end-user-doc -->
- * <p>
- * The following features are implemented:
- * <ul>
- * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#getResourceSet <em>Resource Set</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#getURI <em>URI</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#getContents <em>Contents</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#isModified <em>Modified</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#isLoaded <em>Loaded</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#isTrackingModification <em>Tracking
- * Modification</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#getErrors <em>Errors</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#getWarnings <em>Warnings</em>}</li>
- * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#getTimeStamp <em>Time Stamp</em>}</li>
- * </ul>
- * </p>
- * @generated
- */
-public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, Resource.Internal
-{
- private static final EReference CDO_RESOURCE_CONTENTS = EresourcePackage.eINSTANCE.getCDOResource_Contents();
-
- /**
- * The default URI converter when there is no resource set.
- *
- * @ADDED
- */
- private static URIConverter defaultURIConverter;
-
- /**
- * @ADDED
- */
- private boolean root;
-
- /**
- * @ADDED
- */
- private URI initialURI;
-
- /**
- * TODO Set to true in commit()?
- *
- * @ADDED
- */
- private boolean existing;
-
- /**
- * @ADDED
- */
- private boolean loading;
-
- /**
- * @ADDED
- */
- private boolean loaded;
-
- /**
- * @ADDED
- */
- private boolean modified;
-
- /**
- * @ADDED
- */
- private EList<Diagnostic> errors;
-
- /**
- * @ADDED
- */
- private EList<Diagnostic> warnings;
-
- /**
- * @ADDED
- */
- private transient CDOViewProvider viewProvider;
-
- /**
- * @ADDED
- * @since 2.0
- */
- public CDOResourceImpl(URI initialURI)
- {
- this.initialURI = initialURI;
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated
- */
- protected CDOResourceImpl()
- {
- super();
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated
- */
- @Override
- protected EClass eStaticClass()
- {
- return EresourcePackage.Literals.CDO_RESOURCE;
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated NOT
- * @since 2.0
- */
- @Override
- public Resource.Internal eDirectResource()
- {
- if (isRoot())
- {
- return this;
- }
-
- return super.eDirectResource();
- }
-
- @Override
- public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass)
- {
- if (baseClass == CDOResource.class)
- {
- return baseFeatureID;
- }
-
- if (baseClass == Resource.class)
- {
- return baseFeatureID + EresourcePackage.CDO_RESOURCE_NODE_FEATURE_COUNT;
- }
-
- return super.eBaseStructuralFeatureID(baseFeatureID, baseClass);
- }
-
- @Override
- public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass)
- {
- if (baseClass == CDOResource.class)
- {
- return derivedFeatureID;
- }
-
- if (baseClass == Resource.class)
- {
- return derivedFeatureID - EresourcePackage.CDO_RESOURCE_NODE_FEATURE_COUNT;
- }
-
- return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
- }
-
- /**
- * @since 2.0
- */
- public boolean isRoot()
- {
- return root;
- }
-
- /**
- * @since 3.0
- */
- public void setRoot(boolean root)
- {
- this.root = root;
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated
- */
- public ResourceSet getResourceSet()
- {
- return (ResourceSet)eGet(EresourcePackage.Literals.CDO_RESOURCE__RESOURCE_SET, true);
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated
- */
- public void setResourceSet(ResourceSet newResourceSet)
- {
- eSet(EresourcePackage.Literals.CDO_RESOURCE__RESOURCE_SET, newResourceSet);
- }
-
- /**
- * <!-- begin-user-doc -->
- *
- * @since 2.0 <!-- end-user-doc -->
- * @generated
- */
- public URI getURIGen()
- {
- return (URI)eGet(EresourcePackage.Literals.CDO_RESOURCE__URI, true);
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated NOT
- */
- @Override
- public URI getURI()
- {
- if (cdoID() == null && initialURI != null)
- {
- return initialURI;
- }
-
- if (viewProvider != null)
- {
- URI uri = viewProvider.getResourceURI(cdoView(), getPath());
- if (uri != null)
- {
- return uri;
- }
- }
-
- return super.getURI();
- }
-
- /**
- * <!-- begin-user-doc -->
- *
- * @since 2.0 <!-- end-user-doc -->
- * @generated
- */
- public void setURIGen(URI newURI)
- {
- eSet(EresourcePackage.Literals.CDO_RESOURCE__URI, newURI);
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated NOT
- */
- public void setURI(URI newURI)
- {
- String newPath = CDOURIUtil.extractResourcePath(newURI);
- setPath(newPath);
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated NOT
- */
- @SuppressWarnings("unchecked")
- public EList<EObject> getContents()
- {
- return (EList<EObject>)eGet(EresourcePackage.Literals.CDO_RESOURCE__CONTENTS, true);
- }
-
- /**
- * @since 2.0
- */
- @Override
- public void cdoInternalPostDetach(boolean remote)
- {
- super.cdoInternalPostDetach(remote);
- if (remote)
- {
- existing = false;
- }
-
- removeFromResourceSet();
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated NOT
- */
- public boolean isModified()
- {
- return modified;
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated NOT
- */
- public void setModified(boolean newModified)
- {
- boolean oldModified = modified;
- modified = newModified;
- if (oldModified != newModified && eNotificationRequired())
- {
- Notification notification = new NotificationImpl(Notification.SET, oldModified, newModified)
- {
- @Override
- public Object getNotifier()
- {
- return CDOResourceImpl.this;
- }
-
- @Override
- public int getFeatureID(Class<?> expectedClass)
- {
- return RESOURCE__IS_MODIFIED;
- }
- };
-
- eNotify(notification);
- }
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated NOT
- */
- public boolean isLoaded()
- {
- return loaded;
- }
-
- /**
- * @see ResourceImpl#setLoaded(boolean)
- * @ADDED
- */
- private Notification setLoaded(boolean isLoaded)
- {
- boolean oldIsLoaded = loaded;
- loaded = isLoaded;
-
- if (eNotificationRequired())
- {
- Notification notification = new NotificationImpl(Notification.SET, oldIsLoaded, isLoaded)
- {
- @Override
- public Object getNotifier()
- {
- return CDOResourceImpl.this;
- }
-
- @Override
- public int getFeatureID(Class<?> expectedClass)
- {
- // TODO FIX bug 265136
- return Resource.RESOURCE__IS_LOADED;
- }
- };
-
- return notification;
- }
-
- return null;
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated
- */
- public boolean isTrackingModification()
- {
- return (Boolean)eGet(EresourcePackage.Literals.CDO_RESOURCE__TRACKING_MODIFICATION, true);
- }
-
- /**
- * <!-- begin-user-doc -->
- *
- * @since 4.0 <!-- end-user-doc -->
- * @generated
- */
- public void setTrackingModificationGen(boolean newTrackingModification)
- {
- eSet(EresourcePackage.Literals.CDO_RESOURCE__TRACKING_MODIFICATION, newTrackingModification);
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated NOT
- */
- public void setTrackingModification(boolean newTrackingModification)
- {
- if (cdoView().isReadOnly())
- {
- throw new ReadOnlyException("Underlying view is read-only");
- }
-
- if (newTrackingModification == isTrackingModification())
- {
- return;
- }
-
- EList<Adapter> adapters = eAdapters();
- if (newTrackingModification)
- {
- adapters.add(new CDOModificationTrackingAdapter(this));
- }
- else
- {
- for (Adapter adapter : adapters)
- {
- if (adapter instanceof CDOModificationTrackingAdapter)
- {
- adapters.remove(adapter);
- break;
- }
- }
- }
-
- setTrackingModificationGen(newTrackingModification);
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated NOT
- */
- public EList<Diagnostic> getErrors()
- {
- if (errors == null)
- {
- errors = new NotifyingListImpl<Diagnostic>()
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected boolean isNotificationRequired()
- {
- return CDOResourceImpl.this.eNotificationRequired();
- }
-
- @Override
- public Object getNotifier()
- {
- return CDOResourceImpl.this;
- }
-
- @Override
- public int getFeatureID()
- {
- return EresourcePackage.CDO_RESOURCE__ERRORS;
- }
- };
- }
-
- return errors;
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated NOT
- */
- public EList<Diagnostic> getWarnings()
- {
- if (warnings == null)
- {
- warnings = new NotifyingListImpl<Diagnostic>()
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected boolean isNotificationRequired()
- {
- return CDOResourceImpl.this.eNotificationRequired();
- }
-
- @Override
- public Object getNotifier()
- {
- return CDOResourceImpl.this;
- }
-
- @Override
- public int getFeatureID()
- {
- return EresourcePackage.CDO_RESOURCE__WARNINGS;
- }
- };
- }
-
- return warnings;
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated
- */
- public long getTimeStamp()
- {
- return (Long)eGet(EresourcePackage.Literals.CDO_RESOURCE__TIME_STAMP, true);
- }
-
- /**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated
- */
- public void setTimeStamp(long newTimeStamp)
- {
- eSet(EresourcePackage.Literals.CDO_RESOURCE__TIME_STAMP, newTimeStamp);
- }
-
- /**
- * @ADDED
- * @see ResourceImpl#getAllContents()
- */
- public TreeIterator<EObject> getAllContents()
- {
- return new AbstractTreeIterator<EObject>(this, false)
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- public Iterator<EObject> getChildren(Object object)
- {
- return object == CDOResourceImpl.this ? CDOResourceImpl.this.getContents().iterator() : ((EObject)object)
- .eContents().iterator();
- }
- };
- }
-
- /**
- * <b>Note:</b> URI from temporary objects are going to changed when we commit the CDOTransaction. Objects will not be
- * accessible from their temporary URI once CDOTransaction is committed.
- * <p>
- * <b>Note:</b> This resource is not actually used to lookup the resulting object in CDO. Only the CDOView is used for
- * this lookup! This means that this resource can be used to resolve <em>any</em> fragment with a CDOID of the
- * associated CDOView.
- *
- * @ADDED
- */
- public EObject getEObject(String uriFragment)
- {
- if (uriFragment == null)
- {
- return null;
- }
-
- try
- {
- EObject eObjectByFragment = getEObjectByFragment(uriFragment);
-
- if (eObjectByFragment != null)
- {
- return eObjectByFragment;
- }
-
- CDOID id = CDOIDUtil.read(uriFragment);
- InternalCDOView view = cdoView();
- if (CDOIDUtil.isNull(id) || view.isObjectNew(id) && !view.isObjectRegistered(id))
- {
- return null;
- }
-
- if (id.isObject())
- {
- CDOObject object = view.getObject(id, true);
- return CDOUtil.getEObject(object);
- }
- }
- catch (Exception ex)
- {
- // Do nothing
- // Return null if the object cannot be resolved.
- }
-
- // If it doesn't match to anything we return null like ResourceImpl.getEObject
- return null;
- }
-
- private EObject getEObjectByFragment(String uriFragment)
- {
- int length = uriFragment.length();
- if (length > 0)
- {
- if (uriFragment.charAt(0) == '/')
- {
- ArrayList<String> uriFragmentPath = new ArrayList<String>(4);
- int start = 1;
- for (int i = 1; i < length; ++i)
- {
- if (uriFragment.charAt(i) == '/')
- {
- uriFragmentPath.add(start == i ? "" : uriFragment.substring(start, i));
- start = i + 1;
- }
- }
-
- uriFragmentPath.add(uriFragment.substring(start));
- return getEObject(uriFragmentPath);
- }
- else if (uriFragment.charAt(length - 1) == '?')
- {
- int index = uriFragment.lastIndexOf('?', length - 2);
- if (index > 0)
- {
- uriFragment = uriFragment.substring(0, index);
- }
- }
- }
-
- return null;
- }
-
- private EObject getEObject(List<String> uriFragmentPath)
- {
- int size = uriFragmentPath.size();
- EObject eObject = getEObjectForURIFragmentRootSegment(size == 0 ? "" : uriFragmentPath.get(0));
- for (int i = 1; i < size && eObject != null; ++i)
- {
- eObject = ((InternalEObject)eObject).eObjectForURIFragmentSegment(uriFragmentPath.get(i));
- }
-
- return eObject;
- }
-
- private EObject getEObjectForURIFragmentRootSegment(String uriFragmentRootSegment)
- {
- int position = 0;
- if (uriFragmentRootSegment.length() > 0)
- {
- try
- {
- position = Integer.parseInt(uriFragmentRootSegment);
- }
- catch (NumberFormatException exception)
- {
- throw new RuntimeException(exception);
- }
- }
-
- List<EObject> contents = getContents();
- if (position < contents.size() && position >= 0)
- {
- return contents.get(position);
- }
-
- return null;
- }
-
- /**
- * @ADDED
- */
- public String getURIFragment(EObject object)
- {
- // TODO if object == this ??? what we do. Is it wanted ? How we handle them ?
- InternalCDOObject internalCDOObject = FSMUtil.adapt(object, cdoView());
- StringBuilder builder = new StringBuilder();
- CDOIDUtil.write(builder, internalCDOObject.cdoID());
- return builder.toString();
- }
-
- /**
- * @since 2.0
- */
- @Override
- public void cdoInternalPreLoad()
- {
- try
- {
- load(null);
- }
- catch (IOException ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
-
- /**
- * @ADDED
- */
- public void load(InputStream inputStream, Map<?, ?> options) throws IOException
- {
- // final String baseURI = getBaseURIOption(options);
- // final Map<Resource, CDOResource> resourceMappings = new HashMap<Resource, CDOResource>();
- //
- // class ImportResource extends XMIResourceImpl
- // {
- // private CDOResource delegate;
- //
- // public ImportResource(CDOResource delegate)
- // {
- // super(URI.createURI(baseURI + delegate.getPath()));
- // this.delegate = delegate;
- // }
- //
- // @Override
- // public EList<EObject> getContents()
- // {
- // return delegate.getContents();
- // }
- //
- // @Override
- // public String getURIFragment(EObject eObject)
- // {
- // String id = EcoreUtil.getID(eObject);
- // if (id != null)
- // {
- // return id;
- // }
- //
- // InternalEObject internalEObject = (InternalEObject)eObject;
- // if (getMappedResource(internalEObject.eDirectResource()) == this)
- // {
- // return "/" + getURIFragmentRootSegment(eObject);
- // }
- //
- // List<String> uriFragmentPath = new ArrayList<String>();
- // boolean isContained = false;
- // for (InternalEObject container = internalEObject.eInternalContainer(); container != null; container =
- // internalEObject
- // .eInternalContainer())
- // {
- // uriFragmentPath.add(container.eURIFragmentSegment(internalEObject.eContainingFeature(), internalEObject));
- // internalEObject = container;
- // if (getMappedResource(container.eDirectResource()) == this)
- // {
- // isContained = true;
- // break;
- // }
- // }
- //
- // if (!isContained)
- // {
- // return "/-1";
- // }
- //
- // StringBuilder result = new StringBuilder("/");
- // result.append(getURIFragmentRootSegment(internalEObject));
- //
- // for (int i = uriFragmentPath.size() - 1; i >= 0; --i)
- // {
- // result.append('/');
- // result.append(uriFragmentPath.get(i));
- // }
- //
- // return result.toString();
- // }
- //
- // @Override
- // protected XMLHelper createXMLHelper()
- // {
- // return new XMIHelperImpl(this)
- // {
- // @Override
- // public String getHREF(EObject obj)
- // {
- // InternalEObject o = (InternalEObject)obj;
- //
- // URI objectURI = o.eProxyURI();
- // if (objectURI == null)
- // {
- // Resource otherResource = obj.eResource();
- // otherResource = getMappedResource(otherResource);
- // objectURI = getHREF(otherResource, obj);
- // }
- //
- // objectURI = deresolve(objectURI);
- // return objectURI.toString();
- // }
- //
- // @Override
- // protected URI getHREF(Resource otherResource, EObject obj)
- // {
- // String uriFragment = getURIFragment(otherResource, obj);
- // if (otherResource == ImportResource.this)
- // {
- // return URI.createURI(uriFragment);
- // }
- //
- // return otherResource.getURI().appendFragment(uriFragment);
- // }
- // };
- // }
- //
- // private Resource getMappedResource(Resource otherResource)
- // {
- // Resource resource = resourceMappings.get(otherResource);
- // if (resource != null)
- // {
- // return resource;
- // }
- //
- // if (otherResource instanceof CDOResource)
- // {
- // CDOResource cdoResource = (CDOResource)otherResource;
- // otherResource = new ImportResource(cdoResource);
- // resourceMappings.put(cdoResource, otherResource);
- // }
- //
- // return otherResource;
- // }
- // }
- //
- // XMIResource xmiResource = new ImportResource(this);
- // resourceMappings.put(this, xmiResource);
- // xmiResource.save(outputStream, options);
-
- throw new UnsupportedOperationException();
- }
-
- /**
- * @ADDED
- */
- public void load(Map<?, ?> options) throws IOException
- {
- if (!isLoaded())
- {
- InternalCDOView view = cdoView();
- if (!FSMUtil.isTransient(this))
- {
- CDOID id = cdoID();
- if (id == null)
- {
- registerProxy(view);
- }
- else
- {
- synchronized (view)
- {
- if (!view.isObjectRegistered(id))
- {
- registerProxy(view);
- }
- }
- }
- }
-
- Notification notification = setLoaded(true);
- if (notification != null)
- {
- eNotify(notification);
- }
-
- // URIConverter uriConverter = getURIConverter();
- //
- // // If an input stream can't be created, ensure that the resource is still considered loaded after the failure,
- // // and do all the same processing we'd do if we actually were able to create a valid input stream.
- // //
- // InputStream inputStream = null;
- //
- // try
- // {
- // inputStream = uriConverter.createInputStream(getURI(), options);
- // }
- // catch (IOException exception)
- // {
- // Notification notification = setLoaded(true);
- // loading = true;
- // if (errors != null)
- // {
- // errors.clear();
- // }
- //
- // if (warnings != null)
- // {
- // warnings.clear();
- // }
- //
- // loading = false;
- // if (notification != null)
- // {
- // eNotify(notification);
- // }
- //
- // setModified(false);
- // throw exception;
- // }
- //
- // try
- // {
- // load(inputStream, options);
- // }
- // finally
- // {
- // inputStream.close();
- // // TODO Handle timeStamp
- // // Long timeStamp = (Long)response.get(URIConverter.RESPONSE_TIME_STAMP_PROPERTY);
- // // if (timeStamp != null)
- // // {
- // // setTimeStamp(timeStamp);
- // // }
- // }
- }
- }
-
- private void registerProxy(InternalCDOView view) throws IOWrappedException
- {
- try
- {
- view.registerProxyResource(this);
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- setExisting(false);
- cdoInternalSetState(CDOState.TRANSIENT);
- throw new IOWrappedException(ex);
- }
- }
-
- /**
- * Returns the URI converter. This typically gets the {@link ResourceSet#getURIConverter converter} from the
- * {@link #getResourceSet containing} resource set, but it calls {@link #getDefaultURIConverter} when there is no
- * containing resource set.
- *
- * @return the URI converter.
- * @ADDED
- */
- @SuppressWarnings("unused")
- private URIConverter getURIConverter()
- {
- return getResourceSet() == null ? getDefaultURIConverter() : getResourceSet().getURIConverter();
- }
-
- /**
- * Returns the default URI converter that's used when there is no resource set.
- *
- * @return the default URI converter.
- * @see #getURIConverter
- * @ADDED
- */
- private static synchronized URIConverter getDefaultURIConverter()
- {
- if (defaultURIConverter == null)
- {
- defaultURIConverter = new ExtensibleURIConverterImpl();
- }
-
- return defaultURIConverter;
- }
-
- /**
- * @ADDED
- */
- public void save(Map<?, ?> options) throws IOException
- {
- CDOTransaction transaction = getTransaction(options);
- IProgressMonitor progressMonitor = options != null ? (IProgressMonitor)options
- .get(CDOResource.OPTION_SAVE_PROGRESS_MONITOR) : null;
-
- try
- {
- transaction.commit(progressMonitor);
- }
- catch (CommitException ex)
- {
- throw new TransactionException(ex);
- }
-
- setModified(false);
- }
-
- /**
- * @ADDED
- */
- private CDOTransaction getTransaction(Map<?, ?> options)
- {
- CDOTransaction transaction = options != null ? (CDOTransaction)options
- .get(CDOResource.OPTION_SAVE_OVERRIDE_TRANSACTION) : null;
-
- if (transaction == null)
- {
- CDOView view = cdoView();
- if (view instanceof CDOTransaction)
- {
- transaction = (CDOTransaction)view;
- }
- else
- {
- throw new IllegalStateException("No transaction available");
- }
- }
-
- return transaction;
- }
-
- /**
- * @ADDED
- */
- public void save(OutputStream outputStream, Map<?, ?> options) throws IOException
- {
- final String baseURI = getBaseURIOption(options);
- final Map<CDOResource, Resource> resourceMappings = new HashMap<CDOResource, Resource>();
-
- class ExportResource extends XMIResourceImpl
- {
- private CDOResource delegate;
-
- public ExportResource(CDOResource delegate)
- {
- super(URI.createURI(baseURI + delegate.getPath()));
- this.delegate = delegate;
- }
-
- @Override
- public EList<EObject> getContents()
- {
- return delegate.getContents();
- }
-
- // @Override
- // public String getURIFragment(EObject eObject)
- // {
- // String id = EcoreUtil.getID(eObject);
- // if (id != null)
- // {
- // return id;
- // }
- //
- // InternalEObject internalEObject = (InternalEObject)eObject;
- // if (getMappedResource(internalEObject.eDirectResource()) == this)
- // {
- // return "/" + getURIFragmentRootSegment(eObject);
- // }
- //
- // List<String> uriFragmentPath = new ArrayList<String>();
- // boolean isContained = false;
- // for (InternalEObject container = internalEObject.eInternalContainer(); container != null; container =
- // internalEObject
- // .eInternalContainer())
- // {
- // uriFragmentPath.add(container.eURIFragmentSegment(internalEObject.eContainingFeature(), internalEObject));
- // internalEObject = container;
- // if (getMappedResource(container.eDirectResource()) == this)
- // {
- // isContained = true;
- // break;
- // }
- // }
- //
- // if (!isContained)
- // {
- // return "/-1";
- // }
- //
- // StringBuilder result = new StringBuilder("/");
- // result.append(getURIFragmentRootSegment(internalEObject));
- //
- // for (int i = uriFragmentPath.size() - 1; i >= 0; --i)
- // {
- // result.append('/');
- // result.append(uriFragmentPath.get(i));
- // }
- //
- // return result.toString();
- // }
-
- @Override
- protected boolean useUUIDs()
- {
- return true;
- }
-
- @Override
- protected boolean useIDAttributes()
- {
- return false;
- }
-
- @Override
- public String getID(EObject eObject)
- {
- CDOObject cdoObject = CDOUtil.getCDOObject(eObject);
- StringBuilder builder = new StringBuilder();
- CDOIDUtil.write(builder, cdoObject.cdoID());
- return builder.toString();
- }
-
- @Override
- protected XMLHelper createXMLHelper()
- {
- return new XMIHelperImpl(this)
- {
- @Override
- public String getHREF(EObject obj)
- {
- InternalEObject o = (InternalEObject)obj;
-
- URI objectURI = o.eProxyURI();
- if (objectURI == null)
- {
- Resource otherResource = obj.eResource();
- otherResource = getMappedResource(otherResource);
- objectURI = getHREF(otherResource, obj);
- }
-
- objectURI = deresolve(objectURI);
- return objectURI.toString();
- }
-
- @Override
- protected URI getHREF(Resource otherResource, EObject obj)
- {
- String uriFragment = getURIFragment(otherResource, obj);
- if (otherResource == ExportResource.this)
- {
- return URI.createURI(uriFragment);
- }
-
- return otherResource.getURI().appendFragment(uriFragment);
- }
- };
- }
-
- private Resource getMappedResource(Resource otherResource)
- {
- Resource resource = resourceMappings.get(otherResource);
- if (resource != null)
- {
- return resource;
- }
-
- if (otherResource instanceof CDOResource)
- {
- CDOResource cdoResource = (CDOResource)otherResource;
- otherResource = new ExportResource(cdoResource);
- resourceMappings.put(cdoResource, otherResource);
- }
-
- return otherResource;
- }
- }
-
- XMIResource xmiResource = new ExportResource(this);
- resourceMappings.put(this, xmiResource);
- xmiResource.save(outputStream, options);
- }
-
- private String getBaseURIOption(Map<?, ?> options)
- {
- if (options != null)
- {
- String uri = (String)options.get(OPTION_SAVE_BASE_URI);
- if (uri != null)
- {
- return uri;
- }
- }
-
- return "cdo://";
- }
-
- /**
- * @ADDED
- */
- public void unload()
- {
- // Do nothing
- }
-
- /**
- * @ADDED
- */
- public void delete(Map<?, ?> options) throws IOException
- {
- if (FSMUtil.isTransient(this))
- {
- removeFromResourceSet();
- }
- else
- {
- if (isRoot())
- {
- throw new UnsupportedOperationException();
- }
-
- if (getFolder() == null)
- {
- InternalCDOView view = cdoView();
- view.getRootResource().getContents().remove(this);
- }
- else
- {
- basicSetFolder(null, false);
- }
- }
- }
-
- private void removeFromResourceSet()
- {
- final ResourceSet resourceSet = getResourceSet();
- if (resourceSet != null)
- {
- InternalCDOViewSet viewSet = (InternalCDOViewSet)CDOUtil.getViewSet(resourceSet);
- viewSet.executeWithoutNotificationHandling(new Callable<Boolean>()
- {
- public Boolean call() throws Exception
- {
- resourceSet.getResources().remove(CDOResourceImpl.this);
- return true;
- }
- });
- }
- }
-
- /**
- * @ADDED
- */
- public void attached(EObject object)
- {
- if (!FSMUtil.isTransient(this))
- {
- InternalCDOView view = cdoView();
- if (view instanceof InternalCDOTransaction) // Bug 376075
- {
- InternalCDOTransaction transaction = (InternalCDOTransaction)view;
- InternalCDOObject cdoObject = FSMUtil.adapt(object, transaction);
-
- if (CDOUtil.isLegacyObject(cdoObject) && FSMUtil.isClean(cdoObject))
- {
- // Bug 352204
- return;
- }
-
- attached(cdoObject, transaction);
- }
- }
- }
-
- /**
- * @ADDED
- */
- private void attached(InternalCDOObject cdoObject, InternalCDOTransaction transaction)
- {
- CDOStateMachine.INSTANCE.attach(cdoObject, transaction);
- }
-
- /**
- * @ADDED
- */
- public void detached(EObject object)
- {
- if (!FSMUtil.isTransient(this))
- {
- InternalCDOView view = cdoView();
- if (view instanceof InternalCDOTransaction) // Bug 376075
- {
- InternalCDOObject cdoObject = FSMUtil.adapt(object, view);
- CDOStateMachine.INSTANCE.detach(cdoObject);
- }
- }
- }
-
- /**
- * @ADDED
- * @see ResourceImpl#basicSetResourceSet(ResourceSet, NotificationChain)
- */
- public NotificationChain basicSetResourceSet(ResourceSet resourceSet, NotificationChain notifications)
- {
- final ResourceSet oldResourceSet = getResourceSet();
- if (oldResourceSet != null)
- {
- final NotificationChain finalNotifications = notifications;
-
- InternalCDOViewSet viewSet = (InternalCDOViewSet)CDOUtil.getViewSet(oldResourceSet);
- notifications = viewSet.executeWithoutNotificationHandling(new Callable<NotificationChain>()
- {
- public NotificationChain call() throws Exception
- {
- return ((InternalEList<Resource>)oldResourceSet.getResources()).basicRemove(this, finalNotifications);
- }
- });
- }
-
- setResourceSet(resourceSet);
-
- if (resourceSet != null)
- {
- InternalCDOView view = cdoView();
- if (view == null)
- {
- URI uri = getURI();
- Pair<CDOView, CDOViewProvider> pair = CDOViewProviderRegistry.INSTANCE.provideViewWithInfo(uri, resourceSet);
- if (pair != null)
- {
- view = (InternalCDOView)pair.getElement1();
- view.attachResource(this);
-
- viewProvider = pair.getElement2();
- }
- }
- }
-
- if (eNotificationRequired())
- {
- if (notifications == null)
- {
- notifications = new NotificationChainImpl(2);
- }
-
- notifications.add(new NotificationImpl(Notification.SET, oldResourceSet, resourceSet)
- {
- @Override
- public Object getNotifier()
- {
- return CDOResourceImpl.this;
- }
-
- @Override
- public int getFeatureID(Class<?> expectedClass)
- {
- return RESOURCE__RESOURCE_SET;
- }
- });
- }
-
- return notifications;
- }
-
- /**
- * @ADDED
- */
- public boolean isLoading()
- {
- return loading;
- }
-
- /**
- * @ADDED
- */
- public boolean isExisting()
- {
- return existing;
- }
-
- /**
- * @ADDED
- * @since 3.0
- */
- protected void setExisting(boolean existing)
- {
- this.existing = existing;
- }
-
- /**
- * @ADDED
- */
- @Override
- protected EList<?> createList(EStructuralFeature eStructuralFeature)
- {
- if (eStructuralFeature == CDO_RESOURCE_CONTENTS)
- {
- return new ContentsCDOList(CDO_RESOURCE_CONTENTS);
- // return new _ContentsCDOList<EObject>();
- }
-
- return super.createList(eStructuralFeature);
- }
-
- // /**
- // * A notifying list implementation for supporting {@link Resource#getContents}.
- // */
- // protected class _ContentsCDOList<E extends Object & EObject> extends ResourceContentsEList<E>
- // {
- // private static final long serialVersionUID = 1L;
- //
- // @Override
- // public int getFeatureID()
- // {
- // return CDO_RESOURCE_CONTENTS.getFeatureID();
- // }
- //
- // @Override
- // protected CDOResourceImpl getResource()
- // {
- // return CDOResourceImpl.this;
- // }
- //
- // @Override
- // protected Notification setLoaded(boolean loaded)
- // {
- // return getResource().setLoaded(loaded);
- // }
- //
- // @Override
- // protected boolean isNotificationRequired()
- // {
- // return getResource().eNotificationRequired();
- // }
- //
- // @Override
- // public NotificationChain inverseAdd(E object, NotificationChain notifications)
- // {
- // if (FSMUtil.isTransient(getResource()))
- // {
- // InternalEObject eObject = (InternalEObject)object;
- // return eObject.eSetResource(CDOResourceImpl.this, notifications);
- // // return super.inverseAdd(object, notifications);
- // }
- //
- // InternalCDOTransaction transaction = cdoView().toTransaction();
- // InternalCDOObject cdoObject = FSMUtil.adapt(object, transaction);
- // notifications = cdoObject.eSetResource(getResource(), notifications);
- //
- // // Attach here instead of in CDOObjectImpl.eSetResource because EMF does it also here
- // if (FSMUtil.isTransient(cdoObject))
- // {
- // attached(cdoObject, transaction);
- // }
- //
- // return notifications;
- // }
- //
- // @Override
- // public NotificationChain inverseRemove(E object, NotificationChain notifications)
- // {
- // if (FSMUtil.isTransient(getResource()))
- // {
- // InternalEObject eObject = (InternalEObject)object;
- // return eObject.eSetResource(null, notifications);
- // // return super.inverseRemove(object, notifications);
- // }
- //
- // InternalEObject eObject = (InternalEObject)object;
- // detached(eObject);
- // return eObject.eSetResource(null, notifications);
- // }
- // }
-
- /**
- * An implementation of a CDO specific '<em><b>contents</b></em>' list.
- *
- * @ADDED
- * @author Eike Stepper
- * @since 2.0
- */
- protected class ContentsCDOList extends BasicEStoreEList<Object>
- {
- private static final long serialVersionUID = 1L;
-
- public ContentsCDOList(EStructuralFeature eStructuralFeature)
- {
- super(CDOResourceImpl.this, eStructuralFeature);
- }
-
- /**
- * Optimization taken from ResourceImpl.EContentList.contains.
- *
- * @since 2.0
- */
- @Override
- public boolean contains(Object object)
- {
- if (size() <= 4)
- {
- return super.contains(object);
- }
-
- return object instanceof InternalEObject && ((InternalEObject)object).eDirectResource() == CDOResourceImpl.this;
- }
-
- /**
- * @since 2.0
- */
- @Override
- public NotificationChain inverseAdd(Object object, NotificationChain notifications)
- {
- if (FSMUtil.isTransient(CDOResourceImpl.this))
- {
- InternalEObject eObject = (InternalEObject)object;
- notifications = eObject.eSetResource(CDOResourceImpl.this, notifications);
- }
- else
- {
- InternalCDOTransaction transaction = cdoView().toTransaction();
- InternalCDOObject cdoObject = FSMUtil.adapt(object, transaction);
- notifications = cdoObject.eSetResource(CDOResourceImpl.this, notifications);
-
- // Attach here instead of in CDOObjectImpl.eSetResource because EMF does it also here
- if (FSMUtil.isTransient(cdoObject))
- {
- attached(cdoObject, transaction);
- }
- }
-
- return notifications;
- }
-
- /**
- * @since 2.0
- */
- @Override
- public NotificationChain inverseRemove(Object object, NotificationChain notifications)
- {
- if (FSMUtil.isTransient(CDOResourceImpl.this))
- {
- InternalEObject eObject = (InternalEObject)object;
- notifications = eObject.eSetResource(null, notifications);
- }
- else
- {
- InternalEObject eObject = (InternalEObject)object;
- detached(eObject);
- notifications = eObject.eSetResource(null, notifications);
- }
-
- return notifications;
- }
-
- /**
- * @since 2.0
- */
- protected void loaded()
- {
- Notification notification = setLoaded(true);
- if (notification != null)
- {
- eNotify(notification);
- }
- }
-
- /**
- * @since 2.0
- */
- protected void modified()
- {
- if (isTrackingModification())
- {
- setModified(true);
- }
- }
-
- /**
- * @since 2.0
- */
- @Override
- protected boolean useEquals()
- {
- return false;
- }
-
- /**
- * @since 2.0
- */
- @Override
- protected boolean hasInverse()
- {
- return true;
- }
-
- /**
- * @since 2.0
- */
- @Override
- protected boolean isUnique()
- {
- return true;
- }
-
- /**
- * @since 4.0
- */
- @Override
- protected void didAdd(int index, Object newObject)
- {
- super.didAdd(index, newObject);
-
- if (!isExisting() && !isLoaded())
- {
- loaded();
- }
- }
-
- /**
- * @since 4.0
- */
- @Override
- protected void didClear(int size, Object[] oldObjects)
- {
- super.didClear(size, oldObjects);
-
- if (!isExisting() && !isLoaded())
- {
- loaded();
- }
- }
- }
-} // CDOResourceImpl
+/*
+ * Copyright (c) 2004 - 2012 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
+ * Simon McDuff - maintenance
+ */
+package org.eclipse.emf.cdo.eresource.impl;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.CDOState;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.EresourcePackage;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOModificationTrackingAdapter;
+import org.eclipse.emf.cdo.util.CDOURIUtil;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CommitException;
+import org.eclipse.emf.cdo.util.ReadOnlyException;
+import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.cdo.view.CDOViewProvider;
+import org.eclipse.emf.cdo.view.CDOViewProviderRegistry;
+
+import org.eclipse.emf.internal.cdo.bundle.OM;
+import org.eclipse.emf.internal.cdo.view.CDOStateMachine;
+
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.collection.Pair;
+import org.eclipse.net4j.util.transaction.TransactionException;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.NotificationChain;
+import org.eclipse.emf.common.notify.impl.NotificationChainImpl;
+import org.eclipse.emf.common.notify.impl.NotificationImpl;
+import org.eclipse.emf.common.notify.impl.NotifyingListImpl;
+import org.eclipse.emf.common.util.AbstractTreeIterator;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.URIConverter;
+import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
+import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
+import org.eclipse.emf.ecore.util.InternalEList;
+import org.eclipse.emf.ecore.xmi.XMIResource;
+import org.eclipse.emf.ecore.xmi.XMLHelper;
+import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+import org.eclipse.emf.spi.cdo.FSMUtil;
+import org.eclipse.emf.spi.cdo.InternalCDOObject;
+import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
+import org.eclipse.emf.spi.cdo.InternalCDOView;
+import org.eclipse.emf.spi.cdo.InternalCDOViewSet;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+/**
+ * <!-- begin-user-doc --> An implementation of the model object '<em><b>CDO Resource</b></em>'.
+ *
+ * @extends Resource.Internal
+ * @noextend This interface is not intended to be extended by clients. <!-- end-user-doc -->
+ * <p>
+ * The following features are implemented:
+ * <ul>
+ * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#getResourceSet <em>Resource Set</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#getURI <em>URI</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#getContents <em>Contents</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#isModified <em>Modified</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#isLoaded <em>Loaded</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#isTrackingModification <em>Tracking
+ * Modification</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#getErrors <em>Errors</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#getWarnings <em>Warnings</em>}</li>
+ * <li>{@link org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl#getTimeStamp <em>Time Stamp</em>}</li>
+ * </ul>
+ * </p>
+ * @generated
+ */
+public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, Resource.Internal
+{
+ private static final EReference CDO_RESOURCE_CONTENTS = EresourcePackage.eINSTANCE.getCDOResource_Contents();
+
+ /**
+ * The default URI converter when there is no resource set.
+ *
+ * @ADDED
+ */
+ private static URIConverter defaultURIConverter;
+
+ /**
+ * @ADDED
+ */
+ private boolean root;
+
+ /**
+ * @ADDED
+ */
+ private URI initialURI;
+
+ /**
+ * TODO Set to true in commit()?
+ *
+ * @ADDED
+ */
+ private boolean existing;
+
+ /**
+ * @ADDED
+ */
+ private boolean loading;
+
+ /**
+ * @ADDED
+ */
+ private boolean loaded;
+
+ /**
+ * @ADDED
+ */
+ private boolean modified;
+
+ /**
+ * @ADDED
+ */
+ private EList<Diagnostic> errors;
+
+ /**
+ * @ADDED
+ */
+ private EList<Diagnostic> warnings;
+
+ /**
+ * @ADDED
+ */
+ private transient CDOViewProvider viewProvider;
+
+ /**
+ * @ADDED
+ * @since 2.0
+ */
+ public CDOResourceImpl(URI initialURI)
+ {
+ this.initialURI = initialURI;
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated
+ */
+ protected CDOResourceImpl()
+ {
+ super();
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated
+ */
+ @Override
+ protected EClass eStaticClass()
+ {
+ return EresourcePackage.Literals.CDO_RESOURCE;
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated NOT
+ * @since 2.0
+ */
+ @Override
+ public Resource.Internal eDirectResource()
+ {
+ if (isRoot())
+ {
+ return this;
+ }
+
+ return super.eDirectResource();
+ }
+
+ @Override
+ public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass)
+ {
+ if (baseClass == CDOResource.class)
+ {
+ return baseFeatureID;
+ }
+
+ if (baseClass == Resource.class)
+ {
+ return baseFeatureID + EresourcePackage.CDO_RESOURCE_NODE_FEATURE_COUNT;
+ }
+
+ return super.eBaseStructuralFeatureID(baseFeatureID, baseClass);
+ }
+
+ @Override
+ public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass)
+ {
+ if (baseClass == CDOResource.class)
+ {
+ return derivedFeatureID;
+ }
+
+ if (baseClass == Resource.class)
+ {
+ return derivedFeatureID - EresourcePackage.CDO_RESOURCE_NODE_FEATURE_COUNT;
+ }
+
+ return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public boolean isRoot()
+ {
+ return root;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void setRoot(boolean root)
+ {
+ this.root = root;
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated
+ */
+ public ResourceSet getResourceSet()
+ {
+ return (ResourceSet)eGet(EresourcePackage.Literals.CDO_RESOURCE__RESOURCE_SET, true);
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated
+ */
+ public void setResourceSet(ResourceSet newResourceSet)
+ {
+ eSet(EresourcePackage.Literals.CDO_RESOURCE__RESOURCE_SET, newResourceSet);
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ *
+ * @since 2.0 <!-- end-user-doc -->
+ * @generated
+ */
+ public URI getURIGen()
+ {
+ return (URI)eGet(EresourcePackage.Literals.CDO_RESOURCE__URI, true);
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated NOT
+ */
+ @Override
+ public URI getURI()
+ {
+ if (cdoID() == null && initialURI != null)
+ {
+ return initialURI;
+ }
+
+ if (viewProvider != null)
+ {
+ URI uri = viewProvider.getResourceURI(cdoView(), getPath());
+ if (uri != null)
+ {
+ return uri;
+ }
+ }
+
+ return super.getURI();
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ *
+ * @since 2.0 <!-- end-user-doc -->
+ * @generated
+ */
+ public void setURIGen(URI newURI)
+ {
+ eSet(EresourcePackage.Literals.CDO_RESOURCE__URI, newURI);
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated NOT
+ */
+ public void setURI(URI newURI)
+ {
+ String newPath = CDOURIUtil.extractResourcePath(newURI);
+ setPath(newPath);
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated NOT
+ */
+ @SuppressWarnings("unchecked")
+ public EList<EObject> getContents()
+ {
+ return (EList<EObject>)eGet(EresourcePackage.Literals.CDO_RESOURCE__CONTENTS, true);
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public void cdoInternalPostDetach(boolean remote)
+ {
+ super.cdoInternalPostDetach(remote);
+ if (remote)
+ {
+ existing = false;
+ }
+
+ removeFromResourceSet();
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated NOT
+ */
+ public boolean isModified()
+ {
+ return modified;
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated NOT
+ */
+ public void setModified(boolean newModified)
+ {
+ boolean oldModified = modified;
+ modified = newModified;
+ if (oldModified != newModified && eNotificationRequired())
+ {
+ Notification notification = new NotificationImpl(Notification.SET, oldModified, newModified)
+ {
+ @Override
+ public Object getNotifier()
+ {
+ return CDOResourceImpl.this;
+ }
+
+ @Override
+ public int getFeatureID(Class<?> expectedClass)
+ {
+ return RESOURCE__IS_MODIFIED;
+ }
+ };
+
+ eNotify(notification);
+ }
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated NOT
+ */
+ public boolean isLoaded()
+ {
+ return loaded;
+ }
+
+ /**
+ * @see ResourceImpl#setLoaded(boolean)
+ * @ADDED
+ */
+ private Notification setLoaded(boolean isLoaded)
+ {
+ boolean oldIsLoaded = loaded;
+ loaded = isLoaded;
+
+ if (eNotificationRequired())
+ {
+ Notification notification = new NotificationImpl(Notification.SET, oldIsLoaded, isLoaded)
+ {
+ @Override
+ public Object getNotifier()
+ {
+ return CDOResourceImpl.this;
+ }
+
+ @Override
+ public int getFeatureID(Class<?> expectedClass)
+ {
+ // TODO FIX bug 265136
+ return Resource.RESOURCE__IS_LOADED;
+ }
+ };
+
+ return notification;
+ }
+
+ return null;
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated
+ */
+ public boolean isTrackingModification()
+ {
+ return (Boolean)eGet(EresourcePackage.Literals.CDO_RESOURCE__TRACKING_MODIFICATION, true);
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ *
+ * @since 4.0 <!-- end-user-doc -->
+ * @generated
+ */
+ public void setTrackingModificationGen(boolean newTrackingModification)
+ {
+ eSet(EresourcePackage.Literals.CDO_RESOURCE__TRACKING_MODIFICATION, newTrackingModification);
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated NOT
+ */
+ public void setTrackingModification(boolean newTrackingModification)
+ {
+ if (cdoView().isReadOnly())
+ {
+ throw new ReadOnlyException("Underlying view is read-only");
+ }
+
+ if (newTrackingModification == isTrackingModification())
+ {
+ return;
+ }
+
+ EList<Adapter> adapters = eAdapters();
+ if (newTrackingModification)
+ {
+ adapters.add(new CDOModificationTrackingAdapter(this));
+ }
+ else
+ {
+ for (Adapter adapter : adapters)
+ {
+ if (adapter instanceof CDOModificationTrackingAdapter)
+ {
+ adapters.remove(adapter);
+ break;
+ }
+ }
+ }
+
+ setTrackingModificationGen(newTrackingModification);
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated NOT
+ */
+ public EList<Diagnostic> getErrors()
+ {
+ if (errors == null)
+ {
+ errors = new NotifyingListImpl<Diagnostic>()
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected boolean isNotificationRequired()
+ {
+ return CDOResourceImpl.this.eNotificationRequired();
+ }
+
+ @Override
+ public Object getNotifier()
+ {
+ return CDOResourceImpl.this;
+ }
+
+ @Override
+ public int getFeatureID()
+ {
+ return EresourcePackage.CDO_RESOURCE__ERRORS;
+ }
+ };
+ }
+
+ return errors;
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated NOT
+ */
+ public EList<Diagnostic> getWarnings()
+ {
+ if (warnings == null)
+ {
+ warnings = new NotifyingListImpl<Diagnostic>()
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected boolean isNotificationRequired()
+ {
+ return CDOResourceImpl.this.eNotificationRequired();
+ }
+
+ @Override
+ public Object getNotifier()
+ {
+ return CDOResourceImpl.this;
+ }
+
+ @Override
+ public int getFeatureID()
+ {
+ return EresourcePackage.CDO_RESOURCE__WARNINGS;
+ }
+ };
+ }
+
+ return warnings;
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated
+ */
+ public long getTimeStamp()
+ {
+ return (Long)eGet(EresourcePackage.Literals.CDO_RESOURCE__TIME_STAMP, true);
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated
+ */
+ public void setTimeStamp(long newTimeStamp)
+ {
+ eSet(EresourcePackage.Literals.CDO_RESOURCE__TIME_STAMP, newTimeStamp);
+ }
+
+ /**
+ * @ADDED
+ * @see ResourceImpl#getAllContents()
+ */
+ public TreeIterator<EObject> getAllContents()
+ {
+ return new AbstractTreeIterator<EObject>(this, false)
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Iterator<EObject> getChildren(Object object)
+ {
+ return object == CDOResourceImpl.this ? CDOResourceImpl.this.getContents().iterator() : ((EObject)object)
+ .eContents().iterator();
+ }
+ };
+ }
+
+ /**
+ * <b>Note:</b> URI from temporary objects are going to changed when we commit the CDOTransaction. Objects will not be
+ * accessible from their temporary URI once CDOTransaction is committed.
+ * <p>
+ * <b>Note:</b> This resource is not actually used to lookup the resulting object in CDO. Only the CDOView is used for
+ * this lookup! This means that this resource can be used to resolve <em>any</em> fragment with a CDOID of the
+ * associated CDOView.
+ *
+ * @ADDED
+ */
+ public EObject getEObject(String uriFragment)
+ {
+ if (uriFragment == null)
+ {
+ return null;
+ }
+
+ try
+ {
+ EObject eObjectByFragment = getEObjectByFragment(uriFragment);
+
+ if (eObjectByFragment != null)
+ {
+ return eObjectByFragment;
+ }
+
+ CDOID id = CDOIDUtil.read(uriFragment);
+ InternalCDOView view = cdoView();
+ if (CDOIDUtil.isNull(id) || view.isObjectNew(id) && !view.isObjectRegistered(id))
+ {
+ return null;
+ }
+
+ if (id.isObject())
+ {
+ CDOObject object = view.getObject(id, true);
+ return CDOUtil.getEObject(object);
+ }
+ }
+ catch (Exception ex)
+ {
+ // Do nothing
+ // Return null if the object cannot be resolved.
+ }
+
+ // If it doesn't match to anything we return null like ResourceImpl.getEObject
+ return null;
+ }
+
+ private EObject getEObjectByFragment(String uriFragment)
+ {
+ int length = uriFragment.length();
+ if (length > 0)
+ {
+ if (uriFragment.charAt(0) == '/')
+ {
+ ArrayList<String> uriFragmentPath = new ArrayList<String>(4);
+ int start = 1;
+ for (int i = 1; i < length; ++i)
+ {
+ if (uriFragment.charAt(i) == '/')
+ {
+ uriFragmentPath.add(start == i ? "" : uriFragment.substring(start, i));
+ start = i + 1;
+ }
+ }
+
+ uriFragmentPath.add(uriFragment.substring(start));
+ return getEObject(uriFragmentPath);
+ }
+ else if (uriFragment.charAt(length - 1) == '?')
+ {
+ int index = uriFragment.lastIndexOf('?', length - 2);
+ if (index > 0)
+ {
+ uriFragment = uriFragment.substring(0, index);
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private EObject getEObject(List<String> uriFragmentPath)
+ {
+ int size = uriFragmentPath.size();
+ EObject eObject = getEObjectForURIFragmentRootSegment(size == 0 ? "" : uriFragmentPath.get(0));
+ for (int i = 1; i < size && eObject != null; ++i)
+ {
+ eObject = ((InternalEObject)eObject).eObjectForURIFragmentSegment(uriFragmentPath.get(i));
+ }
+
+ return eObject;
+ }
+
+ private EObject getEObjectForURIFragmentRootSegment(String uriFragmentRootSegment)
+ {
+ int position = 0;
+ if (uriFragmentRootSegment.length() > 0)
+ {
+ try
+ {
+ position = Integer.parseInt(uriFragmentRootSegment);
+ }
+ catch (NumberFormatException exception)
+ {
+ throw new RuntimeException(exception);
+ }
+ }
+
+ List<EObject> contents = getContents();
+ if (position < contents.size() && position >= 0)
+ {
+ return contents.get(position);
+ }
+
+ return null;
+ }
+
+ /**
+ * @ADDED
+ */
+ public String getURIFragment(EObject object)
+ {
+ // TODO if object == this ??? what we do. Is it wanted ? How we handle them ?
+ InternalCDOObject internalCDOObject = FSMUtil.adapt(object, cdoView());
+ StringBuilder builder = new StringBuilder();
+ CDOIDUtil.write(builder, internalCDOObject.cdoID());
+ return builder.toString();
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public void cdoInternalPreLoad()
+ {
+ try
+ {
+ load(null);
+ }
+ catch (IOException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ /**
+ * @ADDED
+ */
+ public void load(InputStream inputStream, Map<?, ?> options) throws IOException
+ {
+ // final String baseURI = getBaseURIOption(options);
+ // final Map<Resource, CDOResource> resourceMappings = new HashMap<Resource, CDOResource>();
+ //
+ // class ImportResource extends XMIResourceImpl
+ // {
+ // private CDOResource delegate;
+ //
+ // public ImportResource(CDOResource delegate)
+ // {
+ // super(URI.createURI(baseURI + delegate.getPath()));
+ // this.delegate = delegate;
+ // }
+ //
+ // @Override
+ // public EList<EObject> getContents()
+ // {
+ // return delegate.getContents();
+ // }
+ //
+ // @Override
+ // public String getURIFragment(EObject eObject)
+ // {
+ // String id = EcoreUtil.getID(eObject);
+ // if (id != null)
+ // {
+ // return id;
+ // }
+ //
+ // InternalEObject internalEObject = (InternalEObject)eObject;
+ // if (getMappedResource(internalEObject.eDirectResource()) == this)
+ // {
+ // return "/" + getURIFragmentRootSegment(eObject);
+ // }
+ //
+ // List<String> uriFragmentPath = new ArrayList<String>();
+ // boolean isContained = false;
+ // for (InternalEObject container = internalEObject.eInternalContainer(); container != null; container =
+ // internalEObject
+ // .eInternalContainer())
+ // {
+ // uriFragmentPath.add(container.eURIFragmentSegment(internalEObject.eContainingFeature(), internalEObject));
+ // internalEObject = container;
+ // if (getMappedResource(container.eDirectResource()) == this)
+ // {
+ // isContained = true;
+ // break;
+ // }
+ // }
+ //
+ // if (!isContained)
+ // {
+ // return "/-1";
+ // }
+ //
+ // StringBuilder result = new StringBuilder("/");
+ // result.append(getURIFragmentRootSegment(internalEObject));
+ //
+ // for (int i = uriFragmentPath.size() - 1; i >= 0; --i)
+ // {
+ // result.append('/');
+ // result.append(uriFragmentPath.get(i));
+ // }
+ //
+ // return result.toString();
+ // }
+ //
+ // @Override
+ // protected XMLHelper createXMLHelper()
+ // {
+ // return new XMIHelperImpl(this)
+ // {
+ // @Override
+ // public String getHREF(EObject obj)
+ // {
+ // InternalEObject o = (InternalEObject)obj;
+ //
+ // URI objectURI = o.eProxyURI();
+ // if (objectURI == null)
+ // {
+ // Resource otherResource = obj.eResource();
+ // otherResource = getMappedResource(otherResource);
+ // objectURI = getHREF(otherResource, obj);
+ // }
+ //
+ // objectURI = deresolve(objectURI);
+ // return objectURI.toString();
+ // }
+ //
+ // @Override
+ // protected URI getHREF(Resource otherResource, EObject obj)
+ // {
+ // String uriFragment = getURIFragment(otherResource, obj);
+ // if (otherResource == ImportResource.this)
+ // {
+ // return URI.createURI(uriFragment);
+ // }
+ //
+ // return otherResource.getURI().appendFragment(uriFragment);
+ // }
+ // };
+ // }
+ //
+ // private Resource getMappedResource(Resource otherResource)
+ // {
+ // Resource resource = resourceMappings.get(otherResource);
+ // if (resource != null)
+ // {
+ // return resource;
+ // }
+ //
+ // if (otherResource instanceof CDOResource)
+ // {
+ // CDOResource cdoResource = (CDOResource)otherResource;
+ // otherResource = new ImportResource(cdoResource);
+ // resourceMappings.put(cdoResource, otherResource);
+ // }
+ //
+ // return otherResource;
+ // }
+ // }
+ //
+ // XMIResource xmiResource = new ImportResource(this);
+ // resourceMappings.put(this, xmiResource);
+ // xmiResource.save(outputStream, options);
+
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @ADDED
+ */
+ public void load(Map<?, ?> options) throws IOException
+ {
+ if (!isLoaded())
+ {
+ InternalCDOView view = cdoView();
+ if (!FSMUtil.isTransient(this))
+ {
+ CDOID id = cdoID();
+ if (id == null)
+ {
+ registerProxy(view);
+ }
+ else
+ {
+ synchronized (view)
+ {
+ if (!view.isObjectRegistered(id))
+ {
+ registerProxy(view);
+ }
+ }
+ }
+ }
+
+ Notification notification = setLoaded(true);
+ if (notification != null)
+ {
+ eNotify(notification);
+ }
+
+ // URIConverter uriConverter = getURIConverter();
+ //
+ // // If an input stream can't be created, ensure that the resource is still considered loaded after the failure,
+ // // and do all the same processing we'd do if we actually were able to create a valid input stream.
+ // //
+ // InputStream inputStream = null;
+ //
+ // try
+ // {
+ // inputStream = uriConverter.createInputStream(getURI(), options);
+ // }
+ // catch (IOException exception)
+ // {
+ // Notification notification = setLoaded(true);
+ // loading = true;
+ // if (errors != null)
+ // {
+ // errors.clear();
+ // }
+ //
+ // if (warnings != null)
+ // {
+ // warnings.clear();
+ // }
+ //
+ // loading = false;
+ // if (notification != null)
+ // {
+ // eNotify(notification);
+ // }
+ //
+ // setModified(false);
+ // throw exception;
+ // }
+ //
+ // try
+ // {
+ // load(inputStream, options);
+ // }
+ // finally
+ // {
+ // inputStream.close();
+ // // TODO Handle timeStamp
+ // // Long timeStamp = (Long)response.get(URIConverter.RESPONSE_TIME_STAMP_PROPERTY);
+ // // if (timeStamp != null)
+ // // {
+ // // setTimeStamp(timeStamp);
+ // // }
+ // }
+ }
+ }
+
+ private void registerProxy(InternalCDOView view) throws IOWrappedException
+ {
+ try
+ {
+ view.registerProxyResource(this);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ setExisting(false);
+ cdoInternalSetState(CDOState.TRANSIENT);
+ throw new IOWrappedException(ex);
+ }
+ }
+
+ /**
+ * Returns the URI converter. This typically gets the {@link ResourceSet#getURIConverter converter} from the
+ * {@link #getResourceSet containing} resource set, but it calls {@link #getDefaultURIConverter} when there is no
+ * containing resource set.
+ *
+ * @return the URI converter.
+ * @ADDED
+ */
+ @SuppressWarnings("unused")
+ private URIConverter getURIConverter()
+ {
+ return getResourceSet() == null ? getDefaultURIConverter() : getResourceSet().getURIConverter();
+ }
+
+ /**
+ * Returns the default URI converter that's used when there is no resource set.
+ *
+ * @return the default URI converter.
+ * @see #getURIConverter
+ * @ADDED
+ */
+ private static synchronized URIConverter getDefaultURIConverter()
+ {
+ if (defaultURIConverter == null)
+ {
+ defaultURIConverter = new ExtensibleURIConverterImpl();
+ }
+
+ return defaultURIConverter;
+ }
+
+ /**
+ * @ADDED
+ */
+ public void save(Map<?, ?> options) throws IOException
+ {
+ CDOTransaction transaction = getTransaction(options);
+ IProgressMonitor progressMonitor = options != null ? (IProgressMonitor)options
+ .get(CDOResource.OPTION_SAVE_PROGRESS_MONITOR) : null;
+
+ try
+ {
+ transaction.commit(progressMonitor);
+ }
+ catch (CommitException ex)
+ {
+ throw new TransactionException(ex);
+ }
+
+ setModified(false);
+ }
+
+ /**
+ * @ADDED
+ */
+ private CDOTransaction getTransaction(Map<?, ?> options)
+ {
+ CDOTransaction transaction = options != null ? (CDOTransaction)options
+ .get(CDOResource.OPTION_SAVE_OVERRIDE_TRANSACTION) : null;
+
+ if (transaction == null)
+ {
+ CDOView view = cdoView();
+ if (view instanceof CDOTransaction)
+ {
+ transaction = (CDOTransaction)view;
+ }
+ else
+ {
+ throw new IllegalStateException("No transaction available");
+ }
+ }
+
+ return transaction;
+ }
+
+ /**
+ * @ADDED
+ */
+ public void save(OutputStream outputStream, Map<?, ?> options) throws IOException
+ {
+ final String baseURI = getBaseURIOption(options);
+ final Map<CDOResource, Resource> resourceMappings = new HashMap<CDOResource, Resource>();
+
+ class ExportResource extends XMIResourceImpl
+ {
+ private CDOResource delegate;
+
+ public ExportResource(CDOResource delegate)
+ {
+ super(URI.createURI(baseURI + delegate.getPath()));
+ this.delegate = delegate;
+ }
+
+ @Override
+ public EList<EObject> getContents()
+ {
+ return delegate.getContents();
+ }
+
+ // @Override
+ // public String getURIFragment(EObject eObject)
+ // {
+ // String id = EcoreUtil.getID(eObject);
+ // if (id != null)
+ // {
+ // return id;
+ // }
+ //
+ // InternalEObject internalEObject = (InternalEObject)eObject;
+ // if (getMappedResource(internalEObject.eDirectResource()) == this)
+ // {
+ // return "/" + getURIFragmentRootSegment(eObject);
+ // }
+ //
+ // List<String> uriFragmentPath = new ArrayList<String>();
+ // boolean isContained = false;
+ // for (InternalEObject container = internalEObject.eInternalContainer(); container != null; container =
+ // internalEObject
+ // .eInternalContainer())
+ // {
+ // uriFragmentPath.add(container.eURIFragmentSegment(internalEObject.eContainingFeature(), internalEObject));
+ // internalEObject = container;
+ // if (getMappedResource(container.eDirectResource()) == this)
+ // {
+ // isContained = true;
+ // break;
+ // }
+ // }
+ //
+ // if (!isContained)
+ // {
+ // return "/-1";
+ // }
+ //
+ // StringBuilder result = new StringBuilder("/");
+ // result.append(getURIFragmentRootSegment(internalEObject));
+ //
+ // for (int i = uriFragmentPath.size() - 1; i >= 0; --i)
+ // {
+ // result.append('/');
+ // result.append(uriFragmentPath.get(i));
+ // }
+ //
+ // return result.toString();
+ // }
+
+ @Override
+ protected boolean useUUIDs()
+ {
+ return true;
+ }
+
+ @Override
+ protected boolean useIDAttributes()
+ {
+ return false;
+ }
+
+ @Override
+ public String getID(EObject eObject)
+ {
+ CDOObject cdoObject = CDOUtil.getCDOObject(eObject);
+ StringBuilder builder = new StringBuilder();
+ CDOIDUtil.write(builder, cdoObject.cdoID());
+ return builder.toString();
+ }
+
+ @Override
+ protected XMLHelper createXMLHelper()
+ {
+ return new XMIHelperImpl(this)
+ {
+ @Override
+ public String getHREF(EObject obj)
+ {
+ InternalEObject o = (InternalEObject)obj;
+
+ URI objectURI = o.eProxyURI();
+ if (objectURI == null)
+ {
+ Resource otherResource = obj.eResource();
+ otherResource = getMappedResource(otherResource);
+ objectURI = getHREF(otherResource, obj);
+ }
+
+ objectURI = deresolve(objectURI);
+ return objectURI.toString();
+ }
+
+ @Override
+ protected URI getHREF(Resource otherResource, EObject obj)
+ {
+ String uriFragment = getURIFragment(otherResource, obj);
+ if (otherResource == ExportResource.this)
+ {
+ return URI.createURI(uriFragment);
+ }
+
+ return otherResource.getURI().appendFragment(uriFragment);
+ }
+ };
+ }
+
+ private Resource getMappedResource(Resource otherResource)
+ {
+ Resource resource = resourceMappings.get(otherResource);
+ if (resource != null)
+ {
+ return resource;
+ }
+
+ if (otherResource instanceof CDOResource)
+ {
+ CDOResource cdoResource = (CDOResource)otherResource;
+ otherResource = new ExportResource(cdoResource);
+ resourceMappings.put(cdoResource, otherResource);
+ }
+
+ return otherResource;
+ }
+ }
+
+ XMIResource xmiResource = new ExportResource(this);
+ resourceMappings.put(this, xmiResource);
+ xmiResource.save(outputStream, options);
+ }
+
+ private String getBaseURIOption(Map<?, ?> options)
+ {
+ if (options != null)
+ {
+ String uri = (String)options.get(OPTION_SAVE_BASE_URI);
+ if (uri != null)
+ {
+ return uri;
+ }
+ }
+
+ return "cdo://";
+ }
+
+ /**
+ * @ADDED
+ */
+ public void unload()
+ {
+ // Do nothing
+ }
+
+ /**
+ * @ADDED
+ */
+ public void delete(Map<?, ?> options) throws IOException
+ {
+ if (FSMUtil.isTransient(this))
+ {
+ removeFromResourceSet();
+ }
+ else
+ {
+ if (isRoot())
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ if (getFolder() == null)
+ {
+ InternalCDOView view = cdoView();
+ view.getRootResource().getContents().remove(this);
+ }
+ else
+ {
+ basicSetFolder(null, false);
+ }
+ }
+ }
+
+ private void removeFromResourceSet()
+ {
+ final ResourceSet resourceSet = getResourceSet();
+ if (resourceSet != null)
+ {
+ InternalCDOViewSet viewSet = (InternalCDOViewSet)CDOUtil.getViewSet(resourceSet);
+ viewSet.executeWithoutNotificationHandling(new Callable<Boolean>()
+ {
+ public Boolean call() throws Exception
+ {
+ resourceSet.getResources().remove(CDOResourceImpl.this);
+ return true;
+ }
+ });
+ }
+ }
+
+ /**
+ * @ADDED
+ */
+ public void attached(EObject object)
+ {
+ if (!FSMUtil.isTransient(this))
+ {
+ InternalCDOView view = cdoView();
+ if (view instanceof InternalCDOTransaction) // Bug 376075
+ {
+ InternalCDOTransaction transaction = (InternalCDOTransaction)view;
+ InternalCDOObject cdoObject = FSMUtil.adapt(object, transaction);
+
+ if (CDOUtil.isLegacyObject(cdoObject) && FSMUtil.isClean(cdoObject))
+ {
+ // Bug 352204
+ return;
+ }
+
+ attached(cdoObject, transaction);
+ }
+ }
+ }
+
+ /**
+ * @ADDED
+ */
+ private void attached(InternalCDOObject cdoObject, InternalCDOTransaction transaction)
+ {
+ CDOStateMachine.INSTANCE.attach(cdoObject, transaction);
+ }
+
+ /**
+ * @ADDED
+ */
+ public void detached(EObject object)
+ {
+ if (!FSMUtil.isTransient(this))
+ {
+ InternalCDOView view = cdoView();
+ if (view instanceof InternalCDOTransaction) // Bug 376075
+ {
+ InternalCDOObject cdoObject = FSMUtil.adapt(object, view);
+ CDOStateMachine.INSTANCE.detach(cdoObject);
+ }
+ }
+ }
+
+ /**
+ * @ADDED
+ * @see ResourceImpl#basicSetResourceSet(ResourceSet, NotificationChain)
+ */
+ public NotificationChain basicSetResourceSet(ResourceSet resourceSet, NotificationChain notifications)
+ {
+ final ResourceSet oldResourceSet = getResourceSet();
+ if (oldResourceSet != null)
+ {
+ final NotificationChain finalNotifications = notifications;
+
+ InternalCDOViewSet viewSet = (InternalCDOViewSet)CDOUtil.getViewSet(oldResourceSet);
+ notifications = viewSet.executeWithoutNotificationHandling(new Callable<NotificationChain>()
+ {
+ public NotificationChain call() throws Exception
+ {
+ return ((InternalEList<Resource>)oldResourceSet.getResources()).basicRemove(this, finalNotifications);
+ }
+ });
+ }
+
+ setResourceSet(resourceSet);
+
+ if (resourceSet != null)
+ {
+ InternalCDOView view = cdoView();
+ if (view == null)
+ {
+ URI uri = getURI();
+ Pair<CDOView, CDOViewProvider> pair = CDOViewProviderRegistry.INSTANCE.provideViewWithInfo(uri, resourceSet);
+ if (pair != null)
+ {
+ view = (InternalCDOView)pair.getElement1();
+ view.attachResource(this);
+
+ viewProvider = pair.getElement2();
+ }
+ }
+
+ String query = getURI().query();
+ if (query != null && query.length() != 0)
+ {
+ Map<String, String> parameters = CDOURIUtil.getParameters(query);
+ String value = parameters.get(CDOResource.PREFETCH_PARAMETER);
+ if (value != null)
+ {
+ boolean prefetch = Boolean.parseBoolean(value);
+ if (prefetch)
+ {
+ cdoPrefetch(CDORevision.DEPTH_INFINITE);
+ }
+ }
+ }
+ }
+
+ if (eNotificationRequired())
+ {
+ if (notifications == null)
+ {
+ notifications = new NotificationChainImpl(2);
+ }
+
+ notifications.add(new NotificationImpl(Notification.SET, oldResourceSet, resourceSet)
+ {
+ @Override
+ public Object getNotifier()
+ {
+ return CDOResourceImpl.this;
+ }
+
+ @Override
+ public int getFeatureID(Class<?> expectedClass)
+ {
+ return RESOURCE__RESOURCE_SET;
+ }
+ });
+ }
+
+ return notifications;
+ }
+
+ /**
+ * @ADDED
+ */
+ public boolean isLoading()
+ {
+ return loading;
+ }
+
+ /**
+ * @ADDED
+ */
+ public boolean isExisting()
+ {
+ return existing;
+ }
+
+ /**
+ * @ADDED
+ * @since 3.0
+ */
+ protected void setExisting(boolean existing)
+ {
+ this.existing = existing;
+ }
+
+ /**
+ * @ADDED
+ */
+ @Override
+ protected EList<?> createList(EStructuralFeature eStructuralFeature)
+ {
+ if (eStructuralFeature == CDO_RESOURCE_CONTENTS)
+ {
+ return new ContentsCDOList(CDO_RESOURCE_CONTENTS);
+ // return new _ContentsCDOList<EObject>();
+ }
+
+ return super.createList(eStructuralFeature);
+ }
+
+ // /**
+ // * A notifying list implementation for supporting {@link Resource#getContents}.
+ // */
+ // protected class _ContentsCDOList<E extends Object & EObject> extends ResourceContentsEList<E>
+ // {
+ // private static final long serialVersionUID = 1L;
+ //
+ // @Override
+ // public int getFeatureID()
+ // {
+ // return CDO_RESOURCE_CONTENTS.getFeatureID();
+ // }
+ //
+ // @Override
+ // protected CDOResourceImpl getResource()
+ // {
+ // return CDOResourceImpl.this;
+ // }
+ //
+ // @Override
+ // protected Notification setLoaded(boolean loaded)
+ // {
+ // return getResource().setLoaded(loaded);
+ // }
+ //
+ // @Override
+ // protected boolean isNotificationRequired()
+ // {
+ // return getResource().eNotificationRequired();
+ // }
+ //
+ // @Override
+ // public NotificationChain inverseAdd(E object, NotificationChain notifications)
+ // {
+ // if (FSMUtil.isTransient(getResource()))
+ // {
+ // InternalEObject eObject = (InternalEObject)object;
+ // return eObject.eSetResource(CDOResourceImpl.this, notifications);
+ // // return super.inverseAdd(object, notifications);
+ // }
+ //
+ // InternalCDOTransaction transaction = cdoView().toTransaction();
+ // InternalCDOObject cdoObject = FSMUtil.adapt(object, transaction);
+ // notifications = cdoObject.eSetResource(getResource(), notifications);
+ //
+ // // Attach here instead of in CDOObjectImpl.eSetResource because EMF does it also here
+ // if (FSMUtil.isTransient(cdoObject))
+ // {
+ // attached(cdoObject, transaction);
+ // }
+ //
+ // return notifications;
+ // }
+ //
+ // @Override
+ // public NotificationChain inverseRemove(E object, NotificationChain notifications)
+ // {
+ // if (FSMUtil.isTransient(getResource()))
+ // {
+ // InternalEObject eObject = (InternalEObject)object;
+ // return eObject.eSetResource(null, notifications);
+ // // return super.inverseRemove(object, notifications);
+ // }
+ //
+ // InternalEObject eObject = (InternalEObject)object;
+ // detached(eObject);
+ // return eObject.eSetResource(null, notifications);
+ // }
+ // }
+
+ /**
+ * An implementation of a CDO specific '<em><b>contents</b></em>' list.
+ *
+ * @ADDED
+ * @author Eike Stepper
+ * @since 2.0
+ */
+ protected class ContentsCDOList extends BasicEStoreEList<Object>
+ {
+ private static final long serialVersionUID = 1L;
+
+ public ContentsCDOList(EStructuralFeature eStructuralFeature)
+ {
+ super(CDOResourceImpl.this, eStructuralFeature);
+ }
+
+ /**
+ * Optimization taken from ResourceImpl.EContentList.contains.
+ *
+ * @since 2.0
+ */
+ @Override
+ public boolean contains(Object object)
+ {
+ if (size() <= 4)
+ {
+ return super.contains(object);
+ }
+
+ return object instanceof InternalEObject && ((InternalEObject)object).eDirectResource() == CDOResourceImpl.this;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public NotificationChain inverseAdd(Object object, NotificationChain notifications)
+ {
+ if (FSMUtil.isTransient(CDOResourceImpl.this))
+ {
+ InternalEObject eObject = (InternalEObject)object;
+ notifications = eObject.eSetResource(CDOResourceImpl.this, notifications);
+ }
+ else
+ {
+ InternalCDOTransaction transaction = cdoView().toTransaction();
+ InternalCDOObject cdoObject = FSMUtil.adapt(object, transaction);
+ notifications = cdoObject.eSetResource(CDOResourceImpl.this, notifications);
+
+ // Attach here instead of in CDOObjectImpl.eSetResource because EMF does it also here
+ if (FSMUtil.isTransient(cdoObject))
+ {
+ attached(cdoObject, transaction);
+ }
+ }
+
+ return notifications;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public NotificationChain inverseRemove(Object object, NotificationChain notifications)
+ {
+ if (FSMUtil.isTransient(CDOResourceImpl.this))
+ {
+ InternalEObject eObject = (InternalEObject)object;
+ notifications = eObject.eSetResource(null, notifications);
+ }
+ else
+ {
+ InternalEObject eObject = (InternalEObject)object;
+ detached(eObject);
+ notifications = eObject.eSetResource(null, notifications);
+ }
+
+ return notifications;
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected void loaded()
+ {
+ Notification notification = setLoaded(true);
+ if (notification != null)
+ {
+ eNotify(notification);
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected void modified()
+ {
+ if (isTrackingModification())
+ {
+ setModified(true);
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ protected boolean useEquals()
+ {
+ return false;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ protected boolean hasInverse()
+ {
+ return true;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ protected boolean isUnique()
+ {
+ return true;
+ }
+
+ /**
+ * @since 4.0
+ */
+ @Override
+ protected void didAdd(int index, Object newObject)
+ {
+ super.didAdd(index, newObject);
+
+ if (!isExisting() && !isLoaded())
+ {
+ loaded();
+ }
+ }
+
+ /**
+ * @since 4.0
+ */
+ @Override
+ protected void didClear(int size, Object[] oldObjects)
+ {
+ super.didClear(size, oldObjects);
+
+ if (!isExisting() && !isLoaded())
+ {
+ loaded();
+ }
+ }
+ }
+} // CDOResourceImpl
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIData.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIData.java
index 72ca20e9ab..0d3724de9f 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIData.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIData.java
@@ -10,8 +10,12 @@
*/
package org.eclipse.emf.cdo.util;
+import org.eclipse.emf.cdo.common.CDOCommonRepository;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+
+import org.eclipse.net4j.util.security.IUserManager;
import org.eclipse.emf.common.util.URI;
@@ -19,9 +23,45 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import java.util.Map;
+import java.util.Map.Entry;
/**
- * Represents the CDO-specific URI data needed to access a resource in a repository.
+ * Represents a CDO-specific {@link URI} in connection-aware format.
+ * <p>
+ * CDO URIs are in one of two different formats, either canonical or connection-aware. The connection-aware format is:
+ *
+ * <blockquote><b>cdo.net4j.</b> <i>ConnectorType</i> <b>://</b> [<i>User</i> [<b>:</b> <i>Password</i>] <b>@</b>]
+ * <i>ConnectorSpecificAuthority</i> <b>/</b> <i>RepositoryName</i> <b>/</b> <i>ResourcePath</i> [<b>?</b> <i>Param</i><b>=</b><i>Value</i>
+ * (<b>&</b> <i>Param</i><b>=</b><i>Value</i>)*]</blockquote>
+ *
+ * The non-terminals being:
+ * <p>
+ * <ul>
+ * <li><i>ConnectorType</i>: one of <b>tcp</b> | <b>ssl</b> | <b>jvm</b> | <b>http</b>
+ * <li><i>User/Password</i>: to be provided if the repository is configured with an
+ * {@link IUserManager} and, hence, triggers authentication on the client. Note: the
+ * password may be stored in resources in clear text!
+ * <li><i>ConnectorSpecificAuthority</i>: examples are
+ * <ul>
+ * <li><i>Host</i> [<b>:</b> <i>Port</i>] (if <i>ConnectorType</i> is <b>tcp</b>)
+ * <li><i>AcceptorName</i> (if <i>ConnectorType</i> is <b>jvm</b>)
+ * </ul>
+ * <li><i>RepositoryName</i>: the {@link CDOCommonRepository#getName() name} of the repository (not the {@link CDOCommonRepository#getUUID() UUID}!).
+ * <li><i>ResourcePath</i>: the full path of the {@link CDOResource resource} within the repository, segments separated by slashes, no leading slash.
+ * <li><i>Param</i>: one of the following
+ * <ul>
+ * <li><b>branch</b>: the value must be a {@link CDOBranch#getPathName() branch path}, the full path of the branch in the branch tree, segments separated by slashes, no leading slash, defaults to <b>MAIN</b>.
+ * <li><b>time</b>: the value must be the time at which the resource is supposed to be valid, parseable by SimpleDateFormat. The special value <b>HEAD</b> indicates a floating view/transaction that always shows the latest state in the chosen branch, the default if no <i>Time</i> parameter is specified.
+ * <li><b>transactional</b>: a boolean value. The value <b>true</b> forces a the resource to be opened in a transaction rather than in a read-only view. This can not be combined with a <i>Time</i> other than <b>HEAD</b>.
+ * <li><b>prefetch</b>: a boolean value. The value <b>true</b> attempts to load all objects contained by the resource in a single server-round trip and cache the results.
+ * </ul>
+ * </ul>
+ * <p>
+ * Note: With the current design and implementation of connection-aware URI
+ * (mainly CDONet4jViewProvider) it is still unclear when and how the allocated
+ * "resources" (aka IConnector, CDOSession, CDOView, etc) are supposed to be freed!
+ * <p>
+ * For a description of the canonical URI format refer to {@link CDOURIUtil}.
*
* @author Eike Stepper
* @since 4.0
@@ -59,6 +99,8 @@ public final class CDOURIData
private boolean transactional;
+ private Map<String, String> extraParameters;
+
public CDOURIData()
{
}
@@ -95,16 +137,16 @@ public final class CDOURIData
resourcePath = path.removeFirstSegments(1);
String query = uri.query();
- if (query != null)
+ if (query != null && query.length() != 0)
{
Map<String, String> parameters = CDOURIUtil.getParameters(query);
- String branch = parameters.get(BRANCH_PARAMETER);
+ String branch = parameters.remove(BRANCH_PARAMETER);
if (branch != null)
{
branchPath = new Path(branch).makeRelative();
}
- String time = parameters.get(TIME_PARAMETER);
+ String time = parameters.remove(TIME_PARAMETER);
if (time != null)
{
if (!"HEAD".equalsIgnoreCase(time))
@@ -113,13 +155,18 @@ public final class CDOURIData
}
}
- viewID = parameters.get(VIEW_ID_PARAMETER);
+ viewID = parameters.remove(VIEW_ID_PARAMETER);
- String transactional = parameters.get(TRANSACTIONAL_PARAMETER);
+ String transactional = parameters.remove(TRANSACTIONAL_PARAMETER);
if (transactional != null)
{
this.transactional = Boolean.parseBoolean(transactional);
}
+
+ if (!parameters.isEmpty())
+ {
+ extraParameters = parameters;
+ }
}
if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE && transactional)
@@ -269,6 +316,14 @@ public final class CDOURIData
this.transactional = transactional;
}
+ /**
+ * @since 4.1
+ */
+ public Map<String, String> getExtraParameters()
+ {
+ return extraParameters;
+ }
+
public URI toURI()
{
return URI.createURI(toString());
@@ -335,6 +390,17 @@ public final class CDOURIData
builder.append(transactional);
}
+ if (extraParameters != null)
+ {
+ for (Entry<String, String> entry : extraParameters.entrySet())
+ {
+ builder.append(params++ == 0 ? "?" : "&");
+ builder.append(entry.getKey());
+ builder.append("=");
+ builder.append(entry.getValue());
+ }
+ }
+
return builder.toString();
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIUtil.java
index e526a8e18f..328c45a05a 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOURIUtil.java
@@ -1,231 +1,261 @@
-/*
- * Copyright (c) 2004 - 2012 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:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.util;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants;
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.net4j.util.StringUtil;
-
-import org.eclipse.emf.common.util.URI;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-/**
- * Various static methods that may help with CDO-specific {@link URI URIs}.
- *
- * @author Simon McDuff
- * @since 2.0
- */
-public final class CDOURIUtil
-{
- /**
- * @since 4.0
- */
- public static final String PROTOCOL_NAME = CDOProtocolConstants.PROTOCOL_NAME;
-
- public static final char SEGMENT_SEPARATOR_CHAR = '/';
-
- public static final String SEGMENT_SEPARATOR = new String(new char[] { SEGMENT_SEPARATOR_CHAR });
-
- static
- {
- CDOUtil.registerResourceFactory(null); // Ensure that the normal resource factory is registered
- }
-
- private CDOURIUtil()
- {
- }
-
- public static void validateURI(URI uri) throws InvalidURIException
- {
- // if (!CDOProtocolConstants.PROTOCOL_NAME.equals(uri.scheme()))
- // {
- // throw new InvalidURIException(uri);
- // }
- //
- // if (!uri.isHierarchical())
- // {
- // throw new InvalidURIException(uri);
- // }
- }
-
- public static String extractRepositoryUUID(URI uri)
- {
- try
- {
- validateURI(uri);
- if (!uri.hasAuthority())
- {
- throw new InvalidURIException(uri);
- }
-
- return uri.authority();
- }
- catch (InvalidURIException ex)
- {
- return null;
- }
- }
-
- public static String[] extractResourceFolderAndName(URI uri) throws InvalidURIException
- {
- String path = extractResourcePath(uri);
- int lastSeparator = path.lastIndexOf(SEGMENT_SEPARATOR_CHAR);
- if (lastSeparator == -1)
- {
- return new String[] { null, path };
- }
-
- String folder = path.substring(0, lastSeparator);
- String name = path.substring(lastSeparator + 1);
- return new String[] { folder, name };
- }
-
- public static String extractResourcePath(URI uri) throws InvalidURIException
- {
- if (!PROTOCOL_NAME.equals(uri.scheme()))
- {
- CDOURIData data = new CDOURIData(uri);
- return data.getResourcePath().toPortableString();
- }
-
- validateURI(uri);
- String path = uri.path();
- if (path == null)
- {
- return SEGMENT_SEPARATOR;
- }
-
- return path;
- }
-
- /**
- * <p>
- * cdo://repositoryUUID/path
- * <p>
- * The path is added at the end of "cdo://repositoryUUID". If path doesn't start with '/', it will be added
- * automatically. <br>
- * e.g.: /resA or resA will give the same result -> cdo://repositoryUUID/resA <br>
- * authority = repositoryUUID <br>
- * path = /resA
- */
- public static URI createResourceURI(String repositoryUUID, String path)
- {
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(PROTOCOL_NAME);
- stringBuilder.append(":"); //$NON-NLS-1$
-
- if (repositoryUUID != null)
- {
- stringBuilder.append("//"); //$NON-NLS-1$
- stringBuilder.append(repositoryUUID);
- }
-
- if (!SEGMENT_SEPARATOR.equals(path))
- {
- if (path.charAt(0) != SEGMENT_SEPARATOR_CHAR)
- {
- stringBuilder.append(SEGMENT_SEPARATOR_CHAR);
- }
-
- stringBuilder.append(path);
- }
-
- return URI.createURI(stringBuilder.toString());
- }
-
- public static URI createResourceURI(CDOView view, String path)
- {
- return createResourceURI(view == null ? null : view.getSession(), path);
- }
-
- public static URI createResourceURI(CDOSession session, String path)
- {
- return createResourceURI(session == null ? null : session.getRepositoryInfo().getUUID(), path);
- }
-
- /**
- * Converting temporary CDOID to External CDOID <br>
- * e.g.: <br>
- * baseURI = cdo://2a57dfcf-8f97-4d39-8e17-9d99ae5c4b3c/resB#5/2<br>
- * newCDOID = OID2<br>
- * return = cdo://2a57dfcf-8f97-4d39-8e17-9d99ae5c4b3c/resB#1/2
- */
- public static CDOID convertExternalCDOID(URI baseURI, CDOID newCDOID)
- {
- StringBuilder builder = new StringBuilder();
- CDOIDUtil.write(builder, newCDOID);
-
- baseURI = baseURI.trimFragment().appendFragment(builder.toString());
- return CDOIDUtil.createExternal(baseURI.toString());
- }
-
- public static List<String> analyzePath(URI uri)
- {
- String path = extractResourcePath(uri);
- return analyzePath(path);
- }
-
- public static List<String> analyzePath(String path)
- {
- List<String> segments = new ArrayList<String>();
- StringTokenizer tokenizer = new StringTokenizer(path, CDOURIUtil.SEGMENT_SEPARATOR);
- while (tokenizer.hasMoreTokens())
- {
- String name = tokenizer.nextToken();
- if (name != null)
- {
- segments.add(name);
- }
- }
-
- return segments;
- }
-
- /**
- * @since 4.0
- */
- public static Map<String, String> getParameters(String query)
- {
- Map<String, String> result = new HashMap<String, String>();
- StringTokenizer tokenizer = new StringTokenizer(query, "&"); //$NON-NLS-1$
- while (tokenizer.hasMoreTokens())
- {
- String parameter = tokenizer.nextToken();
- if (!StringUtil.isEmpty(parameter))
- {
- int pos = parameter.indexOf('=');
- if (pos == -1)
- {
- String key = parameter.trim();
- result.put(key, ""); //$NON-NLS-1$
- }
- else
- {
- String key = parameter.substring(0, pos).trim();
- String value = parameter.substring(pos + 1);
- result.put(key, value);
- }
- }
- }
-
- return result;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 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:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.util;
+
+import org.eclipse.emf.cdo.common.CDOCommonRepository;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.net4j.util.StringUtil;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+/**
+ * Various static methods that may help with CDO-specific {@link URI URIs}.
+ * <p>
+ * CDO URIs are in one of two different formats, either canonical or connection-aware. The canonical format is:
+ *
+ * <blockquote><b>cdo://</b> <i>RepositoryUUID</i> <b>/</b> <i>ResourcePath</i> [<b>?</b> <i>Param</i><b>=</b><i>Value</i>
+ * (<b>&</b> <i>Param</i><b>=</b><i>Value</i>)*]</blockquote>
+ *
+ * The non-terminals being:
+ * <p>
+ * <ul>
+ * <li><i>RepositoryUUID</i>: the {@link CDOCommonRepository#getUUID() UUID} of the repository. By default it's generated when a repository is first started.
+ * If the default format is not adequate the UUID value can be overridden in the repository setup with the <code>overrideUUID</code> property.
+ * <li><i>ResourcePath</i>: the full path of the {@link CDOResource resource} within the repository, segments separated by slashes, no leading slash.
+ * <li><i>Param</i>: one of the following
+ * <ul>
+ * <li><b>prefetch</b>: a boolean value. The value <b>true</b> attempts to load all objects contained by the resource in a single server-round trip and cache the results.
+ * </ul>
+ * </ul>
+ *
+ * URIs in the canonical form to resolve to {@link CDOResource resources} properly require the {@link ResourceSet resource set} to be
+ * configured <i>externally</i> so that the connection to the correct repository can be established, for example:
+ * <blockquote><code>session.openView(resourceSet);</code></blockquote>
+ *
+ * Note that resources preserve their original URI in the scope of the managing {@link CDOView view}, that is not necessarily in canonical format.
+ * <p>
+ * For a description of the connection-aware URI format refer to {@link CDOURIData}.
+ *
+ * @author Simon McDuff
+ * @since 2.0
+ */
+public final class CDOURIUtil
+{
+ /**
+ * @since 4.0
+ */
+ public static final String PROTOCOL_NAME = CDOProtocolConstants.PROTOCOL_NAME;
+
+ public static final char SEGMENT_SEPARATOR_CHAR = '/';
+
+ public static final String SEGMENT_SEPARATOR = new String(new char[] { SEGMENT_SEPARATOR_CHAR });
+
+ static
+ {
+ CDOUtil.registerResourceFactory(null); // Ensure that the normal resource factory is registered
+ }
+
+ private CDOURIUtil()
+ {
+ }
+
+ /**
+ * @deprecated
+ */
+ @Deprecated
+ public static void validateURI(URI uri) throws InvalidURIException
+ {
+ // if (!CDOProtocolConstants.PROTOCOL_NAME.equals(uri.scheme()))
+ // {
+ // throw new InvalidURIException(uri);
+ // }
+ //
+ // if (!uri.isHierarchical())
+ // {
+ // throw new InvalidURIException(uri);
+ // }
+ }
+
+ public static String extractRepositoryUUID(URI uri)
+ {
+ try
+ {
+ if (!uri.hasAuthority())
+ {
+ throw new InvalidURIException(uri);
+ }
+
+ return uri.authority();
+ }
+ catch (InvalidURIException ex)
+ {
+ return null;
+ }
+ }
+
+ public static String[] extractResourceFolderAndName(URI uri) throws InvalidURIException
+ {
+ String path = extractResourcePath(uri);
+ int lastSeparator = path.lastIndexOf(SEGMENT_SEPARATOR_CHAR);
+ if (lastSeparator == -1)
+ {
+ return new String[] { null, path };
+ }
+
+ String folder = path.substring(0, lastSeparator);
+ String name = path.substring(lastSeparator + 1);
+ return new String[] { folder, name };
+ }
+
+ public static String extractResourcePath(URI uri) throws InvalidURIException
+ {
+ if (!PROTOCOL_NAME.equals(uri.scheme()))
+ {
+ CDOURIData data = new CDOURIData(uri);
+ return data.getResourcePath().toPortableString();
+ }
+
+ String path = uri.path();
+ if (path == null)
+ {
+ return SEGMENT_SEPARATOR;
+ }
+
+ return path;
+ }
+
+ /**
+ * <p>
+ * cdo://repositoryUUID/path
+ * <p>
+ * The path is added at the end of "cdo://repositoryUUID". If path doesn't start with '/', it will be added
+ * automatically. <br>
+ * e.g.: /resA or resA will give the same result -> cdo://repositoryUUID/resA <br>
+ * authority = repositoryUUID <br>
+ * path = /resA
+ */
+ public static URI createResourceURI(String repositoryUUID, String path)
+ {
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(PROTOCOL_NAME);
+ stringBuilder.append(":"); //$NON-NLS-1$
+
+ if (repositoryUUID != null)
+ {
+ stringBuilder.append("//"); //$NON-NLS-1$
+ stringBuilder.append(repositoryUUID);
+ }
+
+ if (!SEGMENT_SEPARATOR.equals(path))
+ {
+ if (path.charAt(0) != SEGMENT_SEPARATOR_CHAR)
+ {
+ stringBuilder.append(SEGMENT_SEPARATOR_CHAR);
+ }
+
+ stringBuilder.append(path);
+ }
+
+ return URI.createURI(stringBuilder.toString());
+ }
+
+ public static URI createResourceURI(CDOView view, String path)
+ {
+ return createResourceURI(view == null ? null : view.getSession(), path);
+ }
+
+ public static URI createResourceURI(CDOSession session, String path)
+ {
+ return createResourceURI(session == null ? null : session.getRepositoryInfo().getUUID(), path);
+ }
+
+ /**
+ * Converting temporary CDOID to External CDOID <br>
+ * e.g.: <br>
+ * baseURI = cdo://2a57dfcf-8f97-4d39-8e17-9d99ae5c4b3c/resB#5/2<br>
+ * newCDOID = OID2<br>
+ * return = cdo://2a57dfcf-8f97-4d39-8e17-9d99ae5c4b3c/resB#1/2
+ */
+ public static CDOID convertExternalCDOID(URI baseURI, CDOID newCDOID)
+ {
+ StringBuilder builder = new StringBuilder();
+ CDOIDUtil.write(builder, newCDOID);
+
+ baseURI = baseURI.trimFragment().appendFragment(builder.toString());
+ return CDOIDUtil.createExternal(baseURI.toString());
+ }
+
+ public static List<String> analyzePath(URI uri)
+ {
+ String path = extractResourcePath(uri);
+ return analyzePath(path);
+ }
+
+ public static List<String> analyzePath(String path)
+ {
+ List<String> segments = new ArrayList<String>();
+ StringTokenizer tokenizer = new StringTokenizer(path, CDOURIUtil.SEGMENT_SEPARATOR);
+ while (tokenizer.hasMoreTokens())
+ {
+ String name = tokenizer.nextToken();
+ if (name != null)
+ {
+ segments.add(name);
+ }
+ }
+
+ return segments;
+ }
+
+ /**
+ * @since 4.0
+ */
+ public static Map<String, String> getParameters(String query)
+ {
+ Map<String, String> result = new HashMap<String, String>();
+ StringTokenizer tokenizer = new StringTokenizer(query, "&"); //$NON-NLS-1$
+ while (tokenizer.hasMoreTokens())
+ {
+ String parameter = tokenizer.nextToken();
+ if (!StringUtil.isEmpty(parameter))
+ {
+ int pos = parameter.indexOf('=');
+ if (pos == -1)
+ {
+ String key = parameter.trim();
+ result.put(key, ""); //$NON-NLS-1$
+ }
+ else
+ {
+ String key = parameter.substring(0, pos).trim();
+ String value = parameter.substring(pos + 1);
+ result.put(key, value);
+ }
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewProvider.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewProvider.java
index 1508623872..3d043e63c5 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewProvider.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewProvider.java
@@ -1,56 +1,56 @@
-/*
- * Copyright (c) 2004 - 2012 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:
- * Victor Roldan Betancort - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.view;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-
-/**
- * Capable of opening a <code>CDOView</code> on a target repository, defined by a URI. A regular expression and the
- * priority are used to determine the most suitable provider.
- *
- * @since 2.0
- * @author Victor Roldan Betancort
- */
-public interface CDOViewProvider
-{
- public static final int DEFAULT_PRIORITY = 500;
-
- /**
- * Returns the priority of this provider. Usually used to choose between several <code>CDOViewProvider</code> that
- * match the same repository URI.
- */
- public int getPriority();
-
- /**
- * Returns the regular expression that determines if the provider can handle certain URI
- */
- public String getRegex();
-
- /**
- * Checks if the URI matches with the regular expression of this provider
- */
- public boolean matchesRegex(URI uri);
-
- /**
- * Receives a URI and returns an opened <code>CDOView</code> against the repository. The implementer is responsible to
- * do the UUID to physical host map in case necessary.
- *
- * @return a wired-up and opened <code>CDOView</code>
- */
- public CDOView getView(URI uri, ResourceSet resourceSet);
-
- /**
- * @since 4.0
- */
- public URI getResourceURI(CDOView view, String path);
-}
+/*
+ * Copyright (c) 2004 - 2012 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:
+ * Victor Roldan Betancort - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.view;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+/**
+ * Capable of opening a <code>CDOView</code> on a target repository, defined by a URI. A regular expression and the
+ * priority are used to determine the most suitable provider.
+ *
+ * @since 2.0
+ * @author Victor Roldan Betancort
+ */
+public interface CDOViewProvider
+{
+ public static final int DEFAULT_PRIORITY = 500;
+
+ /**
+ * Returns the priority of this provider. Usually used to choose between several <code>CDOViewProvider</code> that
+ * match the same repository URI.
+ */
+ public int getPriority();
+
+ /**
+ * Returns the regular expression that determines if the provider can handle certain URI
+ */
+ public String getRegex();
+
+ /**
+ * Checks if the URI matches with the regular expression of this provider
+ */
+ public boolean matchesRegex(URI uri);
+
+ /**
+ * Receives a URI and returns an opened <code>CDOView</code> against the repository. The implementer is responsible to
+ * do the UUID to physical host map in case necessary.
+ *
+ * @return a wired-up and opened <code>CDOView</code>
+ */
+ public CDOView getView(URI uri, ResourceSet resourceSet);
+
+ /**
+ * @since 4.0
+ */
+ public URI getResourceURI(CDOView view, String path);
+}

Back to the top