The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

st_clair (8) [Avatar] Offline
#1
Hello,

If I sucessfully created a Factory to produce a Patient object and successfully acess this object in the Activator, what is the best or accepted method to access this Patient object in another class such as in the ApplicationActionBarAdivisor?

I am asking because I need this class in the ApplicationActionBarAdivisor to provide the model so I can start a Wizard.

Thanks.
richard.hall (87) [Avatar] Offline
#2
Re: Accessing a Service in a Class Different from the Activator class
For the most part, the OSGi specification doesn't have much to say about what goes on inside your bundle, it is largely concerned with inter-bundle issues (i.e., class loading and collaboration via services). Inside your bundle, you typically have three options:

<ol>
  • Pass around the bundle context so your various objects can get access to what they need from OSGi directly.

  • Create some sort of manager/controller object that acquires services and exposes them in some way to your internal objects.

  • Use some form of dependency injection pattern to make services available to your internal objects.

  • </ol>

    The first approach is not recommended since it creates dependencies on OSGi API, so some form of the latter two are preferred. If you look at the Paint example from chapter 4, it effectively uses a combination of these latter two approaches. The main paint application is injected with shape services and then the shape components gain access to the shapes from it to do their painting.
    st_clair (8) [Avatar] Offline
    #3
    Re: Accessing a Service in a Class Different from the Activator class
    Thank you very much Richard, I appreciate the help.

    Please let us know when we will be getting some more chapters of your book. The first three chapters merley wet my appetite!

    St Clair
    richard.hall (87) [Avatar] Offline
    #4
    Re: Accessing a Service in a Class Different from the Activator class
    We are working on it, so hopefully not too long!