Example #1
0
  private boolean packObjectType(final Field afield, OutputObjectState os) {
    try {
      if (afield.getType().equals(Boolean.class))
        os.packBoolean(((Boolean) afield.get(_theObject)).booleanValue());
      else if (afield.getType().equals(Byte.class))
        os.packByte(((Byte) afield.get(_theObject)).byteValue());
      else if (afield.getType().equals(Short.class))
        os.packShort(((Short) afield.get(_theObject)).shortValue());
      else if (afield.getType().equals(Integer.class))
        os.packInt(((Integer) afield.get(_theObject)).intValue());
      else if (afield.getType().equals(Long.class))
        os.packLong(((Long) afield.get(_theObject)).longValue());
      else if (afield.getType().equals(Float.class))
        os.packFloat(((Float) afield.get(_theObject)).floatValue());
      else if (afield.getType().equals(Double.class))
        os.packDouble(((Double) afield.get(_theObject)).doubleValue());
      else if (afield.getType().equals(Character.class))
        os.packChar(((Character) afield.get(_theObject)).charValue());
      else if (afield.getType().equals(String.class))
        os.packString((String) afield.get(_theObject));
      else if (afield.getType().isAnnotationPresent(Transactional.class))
        return packTransactionalInstance(afield, os);
      else return false;
    } catch (final Exception ex) {
      ex.printStackTrace();

      return false;
    }

    return true;
  }
Example #2
0
  private boolean packPrimitive(final Field afield, OutputObjectState os) {
    try {
      /*
       * TODO deal with arrays of primitive types.
       *
       * Workaround - provide saveState and restoreState annotations.
       */

      if (afield.getType().equals(Boolean.TYPE)) os.packBoolean(afield.getBoolean(_theObject));
      else if (afield.getType().equals(Byte.TYPE)) os.packByte(afield.getByte(_theObject));
      else if (afield.getType().equals(Short.TYPE)) os.packShort(afield.getShort(_theObject));
      else if (afield.getType().equals(Integer.TYPE)) os.packInt(afield.getInt(_theObject));
      else if (afield.getType().equals(Long.TYPE)) os.packLong(afield.getLong(_theObject));
      else if (afield.getType().equals(Float.TYPE)) os.packFloat(afield.getFloat(_theObject));
      else if (afield.getType().equals(Double.TYPE)) os.packDouble(afield.getDouble(_theObject));
      else if (afield.getType().equals(Character.TYPE)) os.packChar(afield.getChar(_theObject));
      else return false;
    } catch (final IOException ex) {
      return false;
    } catch (final Exception ex) {
      return false;
    }

    return true;
  }
Example #3
0
  private boolean packPrimitiveArray(final Field afield, OutputObjectState 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++) os.packInt(objs[i]);
      } else if (c.equals(boolean[].class)) {
        final boolean[] objs = (boolean[]) afield.get(_theObject);

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

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

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

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

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

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

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

      success = false;
    }

    return success;
  }
Example #4
0
  private boolean packObjectArray(final Field afield, OutputObjectState 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++) {
          if (objs[i] == null) os.packBoolean(false);
          else {
            os.packBoolean(true);
            os.packInt(objs[i]);
          }
        }
      } else if (c.equals(Boolean[].class)) {
        final Boolean[] objs = (Boolean[]) afield.get(_theObject);

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

        for (int i = 0; (i < size) && success; i++) {
          if (objs[i] == null) os.packBoolean(false);
          else {
            os.packBoolean(true);
            os.packByte(objs[i]);
          }
        }
      } else if (c.equals(Short[].class)) {
        final Short[] objs = (Short[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          if (objs[i] == null) os.packBoolean(false);
          else {
            os.packBoolean(true);
            os.packShort(objs[i]);
          }
        }
      } else if (c.equals(Long[].class)) {
        final Long[] objs = (Long[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          if (objs[i] == null) os.packBoolean(false);
          else {
            os.packBoolean(true);
            os.packLong(objs[i]);
          }
        }
      } else if (c.equals(Float[].class)) {
        final Float[] objs = (Float[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          if (objs[i] == null) os.packBoolean(false);
          else {
            os.packBoolean(true);
            os.packFloat(objs[i]);
          }
        }
      } else if (c.equals(Double[].class)) {
        final Double[] objs = (Double[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          if (objs[i] == null) os.packBoolean(false);
          else {
            os.packBoolean(true);
            os.packDouble(objs[i]);
          }
        }
      } else if (c.equals(Character[].class)) {
        final Character[] objs = (Character[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          if (objs[i] == null) os.packBoolean(false);
          else {
            os.packBoolean(true);
            os.packChar(objs[i]);
          }
        }
      } else if (c.equals(String[].class)) {
        final String[] objs = (String[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          if (objs[i] == null) os.packBoolean(false);
          else {
            os.packBoolean(true);
            os.packString(objs[i]);
          }
        }
      } else {
        System.err.println("Array type " + c + " not supported!");

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

      success = false;
    }

    return success;
  }