osgi ds 开发的一个问题

来源:百度知道 编辑:UC知道 时间:2024/06/08 20:11:32
大家好,

最近自己在学习OSGi的一些内容。自己想编写一个程序试一试,可是现在遇到一个问题。想请各位帮个忙,谢谢大家。

我现在想用OSGi的DS实现一个简单的console程序。

CalculateBundle提供计算两个数相加的服务;
CalculateSystemBundle使用CalculateBundle的服务来计算得出结果。

我想把两个Bundle都用DS方式实现。

CalculateBundle可以使用component.xml方式注入组件和所提供的借口。

但我想在OSGi的console执行CalculateSystemBundle来在console打印出计算结果。可不知道CalculateSystemBundle从哪里执行。

原来不用DS的使用,可以使用Activator的start()方来来执行,并打印结果。

现在用DS是注入进来的,我写了一个component.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<component name="test">
<implementation class="com.jordanzt.calculate.test.test"/>
<reference name="calculateService" interface="com.jordanzt.calculate.service.Calculate" bind="setCalculator" unbind="unsetCalculator" policy="dynamic" cardinality="0..1"/>
</component>

test类是:
public class test

What's your OSGi runtime environment?
Check its manual, it probably show you how to "Start" a bundle.
Here is the sample from Apache ipojo:

<ipojo>
<component classname="spell.gui.SpellCheckerGui">
<requires field="m_checker"/>
<callback transition="validate" method="start"/>
<callback transition="invalidate" method="stop"/>
</component>
<instance component="spell.gui.SpellCheckerGui"/>
</ipojo>