2 * DemosceneMusic - Core.java - Copyright © 2012 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.demoscenemusic.core;
20 import javax.naming.Context;
21 import javax.naming.InitialContext;
22 import javax.naming.NamingException;
23 import javax.servlet.ServletContextEvent;
24 import javax.servlet.ServletContextListener;
25 import javax.sql.DataSource;
27 import net.pterodactylus.demoscenemusic.data.DataManager;
28 import net.pterodactylus.util.database.AbstractDatabase;
29 import net.pterodactylus.util.database.Database;
31 import org.openid4java.consumer.ConsumerManager;
36 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
38 public class Core implements ServletContextListener {
40 private DataManager dataManager;
42 private final ConsumerManager consumerManager = new ConsumerManager();
44 public DataManager getDataManager() {
49 * @return the consumerManager
51 public ConsumerManager getConsumerManager() {
52 return consumerManager;
56 // SERVLETCONTEXTLISTENER METHODS
63 public void contextInitialized(ServletContextEvent servletContextEvent) {
64 servletContextEvent.getServletContext().setAttribute("core", this);
66 Context context = new InitialContext();
67 DataSource dataSource = (DataSource) context.lookup("java:/comp/env/jdbc/demosceneMusic");
68 Database database = AbstractDatabase.fromDataSource(dataSource);
69 dataManager = new DataManager(database);
70 servletContextEvent.getServletContext().setAttribute("dataManager", dataManager);
71 } catch (NamingException ne1) {
72 servletContextEvent.getServletContext().log("Could not create database connection.", ne1);
80 public void contextDestroyed(ServletContextEvent arg0) {