ebourg 2004/09/23 04:49:45
Modified: configuration/src/java/org/apache/commons/configuration
AbstractFileConfiguration.java
Log:
Implemented setFileName(), getFile(), setURL()
More javadoc
Revision Changes Path
1.3 +25 -12
jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
Index: AbstractFileConfiguration.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractFileConfiguration.java 22 Sep 2004 17:29:08 -0000 1.2
+++ AbstractFileConfiguration.java 23 Sep 2004 11:49:45 -0000 1.3
@@ -17,6 +17,7 @@
package org.apache.commons.configuration;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -26,12 +27,9 @@
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
-import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;
-import org.apache.commons.lang.NotImplementedException;
-
/**
* Partial implementation of the <code>FileConfiguration</code> interface.
* Developpers of file based configuration may wan't to extend this class,
@@ -203,7 +201,8 @@
}
/**
- * Save the configuration to the specified file.
+ * Save the configuration to the specified file. This doesn't change the
+ * source of the configuration, use setFileName() if you need it.
*
* @param fileName
*
@@ -228,6 +227,8 @@
/**
* Save the configuration to the specified URL if it's a file URL.
+ * This doesn't change the source of the configuration, use setURL()
+ * if you need it.
*
* @param url
*
@@ -242,7 +243,8 @@
}
/**
- * Save the configuration to the specified file.
+ * Save the configuration to the specified file. This doesn't change the
+ * source of the configuration, use setFile() if you need it.
*
* @param file
*
@@ -338,6 +340,9 @@
public void setFileName(String fileName)
{
this.fileName = fileName;
+
+ // update the URL
+ url = ConfigurationUtils.locate(basePath, fileName);
}
/**
@@ -365,8 +370,14 @@
*/
public File getFile()
{
- // todo: implement getFile();
- throw new NotImplementedException("coming soon!");
+ if (url != null && "file".equals(url.getProtocol()))
+ {
+ return new File(url.getFile());
+ }
+ else
+ {
+ return ConfigurationUtils.constructFile(getBasePath(), getFileName());
+ }
}
/**
@@ -380,14 +391,12 @@
{
try
{
- url = file.toURL();
+ setURL(file.toURL());
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
-
- // todo: update the filename and the basepath
}
else
{
@@ -412,6 +421,10 @@
{
this.url = url;
- // todo: update the filename and the basepath
+ // update the base path
+ basePath = ConfigurationUtils.getBasePath(url);
+
+ // update the file name
+ fileName = ConfigurationUtils.getFileName(url);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]