-------------------------------------------------------------------------------------------------------------
Java Code:
-------------------------------------------------------------------------------------------------------------
import java.util.HashMap;
import java.util.Map;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
public class PropertyReader {
public static final String MESSAGE_FILE = "com.wil.util.Messages";
public static final String DB_PRECEDURE_FILE = "com.wil.util.DBProcedures";
private static PropertyReader propReader = new PropertyReader();
private Map<String,PropertyResourceBundle> bundles = new HashMap<String,PropertyResourceBundle>();
private PropertyReader(){
}
public static PropertyReader getInstance(){
return propReader;
}
public String getMessage(String bundleName, String messagekey){
PropertyResourceBundle propertyResBd = bundles.get(bundleName);
if(propertyResBd == null){
propertyResBd = (PropertyResourceBundle) ResourceBundle.getBundle(bundleName);
bundles.put(bundleName, propertyResBd);
}
return propertyResBd.getString(messagekey);
}
}
-------------------------------------------------------------------------------------------------------------
Use :
-------------------------------------------------------------------------------------------------------------
PropertyReader messagesReader = PropertyReader.getInstance();
String errMessage = messagesReader.getMessage(PropertyReader.MESSAGE_FILE,"name_cannot_empty");
String dbMessage = messagesReader.getMessage(PropertyReader.DB_PRECEDURE_FILE,"name_cannot_empty");
-------------------------------------------------------------------------------------------------------------
Place properties files into "com.wilbert.util" package :
-------------------------------------------------------------------------------------------------------------
Messages.properties
name_cannot_empty=Name cannot be empty
DBProcedures.properties
#SchemaName
SchemaName=TESTDB
Java Code:
-------------------------------------------------------------------------------------------------------------
import java.util.HashMap;
import java.util.Map;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
public class PropertyReader {
public static final String MESSAGE_FILE = "com.wil.util.Messages";
public static final String DB_PRECEDURE_FILE = "com.wil.util.DBProcedures";
private static PropertyReader propReader = new PropertyReader();
private Map<String,PropertyResourceBundle> bundles = new HashMap<String,PropertyResourceBundle>();
private PropertyReader(){
}
public static PropertyReader getInstance(){
return propReader;
}
public String getMessage(String bundleName, String messagekey){
PropertyResourceBundle propertyResBd = bundles.get(bundleName);
if(propertyResBd == null){
propertyResBd = (PropertyResourceBundle) ResourceBundle.getBundle(bundleName);
bundles.put(bundleName, propertyResBd);
}
return propertyResBd.getString(messagekey);
}
}
-------------------------------------------------------------------------------------------------------------
Use :
-------------------------------------------------------------------------------------------------------------
PropertyReader messagesReader = PropertyReader.getInstance();
String errMessage = messagesReader.getMessage(PropertyReader.MESSAGE_FILE,"name_cannot_empty");
String dbMessage = messagesReader.getMessage(PropertyReader.DB_PRECEDURE_FILE,"name_cannot_empty");
-------------------------------------------------------------------------------------------------------------
Place properties files into "com.wilbert.util" package :
-------------------------------------------------------------------------------------------------------------
Messages.properties
name_cannot_empty=Name cannot be empty
DBProcedures.properties
#SchemaName
SchemaName=TESTDB