Search in sources :

Example 1 with DynAny

use of org.omg.DynamicAny.DynAny in project ACS by ACS-Community.

the class DynAnyParser method parseEventAny.

private void parseEventAny(DynAny dynAny2, String path) {
    if (monitor != null && monitor.isCanceled()) {
        cancelFlag = true;
        // Check for cancellation each time through
        return;
    }
    DynAny da = dynAny2;
    int tcKind = da.type().kind().value();
    ParsedAnyData entry = new ParsedAnyData(path, "", "");
    try {
        switch(tcKind) {
            case TCKind._tk_short:
                entry.setType("short");
                entry.setValue(String.valueOf(da.get_short()));
                pdlist.add(entry);
                break;
            case TCKind._tk_long:
                entry.setType("long");
                entry.setValue(String.valueOf(da.get_long()));
                pdlist.add(entry);
                break;
            case TCKind._tk_longlong:
                entry.setType("longlong");
                if (path.contains("timestamp")) {
                    entry.setValue(String.valueOf(UTCUtility.getUTCDate(UTCUtility.utcOmgToJava(da.get_longlong()))));
                } else
                    entry.setValue(String.valueOf(da.get_longlong()));
                pdlist.add(entry);
                break;
            case TCKind._tk_ulonglong:
                entry.setType("ulonglong");
                entry.setValue(String.valueOf(da.get_ulonglong()));
                pdlist.add(entry);
                break;
            case TCKind._tk_string:
                entry.setType("string");
                entry.setValue(da.get_string());
                pdlist.add(entry);
                break;
            case TCKind._tk_boolean:
                entry.setType("boolean");
                entry.setValue("" + da.get_boolean());
                pdlist.add(entry);
                break;
            case TCKind._tk_float:
                entry.setType("float");
                entry.setValue("" + da.get_float());
                pdlist.add(entry);
                break;
            case TCKind._tk_double:
                entry.setType("double");
                entry.setValue("" + da.get_double());
                pdlist.add(entry);
                break;
            case TCKind._tk_enum:
                entry.setType("enum");
                entry.setValue(((DynEnum) da).get_as_string());
                pdlist.add(entry);
                break;
            case TCKind._tk_array:
                entry.setType("array");
                entry.setValue("size: " + da.component_count());
                pdlist.add(entry);
                int numDisplayElements = Math.min(da.component_count(), 5);
                int elementType = da.type().content_type().kind().value();
                switch(elementType) {
                    case TCKind._tk_double:
                        for (int j = 0; j < numDisplayElements; j++) {
                            String dname = path + "[" + j + "]";
                            double value = da.current_component().get_double();
                            pdlist.add(new ParsedAnyData(dname, "double", ("" + value)));
                            da.next();
                        }
                        break;
                    default:
                        pdlist.add(new ParsedAnyData(path, "Unimplemented type for array: " + elementType, "Unknown"));
                }
                break;
            case TCKind._tk_struct:
            case TCKind._tk_except:
                DynStruct ds = (DynStruct) da;
                String structName = ds.type().name();
                if (DEBUG)
                    System.out.println("Struct name: " + structName);
                entry.setType("struct");
                if (path.equals("")) {
                    entry.setName(structName);
                } else
                    // TODO: still not
                    entry.setName(path + " / " + structName);
                // working --
                // this doesn't
                // display
                // Actuator
                // Space at all!
                StringBuilder members = new StringBuilder("Members: ");
                for (int i = 0; i < ds.component_count(); i++) {
                    members.append(ds.current_member_name() + ((i == ds.component_count() - 1) ? " " : ", "));
                    ds.next();
                }
                entry.setValue(members.toString());
                pdlist.add(entry);
                ds.rewind();
                for (int i = 0; i < ds.component_count(); i++) {
                    String dname = ds.current_member_name();
                    if (DEBUG)
                        System.out.println("\tMember name: " + dname + " type: " + ds.current_component().type().kind().value());
                    parseEventAny(ds.current_component(), dname);
                    ds.next();
                }
                if (DEBUG) {
                    NameValuePair[] nvp = ds.get_members();
                    for (int i = 0; i < nvp.length; i++) {
                        System.out.println(nvp[i].id + " " + nvp[i].value);
                    }
                }
                break;
            case TCKind._tk_sequence:
                DynSequence dsq = (DynSequence) da;
                String seqName = path + dsq.type().name();
                // TODO: Straighten this
                entry.setType("sequence" + seqName);
                // out
                entry.setValue("IDL sequences not implemented yet");
            default:
                entry.setType(da.type().kind().toString());
                entry.setValue("Unimplemented type");
                pdlist.add(entry);
                break;
        }
    } catch (TypeMismatch e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvalidValue e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (BadKind e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return;
}
Also used : NameValuePair(org.omg.DynamicAny.NameValuePair) InvalidValue(org.omg.DynamicAny.DynAnyPackage.InvalidValue) DynStruct(org.omg.DynamicAny.DynStruct) DynSequence(org.omg.DynamicAny.DynSequence) DynAny(org.omg.DynamicAny.DynAny) TypeMismatch(org.omg.DynamicAny.DynAnyPackage.TypeMismatch) BadKind(org.omg.CORBA.TypeCodePackage.BadKind)

Example 2 with DynAny

use of org.omg.DynamicAny.DynAny in project ACS by ACS-Community.

the class BACIIntrospector method extractTypedef.

/**
 * Insert the method's description here.
 * Creation date: (7.11.2000 1:00:12)
 * @return java.lang.Object
 * @param argument org.omg.CORBA.Any
 */
public java.lang.Object extractTypedef(TypeCode tc, Any argument) {
    if (argument == null)
        throw new NullPointerException("argument");
    DynAny dany;
    try {
        dany = ra.getDynFact().create_dyn_any(argument);
    } catch (org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode e) {
        e.printStackTrace();
        return null;
    }
    DynStruct str = (DynStruct) dany;
    try {
        if (tc.kind() == TCKind.tk_struct) {
            DataStruct ds = new DataStruct(dany.type().id());
            for (int i = 0; i < str.component_count(); i++) {
                ds.add(str.current_member_name(), extractAny(str.current_component().to_any()));
                str.next();
            }
            return ds;
        } else {
            DataException de = new DataException(dany.type().id());
            for (int i = 0; i < str.component_count(); i++) {
                de.add(str.current_member_name(), extractAny(str.current_component().to_any()));
                str.next();
            }
            return de;
        }
    } catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch e) {
        e.printStackTrace();
        return null;
    } catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue e) {
        e.printStackTrace();
        return null;
    } catch (org.omg.CORBA.TypeCodePackage.BadKind e) {
        e.printStackTrace();
        return null;
    }
}
Also used : DynStruct(org.omg.DynamicAny.DynStruct) DataStruct(si.ijs.acs.objectexplorer.engine.DataStruct) DataException(si.ijs.acs.objectexplorer.engine.DataException) DynAny(org.omg.DynamicAny.DynAny)

Example 3 with DynAny

use of org.omg.DynamicAny.DynAny in project ACS by ACS-Community.

the class BACIIntrospector method extractSequence.

public java.lang.Object extractSequence(TypeCode tc, Any argument) {
    if (tc == null)
        throw new NullPointerException("tc");
    if (argument == null)
        throw new NullPointerException("argument");
    DynAny dany;
    try {
        dany = ra.getDynFact().create_dyn_any(argument);
    } catch (org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode e) {
        e.printStackTrace();
        return null;
    }
    Class<?> cl = getClassType(argument.type());
    Any[] els;
    if (tc.kind() == TCKind.tk_sequence)
        els = ((DynSequence) dany).get_elements();
    else if (tc.kind() == TCKind.tk_array)
        els = ((DynArray) dany).get_elements();
    else {
        return null;
    }
    java.lang.Object array = java.lang.reflect.Array.newInstance(cl.getComponentType(), els.length);
    java.lang.Object[] objs;
    if (cl.getComponentType().isPrimitive())
        objs = DataFormatter.convertPrimitiveArray(array);
    else
        objs = (java.lang.Object[]) array;
    for (int i = 0; i < els.length; i++) {
        objs[i] = extractAny(els[i]);
    }
    return objs;
}
Also used : Any(org.omg.CORBA.Any) DynAny(org.omg.DynamicAny.DynAny) DynSequence(org.omg.DynamicAny.DynSequence) DynAny(org.omg.DynamicAny.DynAny) IRObject(org.omg.CORBA.IRObject)

Example 4 with DynAny

use of org.omg.DynamicAny.DynAny in project ACS by ACS-Community.

the class BACIIntrospector method displayTypedef.

public void displayTypedef(TypeCode tc, Any argument) {
    if (argument == null)
        throw new NullPointerException("argument");
    if (tc == null)
        throw new NullPointerException("tc");
    DynAny dany = null;
    try {
        dany = ra.getDynFact().create_dyn_any(argument);
    } catch (org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode e) {
        e.printStackTrace();
    }
    DynStruct str = (DynStruct) dany;
    try {
        if (tc.kind() == TCKind.tk_struct) {
            for (int i = 0; i < str.component_count(); i++) {
                displayAny(str.current_component().to_any());
                str.next();
            }
        } else {
            for (int i = 0; i < str.component_count(); i++) {
                displayAny(str.current_component().to_any());
                str.next();
            }
        }
    } catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch e) {
        e.printStackTrace();
    }
}
Also used : DynAny(org.omg.DynamicAny.DynAny) DynStruct(org.omg.DynamicAny.DynStruct)

Example 5 with DynAny

use of org.omg.DynamicAny.DynAny in project ACS by ACS-Community.

the class BACIIntrospector method displaySequence.

public void displaySequence(TypeCode tc, Any argument) {
    if (tc == null)
        throw new NullPointerException("tc");
    if (argument == null)
        throw new NullPointerException("argument");
    DynAny dany = null;
    try {
        dany = ra.getDynFact().create_dyn_any(argument);
    } catch (org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode e) {
        e.printStackTrace();
    }
    //Class<?> cl = getClassType(argument.type());
    Any[] els;
    if (tc.kind() == TCKind.tk_sequence)
        els = ((DynSequence) dany).get_elements();
    else if (tc.kind() == TCKind.tk_array)
        els = ((DynArray) dany).get_elements();
    else
        els = new Any[0];
    for (int i = 0; i < els.length; i++) {
        displayAny(els[i]);
    }
}
Also used : DynSequence(org.omg.DynamicAny.DynSequence) DynAny(org.omg.DynamicAny.DynAny) Any(org.omg.CORBA.Any) DynAny(org.omg.DynamicAny.DynAny)

Aggregations

DynAny (org.omg.DynamicAny.DynAny)7 DynSequence (org.omg.DynamicAny.DynSequence)4 DynStruct (org.omg.DynamicAny.DynStruct)4 Any (org.omg.CORBA.Any)3 IRObject (org.omg.CORBA.IRObject)2 DataException (si.ijs.acs.objectexplorer.engine.DataException)2 DataStruct (si.ijs.acs.objectexplorer.engine.DataStruct)2 BadKind (org.omg.CORBA.TypeCodePackage.BadKind)1 InvalidValue (org.omg.DynamicAny.DynAnyPackage.InvalidValue)1 TypeMismatch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch)1 DynArray (org.omg.DynamicAny.DynArray)1 NameDynAnyPair (org.omg.DynamicAny.NameDynAnyPair)1 NameValuePair (org.omg.DynamicAny.NameValuePair)1