示例#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;
  }
 /** save the endpoint reference to the coordinator for this participant */
 protected void saveEndpointReference(OutputObjectState oos) throws IOException {
   // the toString method will do what we need
   oos.packString(endpoint.toString());
 }
示例#3
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;
  }
示例#4
0
  public boolean save_state(OutputObjectState os, int t) {
    boolean res = false;

    try {
      os.packInt(_heuristic);
      os.packBoolean(_committed);

      /*
       * Since we don't know what type of Xid we are using, leave it up to
       * XID to pack.
       */

      XidImple.pack(os, _tranID);

      /*
       * If no recovery object set then rely upon object serialisation!
       */

      if (_recoveryObject == null) {
        os.packInt(RecoverableXAConnection.OBJECT_RECOVERY);

        os.packString(_productName);
        os.packString(_productVersion);
        os.packString(_jndiName);

        if (_theXAResource instanceof Serializable) {
          try {
            ByteArrayOutputStream s = new ByteArrayOutputStream();
            ObjectOutputStream o = new ObjectOutputStream(s);

            o.writeObject(_theXAResource);
            o.close();

            os.packBoolean(true);
            String name = _theXAResource.getClass().getName();
            os.packString(name);

            os.packBytes(s.toByteArray());
          } catch (NotSerializableException ex) {
            jtaLogger.i18NLogger.warn_resources_arjunacore_savestate();

            return false;
          }
        } else {
          // have to rely upon XAResource.recover!

          os.packBoolean(false);
        }
      } else {
        os.packInt(RecoverableXAConnection.AUTO_RECOVERY);
        os.packString(_recoveryObject.getClass().getName());

        _recoveryObject.packInto(os);
      }

      res = true;
    } catch (Exception e) {
      jtaLogger.i18NLogger.warn_resources_arjunacore_savestateerror(
          _theXAResource.toString(), XAHelper.xidToString(_tranID), e);

      res = false;
    }

    if (res) res = super.save_state(os, t);

    return res;
  }