/**
 * 
 */
package com.redv.jplanet;

import java.io.File;
import java.io.IOException;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.redv.jplanet.conf.ConfigReader;
import com.redv.jplanet.conf.ConfigWriter;

/**
 * @author sutra
 * 
 */
public class Constant {
	private static final Log log = LogFactory.getLog(Constant.class);

	private static File dataDir;

	private static ConfigReader configReader;

	private static ConfigWriter configWriter;

	private static long aggregatorConfigTimerPeriod;

	static {
		Properties p = new Properties();
		try {
			p.load(Constant.class.getResourceAsStream("/jplanet.properties"));
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		aggregatorConfigTimerPeriod = Long.parseLong(p
				.getProperty("aggregator.configTimer.period"));
		String confDir = replaceSystemProperty(p.getProperty("conf.dir"));
		log.debug("confDir: " + confDir);
		dataDir = new File(confDir);
		try {
			configReader = (ConfigReader) Class.forName(
					p.getProperty("conf.reader")).newInstance();
			configWriter = (ConfigWriter) Class.forName(
					p.getProperty("conf.writer")).newInstance();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static File getDataDir() {
		return dataDir;
	}

	public static long getAggregatorConfigTimerPeriod() {
		return aggregatorConfigTimerPeriod;
	}

	public static ConfigReader getConfigReader() {
		return configReader;
	}

	public static ConfigWriter getConfigWriter() {
		return configWriter;
	}

	private static String replaceSystemProperty(final String orginalString) {
		String ret = new String(orginalString);
		int dollarIndex = ret.indexOf('$');
		while (dollarIndex != -1) {
			String var = orginalString.substring(
					orginalString.indexOf('{') + 1, orginalString.indexOf('}'));
			log.debug("var: " + var);
			ret = StringUtils.replace(orginalString, String.format("${%1$s}",
					var), System.getProperty(var));
			dollarIndex = orginalString.indexOf('$', dollarIndex + 1);
		}
		return ret;
	}
}

@@ -332,16 +332,46 @@
 r;%0A%0A/**%0A
+ * Constants for JPlanet.%0A * %0A
  * @auth
@@ -377,13 +377,18 @@
 hor 
-s
+S
 utra
+ Zhou
 %0A * 
@@ -1357,63 +1357,232 @@
 %7D%0A%0A%09
-public static File getDataDir() %7B%0A%09%09return dataDir;%0A%09%7D%0A
+/**%0A%09 * Return the data directory of configuration etc.%0A%09 * %0A%09 * @return%0A%09 */%0A%09public static File getDataDir() %7B%0A%09%09return dataDir;%0A%09%7D%0A%0A%09/**%0A%09 * Return the config timer (to refresh fetcher timer) period.%0A%09 * %0A%09 * @return%0A%09 */
 %0A%09pu
@@ -1671,24 +1671,77 @@
 Period;%0A%09%7D%0A%0A
+%09/**%0A%09 * Return config reader.%0A%09 * %0A%09 * @return%0A%09 */%0A
 %09public stat
@@ -1803,16 +1803,69 @@
 er;%0A%09%7D%0A%0A
+%09/**%0A%09 * Return config writer.%0A%09 * %0A%09 * @return%0A%09 */%0A
 %09public 

Add comments to Constant.java.