You are correct Niclas.

I created 2 bundles, a client and a server to demonstrate the problem I am having.

In the client...

package client;
public class ClientActivator implements BundleActivator {

    public void start(BundleContext context) throws Exception {
        ServiceTracker tracker = new ServiceTracker(context,
                ServerService.class.getName(), null);
        tracker.open();

        SystemService sys = (SystemService) tracker.getService();

        sys.init("applicationContext.xml",
                "client.ClientActivator");
    }

    public void stop(BundleContext context) throws Exception {
    }

}


In the server...

package server;
public class SystemServiceImpl implements SystemService {

    BundleContext bundleContext;

    public SystemServiceImpl(BundleContext context) {
// This gets initialized with the BundleContext from the SystemActivator
        this.bundleContext = context;
    }

    public void init(String someFile, String someClass) {

        try {
            System.out.println("via bundle: "
                    + bundleContext.getBundle().loadClass(someClass));
            System.out.println("via Class: " + Class.forName(someClass));
            System.out.println ("via bundle: "
                    + bundleContext.getBundle().getEntry(someFile));
            System.out.println("via ClassLoader: "
                    + getClass().getClassLoader().getResource(someFile));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}


As normal it throws an exception on the first println.  Which is what I expect.

With Eclipse-RegisterBuddy/Eclipse-BuddyPolicy the first 2 println statements work.  But the 3rd does not find the file.  It should, correct?  This is one problem I'm trying to figure out.

The next question is, is there a way to do this without the specialized Eclipse-RegisterBuddy.

I'm going to take a look at Pax-wicket

Thanks


On 10/19/06, Niclas Hedhman <[EMAIL PROTECTED]> wrote:


On 10/19/06, Benjamin Schmaus < [EMAIL PROTECTED]> wrote:
> I knew about spring-osgi. I really wanted to know how to let an existing
> class retrieve resources from another bundle

Like Peter Kriens said, the Bundle object provides methods for
retrieving resources from a given bundle, namely,
Bundle.getEntry(String resource) and Bundle.findEntries(String path,
String filePattern, boolean recurse).

In the past I've used a BundleListener to inspect bundle's that have
been INSTALLED to see if they provide a "conf/testng.xml" file, and if
so add them to a datastructure that can be used to locate bundles that
provide TestNG unit tests, which can later be run from a UI.

Joe,
if I understand you correctly, you are essentially trying to grasp how to create bundles that are agnostic of future providers of resources (such as classes), yet use those resources as if they were available on the classpath as most legacy frameworks assumes.

If so, Peter and Benjamin are very accurate, and if you want to check some actual code out, you could peek at Pax Wicket in https://scm.ops4j.org/repos/ops4j/projects/pax/wicket/service , which does exactly that. Can't quite remember what happens where, but if you want more precise pointers, I will look that up tomorrow, or perhaps Edward can point you in the right direction...


Cheers
Niclas

_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general



_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general

Reply via email to