![JAR search and dependency download from the Maven repository](/logo.png)
org.coos.messaging.android.AndroidCOContainer Maven / Gradle / Ivy
The newest version!
/**
* COOS - Connected Objects Operating System (www.connectedobjects.org).
*
* Copyright (C) 2009 Telenor ASA and Tellu AS. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* You may also contact one of the following for additional information:
* Telenor ASA, Snaroyveien 30, N-1331 Fornebu, Norway (www.telenor.no)
* Tellu AS, Hagalokkveien 13, N-1383 Asker, Norway (www.tellu.no)
*/
package org.coos.messaging.android;
import java.io.IOException;
import java.io.InputStream;
import org.coos.messaging.COContainer;
import org.coos.messaging.Plugin;
import org.coos.messaging.jmx.ManagementFactory;
import android.app.Application;
import android.content.res.Configuration;
/**
* This COOS container is an Android Application object. It is created at
* application startup, with the first Activity, and will live on even after all
* Activities are gone. We can't remove the Application programatically, so we
* may want to create and remove the COOS contents based on the coming and going
* of activities. Therefore the AndroidCOContainer does not start itself - the
* initial Activity should call the start and stop methods.
*
* This container will contain a single plugin, configured by the method setPluginParams.
*
* @author Lars Thomas Boye, Tellu AS
*/
public class AndroidCOContainer extends Application implements COContainer {
String pluginName;
String endpointClassName;
String hostIp;
String hostPort;
Plugin plugin;
// ***************** COContainer methods *****************
/**
* @return null
*/
public Object getObject(String name) {
return null;
}
/**
* TODO: Not yet implemented
*/
public InputStream getResource(String resourceName) throws IOException {
/*
InputStream is = null;
String baseName;
if (resourceName.isEmpty()) {
return null;
}
if (resourceName.startsWith("/")) {
baseName = resourceName.substring(1);
} else {
baseName = resourceName;
resourceName = "/" + resourceName;
}
*/
return null;
}
@SuppressWarnings("unchecked")
public Class loadClass(String className) throws ClassNotFoundException {
return Class.forName(className);
}
/**
* Call to start the container. A plugin is created and started based on
* parameters set with setPluginParams. Should be called from the startup
* of the initial Activity.
*/
public void start() throws Exception {
//String configDir = "file:///android_asset";
ManagementFactory.setManagementServiceImplClass("org.coos.messaging.android.AndroidManagementServiceImpl");
plugin = PluginFactory.createPluginWithTCPTransport(pluginName, endpointClassName, null, null, hostIp, hostPort, this);
plugin.connect();
}
/**
* Call to stop and remove any COOS content (plugins). Should be called
* to terminate the application, when removing the initial Activity.
*/
public void stop() {
if (plugin!= null) {
plugin.disconnect();
plugin = null;
}
}
// ***************** Android Application methods *****************
/**
* Called on application startup, before the first Activity is started.
* Can do any needed initialization. Does not start the COOS contents -
* the initial Android Activity should call start.
*/
public void onCreate() {
super.onCreate();
}
/**
* Called by the Android system when the application is stopping, after all
* activities are stopped. It stops the COOS contents.
*
* @inheritDoc
*/
public void onTerminate() {
stop();
super.onTerminate();
}
public void onLowMemory() {
super.onLowMemory();
}
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
// ***************** New methods *****************
/**
* Configure the plugin to start. Must be done before calling start.
*/
public void setPluginParams(String name, String endpointClassName, String hostIp, String port) {
pluginName = name;
this.endpointClassName = endpointClassName;
this.hostIp = hostIp;
hostPort = port;
}
/**
* @return The plugin running in this container
*/
public Plugin getPlugin() {
return plugin;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy