Search in sources :

Example 1 with DynStruct

use of org.omg.DynamicAny.DynStruct 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 DynStruct

use of org.omg.DynamicAny.DynStruct 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 DynStruct

use of org.omg.DynamicAny.DynStruct 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 4 with DynStruct

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

the class BACIIntrospector method insertTypedef.

public Any insertTypedef(TypeCode tc, java.lang.Object obj) {
    DynAny dany;
    try {
        dany = ra.getDynFact().create_dyn_any_from_type_code(tc);
    } catch (org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode e) {
        e.printStackTrace();
        return null;
    }
    //Class<?> cl = getClassType(tc);
    DynStruct str = (DynStruct) dany;
    NameDynAnyPair[] mems = str.get_members_as_dyn_any();
    try {
        if (tc.kind() == TCKind.tk_struct) {
            DataStruct ds = (DataStruct) obj;
            for (int i = 0; i < mems.length; i++) {
                mems[i].value.from_any(insertAny(mems[i].value.to_any(), ds.get(mems[i].id)));
            }
        } else {
            DataException de = (DataException) obj;
            for (int i = 0; i < mems.length; i++) {
                mems[i].value.from_any(insertAny(mems[i].value.to_any(), de.get(mems[i].id)));
            }
        }
        str.set_members_as_dyn_any(mems);
    } catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch e) {
        e.printStackTrace();
        return null;
    } catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue e) {
        e.printStackTrace();
        return null;
    }
    //displayAny(dany.to_any());
    return dany.to_any();
}
Also used : DynStruct(org.omg.DynamicAny.DynStruct) DataStruct(si.ijs.acs.objectexplorer.engine.DataStruct) DataException(si.ijs.acs.objectexplorer.engine.DataException) NameDynAnyPair(org.omg.DynamicAny.NameDynAnyPair) DynAny(org.omg.DynamicAny.DynAny)

Aggregations

DynAny (org.omg.DynamicAny.DynAny)4 DynStruct (org.omg.DynamicAny.DynStruct)4 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 DynSequence (org.omg.DynamicAny.DynSequence)1 NameDynAnyPair (org.omg.DynamicAny.NameDynAnyPair)1 NameValuePair (org.omg.DynamicAny.NameValuePair)1