mibble-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Mibble-users] How to print Enum names


From: Per Cederberg
Subject: Re: [Mibble-users] How to print Enum names
Date: Mon, 20 Mar 2006 22:03:34 +0100
User-agent: Mozilla Thunderbird 1.0.7 (Macintosh/20050923)

As Birgit's answer suggests, you'll want to take a look at
the IntegerType.getAllSymbols() method. In your case, for a
quick hack, I'd change IntegerType.toString() like this:

    public String toString() {
        StringBuffer     buffer = new StringBuffer();
        MibValueSymbol[] syms;

        buffer.append(super.toString());
        if (symbols.size() > 0) {
            buffer.append(" (");
            syms = getAllSymbols();
            for (int i = 0; i < syms.length; i++) {
                // TODO: print symbol name + value
            }
            buffer.append(")");
        } else if (constraint != null) {
            buffer.append(" (");
            buffer.append(constraint.toString());
            buffer.append(")");
        }
        return buffer.toString();
    }

Ideally, though, you shouldn't depend on the
MibblePrinter application to do anything particularly
useful when run with "--debug". The output format is
subject to change between Mibble versions.

Much better to traverse the Mib tree yourself and
print/extract what you need from there.

Cheers,

/Per

Birgit Arkesteijn wrote:
Hi MK,

We use something like this ..

public String printEnumNames(MibNode node)
{
    StringBuffer buf = new StringBuffer();

    MibValueSymbol symb = node.getSymbol();
    SnmpObjectType snmpOT = node.getSnmpObjectType();
    MibType syntax = snmpOT.getSyntax();
    if (syntax != null)
    {
        if (syntax instanceof IntegerType)
        {
            IntegerType t = (IntegerType)syntax;
            if (t.hasSymbols())
            {
                MibValueSymbol[] symbs = t.getAllSymbols();
                int nr = symbs.length;

                for (int i=0; i<nr; i++)
                {
                    MibValueSymbol iSymb = symbs[i];
                    MibValue value = iSymb.getValue();
                    Object obj = value.toObject();

                    buf.append(obj.toString());   // value
                    buf.append(",");
                    buf.append(iSymb.getName());  // name
                }
                buf.append("\n");
            }
        }
    }
    return buf.toString();
}


Hope this helps.

Cheers, Birgit


On Mon, Mar 20, 2006 at 02:01:07PM +0530, Srinivasan, Muralikrishna (Murali 
Krishna) wrote:

Hi,
I am currently using the 2.6 version of mibble with a --debug option to
produce a fully RESOLVED text.

When enumerated values are resolved
e.g

abcAction OBJECT-TYPE
   SYNTAX      INTEGER { none(0),
                         restart(1),
                         shutdown(2)
                }

MIBBLE PRODUCES:
VALUE abcAction OBJECT-TYPE (
 Syntax: [UNIVERSAL 2] INTEGER (0 | 1 | 2 )

I WANT the name of the Enums to be produced as well such as
VALUE abcAction OBJECT-TYPE (
 Syntax: [UNIVERSAL 2] INTEGER (none,0 | restart,1 | shutdown,2 )

I want none, restart and shutdown to be printed as well.

How can this be done?

I tried changing ValueConstraint.java as
   public String toString() {
       StringBuffer buf = new StringBuffer();
       buf.append(value.getName());
       buf.append(",");
       buf.append(value.toString());
       return buf.toString();
       //return value.toString();
   }

but found that the values are all NumberValue and so do not have a  "name".

Pls Help me out on this.

Thanks
MK.







reply via email to

[Prev in Thread] Current Thread [Next in Thread]