try {
configFile = ResourceBundle.getBundle(configFileName);
}
catch(MissingResourceException e) {
e.printStackTrace();
throw new LocatorException(
"Error : configuration file " + configFileName + ".properties not found : " + e.getMessage(), e);
}
// Classe du locator.
String locatorClassName = configFile.getString(LOCATOR_CLASS_KEY);
Class<ILocator> locatorClass;
try {
locatorClass = (Class<ILocator>) Class.forName(locatorClassName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new LocatorException(
"Erreur : locator class " + locatorClassName + " not found. Check "
+ configFileName + ".properties. Cause : " + e.getMessage(), 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)) {
throw new LocatorException("Error : the configuration file " + configFileName
+ " gives itself as its own default.");
}
else {
defaultLocator = getLocator(defaultFileName);
if (log.isDebugEnabled()) {
log.debug("Initialization of the locator " + defaultLocator.getClass().getCanonicalName()
+ " as default locator for " + locatorClass.getCanonicalName() + ".");
}
}
}
catch(MissingResourceException e) {
// Ce n'est pas une erreur : avoir un locator par d�faut est optionnel.
defaultLocator = null;
}
// Constructeur du locator.
Constructor<ILocator> locatorConstructor;
try {
locatorConstructor = locatorClass.getConstructor(String.class, ResourceBundle.class, ILocator.class);
} catch (SecurityException e) {
e.printStackTrace();
throw new LocatorException(
"Error : access to the constructor of " + locatorClassName
+ " with parameters String, ResourceBundle, Locator forbidden. Cause : " + e.getMessage(), e);
} catch (NoSuchMethodException e) {
e.printStackTrace();
throw new LocatorException(
"Error : the locator " + locatorClassName
+ " has no constructor with parameters String, ResourceBundle, Locator forbidden. Cause : " + e.getMessage(), e);
}
// Instanciation du locator.
ILocator locator;
try {
locator = locatorConstructor.newInstance(configFileName, configFile, defaultLocator);
} catch (IllegalArgumentException e) {
e.printStackTrace();
throw new LocatorException(
"Error " + e.getClass().getSimpleName()
+ " when initializing the locator " + locatorClassName + " : " + e.getMessage(), e);
} catch (InstantiationException e) {
e.printStackTrace();
throw new LocatorException(
"Error " + e.getClass().getSimpleName()
+ " when initializing the locator " + locatorClassName + " : " + e.getMessage(), e);
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new LocatorException(
"Error " + e.getClass().getSimpleName()
+ " when initializing the locator " + locatorClassName + " : " + e.getMessage(), e);
} catch (InvocationTargetException e) {
e.printStackTrace();
throw new LocatorException(
"Error " + e.getClass().getSimpleName()
+ " when initializing the locator " + locatorClassName + " : " + e.getMessage(), e);
}
log.debug("Initialization of the locator " + locator.getClass().getCanonicalName()