Esempio n. 1
0
 /**
  * Unwrap data, i.e. build an object instance from a received response packet.
  *
  * @param dataPacket data packet
  * @return value of object, or null if it cannot be build for instance if the response packet does
  *     not corresponds to a managed request
  */
 @SuppressWarnings("unchecked")
 public Object unwrap(RecvSimObjectData dataPacket) {
   int defId = dataPacket.getDefineID();
   for (Map.Entry<Class<?>, Integer> me : definitionIds.entrySet()) {
     if (me.getValue().intValue() == defId) {
       //
       // build object
       try {
         return unwrap(me.getKey(), dataPacket);
       } catch (IllegalDataDefinition e) {
         return null;
       }
     }
   }
   return null;
 }
Esempio n. 2
0
  /**
   * Unwrap a field
   *
   * @param o destination object
   * @param f field
   * @param ro receive bufer
   * @throws IllegalArgumentException
   * @throws IllegalAccessException
   */
  private void unwrapField(Object o, Field f, RecvSimObjectData ro)
      throws IllegalArgumentException, IllegalAccessException {
    FlightSimData fsd = f.getAnnotation(FlightSimData.class);

    boolean accStatus = f.isAccessible();
    f.setAccessible(true);

    // determinate field class
    if (f.getType().equals(Float.class) || f.getType().equals(float.class)) {
      Float val = new Float(ro.getDataFloat32());
      f.set(o, val);
    } else if (f.getType().equals(Double.class) || f.getType().equals(double.class)) {
      Double val = new Double(ro.getDataFloat64());
      f.set(o, val);
    } else if (f.getType().equals(Integer.class) || f.getType().equals(int.class)) {
      Integer val = new Integer(ro.getDataInt32());
      f.set(o, val);
    } else if (f.getType().equals(Long.class) || f.getType().equals(long.class)) {
      Long val = new Long(ro.getDataInt64());
      f.set(o, val);
    } else if (f.getType().equals(Boolean.class) || f.getType().equals(boolean.class)) {
      Boolean val = new Boolean(ro.getDataInt32() != 0);
      f.set(o, val);
    } else if (f.getType().equals(Short.class) || f.getType().equals(short.class)) {
      Short val = new Short((short) ro.getDataInt32());
      f.set(o, val);
    } else if (f.getType().equals(LatLonAlt.class)) {
      LatLonAlt val = ro.getLatLonAlt();
      f.set(o, val);
    } else if (f.getType().equals(XYZ.class)) {
      XYZ val = ro.getXYZ();
      f.set(o, val);
    } else if (f.getType().equals(Waypoint.class)) {
      Waypoint val = ro.getWaypoint();
      f.set(o, val);
    } else if (f.getType().equals(MarkerState.class)) {
      MarkerState val = ro.getMarkerState();
      f.set(o, val);
    } else if (f.getType().equals(String.class)) {
      int len = fsd.stringWidth();
      String val = null;
      switch (len) {
        case 8:
          val = ro.getDataString8();
          break;
        case 32:
          val = ro.getDataString32();
          break;
        case 64:
          val = ro.getDataString64();
          break;
        case 128:
          val = ro.getDataString128();
          break;
        case 256:
          val = ro.getDataString256();
          break;
        case 260:
          val = ro.getDataString260();
          break;
      }
      f.set(o, val);
    }

    f.setAccessible(accStatus);
  }