Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow interfacing with other adapter frameworks by using a proxy #650

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundles/org.eclipse.equinox.common/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.common; singleton:=true
Bundle-Version: 3.19.100.qualifier
Bundle-Version: 3.20.0.qualifier
Bundle-Localization: plugin
Export-Package: org.eclipse.core.internal.boot;x-friends:="org.eclipse.core.resources,org.eclipse.pde.build",
org.eclipse.core.internal.runtime;common=split;mandatory:=common;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.eclipse.core.runtime;

/**
* <p>
* An {@link AdapterProxy} can be used to interface the Eclipse Adapter
* Framework with other techniques. To do so one has to provide a generic
* {@link IAdapterFactory} that adapts this other frameworks objects to the
* {@link AdapterProxy} interface, then as a last resort, the Eclipse Adapter
* Framework will ask this proxy as if the original object would have
* implemented {@link IAdaptable}.
* </p>
* <p>
* One example is the OSGi <a href=
* "https://docs.osgi.org/specification/osgi.cmpn/7.0.0/util.converter.html">Converter
* Specification</a> that allows to adapt/convert objects in an extensible way,
* therefore it is not possible to register a "classic" {@link IAdapterFactory}
* because the types that are probably convertible are unknown in advance. Also
* the objects itself can't be made to implement the {@link IAdaptable}
* interface. An implementation then might look like this:
* </p>
*
* <pre>
* &#64;Component
* &#64;AdapterTypes(adaptableClass = Object.class, adapterNames = AdapterProxy.class)
* public class OSGiConverterProxyFactory implements IAdapterFactory {
*
* &#64;Reference
* private Converter converter;
*
* public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
* Converting converting = converter.convert(adaptableObject);
* return converting.to(adapterType);
* }
*
* }
* </pre>
*
* @since 3.20
*/
public interface AdapterProxy extends IAdaptable {
// This is a specialized type that do not define any methods
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public static <T> T adapt(Object sourceObject, Class<T> adapter, boolean allowAc

String adapterId = adapter.getName();
Object result = queryAdapterManager(sourceObject, adapterId, allowActivation);
if (result == null) {
// Last resort, this object is maybe using a different adaption technique
if (queryAdapterManager(sourceObject, AdapterProxy.class.getName(),
allowActivation) instanceof AdapterProxy proxy) {
result = proxy.getAdapter(adapter);
}
}
if (result != null) {
// Sanity-check
if (!adapter.isInstance(result)) {
Expand Down
Loading