Skip to content

Commit

Permalink
Add IContextFunction.ServiceContextKey OSGi component property type
Browse files Browse the repository at this point in the history
This annotation simplifies the specification of the
'service.context.key' service property for IContextFunction
implementations and makes it type-safe and more robust:
'''
@component(service = IContextFunction.class)
@IContextFunction.ServiceContextKey(IProgressService.class)
public class ProgressServiceCreationFunction extends ContextFunction {
'''
  • Loading branch information
HannesWell committed Oct 12, 2024
1 parent 7fa51b7 commit e14565e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dsVersion=V1_4
eclipse.preferences.version=1
enabled=true
generateBundleActivationPolicyLazy=true
path=OSGI-INF
validationErrorLevel=error
validationErrorLevel.missingImplicitUnbindMethod=error
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.e4.core.contexts
Bundle-Version: 1.12.600.qualifier
Bundle-Version: 1.13.0.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2013 IBM Corporation and others.
* Copyright (c) 2009, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,11 +10,15 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Hannes Wellmann - Add IContextFunction.ServiceContextKey OSGi component property type
*******************************************************************************/

package org.eclipse.e4.core.contexts;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.ComponentPropertyType;

/**
* A context function encapsulates evaluation of some code within an
Expand Down Expand Up @@ -58,9 +62,23 @@ public interface IContextFunction {
* should be registered in.
*
* @see BundleContext#getServiceReference(String)
* @see ServiceContextKey
*/
String SERVICE_CONTEXT_KEY = "service.context.key"; //$NON-NLS-1$

/**
* An OSGi service component property type used to indicate the context key this
* function should be registered in.
*
* @since 1.13
* @see #SERVICE_CONTEXT_KEY
*/
@ComponentPropertyType
@Retention(RetentionPolicy.SOURCE)
public @interface ServiceContextKey {
Class<?> value();
}

/**
* Evaluates the function based on the provided arguments and context to
* produce a consistent result.
Expand Down

0 comments on commit e14565e

Please sign in to comment.