Android Open Source - droidBBpush Application Listener






From Project

Back to project page droidBBpush.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project droidBBpush listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.arg3.examples.push;
//from  w w  w. j av a  2s .  c o m
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import dagger.ObjectGraph;

/**
 * Created by c0der78 on 2014-09-27.
 */
public class ApplicationListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {

        initObjectGraph(sce.getServletContext());

        initDatabase(sce.getServletContext());
    }

    private static void initObjectGraph(ServletContext context) {
        Object[] modules = new Object[]{
                new MainModule(context)
        };

        ObjectGraph mObjectGraph = ObjectGraph.create(modules);

        context.setAttribute(ObjectGraph.class.getName(), mObjectGraph);

    }

    private static void initDatabase(ServletContext context) {

        try {
            Class.forName("org.hsqldb.jdbcDriver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace(System.out);
        }
        try {
            Connection connection = DriverManager.getConnection("jdbc:hsqldb:exampledb", "SA", "");

            initSqlConnection(connection);

            context.setAttribute(Connection.class.getName(), connection);

        } catch (SQLException e) {
            e.printStackTrace(System.out);
        }

    }

    private static void initSqlConnection(Connection connection) throws SQLException {
        Statement stmt = null;

        try {
            stmt = connection.createStatement();

            stmt.executeUpdate("create table if not exists devices (id integer generated by default as identity primary key, type varchar(45) not null, token varchar(1024) not null)");
        } finally {
            if (stmt != null)
                stmt.close();
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        Connection connection = (Connection) sce.getServletContext().getAttribute(Connection.class.getName());

        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}




Java Source Code List

com.arg3.droid.bbpush.ApplicationTest.java
com.arg3.examples.droidbb.MainActivity.java
com.arg3.examples.droidbb.MainApplication.java
com.arg3.examples.droidbb.MainModule.java
com.arg3.examples.droidbb.PushNotifier.java
com.arg3.examples.droidbb.PushRegistrar.java
com.arg3.examples.droidbb.PushService.java
com.arg3.examples.droidbb.annotations.ForApplication.java
com.arg3.examples.droidbb.gcm.GCMBroadcastReceiver.java
com.arg3.examples.droidbb.gcm.GCMBroadcastReceiver.java
com.arg3.examples.droidbb.gcm.GCMHandler.java
com.arg3.examples.droidbb.gcm.GCMHandler.java
com.arg3.examples.droidbb.gcm.GCMIntentService.java
com.arg3.examples.droidbb.gcm.GCMIntentService.java
com.arg3.examples.push.AndroidPushService.java
com.arg3.examples.push.ApplicationListener.java
com.arg3.examples.push.BaseServlet.java
com.arg3.examples.push.BlackberryPushService.java
com.arg3.examples.push.MainModule.java
com.arg3.examples.push.PushServlet.java
com.arg3.examples.push.SendServlet.java
com.arg3.examples.push.ViewServlet.java
com.arg3.examples.push.api.BaseAPIServlet.java
com.arg3.examples.push.api.RegisterDeviceServlet.java
com.arg3.examples.push.dao.DeviceDAO.java
com.arg3.examples.push.enums.DeviceType.java
com.arg3.examples.push.model.Device.java