Java Object Networking Selfip

Problem this snippet solves:

This Java class will wrap the iControl Networking::SelfIP interface to make it look like an object.

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

Code :

package iControl.Objects.Networking;

import iControl.Objects.System.Service;

public class SelfIP {
  private iControl.Interfaces _interfaces = null;
  private String _address = null;
  private String _netmask = null;
  private iControl.CommonEnabledState _floating_state = null;
  private long _unit_id = -1;
  private String _vlan = null;

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

  public String getAddress() { return _address; }
  public void setAddress(String address) { _address = address; }
  
  //-----------------------------------------------------------------------
  // Constructors
  //-----------------------------------------------------------------------
  public SelfIP(iControl.Interfaces interfaces, String address)
  {
    _interfaces = interfaces; 
    _address = address;
  }

  protected void validateMembers() throws Exception
  {
    if ( (null == _interfaces) || (null == _address) )
    {
      throw new Exception("Invalid Pool Parameters");
    }
  }
  
  //-----------------------------------------------------------------------
  // Attribute Accessors
  //-----------------------------------------------------------------------
  // floating_state
  public iControl.CommonEnabledState getFloatingState() throws Exception
  {
    if ( null == _floating_state )
    {
      validateMembers();
      String [] self_ips = { _address };
      iControl.CommonEnabledState [] states =
        _interfaces.getNetworkingSelfIP().get_floating_state(self_ips);
      _floating_state = states[0];
    }
    return _floating_state;
  }
  public void setFloatingState(iControl.CommonEnabledState state) throws Exception
  {
    validateMembers();
    String [] self_ips = { _address };
    iControl.CommonEnabledState [] states = { state };
    _interfaces.getNetworkingSelfIP().set_floating_state(self_ips, states);
    _floating_state = state;
  }
  
  // netmask
  public String getNetmask() throws Exception
  {
    if ( null == _netmask )
    {
      validateMembers();
      String [] self_ips = { _address };
      String [] netmasks = _interfaces.getNetworkingSelfIP().get_netmask(self_ips);
      _netmask = netmasks[0];
    }
    return _netmask;
  }
  public void setNetmask(String netmask) throws Exception
  {
    validateMembers();
    String [] self_ips = { _address };
    String [] netmasks = { netmask};
    _interfaces.getNetworkingSelfIP().set_netmask(self_ips, netmasks);
    _netmask = netmask;
  }
  
  // unit_id
  public long getUnitId() throws Exception
  {
    if ( -1 == _unit_id )
    {
      validateMembers();
      String [] self_ips = { _address };
      long [] unit_ids = _interfaces.getNetworkingSelfIP().get_unit_id(self_ips);
      _unit_id = unit_ids[0];
    }
    return _unit_id;
  }
  public void setUnitIdState(long unit_id) throws Exception
  {
    validateMembers();
    String [] self_ips = { _address };
    long [] unit_ids = { unit_id };
    _interfaces.getNetworkingSelfIP().set_unit_id(self_ips, unit_ids);
    _unit_id = unit_id;
  }
  
  // vlan
  public String getVLAN() throws Exception
  {
    if ( null == _vlan )
    {
      validateMembers();
      String [] self_ips = { _address };
       String [] vlans = _interfaces.getNetworkingSelfIP().get_vlan(self_ips);
      _vlan = vlans[0];
    }
    return _vlan;
  }
  public void setVLAN(String vlan) throws Exception
  {
    validateMembers();
    String [] self_ips = { _address };
    String [] vlans= { vlan };
    _interfaces.getNetworkingSelfIP().set_vlan(self_ips, vlans);
    _vlan = vlan;
  }
  
  
  //-----------------------------------------------------------------------
  // Public Methods
  //-----------------------------------------------------------------------
  public void create(
    String vlan,
    String netmask,
    long unit_id,
    iControl.CommonEnabledState state
  ) throws Exception
  {
    validateMembers();
    
    String [] self_ips = { _address };
    String [] vlan_names = { vlan };
    String [] netmasks = { netmask };
    long [] unit_ids = { unit_id };
    iControl.CommonEnabledState [] states = { state };
    
    _interfaces.getNetworkingSelfIP().create(self_ips, vlan_names, netmasks, unit_ids, states);
    
    _unit_id = unit_id;
    _netmask = netmask;
    _floating_state = state;
    _vlan = vlan;
  }
  
  public void remove() throws Exception
  {
    validateMembers();
    String [] self_ips = { _address };
    _interfaces.getNetworkingSelfIP().delete_self_ip(self_ips);
  }
  
  public void syncProperties() throws Exception
  {
    validateMembers();
    getFloatingState();
    getNetmask();
    getUnitId();
    getVLAN();
  }
  
  //-----------------------------------------------------------------------
  // Public Static Methods
  //-----------------------------------------------------------------------
  public static SelfIP [] getList(iControl.Interfaces interfaces) throws Exception
  {
    SelfIP [] selfips = null;
    if ( null != interfaces )
    {
      String [] selfip_list = interfaces.getNetworkingSelfIP().get_list();

      selfips = new SelfIP[selfip_list.length];
      for(int i=0; i
Published Mar 08, 2015
Version 1.0
No CommentsBe the first to comment