// 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.*;


/**
 * Class for registering MBeans
 */
public class AgentMib
{
    // MBeanServer reference
    private static MBeanServer _server;
    // Root node of OID tree
    private static OIDTreeNode _root;
    
    /**
     * Registers all necessary MBeans
     */
    public static void registerMBeans(MBeanServer server, OIDTreeNode root)
    {
        _server = server;
        _root = root;
        try
        {
            registerInterfacesGroup();
            registerIfTable();
            registerIfXTable();

            //two dynamic tables
            registerIfRcvAddressTable();
            registerIfStackTable();
            
            // registerSnmpSetGroup();
            // registerIfMIBObjectsGroup();
            // registerIfTestTable();
        }
        catch(Exception e)
        {
            Logger.error(e);
            throw new SnmpException(e.toString());
        }
    }
    
    /**
     * Create instance and register MBean
     */
    public static void registerInterfacesGroup() throws Exception
    {
        if ( _interfacesGroup != null ) return;
        _interfacesGroup = new InterfacesGroup(_root, ".1.3.6.1.2.1.2", null);
        _server.registerMBean(_interfacesGroup, new ObjectName("iReasoning:name=InterfacesGroup"));
    }
    
    /**
     * Create instance and register MBean
     */
    public static void registerIfXTable() throws Exception
    {
        if ( _ifXTable != null ) return;
        _ifXTable = new IfXTable(_root, ".1.3.6.1.2.1.31.1.1", null);
        _server.registerMBean(_ifXTable, new ObjectName("iReasoning:name=IfXTable"));
    }
    
    /**
     * Create instance and register MBean
     */
    public static void registerIfStackTable() throws Exception
    {
        if ( _ifStackTable != null ) return;
        _ifStackTable = new IfStackTable(_root, ".1.3.6.1.2.1.31.1.2", null);
        _server.registerMBean(_ifStackTable, new ObjectName("iReasoning:name=IfStackTable"));
    }
    
    /**
     * Create instance and register MBean
     */
    public static void registerIfRcvAddressTable() throws Exception
    {
        if ( _ifRcvAddressTable != null ) return;
        _ifRcvAddressTable = new IfRcvAddressTable(_root, ".1.3.6.1.2.1.31.1.4", null);
        _server.registerMBean(_ifRcvAddressTable, new ObjectName("iReasoning:name=IfRcvAddressTable"));
    }
    
    /**
     * Create instance and register MBean
     */
    public static void registerIfTable() throws Exception
    {
        if ( _ifTable != null ) return;
        _ifTable = new IfTable(_root, ".1.3.6.1.2.1.2.2", null);
        _server.registerMBean(_ifTable, new ObjectName("iReasoning:name=IfTable"));
    }
    
    /**
     * Returns InterfacesGroup object. If InterfacesGroup is null, it 'll register the corresponding MBean first
     */
    public static InterfacesGroup getInterfacesGroup( )
    {
        if( _interfacesGroup == null )
        {
            try
            {
                registerInterfacesGroup();
            }
            catch(Exception e)
            {
                Logger.error(e);
            }
        }
        return _interfacesGroup;
    }
    
    /**
     * Returns IfXTable object. If IfXTable is null, it 'll register the corresponding MBean first
     */
    public static IfXTable getIfXTable( )
    {
        if( _ifXTable == null )
        {
            try
            {
                registerIfXTable();
            }
            catch(Exception e)
            {
                Logger.error(e);
            }
        }
        return _ifXTable;
    }
    
    /**
     * Returns IfStackTable object. If IfStackTable is null, it 'll register the corresponding MBean first
     */
    public static IfStackTable getIfStackTable( )
    {
        if( _ifStackTable == null )
        {
            try
            {
                registerIfStackTable();
            }
            catch(Exception e)
            {
                Logger.error(e);
            }
        }
        return _ifStackTable;
    }
    
    /**
     * Returns IfRcvAddressTable object. If IfRcvAddressTable is null, it 'll register the corresponding MBean first
     */
    public static IfRcvAddressTable getIfRcvAddressTable( )
    {
        if( _ifRcvAddressTable == null )
        {
            try
            {
                registerIfRcvAddressTable();
            }
            catch(Exception e)
            {
                Logger.error(e);
            }
        }
        return _ifRcvAddressTable;
    }
    
    /**
     * Returns IfTable object. If IfTable is null, it 'll register the corresponding MBean first
     */
    public static IfTable getIfTable( )
    {
        if( _ifTable == null )
        {
            try
            {
                registerIfTable();
            }
            catch(Exception e)
            {
                Logger.error(e);
            }
        }
        return _ifTable;
    }
    
    
    static InterfacesGroup _interfacesGroup;
    static IfXTable _ifXTable;
    static IfStackTable _ifStackTable;
    static IfRcvAddressTable _ifRcvAddressTable;
    static IfTable _ifTable;
}