/* * Server.java * ----------- * * Part of the URY Server Platform * * V0.00 2011/03/20 * * (C) 2011 URY Computing */ package uk.org.ury.backend.server; import java.io.IOException; import uk.org.ury.backend.config.ConfigReader; import uk.org.ury.backend.database.DatabaseDriver; import uk.org.ury.backend.database.UserClass; import uk.org.ury.backend.database.exceptions.ConnectionFailureException; import uk.org.ury.backend.database.exceptions.MissingCredentialsException; /** * The unified URY server, accepting requests over HTTP. * * @author Matt Windsor * @version 2011.0320 */ public class Server { public static final String SERVER_VERSION = "SLUT 0.0"; public static final String DOCTYPE = ""; public static final String INDEX_HTML = "\n" + "\n " + "\n " + SERVER_VERSION + "" + "\n " + "\n " + "\n

Welcome to the " + SERVER_VERSION + " server

" + "\n

This server exposes a class-based API for accessing" + "\n the internals of the " + SERVER_VERSION + " system.

" + "\n

See the documentation for details.

" + "\n " + "\n"; /** * The main method, which serves to create a server. * * @param args * The argument vector. */ public static void main(String[] args) { Server srv = new Server(); srv.run(); } /** * Run the server. */ private void run() { Thread thread = null; try { thread = new HttpListenerThread(8000, this); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } thread.setDaemon(false); thread.run(); } /** * Gets a database connection using the given user class. * * @param userClass * The user class to get a connection for. * * @return a database connection, which may or may not have been created on * this call. * * @throws MissingCredentialsException * if the credentials for the given userclass are missing. * * @throws ConnectionFailureException * if the connection failed. */ public DatabaseDriver getDatabaseConnection(UserClass userClass) throws MissingCredentialsException, ConnectionFailureException { // TODO: Singleton ConfigReader config = new ConfigReader("res/conf.xml"); return new DatabaseDriver(config, UserClass.READ_ONLY); } /** * @return the version string of the server. */ public String getVersion() { return SERVER_VERSION; } }