/**
* HelloWorld.java
* Copyright (C) 2001-2003 Research In Motion Limited. All rights reserved.
*/
package net.homeip.mleclerc.omnilinkbbclient;
import java.rmi.RemoteException;
import net.homeip.mleclerc.omnilinkbbclient.category.ButtonCategory;
import net.homeip.mleclerc.omnilinkbbclient.category.InformationCategory;
import net.homeip.mleclerc.omnilinkbbclient.category.MessageCategory;
import net.homeip.mleclerc.omnilinkbbclient.category.SystemCategory;
import net.homeip.mleclerc.omnilinkbbclient.category.ThermostatCategory;
import net.homeip.mleclerc.omnilinkbbclient.category.UnitCategory;
import net.homeip.mleclerc.omnilinkbbclient.category.ZoneCategory;
import net.homeip.mleclerc.omnilinkbbclient.model.ButtonModel;
import net.homeip.mleclerc.omnilinkbbclient.model.InformationModel;
import net.homeip.mleclerc.omnilinkbbclient.model.MessageModel;
import net.homeip.mleclerc.omnilinkbbclient.model.SystemModel;
import net.homeip.mleclerc.omnilinkbbclient.model.ThermostatModel;
import net.homeip.mleclerc.omnilinkbbclient.model.UnitModel;
import net.homeip.mleclerc.omnilinkbbclient.model.ZoneModel;
import net.homeip.mleclerc.omnilinkbbclient.resources.OmniLinkClientResource;
import net.homeip.mleclerc.omnilinkbbclient.stubs.AegisWebService_Stub;
import net.rim.device.api.i18n.ResourceBundle;
import net.rim.device.api.ui.UiApplication;
public class OmniLinkBBClient extends UiApplication {
private final static String WEBSERVICE_ADDR = getString(OmniLinkClientResource.WEB_SERVICE_URL);
//private final static String WEBSERVICE_ADDR = "http://cpe000f66256165-cm001225d879c8.cpe.net.cable.rogers.com/aegiswebservice/aegiswebservice";
public void run(String[] args) {
AegisWebService_Stub client = new AegisWebService_Stub();
client._setProperty(AegisWebService_Stub.ENDPOINT_ADDRESS_PROPERTY, WEBSERVICE_ADDR);
client._setProperty(AegisWebService_Stub.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
SystemModel systemModel = new SystemModel(client);
ThermostatModel thermostatModel = new ThermostatModel(client);
MessageModel messageModel = new MessageModel(client);
ButtonModel buttonModel = new ButtonModel(client);
UnitModel unitModel = new UnitModel(client);
ZoneModel zoneModel = new ZoneModel(client);
InformationModel infoModel = new InformationModel(client);
final OmniLinkBBClientScreen screen = new OmniLinkBBClientScreen();
screen.addCategory(new SystemCategory(systemModel));
screen.addCategory(new ThermostatCategory(thermostatModel));
screen.addCategory(new MessageCategory(messageModel, infoModel));
screen.addCategory(new ButtonCategory(buttonModel));
screen.addCategory(new UnitCategory(unitModel));
screen.addCategory(new ZoneCategory(zoneModel));
screen.addCategory(new InformationCategory(infoModel, systemModel));
pushScreen(screen);
enterEventDispatcher();
}
public static String getString(int resourceKey) {
ResourceBundle resBundle = ResourceBundle.getBundle(OmniLinkClientResource.BUNDLE_NAME);
return resBundle.getString(resourceKey);
}
public static void main(String[] args) {
OmniLinkBBClient app = new OmniLinkBBClient();
app.run(args);
}
private static class ObjectHolder {
private Object object;
public void setObject(Object object) {
this.object = object;
}
public Object getObject() {
return object;
}
}
public static interface Execution {
Object execute() throws RemoteException;
}
public static abstract class BoolExecution implements Execution {
protected abstract boolean boolExecute() throws RemoteException;
public Object execute() throws RemoteException {
boolean ret = boolExecute();
return new Boolean(ret);
}
}
public static class ExecutionException extends Exception {
}
private final static long TIMEOUT = 10 * 1000;
public static boolean execute(BoolExecution execute) throws ExecutionException {
Boolean ret = (Boolean) execute((Execution) execute);
return ret.booleanValue();
}
public static Object execute(final Execution execute) throws ExecutionException {
final ObjectHolder holder = new ObjectHolder();
Runnable runnable = new Runnable() {
public void run() {
synchronized(holder) {
try {
Object object = execute.execute();
holder.setObject(object);
} catch(RemoteException ex) {
holder.setObject(null);
}
holder.notify();
}
}
};
Thread thread = new Thread(runnable);
thread.start();
synchronized(holder) {
Object object = holder.getObject();
if (object != null) {
return object;
} else {
try { holder.wait(TIMEOUT); } catch(InterruptedException ex) { }
object = holder.getObject();
if (object != null) {
return object;
} else {
throw new ExecutionException();
}
}
}
}
}