
package com.exedio.cope.lib;

import java.io.FileInputStream;
import java.io.IOException;

final class Properties
{
	private static Properties theInstance = null;
	
	static Properties getInstance()
	{
		if(theInstance!=null)
			return theInstance;
		
		theInstance = new Properties();
		return theInstance;
	}

	private static final String FILE_NAME = "cope.properties";
	
	private final String database;
	private final String driver;
	private final String url;
	private final String user;
	private final String password;

	private Properties()
	{
		final java.util.Properties properties = new java.util.Properties();
		FileInputStream stream = null;
		try
		{
			stream = new FileInputStream(FILE_NAME);
			properties.load(stream);
		}
		catch(IOException e)
		{
			throw new SystemException(e);
		}
		finally
		{
			if(stream!=null)
			{
				try
				{
					stream.close();
				}
				catch(IOException e) {}
			}
		}
		database = getPropertyNotNull(properties, "database");
		driver = getPropertyNotNull(properties, "database.driver");
		url = getPropertyNotNull(properties, "database.url");
		user = getPropertyNotNull(properties, "database.user");
		password = getPropertyNotNull(properties, "database.password");
	}
	
	private static String getPropertyNotNull(final java.util.Properties properties, final String key)
	{
		final String result = properties.getProperty(key);
		if(result==null)
		{
			final String m = "ERROR: property "+key+" in "+FILE_NAME+" not set.";
			System.out.println(m);
			throw new RuntimeException(m);
		}
		return result;
	}

	public String getDatabase()
	{
		return database;
	}

	public String getDriver()
	{
		return driver;
	}

	public String getUrl()
	{
		return url;
	}

	public String getUser()
	{
		return user;
	}

	public String getPassword()
	{
		return password;
	}

}

@@ -24,16 +24,37 @@
 e.lib;%0A%0A
+import java.io.File;%0A
 import j
@@ -633,16 +633,36 @@
 ties();%0A
+%09%09File file = null;%0A
 %09%09FileIn
@@ -696,16 +696,47 @@
 try%0A%09%09%7B%0A
+%09%09%09file = new File(FILE_NAME);%0A
 %09%09%09strea
@@ -759,25 +759,20 @@
 tStream(
-FILE_NAME
+file
 );%0A%09%09%09pr
@@ -855,16 +855,51 @@
 eption(e
+, file.getAbsolutePath().toString()
 );%0A%09%09%7D%0A%09

print absolute path of cope.properties, if error occurs