configFile = ResourceBundle.getBundle(configFileName);
} catch (MissingResourceException e) {
String errorMessage = "Configuration file " + configFileName + ".properties not found " + e.getMessage();
LOGGER.error(errorMessage);
LOGGER.debug("Stack trace", e);
throw new LocatorException(errorMessage, e);
}
// Classe du locator.
String locatorClassName = configFile.getString(LOCATOR_CLASS_KEY);
Class<? extends ILocator> locatorClass;
try {
locatorClass = (Class<? extends ILocator>) Class.forName(locatorClassName);
} catch (ClassNotFoundException e) {
String errorMessage = "Locator class " + locatorClassName + " not found. Check " + configFileName
+ ".properties " + e.getMessage();
LOGGER.error(errorMessage);
throw new LocatorException(errorMessage, e);
}
// Locator par d�faut.
ILocator defaultLocator;
try {
String defaultFileName = configFile.getString(DEFAULT_LOCATOR_KEY);
if ((defaultFileName == null) || "".equals(defaultFileName.trim())) {
defaultLocator = null;
} else if (defaultFileName.equals(configFileName)) {
String errorMessage = "Configuration file " + configFileName + " gives itself as its own default.";
LOGGER.error(errorMessage);
LocatorException locatorException = new LocatorException(errorMessage);
LOGGER.debug("Stack trace", locatorException);
throw locatorException;
} else {
defaultLocator = getLocator(defaultFileName);
String infoMessage = "Initialization of the locator " + defaultLocator.getClass().getCanonicalName()
+ " as default locator for " + locatorClass.getCanonicalName();
LOGGER.debug(infoMessage);
}
} catch (MissingResourceException e) {
// Ce n'est pas une erreur : avoir un locator par d�faut est optionnel.
defaultLocator = null;
LOGGER.warn("Default locator not found {}", e.getMessage());
LOGGER.debug("Stack trace", e);
}
// Constructeur du locator.
Constructor<? extends ILocator> locatorConstructor;
try {
locatorConstructor = locatorClass.getConstructor(String.class, ResourceBundle.class, ILocator.class);
} catch (SecurityException e) {
String errorMessage = "Access to the constructor of " + locatorClassName + " with parameters is forbidden "
+ e.getMessage();
LOGGER.error(errorMessage);
LOGGER.debug("Stack trace", e);
throw new LocatorException(errorMessage, e);
} catch (NoSuchMethodException e) {
String errorMessage = "Constructor of " + locatorClassName + " with parameters not found " + e.getMessage();
LOGGER.error(errorMessage);
LOGGER.debug("Stack trace", e);
throw new LocatorException(errorMessage, e);
}
// Instanciation du locator.
ILocator locator;
try {
locator = locatorConstructor.newInstance(configFileName, configFile, defaultLocator);
LOGGER.debug("Initialization of the locator " + locator.getClass().getCanonicalName()
+ " as primary locator.");
} catch (Exception e) {
String errorMessage = "Cannot initialize the locator " + e.getMessage();
LOGGER.error(errorMessage);
LOGGER.debug("Stack trace", e);
throw new LocatorException(errorMessage, e);
}
return locator;
}