4

I'm using Eclipse 3.7 with Eclipse Gemini JPA / DBAccess. I implemented a declarative ServiceComponent which references EntityManagerBuilderFactory. The bind method looks like this:

public void bindEntityManagerFactoryBuilder(EntityManagerFactoryBuilder emfBuilder) {
    emfFactoryBuilders.add(emfBuilder);
}

However I need the ServiceReference to obtain the properties of this service, like:

    ServiceReference ref = ...
    String unitName = (String)ref.getProperty(EntityManagerFactoryBuilder.JPA_UNIT_NAME);

Do I have to search the ServiceRegistry for this ServiceReference, or is there a more elegant approach?

cheers, Muki

Muki
  • 3,513
  • 3
  • 27
  • 50

2 Answers2

10

If you are using Declarative Services 1.1 (the most recent spec version), you can change the signature of your bind method to:

public void bindEntityManagerFactoryBuilder(EntityManagerFactoryBuilder emfBuilder, Map properties)

The map will contain the service properties of the bound service.

BJ Hargrave
  • 9,324
  • 1
  • 19
  • 27
1

If you like to have access to ServiceReference object you can use this way (it's supported by 1.0 and 1.1 DS):

public void bindEntityManagerFactoryBuilder(ServiceReference reference)
Dmytro Pishchukhin
  • 2,369
  • 1
  • 14
  • 19