I've got a question about constants in a local interface of a bean that come from evaluation an expression. If I evaluate the expression ConfigurationManager.getInstance().getProperty("welcomeSMSTriggerEnabled"); during debugging then I get the string ENABLED. If I evaluate the constant variable using the call SMSMsgHandlerLocal.WELCOME_SMS_TRIGGER_ENABLED on the local interface, then I get the null value.
Can anyone help me with this "problem"? Does it also not work in a normal Java environment without J2EE?
/**
* @author Mark Noten <mark dot noten dot ext at siemens dot com>
* (c) 2005 SIEMENS AG
*/
package com.siemens.mobile.imc.core.imes;
import ...
public interface SMSMsgHandlerLocal extends EJBLocalObject {
public static final String WELCOME_SMS_TRIGGER_ENABLED = ConfigurationManager
.getInstance().getProperty("welcomeSMSTriggerEnabled");
public int createWelcomeMessage(String msisdn, String password)
throws ProtocolSenderException;
}
Best regards,
Mark
-
static final constants in local bean interface (2 messages)
- Posted by: Mark Noten
- Posted on: November 14 2005 07:44 EST
Threaded Messages (2)
- static final constants in local bean interface by Eric Bowman on November 14 2005 12:25 EST
- RE: static final constants in local bean interface by Mark Noten on November 15 2005 03:50 EST
-
static final constants in local bean interface[ Go to top ]
- Posted by: Eric Bowman
- Posted on: November 14 2005 12:25 EST
- in response to Mark Noten
Are you sure ConfigurationManager.getInstance() returns something that's ready to go the very first time it might be called when SMSMsgHandlerLocal has its statics initialized?
Have you checked for console output? If an exception is thrown while initializing statics, you'll probably see a stack trace in the console. -
RE: static final constants in local bean interface[ Go to top ]
- Posted by: Mark Noten
- Posted on: November 15 2005 03:50 EST
- in response to Eric Bowman
Here's the code of the ConfigurationManager class. When the getInstance method is called, it will return an unique instance or create a new. No exceptions are thrown. I just don't get it.
public class ConfigurationManager {
private static ConfigurationManager instance = null;
private static Properties imcProperties = null;
// TODO Get the config files URL from a system environment variable
private static final String CONFIG_FILES_URL = "config/MAGELLAN/configfiles.properties";
private static Logger logger = Logger.getLogger(ConfigurationManager.class);
private ConfigurationManager() {
init();
}
public static ConfigurationManager getInstance() {
if (instance == null) {
instance = new ConfigurationManager();
}
return instance;
}
public String getProperty(String key) {
if (!imcProperties.containsKey(key)) {
return null;
} else {
return imcProperties.getProperty(key).trim();
}
}
private static void init() {
imcProperties = new Properties();
InputStream inputStream = ConfigurationManager.class.getClassLoader()
.getResourceAsStream(ConfigurationManager.CONFIG_FILES_URL);
Properties configFilesProperties = new Properties();
try {
configFilesProperties.load(inputStream);
Enumeration configFilesKeys = configFilesProperties.keys();
while (configFilesKeys.hasMoreElements()) {
String propertiesFileURLKey = (String) configFilesKeys
.nextElement();
String propertiesFileURL = configFilesProperties
.getProperty(propertiesFileURLKey);
readPropertiesFromFile(propertiesFileURL);
}
} catch (IOException exc) {
logger
.error("Could not load properties file from imc/config/IMC210/configfiles.properties");
exc.printStackTrace();
}
}
private static void readPropertiesFromFile(String fileURL) {
InputStream inputStream = ConfigurationManager.class.getClassLoader()
.getResourceAsStream(fileURL);
Properties properties = new Properties();
try {
properties.load(inputStream);
imcProperties.putAll(properties);
} catch (IOException exc) {
logger
.error("Could not load properties file from " + fileURL
+ ".");
exc.printStackTrace();
}
}
}