Use only one Messages.java common for all the projects
virchete Jul 29, 2014 7:53 AMI was thinking about how to improve the Messages.java and try to simplify the code.
Firstly I have seen that in both dtgov and sramp, all the messages.java extends from a AbstractMessages file, property of dtgov and sramp respectively. OverlordCommons Messages files are different from sramp and dtgov.
In my opinion we can include this AbstractMessages in the overlord-commons-i18n project and modify sramp/dtgov/overlord commons to extend from this class.
The second option I was thinking about: removing all the Messages.java files, and have only one Messages file. You can notice the number of Messages.java files....
Right now, the way we call the Messages is:
Messages.i18n.format --> Messages.i18n is an static call and internally it knows where to find the messages.properties (in the same package than the Messages.java).
Then, if we have only one Messages.java file located in overlord-commons we need to find out where is the messages.properties, because we ll have different messages.properties, located in different packages.
My solution:
class Messages extends AbstractMessages{
public static final Messages i18n = new Messages();
public Messages() {
//With this instruction we get the caller class and then the package
//In the super class we will find out where is located the messages.properties
super(Reflection.getCallerClass(1));
}
}
public class AbstractMessages{
private static List<String> propertiesPaths;
static{
propertiesPaths=new ArrayList();
Set<PropertiesPathProvider> providers = ServiceRegistryUtil.getServices(PropertiesPathProvider.class);
//Here for every path provider, sramp, dtgov, overlord commons we ll load the paths defined by them
for(PropertiesPathProvider providerroviders){
propertiesPaths.addAll(provider.getPropertiesPaths());
}
}
public AbstractMessages(String packagePath){
//Here we try to find the properties path that matches better the packagePath
}
}
This is only a pseudocode. Then we only need one PropertiesPathProvider class in every subproject, sramp, dtgov, overlord-commons and dtgov.
Every time we want to include for a project a messages.properties we should include a messages.properties in src/main/resource/{package} and include an entry in the PropertiesPathProvider.