package org.japura;
import java.util.Random;
import org.japura.controller.manager.ControllerManager;
import org.japura.controller.manager.DefaultControllerManager;
import org.japura.dialogs.DefaultMessageDialogs;
import org.japura.dialogs.MessageDialogs;
import org.japura.exception.DefaultHandlerExceptionManager;
import org.japura.exception.HandlerExceptionManager;
import org.japura.message.DefaultMessageManager;
import org.japura.message.MessageManager;
import org.japura.task.manager.DefaultTaskManager;
import org.japura.task.manager.TaskManager;
/**
* <P>
* Copyright (C) 2012-2013 Carlos Eduardo Leite de Andrade
* <P>
* This library is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
* <P>
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
* <P>
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <A
* HREF="www.gnu.org/licenses/">www.gnu.org/licenses/</A>
* <P>
* For more information, contact: <A HREF="www.japura.org">www.japura.org</A>
* <P>
*
* @author Carlos Eduardo Leite de Andrade
*/
public final class Application{
private static Random randomID = new Random();
private static MessageDialogs messageDialogs = new DefaultMessageDialogs();
private static ControllerManager controlllerManager =
new DefaultControllerManager();
private static HandlerExceptionManager handlerExceptionManager =
new DefaultHandlerExceptionManager();
private static TaskManager taskManager = new DefaultTaskManager();
private static MessageManager messageManager = new DefaultMessageManager();
private Application() {}
public static void reset() {
Application.messageDialogs = new DefaultMessageDialogs();
Application.controlllerManager = new DefaultControllerManager();
Application.handlerExceptionManager = new DefaultHandlerExceptionManager();
Application.taskManager = new DefaultTaskManager();
Application.messageManager = new DefaultMessageManager();
}
public static MessageManager getMessageManager() {
return messageManager;
}
public static void setMessageManager(MessageManager messageManager) {
if (messageManager == null) {
messageManager = new DefaultMessageManager();
}
Application.messageManager = messageManager;
}
public static MessageDialogs getMessageDialogs() {
return Application.messageDialogs;
}
public static void setMessageDialogs(MessageDialogs messageDialogs) {
if (messageDialogs == null) {
messageDialogs = new DefaultMessageDialogs();
}
Application.messageDialogs = messageDialogs;
}
public static ControllerManager getControllerManager() {
return controlllerManager;
}
public static void setControllerManager(ControllerManager controllerManager) {
if (controllerManager == null) {
controllerManager = new DefaultControllerManager();
}
Application.controlllerManager = controllerManager;
}
public static HandlerExceptionManager getHandlerExceptionManager() {
return handlerExceptionManager;
}
public static void setHandlerExceptionManager(HandlerExceptionManager handlerExceptionManager) {
if (handlerExceptionManager == null) {
handlerExceptionManager = new DefaultHandlerExceptionManager();
}
Application.handlerExceptionManager = handlerExceptionManager;
}
public static TaskManager getTaskManager() {
return taskManager;
}
public static void setTaskManager(TaskManager taskManager) {
if (taskManager == null) {
taskManager = new DefaultTaskManager();
}
Application.taskManager = taskManager;
}
public static String buildId() {
int randomInt = randomID.nextInt();
int c = randomID.nextInt(24) + 97;
long nanoTime = System.nanoTime();
return Integer.toHexString(randomInt) + ":" + (char) c + ":"
+ Long.toHexString(nanoTime);
}
}