* @param level the level of the message.
* @param msg the message to log
* @param exception the exception attached to the message
*/
private void dispatch(int level, String msg, Throwable exception) {
LogService log = null;
ServiceReference ref = null;
try {
// Security Check
if (SecurityHelper.hasPermissionToGetService(LogService.class.getName(), m_context)) {
ref = m_context.getServiceReference(LogService.class.getName());
} else {
Extender.getIPOJOBundleContext().getServiceReference(LogService.class.getName());
}
if (ref != null) {
log = (LogService) m_context.getService(ref);
}
} catch (IllegalStateException e) {
// Handle the case where the iPOJO bundle is stopping
}
String message = null;
String name = m_name;
if (name == null) {
name = "";
}
switch (level) {
case DEBUG:
message = "[DEBUG] " + name + " : " + msg;
if (log != null) {
log.log(LogService.LOG_DEBUG, message, exception);
} else {
System.err.println(message);
exception.printStackTrace();
}
break;
case ERROR:
message = "[ERROR] " + name + " : " + msg;
if (log != null) {
log.log(LogService.LOG_ERROR, message, exception);
} else {
System.err.println(message);
exception.printStackTrace();
}
break;
case INFO:
message = "[INFO] " + name + " : " + msg;
if (log != null) {
log.log(LogService.LOG_INFO, message, exception);
} else {
System.err.println(message);
exception.printStackTrace();
}
break;
case WARNING:
message = "[WARNING] " + name + " : " + msg;
if (log != null) {
log.log(LogService.LOG_WARNING, message, exception);
} else {
System.err.println(message);
exception.printStackTrace();
}
break;