Skip to content

Commit 7ca3fd9

Browse files
committed
Allow interfacing with other adapter frameworks by using a proxy
While the Eclipse Adapter Framework is very powerful it currently does not allow to interface with other adaption techniques (e.g. OSGi Converter Specification). This adds a new way to adapt a class of objects to a proxy that then is asked for further adaption.
1 parent b1adfa2 commit 7ca3fd9

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

bundles/org.eclipse.equinox.common/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.equinox.common; singleton:=true
5-
Bundle-Version: 3.19.100.qualifier
5+
Bundle-Version: 3.20.0.qualifier
66
Bundle-Localization: plugin
77
Export-Package: org.eclipse.core.internal.boot;x-friends:="org.eclipse.core.resources,org.eclipse.pde.build",
88
org.eclipse.core.internal.runtime;common=split;mandatory:=common;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.eclipse.core.runtime;
2+
3+
/**
4+
* <p>
5+
* An {@link AdapterProxy} can be used to interface the Eclipse Adapter
6+
* Framework with other techniques. To do so one has to provide a generic
7+
* {@link IAdapterFactory} that adapts this other frameworks objects to the
8+
* {@link AdapterProxy} interface, then as a last resort, the Eclipse Adapter
9+
* Framework will ask this proxy as if the original object would have
10+
* implemented {@link IAdaptable}.
11+
* </p>
12+
* <p>
13+
* One example is the OSGi <a href=
14+
* "https://docs.osgi.org/specification/osgi.cmpn/7.0.0/util.converter.html">Converter
15+
* Specification</a> that allows to adapt/convert objects in an extensible way,
16+
* therefore it is not possible to register a "classic" {@link IAdapterFactory}
17+
* because the types that are probably convertible are unknown in advance. Also
18+
* the objects itself can't be made to implement the {@link IAdaptable}
19+
* interface. An implementation then might look like this:
20+
* </p>
21+
*
22+
* <pre>
23+
* &#64;Component
24+
* &#64;AdapterTypes(adaptableClass = Object.class, adapterNames = AdapterProxy.class)
25+
* public class OSGiConverterProxyFactory implements IAdapterFactory {
26+
*
27+
* &#64;Reference
28+
* private Converter converter;
29+
*
30+
* public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
31+
* Converting converting = converter.convert(adaptableObject);
32+
* return converting.to(adapterType);
33+
* }
34+
*
35+
* }
36+
* </pre>
37+
*
38+
* @since 3.20
39+
*/
40+
public interface AdapterProxy extends IAdaptable {
41+
// This is a specialized type that do not define any methods
42+
}

bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/Adapters.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ public static <T> T adapt(Object sourceObject, Class<T> adapter, boolean allowAc
8484

8585
String adapterId = adapter.getName();
8686
Object result = queryAdapterManager(sourceObject, adapterId, allowActivation);
87+
if (result == null) {
88+
// Last resort, this object is maybe using a different adaption technique
89+
if (queryAdapterManager(sourceObject, AdapterProxy.class.getName(),
90+
allowActivation) instanceof AdapterProxy proxy) {
91+
result = proxy.getAdapter(adapter);
92+
}
93+
}
8794
if (result != null) {
8895
// Sanity-check
8996
if (!adapter.isInstance(result)) {

0 commit comments

Comments
 (0)