use of org.omg.DynamicAny.DynSequence 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;
}
use of org.omg.DynamicAny.DynSequence 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;
}
use of org.omg.DynamicAny.DynSequence 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]);
}
}
use of org.omg.DynamicAny.DynSequence in project ACS by ACS-Community.
the class BACIIntrospector method insertSequence.
public Any insertSequence(TypeCode tc, Any argument, java.lang.Object obj) {
if (argument == null)
throw new NullPointerException("argument");
if (obj == null)
throw new NullPointerException("obj");
if (!obj.getClass().isArray())
throw new IllegalArgumentException("The parameter obj has to be a sequence");
java.lang.Object[] objs;
if (obj.getClass().getComponentType().isPrimitive())
objs = DataFormatter.convertPrimitiveArray(obj);
else
objs = (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;
}
Any[] els = new Any[objs.length];
try {
for (int i = 0; i < els.length; i++) {
DynAny dany2;
try {
dany2 = ra.getDynFact().create_dyn_any_from_type_code(tc.content_type());
} catch (org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode e) {
e.printStackTrace();
return null;
}
els[i] = dany2.to_any();
els[i] = insertAny(tc.content_type(), els[i], objs[i]);
}
if (tc.kind() == TCKind.tk_sequence) {
((DynSequence) dany).set_elements(els);
((DynSequence) dany).set_length(els.length);
} else if (tc.kind() == TCKind.tk_array)
((DynArray) dany).set_elements(els);
} catch (org.omg.DynamicAny.DynAnyPackage.TypeMismatch e) {
e.printStackTrace();
} catch (org.omg.DynamicAny.DynAnyPackage.InvalidValue e) {
e.printStackTrace();
} catch (org.omg.CORBA.TypeCodePackage.BadKind e) {
e.printStackTrace();
}
return dany.to_any();
}
Aggregations