[SNMP4J] SNMP4J and CORBA "Any" class

Marco.Bresciani at alcatel.it Marco.Bresciani at alcatel.it
Mon Jan 16 09:05:33 CET 2006


Matthias Wiesmann <matthias.wiesmann at gmail.com>
15/01/2006 01.46
 
        To:     Marco BRESCIANI/IT/ALCATEL at ALCATEL
        cc: 
        Subject:        Re: [SNMP4J] SNMP4J and CORBA "Any" class
>If I understad well you code should un-marshall SNMP traps and
>transport the data further on using CORBA? There are multiple ways to

Yes. That's right. Actually it seems CORBA is not used anymor as 
"transport layer" but it's simply going to be a common and standard 
container... Anyway I think I should use it again...

>put SNMP data into a CORBA Any, technically, you could put the bytes
>from the BER encoded values into the Any. I doubt you want this, but
>it all depends on the format the final application expects.

Uhm... Could you please explain this use of the BER encoding?

>You legacy code seems to convert SNMP variable bindings into instances
>of AttrVal. You will need to implement a method that does the same

Yes, it does.

>conversion. How this conversion is done actually depends on the
>interface of AttrVal: are there subclasses for the different types of
>data? Could you send the IDL description of this class?

I'm not sure but I think IDL does not exist. As I probably wrote in my 
first messages, I'm working on a ton of bad code... so I have to adapt 
myself to it... I'm writing here the way the CORBA AttrVal is used and 
"decoded".

I wrote that the older getObject method use this instruction:

holder.setData((Object) 
Converter.convertToStructure(holder.getStructureClass(), fieldName, p1));

to manage data received from proprietary SMTP manager/agent/API. I 
actually don't how this works because I have the JAr API only. I don't 
have neither source code nor a usable JavaDoc! :-( I only have this call:

res = ((NEMonitor) monitor).getEmlim().Get(((NEMonitor) 
monitor).getNEname(), p1);

that I replaced with the code I wrote before. As I also wrote, p1 is:

Any[] pp1 = new Any[1];
pp1[0] = orb.create_any();
Any p3 = orb.create_any();
AttrVal p0 = new AttrVal(oid, pp1, ASNSnmpType.Null, p3);
AttrValHolder p1 = new AttrValHolder(p0);

(what useful names...) and I probably have to fill in the p1 or p0 or p3 
data... or whatsoever! :-( Also I have the convertToStructure method that 
is quite simple:

static Object convertToStructure(Class struct, String fieldName, 
AttrValHolder holder) throws IllegalAccessException, 
InstantiationException {
 Object result = null;
 Object[] objects = new Object[struct.getDeclaredFields().length + 1];
 Class[] types = struct.getDeclaredConstructors()[0].getParameterTypes();

 objects[0] = holder.value.oid;
 for (int i = 1; i < objects.length; i++) {
     if (struct.getDeclaredFields()[i - 1].getName().equals(fieldName)) {
         objects[i] = parse(holder.value.val);
     } else {
         objects[i] = getDefaultValue(types[i]);
     }
 }

 Class[] cClass = new Class[objects.length];
 for (int i = 0; i < objects.length; i++) {
     cClass[i] = objects[i].getClass();
 }

 try {
     Constructor myC = struct.getDeclaredConstructor(cClass);

     result = myC.newInstance(objects);
 } catch (InvocationTargetException ite) {
     ite.printStackTrace();
 } catch (InstantiationException ie) {
     System.out.println(ie);
 } catch (IllegalArgumentException iae) {
     iae.printStackTrace();
     System.out.println(iae);
 } catch (NoSuchMethodException nse) {
     nse.printStackTrace();
     System.out.println(nse);
 }
 return result;

And the problem is probably due to the "parse" method used inside first 
"for" statement. This could be the method that "translates" data from 
CORBA Any to... whatever:

static java.lang.Object parse(Any any) throws NullPointerException, 
IllegalArgumentException {
 if (any == null) {
     return null;
 }

 InputStream inputstream = any.create_input_stream();
 TypeCode typecode = any.type();
 TCKind tckind = typecode.kind();
 int i = tckind.value();

 switch (i) {
     case TCKind._tk_sequence: int j = inputstream.read_long();
         try {
             TypeCode contentType = typecode.content_type();
             return parseArray(inputstream, contentType, j);
         } catch (Exception ex) {
             throw new IllegalArgumentException("Cannot extract the type 
of entries in the array.");
         }
     case TCKind._tk_long:
         return new Integer(inputstream.read_long());
     case TCKind._tk_boolean:
         return new Boolean(inputstream.read_boolean());
     case TCKind._tk_double:
         return new Double(inputstream.read_double());
     case TCKind._tk_ulong:
         return new Long(inputstream.read_ulong());
     case TCKind._tk_longlong:
         return new Long(inputstream.read_longlong());
     case TCKind._tk_ulonglong:
         return new Long(inputstream.read_ulonglong());
     case TCKind._tk_octet:
         return new Byte(inputstream.read_octet());
     case TCKind._tk_string:
         return inputstream.read_string();
     case TCKind._tk_enum:
         return new Integer(inputstream.read_long());
     case TCKind._tk_any:
         return inputstream.read_any();
     case TCKind._tk_ushort:
     case TCKind._tk_float:
     case TCKind._tk_char:
            return new Integer(0);
     case TCKind._tk_TypeCode:
     case TCKind._tk_Principal:
     case TCKind._tk_objref:
     case TCKind._tk_struct:
     case TCKind._tk_union:
     case TCKind._tk_array:
     case TCKind._tk_alias:
         int k = inputstream.read_long();
         try {
             TypeCode contentType = typecode.content_type();
             return parseArray(inputstream, contentType, k);
         } catch (Exception ex) {
             throw new IllegalArgumentException("Cannot extract the type 
of entries in the array.");
         }
     case TCKind._tk_except:
     default:
         throw new IllegalArgumentException("Unknown Any type: " + 
typecode.kind().value());
 }

This is probably the interesting part of the code. Anyone can help me?! 
:-) Thank you VERY much.


...and sorry for my newbiness with SMTP (and CORBA too) :-)

Dott. Ing. Marco Bresciani

-- 
Alcatel - WTD R&D SW Lab. [Stage]
Via Trento, 30
20059 Vimercate (Mi) Italia
Phone: +39.039.686.5546
E-Mail: Marco.Bresciani at Alcatel.It



More information about the SNMP4J mailing list