Using Java Classes and Functions in BML

We can use Java Classes and Methods directly in BML as shown in below code snippet.

# BML Acvtivity test facet NewFacetInstance(fid: test, name: test, type: SffMessageFacet3): Action(name: OnOpen): ModifyPipeline: WsServerExtensionArgs; Action(name: OnRequest): $num = 10; $mathClass = new("com.atomiton.utilfunctions.MathFunctions"); $res = $mathClass.squareFunction($num); logInfo = "Num is " + $num + " res is " + $res;

The Java Classes and Methods we are planning to use must be present in an OSGI Jar which should be placed in sff.auto.launch folder of the engine, below are the steps to create OSGI Jar from scratch.

 

  1. Install Bnd tools from Eclipse Market place.

  2. In Eclipse Create a new workspace, then go to window → Perspective → Open Perspective → other and select bndtools.

     

  3. Then go to File → New and select Osgi Workspace, click next and then Finish.

  4. Then go to File → New and select Bnd Osgi project, select template as Empty Template click next and give a name to the Project.

  5. Right click on the src folder and create new package.

     

  6. Create a new class in the above created package, make sure the arguments and return in the methods are of type Object, below is sample class for your reference.

     

    package com.atomiton.utilfunctions; public class MathFunctions { public Object squareFunction(Object var) { double x = new Double(var.toString()); return x*x; } }
  7. Right Click on the Project folder and select New → Bundle Descriptor File, give a name to the bnd and create the bnd.

     

  8. click on the bnd file you created and add the package you created earlier to Private Packages and Export Packages in the bnd.

     

  9. The resulting jar is placed in generated folder of the project, copy this jar and paste in sff.auto.launch folder of the engine.

     

  10. Then this class and method can be used in BML as shown in the code snippet at the start of this document.

Related pages