Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 281148 | Differences between
and this patch

Collapse All | Expand All

(-)build.properties (-2 / +3 lines)
Lines 1-5 Link Here
1
source.. = src/
2
output.. = bin/
1
output.. = bin/
3
bin.includes = META-INF/,\
2
bin.includes = META-INF/,\
4
               .,\
3
               .,\
5
               test.xml
4
               test.xml,\
5
               OSGI-INF/
6
source.. = src/
(-).project (+5 lines)
Lines 20-25 Link Here
20
			<arguments>
20
			<arguments>
21
			</arguments>
21
			</arguments>
22
		</buildCommand>
22
		</buildCommand>
23
		<buildCommand>
24
			<name>org.eclipse.pde.ds.core.builder</name>
25
			<arguments>
26
			</arguments>
27
		</buildCommand>
23
	</buildSpec>
28
	</buildSpec>
24
	<natures>
29
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
30
		<nature>org.eclipse.pde.PluginNature</nature>
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 11-13 Link Here
11
Import-Package: org.eclipse.osgi.service.debug;version="1.1.0",
11
Import-Package: org.eclipse.osgi.service.debug;version="1.1.0",
12
 org.osgi.framework;version="1.5.0"
12
 org.osgi.framework;version="1.5.0"
13
Bundle-ActivationPolicy: lazy
13
Bundle-ActivationPolicy: lazy
14
Service-Component: OSGI-INF/adder.xml
(-)src/org/eclipse/e4/core/services/internal/context/ServiceContextTest.java (+12 lines)
Lines 80-85 Link Here
80
			((IDisposable)context).dispose();
80
			((IDisposable)context).dispose();
81
		super.tearDown();
81
		super.tearDown();
82
	}
82
	}
83
	
84
	public void testDeclarativeService() {
85
		IEclipseContext context = EclipseContextFactory.createServiceContext(TestActivator.bundleContext);
86
		assertNull(context.get("sum"));
87
		context.set("x", 1);
88
		context.set("y", 2);
89
		int result = (Integer)context.get("sum");
90
		assertEquals("1.0", 3, result);
91
		context.set("x", 5);
92
		result = (Integer)context.get("sum");
93
		assertEquals("1.0", 7, result);
94
	}
83
95
84
	/**
96
	/**
85
	 * Tests accessing OSGi services through a child context that is not aware of them.
97
	 * Tests accessing OSGi services through a child context that is not aware of them.
(-)src/org/eclipse/e4/core/services/internal/context/AddContextFunction.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.e4.core.services.internal.context;
13
14
import org.eclipse.e4.core.services.context.IEclipseContext;
15
16
import org.eclipse.e4.core.services.context.spi.ContextFunction;
17
18
/**
19
 * A function provided as a declarative service. See OSGI-INF/adder.xml.
20
 */
21
public class AddContextFunction extends ContextFunction {
22
23
	/*
24
	 * (non-Javadoc)
25
	 * 
26
	 * @see
27
	 * org.eclipse.e4.core.services.context.spi.ContextFunction#compute(org.
28
	 * eclipse.e4.core.services.context.IEclipseContext, java.lang.Object[])
29
	 */
30
	@Override
31
	public Object compute(IEclipseContext context, Object[] arguments) {
32
		if (context.get("x") != null && context.get("y") != null)
33
			return (Integer) context.get("x") + (Integer) context.get("y");
34
		return null;
35
	}
36
}
(-)OSGI-INF/adder.xml (+8 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.e4.core.tests.services">
3
   <implementation class="org.eclipse.e4.core.services.internal.context.AddContextFunction"/>
4
   <service>
5
      <provide interface="org.eclipse.e4.core.services.context.IContextFunction"/>
6
   </service>
7
   <property name="service.context.key" type="String" value="sum"/>
8
</scr:component>

Return to bug 281148