Package net.homeip.mleclerc.omnilinkbbclient.model

Source Code of net.homeip.mleclerc.omnilinkbbclient.model.SystemModel

package net.homeip.mleclerc.omnilinkbbclient.model;

import java.rmi.RemoteException;

import net.homeip.mleclerc.omnilinkbbclient.OmniLinkBBClient;
import net.homeip.mleclerc.omnilinkbbclient.stubs.AegisWebService;
import net.homeip.mleclerc.omnilinkbbclient.stubs.BasicUnitControl;
import net.homeip.mleclerc.omnilinkbbclient.stubs.EventLogResponse;
import net.homeip.mleclerc.omnilinkbbclient.stubs.PhoneLineStatus;
import net.homeip.mleclerc.omnilinkbbclient.stubs.SecurityMode;
import net.homeip.mleclerc.omnilinkbbclient.stubs.SystemStatus;
import net.homeip.mleclerc.omnilinkbbclient.stubs.SystemStatusResponse;

public class SystemModel {
  private AegisWebService client;
  private SystemStatusResponse cachedSystemStatus;
 
  public SystemModel(AegisWebService client) {
    this.client = client;
  }
 
  public long getDate() {
    return getSystemStatusResponse().getDate();
  }
 
  public long getSunrise() {
    return getSystemStatusResponse().getSunrise();
  }
 
  public long getSunset() {
    return getSystemStatusResponse().getSunset();
  }
 
  public PhoneLineStatus getPhoneLineStatus() {
    return getSystemStatusResponse().getPhoneLineStatus();
  }
 
  public SystemStatus getSystemStatus() {
    return getSystemStatusResponse().getSystemStatus();
  }

  public SecurityMode getSecurityMode() {
    return getSystemStatusResponse().getSecurityMode();
  }
 
  public EventLogResponse[] getEventLog(final boolean download) {
    try {
      return (EventLogResponse[]) OmniLinkBBClient.execute(new OmniLinkBBClient.Execution() {
        public Object execute() throws RemoteException {
          return client.getEventLog(download);
        }
      });
    } catch(OmniLinkBBClient.ExecutionException ex) {
      return new EventLogResponse[0];
   
  }
 
  public boolean setSecurityMode(final SecurityMode securityMode) {
    try {
      return OmniLinkBBClient.execute(new OmniLinkBBClient.BoolExecution() {
        public boolean boolExecute() throws RemoteException {
          return client.setSecurity(securityMode);
        }
      });
    } catch(OmniLinkBBClient.ExecutionException ex) {
      return false;
   
  }
 
  public boolean setAllUnitsControl(final BasicUnitControl control) {
    try {
      return OmniLinkBBClient.execute(new OmniLinkBBClient.BoolExecution() {
        public boolean boolExecute() throws RemoteException {
          return client.setAllUnitsControl(control);
        }
      });
    } catch(OmniLinkBBClient.ExecutionException ex) {
      return false;
   
  }
 
  public void reset() {
    cachedSystemStatus = null;
  }
 
  private SystemStatusResponse getSystemStatusResponse() {
    if (cachedSystemStatus == null) {     
      try {
        cachedSystemStatus = (SystemStatusResponse) OmniLinkBBClient.execute(new OmniLinkBBClient.Execution() {
          public Object execute() throws RemoteException {
            return client.getSystemStatus();
          }
        });
      } catch(OmniLinkBBClient.ExecutionException ex) {
        cachedSystemStatus = new SystemStatusResponse();
     
    }
   
    return cachedSystemStatus;
  }
}
TOP

Related Classes of net.homeip.mleclerc.omnilinkbbclient.model.SystemModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.