E
El Durango
I am having problems with initializing runtime constants.
Basically I have a config file but would like the value data to be assigned
to a constant rather than an instance variable.
I tried the following code but it is not working there are 3 files pasted
here:
package proptest;
import java.util.*;
import java.io.*;
public class PropertyInitializer{
String CONFIGFILENAME = "ixmlsysinfo.config";
private static Properties props = new Properties();
FileInputStream fis = null;
PropertyInitializer(){
try{
fis = new FileInputStream(CONFIGFILENAME);
props.load(fis);
}
catch(FileNotFoundException fnf){
// stump
}
catch(IOException ioe){
// stump
}
}
public static String confValue(String key){
String propVal = props.getProperty(key);
return propVal;
}
}
package proptest;
public interface PropertyInfo
{
public static final String CONFIGPATH =
PropertyInitializer.confValue("ConfigPath");
public static final String RTFPATH =
PropertyInitializer.confValue("RTFDir");
public static final String XMLPATH =
PropertyInitializer.confValue("ProcedurePath");
public static final String IPVPATH =
PropertyInitializer.confValue("IPVPath");
public static final String IPVURL =
PropertyInitializer.confValue("IPVUrl");
public static final String XSLFILEPATH =
PropertyInitializer.confValue("XSLFilePath");
public static final int INTVALUE = (int)Math.random();
}
import proptest.PropertyInfo;
public class PropertyDriver implements PropertyInfo{
public static void main(String[] args){
System.out.println("CONFIGPATH: "+CONFIGPATH);
System.out.println("RTFPATH: "+RTFPATH);
System.out.println("XMLPATH: "+XMLPATH);
System.out.println("IPVPATH: "+IPVPATH);
System.out.println("IPVURL: "+IPVURL);
System.out.println("XSLFILEPATH: "+XSLFILEPATH);
System.out.println("INTVALUE: "+INTVALUE);
}
}
The reason I would like to keep it like this is I would like to reference
these variables like a global const by implementing the interface on the
classes that call these constants.
If anyone has a good suggestion I would appreciate it.
thank you for your assistance.
Basically I have a config file but would like the value data to be assigned
to a constant rather than an instance variable.
I tried the following code but it is not working there are 3 files pasted
here:
package proptest;
import java.util.*;
import java.io.*;
public class PropertyInitializer{
String CONFIGFILENAME = "ixmlsysinfo.config";
private static Properties props = new Properties();
FileInputStream fis = null;
PropertyInitializer(){
try{
fis = new FileInputStream(CONFIGFILENAME);
props.load(fis);
}
catch(FileNotFoundException fnf){
// stump
}
catch(IOException ioe){
// stump
}
}
public static String confValue(String key){
String propVal = props.getProperty(key);
return propVal;
}
}
package proptest;
public interface PropertyInfo
{
public static final String CONFIGPATH =
PropertyInitializer.confValue("ConfigPath");
public static final String RTFPATH =
PropertyInitializer.confValue("RTFDir");
public static final String XMLPATH =
PropertyInitializer.confValue("ProcedurePath");
public static final String IPVPATH =
PropertyInitializer.confValue("IPVPath");
public static final String IPVURL =
PropertyInitializer.confValue("IPVUrl");
public static final String XSLFILEPATH =
PropertyInitializer.confValue("XSLFilePath");
public static final int INTVALUE = (int)Math.random();
}
import proptest.PropertyInfo;
public class PropertyDriver implements PropertyInfo{
public static void main(String[] args){
System.out.println("CONFIGPATH: "+CONFIGPATH);
System.out.println("RTFPATH: "+RTFPATH);
System.out.println("XMLPATH: "+XMLPATH);
System.out.println("IPVPATH: "+IPVPATH);
System.out.println("IPVURL: "+IPVURL);
System.out.println("XSLFILEPATH: "+XSLFILEPATH);
System.out.println("INTVALUE: "+INTVALUE);
}
}
The reason I would like to keep it like this is I would like to reference
these variables like a global const by implementing the interface on the
classes that call these constants.
If anyone has a good suggestion I would appreciate it.
thank you for your assistance.