Community
Participate
Working Groups
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
test.xml
test.xml,\
OSGI-INF/
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
Import-Package: org.eclipse.osgi.service.debug;version="1.1.0",
org.osgi.framework;version="1.5.0"
Bundle-ActivationPolicy: lazy
Service-Component: OSGI-INF/adder.xml
((IDisposable)context).dispose();
super.tearDown();
}
public void testDeclarativeService() {
IEclipseContext context = EclipseContextFactory.createServiceContext(TestActivator.bundleContext);
assertNull(context.get("sum"));
context.set("x", 1);
context.set("y", 2);
int result = (Integer)context.get("sum");
assertEquals("1.0", 3, result);
context.set("x", 5);
result = (Integer)context.get("sum");
assertEquals("1.0", 7, result);
/**
* Tests accessing OSGi services through a child context that is not aware of them.
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation 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:
* IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.e4.core.services.internal.context;
import org.eclipse.e4.core.services.context.IEclipseContext;
import org.eclipse.e4.core.services.context.spi.ContextFunction;
* A function provided as a declarative service. See OSGI-INF/adder.xml.
*/
public class AddContextFunction extends ContextFunction {
/*
* (non-Javadoc)
* @see
* org.eclipse.e4.core.services.context.spi.ContextFunction#compute(org.
* eclipse.e4.core.services.context.IEclipseContext, java.lang.Object[])
@Override
public Object compute(IEclipseContext context, Object[] arguments) {
if (context.get("x") != null && context.get("y") != null)
return (Integer) context.get("x") + (Integer) context.get("y");
return null;
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.e4.core.tests.services">
<implementation class="org.eclipse.e4.core.services.internal.context.AddContextFunction"/>
<service>
<provide interface="org.eclipse.e4.core.services.context.IContextFunction"/>
</service>
<property name="service.context.key" type="String" value="sum"/>
</scr:component>