Java Object System Service

Problem this snippet solves:

This class is part of the "Java iControl Objects" series of Articles on DevCentral. This class creates a Service object and allows a developer to interact with the iControl System Services API methods in the context of using an object.

Code :

package iControl.Objects.System;

public class Service {
  private iControl.Interfaces _interfaces = null;
  private iControl.SystemServicesServiceType _type =
    iControl.SystemServicesServiceType.SERVICE_UNKNOWN;

  //-----------------------------------------------------------------------
  // Member Accessors
  //-----------------------------------------------------------------------
  public iControl.Interfaces getInterfaces() { return _interfaces; }
  public void setInterfaces(iControl.Interfaces interfaces) { _interfaces = interfaces; }

  public iControl.SystemServicesServiceType getType() { return _type;  }
  public void setType(iControl.SystemServicesServiceType type) { _type = type; }
  
  //-----------------------------------------------------------------------
  // Constructors
  //-----------------------------------------------------------------------
  public Service(iControl.Interfaces interfaces, iControl.SystemServicesServiceType type)
  {
    _interfaces = interfaces; 
    _type = type;
  }

  protected void validateMembers() throws Exception
  {
    if ( (null == _interfaces) || (null == _type) )
    {
      throw new Exception("Invalid Service Parameters");
    }
  }

  //-----------------------------------------------------------------------
  // Public Methods
  //-----------------------------------------------------------------------
  public void setAction(iControl.SystemServicesServiceAction action) throws Exception
  {
    validateMembers();

    iControl.SystemServicesServiceType [] services = { _type };
    
    _interfaces.getSystemServices().set_service(services, action);
  }
  
  public iControl.SystemServicesServiceStatusType getServiceStatus() throws Exception
  {
    validateMembers();
    
    iControl.SystemServicesServiceType [] services = { _type };
    iControl.SystemServicesServiceStatus [] statuses = 
      _interfaces.getSystemServices().get_service_status(services);
    
    return statuses[0].getStatus();
  }
  
  
  //-----------------------------------------------------------------------
  // Public Static Methods
  //-----------------------------------------------------------------------
  public static iControl.Objects.System.Service []
    getServices(iControl.Interfaces interfaces) throws Exception
  {
    iControl.SystemServicesServiceType [] serviceTypes = 
      interfaces.getSystemServices().get_list();
    
    Service [] services = new Service[serviceTypes.length];
    for(int i=0; i
Published Mar 08, 2015
Version 1.0
No CommentsBe the first to comment