summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-04-27 03:55:00 (EDT)
committerEike Stepper2008-04-27 03:55:00 (EDT)
commit6b28c52a080649bafbbbfc75bd9615d8b10ac91b (patch)
tree2583c6335a921055f506ea51019969419f9fddd0
parentced77ab2fc7eff3cde90ac6860a33d6ef18567de (diff)
downloadcdo-6b28c52a080649bafbbbfc75bd9615d8b10ac91b.zip
cdo-6b28c52a080649bafbbbfc75bd9615d8b10ac91b.tar.gz
cdo-6b28c52a080649bafbbbfc75bd9615d8b10ac91b.tar.bz2
[227995] Implement a self-populating EPackageRegistry
https://bugs.eclipse.org/bugs/show_bug.cgi?id=227995
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageRegistry.java4
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java129
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java3
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java27
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java16
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java8
6 files changed, 55 insertions, 132 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageRegistry.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageRegistry.java
index 812f95c..8a5b312 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageRegistry.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageRegistry.java
@@ -10,6 +10,8 @@
**************************************************************************/
package org.eclipse.emf.cdo.util;
+import org.eclipse.emf.cdo.protocol.model.CDOPackage;
+
import org.eclipse.emf.ecore.EPackage;
/**
@@ -25,4 +27,6 @@ public interface CDOPackageRegistry extends EPackage.Registry
* @return the package that is registered under the <code>nsURI</code> of the top level package or <code>null</code>.
*/
public EPackage putEPackage(EPackage ePackage);
+
+ public void putPackageDescriptor(CDOPackage proxy);
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
index 6a3d641..941624a 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
@@ -15,7 +15,6 @@ import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.eresource.CDOResourceFactory;
import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
-import org.eclipse.emf.cdo.protocol.id.CDOID;
import org.eclipse.emf.internal.cdo.CDOSessionFactory;
import org.eclipse.emf.internal.cdo.CDOSessionImpl;
@@ -45,8 +44,6 @@ import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.Resource.Factory.Registry;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
@@ -57,7 +54,6 @@ import org.osgi.framework.Constants;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
/**
@@ -133,21 +129,25 @@ public final class CDOUtil
}
public static CDOSession openSession(IConnector connector, String repositoryName, boolean disableLegacyObjects,
- IFailOverStrategy failOverStrategy) throws ConnectorException
+ boolean automaticPackageRegistry, IFailOverStrategy failOverStrategy) throws ConnectorException
{
- CDOSessionImpl session = new CDOSessionImpl();
- session.setFailOverStrategy(failOverStrategy);
+ CDOSessionImpl session = CDOSessionFactory.createSession(repositoryName, disableLegacyObjects,
+ automaticPackageRegistry, failOverStrategy);
session.setConnector(connector);
- session.setRepositoryName(repositoryName);
- session.setDisableLegacyObjects(disableLegacyObjects);
session.activate();
return session;
}
+ public static CDOSession openSession(IConnector connector, String repositoryName, boolean disableLegacyObjects,
+ boolean automaticPackageRegistry) throws ConnectorException
+ {
+ return openSession(connector, repositoryName, disableLegacyObjects, automaticPackageRegistry, null);
+ }
+
public static CDOSession openSession(IConnector connector, String repositoryName, boolean disableLegacyObjects)
throws ConnectorException
{
- return openSession(connector, repositoryName, disableLegacyObjects, null);
+ return openSession(connector, repositoryName, disableLegacyObjects, false, null);
}
public static CDOSession openSession(IConnector connector, String repositoryName) throws ConnectorException
@@ -213,41 +213,6 @@ public final class CDOUtil
return uri.path();
}
- @Deprecated
- public static CDOID extractResourceID(URI uri)
- {
- throw new UnsupportedOperationException();
- // if (!CDOProtocolConstants.PROTOCOL_NAME.equals(uri.scheme()))
- // {
- // return null;
- // }
- //
- // if (uri.hasAuthority())
- // {
- // return null;
- // }
- //
- // if (!uri.isHierarchical())
- // {
- // return null;
- // }
- //
- // if (uri.hasAbsolutePath())
- // {
- // return null;
- // }
- //
- // try
- // {
- // String path = uri.path();
- // return CDOModelUtil.parse(path);
- // }
- // catch (RuntimeException ex)
- // {
- // return null;
- // }
- }
-
public static URI createResourceURI(String path)
{
return URI.createURI(CDOProtocolConstants.PROTOCOL_NAME + ":" + path);
@@ -293,23 +258,6 @@ public final class CDOUtil
return eReference;
}
- /**
- * Returns a self-contained copy of the eObject with all proxies resolved.
- *
- * @param eObject
- * the object to copy.
- * @return the copy.
- * @see EcoreUtil#copy(EObject)
- */
- @Deprecated
- public static EObject copy(EObject eObject, CDOView view)
- {
- Copier copier = new CDOCopier(view);
- EObject result = copier.copy(eObject);
- copier.copyReferences();
- return result;
- }
-
public static void load(EObject eObject, CDOView view)
{
InternalCDOObject cdoObject = FSMUtil.adapt(eObject, view);
@@ -321,61 +269,4 @@ public final class CDOUtil
load(content, view);
}
}
-
- /**
- * @author Eike Stepper
- */
- @Deprecated
- public static final class CDOCopier extends Copier
- {
- private static final long serialVersionUID = 1L;
-
- private CDOView view;
-
- public CDOCopier(CDOView view)
- {
- this.view = view;
- }
-
- @Override
- protected void copyReference(EReference eReference, EObject eObject, EObject copyEObject)
- {
- resolve(eReference, eObject);
- super.copyReference(eReference, eObject, copyEObject);
- }
-
- @Override
- protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject)
- {
- resolve(eReference, eObject);
- super.copyContainment(eReference, eObject, copyEObject);
- }
-
- protected void resolve(EReference eReference, EObject eObject)
- {
- if (eObject.eIsSet(eReference))
- {
- if (eReference.isMany())
- {
- @SuppressWarnings("unchecked")
- List<EObject> list = (List<EObject>)eObject.eGet(eReference);
- for (EObject element : list)
- {
- if (element.eIsProxy())
- {
- EcoreUtil.resolve(element, view.getResourceSet());
- }
- }
- }
- else
- {
- EObject childEObject = (EObject)eObject.eGet(eReference);
- if (childEObject.eIsProxy())
- {
- EcoreUtil.resolve(childEObject, view.getResourceSet());
- }
- }
- }
- }
- }
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java
index bd69aae..7572533 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOPackageRegistryImpl.java
@@ -33,7 +33,6 @@ import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
import java.text.MessageFormat;
import java.util.Map;
-import java.util.Map.Entry;
/**
* @author Eike Stepper
@@ -212,7 +211,7 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
protected void populate()
{
Map<String, CDOPackageType> packageTypes = CDOUtil.getPackageTypes();
- for (Entry<String, CDOPackageType> entry : packageTypes.entrySet())
+ for (Map.Entry<String, CDOPackageType> entry : packageTypes.entrySet())
{
CDOPackageType packageType = entry.getValue();
if (packageType != CDOPackageType.LEGACY)
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java
index 339733a..c5f214f 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.internal.cdo;
import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.net4j.internal.util.factory.Factory;
+import org.eclipse.net4j.signal.failover.IFailOverStrategy;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.emf.common.util.URI;
@@ -36,10 +37,8 @@ public class CDOSessionFactory extends Factory
public CDOSession create(String description)
{
- CDOSessionImpl session = new CDOSessionImpl();
- session.setRepositoryName(getRepositoryName(description));
- session.setDisableLegacyObjects(isDisableLegacyObjects(description));
- return session;
+ return createSession(getRepositoryName(description), isDisableLegacyObjects(description),
+ isAutomaticPackageRegistry(description), null);
}
public static String getRepositoryName(String description)
@@ -54,8 +53,28 @@ public class CDOSessionFactory extends Factory
return description.contains("disableLegacyObjects=true");
}
+ public boolean isAutomaticPackageRegistry(String description)
+ {
+ return description.contains("automaticPackageRegistry=true");
+ }
+
public static CDOSession get(IManagedContainer container, String description)
{
return (CDOSession)container.getElement(PRODUCT_GROUP, TYPE, description);
}
+
+ public static CDOSessionImpl createSession(String repositoryName, boolean disableLegacyObjects,
+ boolean automaticPackageRegistry, IFailOverStrategy failOverStrategy)
+ {
+ CDOSessionImpl session = new CDOSessionImpl();
+ if (automaticPackageRegistry)
+ {
+ session.setPackageRegistry(new CDOPackageRegistryImpl.SelfPopulating(session));
+ }
+
+ session.setRepositoryName(repositoryName);
+ session.setDisableLegacyObjects(disableLegacyObjects);
+ session.setFailOverStrategy(failOverStrategy);
+ return session;
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
index 16f2263..e7bb4c2 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
@@ -27,6 +27,7 @@ import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
import org.eclipse.emf.cdo.protocol.util.TransportException;
+import org.eclipse.emf.cdo.util.CDOPackageRegistry;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.LegacySystemNotAvailableException;
@@ -115,7 +116,7 @@ public class CDOSessionImpl extends Container<CDOView> implements CDOSession, CD
private String repositoryUUID;
- private CDOPackageRegistryImpl packageRegistry;
+ private CDOPackageRegistry packageRegistry;
private CDOSessionPackageManagerImpl packageManager;
@@ -146,7 +147,6 @@ public class CDOSessionImpl extends Container<CDOView> implements CDOSession, CD
public CDOSessionImpl()
{
- packageRegistry = createPackageRegistry();
packageManager = createPackageManager();
revisionManager = createRevisionManager();
referenceChunkSize = OM.PREF_REFERENCE_CHUNK_SIZE.getValue();
@@ -257,7 +257,12 @@ public class CDOSessionImpl extends Container<CDOView> implements CDOSession, CD
deactivate();
}
- public CDOPackageRegistryImpl getPackageRegistry()
+ public void setPackageRegistry(CDOPackageRegistryImpl packageRegistry)
+ {
+ this.packageRegistry = packageRegistry;
+ }
+
+ public CDOPackageRegistry getPackageRegistry()
{
return packageRegistry;
}
@@ -625,6 +630,11 @@ public class CDOSessionImpl extends Container<CDOView> implements CDOSession, CD
protected void doActivate() throws Exception
{
super.doActivate();
+ if (packageRegistry == null)
+ {
+ packageRegistry = createPackageRegistry();
+ }
+
if (channel == null)
{
channel = connector.openChannel(CDOProtocolConstants.PROTOCOL_NAME, this);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
index c01db7c..fd6b77a 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/ModelUtil.java
@@ -26,10 +26,10 @@ import org.eclipse.emf.cdo.protocol.model.CDOType;
import org.eclipse.emf.cdo.protocol.model.core.CDOCorePackage;
import org.eclipse.emf.cdo.protocol.model.resource.CDOResourceClass;
import org.eclipse.emf.cdo.protocol.model.resource.CDOResourcePackage;
+import org.eclipse.emf.cdo.util.CDOPackageRegistry;
import org.eclipse.emf.cdo.util.EMFUtil;
import org.eclipse.emf.internal.cdo.CDOFactoryImpl;
-import org.eclipse.emf.internal.cdo.CDOPackageRegistryImpl;
import org.eclipse.emf.internal.cdo.CDOSessionImpl;
import org.eclipse.emf.internal.cdo.CDOSessionPackageManagerImpl;
import org.eclipse.emf.internal.cdo.bundle.OM;
@@ -267,7 +267,7 @@ public final class ModelUtil
return CDOModelUtil.createAttribute(containingClass, featureID, name, type, many);
}
- public static EPackage getEPackage(CDOPackage cdoPackage, CDOPackageRegistryImpl packageRegistry)
+ public static EPackage getEPackage(CDOPackage cdoPackage, CDOPackageRegistry packageRegistry)
{
EPackage ePackage = (EPackage)cdoPackage.getClientInfo();
if (ePackage == null)
@@ -286,7 +286,7 @@ public final class ModelUtil
return ePackage;
}
- public static EClass getEClass(CDOClass cdoClass, CDOPackageRegistryImpl packageRegistry)
+ public static EClass getEClass(CDOClass cdoClass, CDOPackageRegistry packageRegistry)
{
EClass eClass = (EClass)cdoClass.getClientInfo();
if (eClass == null)
@@ -299,7 +299,7 @@ public final class ModelUtil
return eClass;
}
- public static EStructuralFeature getEFeature(CDOFeature cdoFeature, CDOPackageRegistryImpl packageRegistry)
+ public static EStructuralFeature getEFeature(CDOFeature cdoFeature, CDOPackageRegistry packageRegistry)
{
EStructuralFeature eFeature = (EStructuralFeature)cdoFeature.getClientInfo();
if (eFeature == null)