// Home | Go Back //

/*
 * Copyright (c) 2002-2003 iReasoning Inc. All Rights Reserved.
 * 
 * This SOURCE CODE FILE, which has been provided by iReasoning Inc. as part
 * of an iReasoning Software product for use ONLY by licensed users of the product,
 * includes CONFIDENTIAL and PROPRIETARY information of iReasoning Inc.  
 *
 * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
 * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
 * THE PRODUCT.
 *
 * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD IREASONING SOFTWARE, ITS
 * RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY
 * CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR
 * DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES
 * ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR
 * DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR
 * DERIVED FROM THIS SOURCE CODE FILE.
 */

package agent.ifmib;
import java.io.*;
import java.util.*;
import com.ireasoning.util.*;
import com.ireasoning.protocol.snmp.*;
import javax.management.*;

/**
 * Table entry class
 */
public class IfRcvAddressEntry extends SnmpTableEntry
{
    // SnmpOID: .1.3.6.1.2.1.31.1.4.1.1
    protected String _ifRcvAddressAddress = "";
    // SnmpOID: .1.3.6.1.2.1.31.1.4.1.2
    protected int _ifRcvAddressStatus = 0;
    // SnmpOID: .1.3.6.1.2.1.31.1.4.1.3
    protected int _ifRcvAddressType = 0;
    
    /**
     * Constructor
     * @param table the Table which contains this table entry class
     */
    public IfRcvAddressEntry(SnmpTable table)
    {
        super(table);
    }
    
    /**
     * Constructor. Initializes member variables
     * @param table the Table which contains this table entry class
     */
    public IfRcvAddressEntry( SnmpTable table, String ifRcvAddressAddress, int ifRcvAddressStatus, int ifRcvAddressType)
    {
        super(table);
        
        this._ifRcvAddressAddress = ifRcvAddressAddress;
        this._ifRcvAddressStatus = ifRcvAddressStatus;
        this._ifRcvAddressType = ifRcvAddressType;
        
    }
    
    /**
     * This table use index from other table. This method returns its base table
     */
    private SnmpTable getBaseTable()
    {
        // Gets the base table reference
        IfTable table = AgentMib.getIfTable();
        return table;
    }
    
    /**
     * Returns the base table's row at specified index
     */
    private SnmpTableEntry getBaseTableEntry(int index)
    {
        SnmpTable table = getBaseTable();
        return table.getRow(index);
    }
    
    /**
     * Returns the index string for this row
     * @return the index string for this row. Return null to indicate that this row will not be added
     */
    public String getIndexSuffix()
    {
        if(_suffix.length() == 0)
        {
            _suffix = "." + SnmpTableEntry.getIndexString( physAddressToIndexSuffix("" + _ifRcvAddressAddress), true);
            SnmpTable baseTable = getBaseTable();
            
            // ========================================================================================
            // TODO: The following code is for reference only. It's not like augmentation relationship.
            //       There's no one to one mapping between this row and base table's row. So you may
            //       need to customize them to suite your needs.
            // ========================================================================================
            
            int count = baseTable.getRowCount();
            int currentNumOfRows = _table.getRowCount();
            if(currentNumOfRows > count - 1)
            {
                // This table can not have more rows than base table. So this row won't be added
                return null;
            }
            SnmpTableEntry baseEntry = getBaseTableEntry(currentNumOfRows);
            
            // Important: Add this row to the base table's dependents list
            baseEntry.addDependentRow(_table, this);
            _suffix = baseEntry.getIndexSuffix() + _suffix;
        }
        return _suffix;
    }
    
    /**
     * Sets column value at specified index
     * @param index the index of column to be set new value
     * @param value new value of the column
     */
    public void set(int index, SnmpDataType value)
    {
        switch(index)
        {
            case 0 :
            _ifRcvAddressAddress = value.toString();
            break;
            case 1 :
            _ifRcvAddressStatus = ((SnmpInt) value).getValue();
            break;
            case 2 :
            _ifRcvAddressType = ((SnmpInt) value).getValue();
            break;
        }
    }
    
}