2

I have an XPage that runs in the browser and in the Notes client. In the client I want to talk to the Java client UI. So I built an Extlib that encapsulated the calls. And I built one with the same signature for the web.

How can I make the app depend on one or the other based on running in the client or on the server?

stwissel
  • 20,110
  • 6
  • 54
  • 101

2 Answers2

2

You should use OSGi Services for this.

  1. Define your API in terms of Java interfaces. Write a single bundle that exports the API package.
  2. Write two implementations of the API, one that implements it for "thick client" and the other that implements it for the web. Each bundle provides its implementation as a Service.
  3. Include the thick client bundle in the thick client app; include the web bundle in the web app.

To ease the task of implementing and consuming the service, I strongly recommend using Declarative Services (DS).

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • Hi Neil, thx for chipping in. I got the interfaces, I got the implementation. The special challenge here: there is only one application that gets processed by both a server and a rich client (same code base) - short of my libraries that is. Where can I find more about DS? – stwissel Sep 18 '13 at 13:26
  • Unfortunately XPages doesn't seem to support declarative services, so I travel down a different path – stwissel Sep 19 '13 at 15:33
  • I don't know much about XPages but I believe it's based on OSGi. And DS is standard OSGi. Therefore DS should work on XPages. – Neil Bartlett Sep 19 '13 at 20:06
0

For a Java plug-in that gets used in an XPage there are (according to the master) 2 basic approaches feasible (all implement interfaces, so Neil is spot on):

  • Provide the implementations as fragments to the base plug-in and load the appropriate fragment. Can be a challenge if the same plug-in instance gets deployed to clients and servers equally
  • Provide both implementations (e.g. com.acme.server.SomeClass and com.acme.client.SomeClass ) and have a factory class pick the right class for the current runtime
stwissel
  • 20,110
  • 6
  • 54
  • 101