The interesting challenge is to get hands on the session and/or database inside your Java class. The class could be in your NSF, in a plug-in, or a jar in jvm/lib/ext.
You don't want to depend on where it came from, so you use dependency injection to provide them (which is a fancy word for: provide as parameter) something like:
public class Leon implements Serializable {
public void cleanerDoYourWork(Database db) {
Agent theProfessional = db.getAgent("acidAndGuns");
theProfessional.run();
theProfessional.recycle();
}
}
In case you don't get the pun, search IMDB for Leon :-)
Remark: In SSJS you don't need session.getCurrentDatabase();
, it is already there as "database"