aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Lasseter <nathan.je.lasseter@googlemail.com>2011-02-20 14:23:52 +0000
committerNathan Lasseter <nathan.je.lasseter@googlemail.com>2011-02-20 14:23:52 +0000
commit1873252f1ec11794092dcaedaed477afc0572da7 (patch)
tree6e1e7fb41122dc49b344f2ff0ed089d942903268
parent904caa25f8de49cc20823a25ce8051dfdcae7c26 (diff)
Comment, comment, comment! Shout at me if i dont comment. I tend not to.
-rw-r--r--res/conf.xml5
-rw-r--r--src/uk/org/ury/config/Auth.java26
-rw-r--r--src/uk/org/ury/config/ConfigReader.java26
-rw-r--r--src/uk/org/ury/config/Database.java26
4 files changed, 80 insertions, 3 deletions
diff --git a/res/conf.xml b/res/conf.xml
index 215695c..3665cb1 100644
--- a/res/conf.xml
+++ b/res/conf.xml
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ At the moment the database and auth tags do nothing.
+ Only the first of each tag is read. Proceeding tags are ignored.
+-->
+
<config version="1.0" >
<database>
diff --git a/src/uk/org/ury/config/Auth.java b/src/uk/org/ury/config/Auth.java
index ff22c12..d68fc55 100644
--- a/src/uk/org/ury/config/Auth.java
+++ b/src/uk/org/ury/config/Auth.java
@@ -2,16 +2,42 @@ package uk.org.ury.config;
import uk.org.ury.database.UserClass;
+/**
+ * A login authorisation configuration
+ *
+ * @author Nathan
+ */
public class Auth {
private String user;
private String pass;
private UserClass type;
+ /**
+ * Get the username of the login
+ *
+ * @return String username
+ */
public String getUser() { return user; }
+ /**
+ * Get the password of the login
+ *
+ * @return String password
+ */
public String getPass() { return pass; }
+ /**
+ * Get the access level of the login
+ *
+ * @return UserClass type
+ */
public UserClass getType() { return type; }
+ /**
+ * Create a login auth object
+ * @param user The username for the login
+ * @param pass The password for the login
+ * @param type The access type for the login
+ */
public Auth(String user, String pass, UserClass type) {
this.user = user;
this.pass = pass;
diff --git a/src/uk/org/ury/config/ConfigReader.java b/src/uk/org/ury/config/ConfigReader.java
index 6b66e24..6166ec4 100644
--- a/src/uk/org/ury/config/ConfigReader.java
+++ b/src/uk/org/ury/config/ConfigReader.java
@@ -10,24 +10,44 @@ import org.xml.sax.SAXParseException;
import uk.org.ury.database.UserClass;
+/**
+ * Reads in an XML config file and creates config objects
+ *
+ * @author Nathan
+ */
public class ConfigReader {
private Database database;
private Auth auth;
+ /**
+ * Get the database configuration
+ *
+ * @return Database database
+ */
public Database getDatabase() { return database; }
+ /**
+ * Get the login auth configuration
+ *
+ * @return Auth auth
+ */
public Auth getAuth() { return auth; }
+ /**
+ * Read in the config file and create the Database and Auth configuration objects.
+ */
public ConfigReader() {
+ new ConfigReader("res/conf.xml");
+ }
+
+ public ConfigReader(String configFile) {
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
- Document doc = docBuilder.parse (new File("res/conf.xml"));
+ Document doc = docBuilder.parse (new File(configFile));
doc.getDocumentElement().normalize();
- System.out.println(doc.getDocumentElement().getNodeName());
-
String user = doc.getElementsByTagName("user").item(0).getTextContent();
String pass = doc.getElementsByTagName("pass").item(0).getTextContent();
UserClass type;
diff --git a/src/uk/org/ury/config/Database.java b/src/uk/org/ury/config/Database.java
index c1074df..a82f775 100644
--- a/src/uk/org/ury/config/Database.java
+++ b/src/uk/org/ury/config/Database.java
@@ -1,15 +1,41 @@
package uk.org.ury.config;
+/**
+ * A Database Server configuration
+ *
+ * @author Nathan
+ */
public class Database {
private String host;
private int port;
private String db;
+ /**
+ * Get the hostname of the database server
+ *
+ * @return String hostname
+ */
public String getHost() { return host; }
+ /**
+ * Get the port the database server is running on
+ *
+ * @return int port
+ */
public int getPort() { return port; }
+ /**
+ * Get the name of the database
+ *
+ * @return String database name
+ */
public String getDb() { return db; }
+ /**
+ * Create a database object
+ * @param host The hostname of the database server
+ * @param port The port that the database server listens on
+ * @param db The name of the database on the server
+ */
public Database(String host, int port, String db) {
this.host = host;
this.port = port;