Exemplo n.º 1
0
  private boolean unpackPrimitive(final Field afield, InputObjectState os) {
    try {
      // TODO arrays

      if (afield.getType().equals(Boolean.TYPE)) afield.setBoolean(_theObject, os.unpackBoolean());
      else if (afield.getType().equals(Byte.TYPE)) afield.setByte(_theObject, os.unpackByte());
      else if (afield.getType().equals(Short.TYPE)) afield.setShort(_theObject, os.unpackShort());
      else if (afield.getType().equals(Integer.TYPE)) afield.setInt(_theObject, os.unpackInt());
      else if (afield.getType().equals(Long.TYPE)) afield.setLong(_theObject, os.unpackLong());
      else if (afield.getType().equals(Float.TYPE)) afield.setFloat(_theObject, os.unpackFloat());
      else if (afield.getType().equals(Double.TYPE))
        afield.setDouble(_theObject, os.unpackDouble());
      else if (afield.getType().equals(Character.TYPE)) afield.setChar(_theObject, os.unpackChar());
      else return false;
    } catch (final IOException ex) {
      ex.printStackTrace();

      return false;
    } catch (final Exception ex) {
      ex.printStackTrace();

      return false;
    }

    return true;
  }
Exemplo n.º 2
0
  private boolean unpackPrimitiveArray(final Field afield, InputObjectState os) {
    boolean success = true;

    try {
      Class<?> c = afield.getType();
      final int size = Array.getLength(afield.get(_theObject));

      if (c.equals(int[].class)) {
        final int[] objs = (int[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackInt();
      } else if (c.equals(boolean[].class)) {
        final boolean[] objs = (boolean[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackBoolean();
      } else if (c.equals(byte[].class)) {
        final byte[] objs = (byte[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackByte();
      } else if (c.equals(short[].class)) {
        final short[] objs = (short[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackShort();
      } else if (c.equals(long[].class)) {
        final long[] objs = (long[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackLong();
      } else if (c.equals(float[].class)) {
        final float[] objs = (float[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackFloat();
      } else if (c.equals(double[].class)) {
        final double[] objs = (double[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackDouble();
      } else if (c.equals(char[].class)) {
        final char[] objs = (char[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackChar();
      } else success = false;
    } catch (final Throwable ex) {
      ex.printStackTrace();

      success = false;
    }

    return success;
  }
Exemplo n.º 3
0
  private boolean unpackObjectType(final Field afield, InputObjectState os) {
    try {
      // TODO arrays

      if (afield.getType().equals(Boolean.class))
        afield.set(_theObject, new Boolean(os.unpackBoolean()));
      else if (afield.getType().equals(Byte.class))
        afield.set(_theObject, new Byte(os.unpackByte()));
      else if (afield.getType().equals(Short.class))
        afield.set(_theObject, new Short(os.unpackShort()));
      else if (afield.getType().equals(Integer.class))
        afield.set(_theObject, new Integer(os.unpackInt()));
      else if (afield.getType().equals(Long.class))
        afield.set(_theObject, new Long(os.unpackLong()));
      else if (afield.getType().equals(Float.class))
        afield.set(_theObject, new Float(os.unpackFloat()));
      else if (afield.getType().equals(Double.class))
        afield.set(_theObject, new Double(os.unpackDouble()));
      else if (afield.getType().equals(Character.class))
        afield.set(_theObject, new Character(os.unpackChar()));
      else if (afield.getType().equals(String.class)) afield.set(_theObject, os.unpackString());
      else if (afield.getType().isAnnotationPresent(Transactional.class))
        return unpackTransactionalInstance(afield, os);
      else return false;
    } catch (final IOException ex) {
      ex.printStackTrace();

      return false;
    } catch (final Exception ex) {
      ex.printStackTrace();

      return false;
    }

    return true;
  }
Exemplo n.º 4
0
  private boolean unpackObjectArray(final Field afield, InputObjectState os) {
    boolean success = true;

    try {
      Class<?> c = afield.getType();
      final int size = Array.getLength(afield.get(_theObject));

      if (c.equals(Integer[].class)) {
        final Integer[] objs = (Integer[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackInt();
          else objs[i] = null;
        }
      } else if (c.equals(Boolean[].class)) {
        final Boolean[] objs = (Boolean[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackBoolean();
          else objs[i] = null;
        }
      } else if (c.equals(Byte[].class)) {
        final Byte[] objs = (Byte[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackByte();
          else objs[i] = null;
        }
      } else if (c.equals(Short[].class)) {
        final Short[] objs = (Short[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackShort();
          else objs[i] = null;
        }
      } else if (c.equals(Long[].class)) {
        final Long[] objs = (Long[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackLong();
          else objs[i] = null;
        }
      } else if (c.equals(Float[].class)) {
        final Float[] objs = (Float[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackFloat();
          else objs[i] = null;
        }
      } else if (c.equals(Double[].class)) {
        final Double[] objs = (Double[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackDouble();
          else objs[i] = null;
        }
      } else if (c.equals(Character[].class)) {
        final Character[] objs = (Character[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackChar();
          else objs[i] = null;
        }
      } else if (c.equals(String[].class)) {
        final String[] objs = (String[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackString();
          else objs[i] = null;
        }
      } else {
        System.err.println("Array type " + c + " not supported!");

        success = false;
      }
    } catch (final Throwable ex) {
      ex.printStackTrace();

      success = false;
    }

    return success;
  }