Hello Bokie,

On Nov 10, 2012, at 14:18 PM, bokie <[email protected]> wrote:

> There must be something about the ResourceDependency which I don't
> understand because nothing happens in the class that depends on a specific
> resource.
> 
> I have embedded a text file with my bundle (/res/file.txt).
> In my bundle Activator, which extends DependencyActivatorBase I have added
> the dependency with the DependencyManager in the init method:
> 
> public void init(final BundleContext context, final DependencyManager
> dependencyManager) throws Exception {
>    dependencyManager.add(
>        createComponent()
>            .setImplementation(ResDependent.instance())
>            .add(createResourceDependency()
>                .setResource(context.getBundle().getEntry("/res/file.txt"))
>                .setRequired(true)
>            )
>        );
>  }
> 
> If I set required = true, ResDependent.start does not get called. 
> If I set required = false, ResDependent.start gets called but nothing else
> happens.
> 
> What am I missing here?

A resource in the context of the dependency manager is an abstract thing that 
is identified by a URL. So a resource can be anything that can be represented 
by a URL. That means resources can come from (a folder in) a bundle, the 
filesystem, some remote location or anywhere else you can point a URL.

What you are missing is that the dependency manager currently does not come 
with any implementation of a resource provider. Therefore, whenever you define 
a resource dependency (like in your example) you will find it's not there.

What you need to provide yourself, is a resource provider that "serves" all 
resources in your bundle. Now you're not completely on your own here, as there 
are tests that you can use as examples. Take a look at:

in: test/src/main/java
org.apache.felix.dm.impl.ResourceAdapterTest

It contains a nested static class called ResourceProvider. It is not exactly 
what you want, because this implementation serves resources from a static list 
(with one item for this test) but it should be enough to get you going.

Hope this helps.

Greetings, Marcel


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to