JApptools
JApptools - Page 4
The pin of the component.

JApptools is a component that has a single active entry point that is its pin: JApptoolsPin class. Only one other class is visible: Serverconf, but he is a class without methods that only used to transport data. It follows that any use of the component begins by instantiating an object of its pin. The second step is the initialization of the configuration.

 
Example 1: Connecting to a database.

Our application JAPP, that uses JApptools, must connect to a database PostgreSQL. The configuration file is prepared and installed it in the /etc/ japp folder. This configuration file is named "config.xml".

JApptoolsPin toolsPin = JApptoolsPin.getInstance(); // recovering an instance of JApptools
toolsPin.initConfig("/etc/japp"); // the name config.xml is taken by default, unnecessary to pass it
Serverconf myDatabaseconf = toolsPin.getServerconf("mydatabase"); // mydatabase: id of the Server element
String login = myDatabaseconf.getLogin();
String url = myDatabaseconf.getConnectionUrl(); // url="jdbc:postgresql://myserver.mydomain.com:5432/mydbid"
Connection connection = null;
try{
  connection = DriverManager.getConnection(url, login, myDatabaseconf.getPassword());
} catch (SQLException e) {
  e.printStackTrace();
}

 
Example 2: sending email.

An application called japp2, that uses JApptools must send email. The configuration file is prepared and installed it in the /etc/japp2 folder. This configuration file is named "japp2-config.xml".

JApptoolsPin toolsPin = JApptoolsPin.getInstance(); // recovering an instance of JApptools
toolsPin.initConfig("/etc/japp2", "japp2-config.xml"); // because japp2-config.xml <> config.xml
ArrayList<String> body = new ArrayList<String>();
body.add("Message to send, paragraph 1");
body.add("Message to send, paragraph 2");
toolsPin.sendMail("Sujet du courriel", body, "myMailserver"); // email receivers in japp2-config.xml