From 0e4d5df279b8c92255af38579cdc15a545766a21 Mon Sep 17 00:00:00 2001 From: Eike Stepper Date: Tue, 10 Jan 2012 15:52:23 +0100 Subject: [367905] [CDO] Allow Adapters to be notified during loading https://bugs.eclipse.org/bugs/show_bug.cgi?id=367905 --- plugins/org.eclipse.emf.cdo.doc/build.xml | 6 + .../html/programmers/client/Architecture.html | 4 +- .../html/programmers/client/ViewProviders.html | 190 +++++++++++++++++++++ .../html/programmers/client/index.html | 4 + .../html/programmers/index.html | 4 + .../html/programmers/server/index.html | 4 +- .../cdo/doc/programmers/client/ViewProviders.java | 146 ++++++++++++++++ plugins/org.eclipse.emf.cdo.doc/toc.html | 1 + plugins/org.eclipse.emf.cdo.doc/toc.xml | 1 + plugins/org.eclipse.emf.cdo.releng.help/build.xml | 6 + plugins/org.eclipse.emf.cdo.releng/help/toc.html | 1 + plugins/org.eclipse.net4j.db.doc/build.xml | 6 + plugins/org.eclipse.net4j.doc/build.xml | 6 + plugins/org.eclipse.net4j.util.doc/build.xml | 6 + 14 files changed, 381 insertions(+), 4 deletions(-) create mode 100644 plugins/org.eclipse.emf.cdo.doc/html/programmers/client/ViewProviders.html create mode 100644 plugins/org.eclipse.emf.cdo.doc/src/org/eclipse/emf/cdo/doc/programmers/client/ViewProviders.java diff --git a/plugins/org.eclipse.emf.cdo.doc/build.xml b/plugins/org.eclipse.emf.cdo.doc/build.xml index 7447d450ca..973fa58e87 100644 --- a/plugins/org.eclipse.emf.cdo.doc/build.xml +++ b/plugins/org.eclipse.emf.cdo.doc/build.xml @@ -53,6 +53,8 @@ classpathref="javadoc.classpath" /> + + @@ -290,6 +292,8 @@ + + @@ -316,6 +320,8 @@ + + diff --git a/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/Architecture.html b/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/Architecture.html index 79a914ee5e..fe3b567dcb 100644 --- a/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/Architecture.html +++ b/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/Architecture.html @@ -23,7 +23,7 @@ function windowTitle() - +

Understanding the Architecture of a Client Application

  

Author: Eike Stepper

@@ -60,7 +60,7 @@ function windowTitle()

- 

+ 


Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others. diff --git a/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/ViewProviders.html b/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/ViewProviders.html new file mode 100644 index 0000000000..d1d2cf3a59 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/ViewProviders.html @@ -0,0 +1,190 @@ + + + + +View Providers (CDO Model Repository Documentation) + + + + + + + + + + + + + + + +

View Providers

 
+

Author: Victor Roldan Betancort

+

+ A view provider allows clients to inject custom logic into the resource factory mechansim, capable of handling the whole session and view + instantiation process. This permits to obtain resources through the resource set + API transparently, without any prior CDO client API code. The view provider automatically kicks in the middle of the + ResourceSet.getResource() call, forgetting + about the whole openning session / openning transaction process, which happens behind the scenes. +

+ This is quite useful when integrating CDO with EMF-based frameworks and tools that are not prepared for a CDO + scenario themselves. +

+ Table of Contents

+ + + + +
Implementing a View Provider
Contributing View Providers Programmatically
Contributing View Providers Using Extension Points
+

+ + +

1  Implementing a View Provider

+

+ Clients should implement the CDOViewProvider interface, or sub class the AbstractCDOViewProvider + class, which provides common functionality. +

+ The example below shows a simple implementation that opens a new session to a local + server and a new transaction on that session. +

+ + +

+ + + + + + + + + + + + + + + + + + + +
ExampleViewProvider.java 
  +
+ +  new AbstractCDOViewProvider("cdo\\.local:.*"100)
+ {
+   private IManagedContainer container;
+
+    public CDOView getView(URI uri, ResourceSet resourceSet)
+   {
+     if (container == null)
+     {
+       container = new ManagedContainer();
+       Net4jUtil.prepareContainer(container);
+       TCPUtil.prepareContainer(container);
+       container.activate();
+     }
+
+     int startIndex = uri.toString().indexOf(':');
+     String repoName = uri.toString().substring(startIndex);
+
+     IConnector connector = (IConnector)container.getElement("org.eclipse.net4j.connectors""tcp""localhost");
+
+     CDONet4jSessionConfiguration config = CDONet4jUtil.createNet4jSessionConfiguration();
+     config.setConnector(connector);
+     config.setRepositoryName(repoName);
+
+     CDOSession session = config.openNet4jSession();
+     return session.openTransaction();
+   }
+ }; +
+
+
 
 
+
+

+

 The example provider catches all URIs with shape "cdo.local:". + +
+
 Register the provider with CDOViewProviderRegistry. + +
+

+ + +

2  Contributing View Providers Programmatically

+

+ A client's view provider implementation can be contributed programmatically to the CDOViewProviderRegistry, + as the following example suggests: +

+ + +

+ + + + + + + + + + + + + + + + + + + +
ProviderContribution.java 
  +
+ + // Instantiate your view provider
+ CDOViewProvider viewProvider =  org.eclipse.emf.internal.cdo.view.PluginContainerViewProvider.INSTANCE;
+
+ // Add the instance to the registry
+  CDOViewProviderRegistry.INSTANCE.addViewProvider(viewProvider); +
+
+
 
 
+
+

+

 Get the target CDOViewProvider implementation. + +
+
 Add the provider instance to CDOViewProviderRegistry. + +
+

+ + +

3  Contributing View Providers Using Extension Points

+

+ A specific CDOViewProvider implementation can also be contributed using the + org.eclipse.emf.cdo.viewProviders extension point. Clients specify: +

+

+ +

+ 

+
+Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others. + + diff --git a/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/index.html b/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/index.html index 79b4b9eaa6..d58f54b6d6 100644 --- a/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/index.html +++ b/plugins/org.eclipse.emf.cdo.doc/html/programmers/client/index.html @@ -36,6 +36,10 @@ function windowTitle() 5 ModelsProtocolTransport + View Providers +1 Implementing a View Provider +2 Contributing View Providers Programmatically +3 Contributing View Providers Using Extension Points

diff --git a/plugins/org.eclipse.emf.cdo.doc/html/programmers/index.html b/plugins/org.eclipse.emf.cdo.doc/html/programmers/index.html index 1f8ff46fcc..8e7885d9e6 100644 --- a/plugins/org.eclipse.emf.cdo.doc/html/programmers/index.html +++ b/plugins/org.eclipse.emf.cdo.doc/html/programmers/index.html @@ -37,6 +37,10 @@ function windowTitle() 5 ModelsProtocolTransport + View Providers +1 Implementing a View Provider +2 Contributing View Providers Programmatically +3 Contributing View Providers Using Extension Points  Dealing with Servers  Understanding the Architecture of a RepositoryOSGi diff --git a/plugins/org.eclipse.emf.cdo.doc/html/programmers/server/index.html b/plugins/org.eclipse.emf.cdo.doc/html/programmers/server/index.html index 3a2d402c2f..a0ceed2b34 100644 --- a/plugins/org.eclipse.emf.cdo.doc/html/programmers/server/index.html +++ b/plugins/org.eclipse.emf.cdo.doc/html/programmers/server/index.html @@ -23,7 +23,7 @@ function windowTitle() - +

Dealing with Servers

  

@@ -41,7 +41,7 @@ function windowTitle()

- 

+ 


Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others. diff --git a/plugins/org.eclipse.emf.cdo.doc/src/org/eclipse/emf/cdo/doc/programmers/client/ViewProviders.java b/plugins/org.eclipse.emf.cdo.doc/src/org/eclipse/emf/cdo/doc/programmers/client/ViewProviders.java new file mode 100644 index 0000000000..80b6712592 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.doc/src/org/eclipse/emf/cdo/doc/programmers/client/ViewProviders.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2004 - 2011 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 + */ +package org.eclipse.emf.cdo.doc.programmers.client; + +import org.eclipse.emf.cdo.eresource.CDOResourceFactory; +import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration; +import org.eclipse.emf.cdo.net4j.CDONet4jUtil; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.view.AbstractCDOViewProvider; +import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.emf.cdo.view.CDOViewProvider; +import org.eclipse.emf.cdo.view.CDOViewProviderRegistry; + +import org.eclipse.net4j.Net4jUtil; +import org.eclipse.net4j.connector.IConnector; +import org.eclipse.net4j.tcp.TCPUtil; +import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.container.ManagedContainer; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; + +/** + * View Providers + *

+ * A {@link CDOViewProvider view provider} allows clients to inject custom logic into the {@link CDOResourceFactory + * resource factory} mechansim, capable of handling the whole {@link CDOSession session} and {@link CDOView view} + * instantiation process. This permits to obtain {@link Resource resources} through the {@link ResourceSet resource set} + * API transparently, without any prior CDO client API code. The view provider automatically kicks in the middle of the + * {@link ResourceSet#getResource(org.eclipse.emf.common.util.URI, boolean) ResourceSet.getResource()} call, forgetting + * about the whole openning session / openning transaction process, which happens behind the scenes. + *

+ * This is quite useful when integrating CDO with EMF-based frameworks and tools that are not prepared for a CDO + * scenario themselves. + *

+ * Table of Contents {@toc} + * + * @author Victor Roldan Betancort + */ +public class ViewProviders +{ + /** + * Implementing a View Provider + *

+ * Clients should implement the {@link CDOViewProvider} interface, or sub class the {@link AbstractCDOViewProvider} + * class, which provides common functionality. + *

+ * The example below shows a simple implementation that opens a new {@link CDOSession session} to a local + * server and a new {@link CDOTransaction transaction} on that session. + *

+ * {@link #example() ExampleViewProvider.java} + */ + public class ProviderImplementation + { + /** + * @snippet + * @callout The example provider catches all URIs with shape "cdo.local:". + * @callout Register the provider with {@link CDOViewProviderRegistry}. + */ + public void example() + { + /* callout */new AbstractCDOViewProvider("cdo\\.local:.*", 100) + { + private IManagedContainer container; + + /* callout */public CDOView getView(URI uri, ResourceSet resourceSet) + { + if (container == null) + { + container = new ManagedContainer(); + Net4jUtil.prepareContainer(container); + TCPUtil.prepareContainer(container); + container.activate(); + } + + int startIndex = uri.toString().indexOf(':'); + String repoName = uri.toString().substring(startIndex); + + IConnector connector = (IConnector)container.getElement("org.eclipse.net4j.connectors", "tcp", "localhost"); + + CDONet4jSessionConfiguration config = CDONet4jUtil.createNet4jSessionConfiguration(); + config.setConnector(connector); + config.setRepositoryName(repoName); + + CDOSession session = config.openNet4jSession(); + return session.openTransaction(); + } + }; + } + } + + /** + * Contributing View Providers Programmatically + *

+ * A client's view provider implementation can be contributed programmatically to the {@link CDOViewProviderRegistry}, + * as the following example suggests: + *

+ * {@link #snippet2() ProviderContribution.java} + */ + public class ContributeProviderProgrammatically + { + /** + * @snippet + * @callout Get the target {@link CDOViewProvider} implementation. + * @callout Add the provider instance to {@link CDOViewProviderRegistry}. + */ + @SuppressWarnings("restriction") + public void snippet2() + { + // Instantiate your view provider + CDOViewProvider viewProvider = /* callout */org.eclipse.emf.internal.cdo.view.PluginContainerViewProvider.INSTANCE; + + // Add the instance to the registry + /* callout */CDOViewProviderRegistry.INSTANCE.addViewProvider(viewProvider); + } + } + + /** + * Contributing View Providers Using Extension Points + *

+ * A specific {@link CDOViewProvider} implementation can also be contributed using the + * org.eclipse.emf.cdo.viewProviders extension point. Clients specify: + *

+ *

+ */ + public class ContributeProviderUsingExtensionPoint + { + } +} diff --git a/plugins/org.eclipse.emf.cdo.doc/toc.html b/plugins/org.eclipse.emf.cdo.doc/toc.html index 3f47c7a56c..ab69ba6204 100644 --- a/plugins/org.eclipse.emf.cdo.doc/toc.html +++ b/plugins/org.eclipse.emf.cdo.doc/toc.html @@ -6,6 +6,7 @@