407 Debug.print(Debug.VERBOSE,
"Deserializing from " + parameter.getClass() +
" to " + type.getClass());
408 if (null == parameter)
412 if (type instanceof TypeVariable
413 && parameter instanceof Variant) {
414 parameter = ((Variant) parameter).getValue();
418 if (type instanceof Class
419 && ((Class) type).isArray()
420 && ((Class) type).getComponentType().equals(Type.class)
421 && parameter instanceof String) {
422 Vector<Type> rv =
new Vector<Type>();
424 parameter = rv.toArray(
new Type[0]);
428 if (parameter instanceof ObjectPath) {
429 if (type instanceof Class && DBusInterface.class.isAssignableFrom((Class) type))
430 parameter = conn.getExportedObject(
431 ((ObjectPath) parameter).source,
432 ((ObjectPath) parameter).path);
434 parameter =
new Path(((ObjectPath) parameter).path);
438 if (parameter instanceof Object[] &&
439 type instanceof Class &&
440 Struct.class.isAssignableFrom((Class) type)) {
441 if (Debug.debug) Debug.print(Debug.VERBOSE,
"Creating Struct " + type +
" from " + parameter);
442 Type[] ts = Container.getTypeCache(type);
444 Field[] fs = ((Class) type).getDeclaredFields();
445 ts =
new Type[fs.length];
447 Position p = f.getAnnotation(Position.class);
448 if (null == p)
continue;
449 ts[p.value()] = f.getGenericType();
451 Container.putTypeCache(type, ts);
456 for (Constructor con : ((Class) type).getDeclaredConstructors()) {
458 parameter = con.newInstance((Object[]) parameter);
460 }
catch (IllegalArgumentException IAe) {
466 if (parameter instanceof Object[]) {
467 Type[] ts =
new Type[((Object[]) parameter).length];
468 Arrays.fill(ts, parameter.getClass().getComponentType());
472 if (parameter instanceof List) {
474 if (type instanceof ParameterizedType)
475 type2 = ((ParameterizedType) type).getActualTypeArguments()[0];
476 else if (type instanceof GenericArrayType)
477 type2 = ((GenericArrayType) type).getGenericComponentType();
478 else if (type instanceof Class && ((Class) type).isArray())
479 type2 = ((Class) type).getComponentType();
487 if (type.equals(Float.class) || type.equals(Float.TYPE))
488 if (!(parameter instanceof Float))
489 parameter = ((Number) parameter).floatValue();
492 if (parameter instanceof Object[] ||
493 parameter instanceof List ||
494 parameter.getClass().isArray()) {
495 if (type instanceof ParameterizedType)
496 parameter = ArrayFrob.convert(parameter,
497 (Class<? extends Object>) ((ParameterizedType) type).getRawType());
498 else if (type instanceof GenericArrayType) {
499 Type ct = ((GenericArrayType) type).getGenericComponentType();
501 if (ct instanceof Class)
503 if (ct instanceof ParameterizedType)
504 cc = (Class) ((ParameterizedType) ct).getRawType();
505 Object o = Array.newInstance(cc, 0);
506 parameter = ArrayFrob.convert(parameter,
508 }
else if (type instanceof Class &&
509 ((Class) type).isArray()) {
510 Class cc = ((Class) type).getComponentType();
511 if ((cc.equals(Float.class) || cc.equals(Float.TYPE))
512 && (parameter instanceof
double[])) {
513 double[] tmp1 = (
double[]) parameter;
514 float[] tmp2 =
new float[tmp1.length];
515 for (
int i = 0; i < tmp1.length; i++)
516 tmp2[i] = (
float) tmp1[i];
519 Object o = Array.newInstance(cc, 0);
520 parameter = ArrayFrob.convert(parameter,
524 if (parameter instanceof DBusMap) {
525 if (Debug.debug) Debug.print(Debug.VERBOSE,
"Deserializing a Map");
526 DBusMap dmap = (DBusMap) parameter;
527 Type[] maptypes = ((ParameterizedType) type).getActualTypeArguments();
528 for (
int i = 0; i < dmap.entries.length; i++) {
static int getJavaType(String dbus, List< Type > rv, int limit)
Definition: Marshalling.java:255
static List< Object > deSerializeParameters(List< Object > parameters, Type type, AbstractConnection conn)
Definition: Marshalling.java:536
static Object deSerializeParameter(Object parameter, Type type, AbstractConnection conn)
Definition: Marshalling.java:405