@SuppressWarnings("unchecked") private boolean packTransactionalInstance(final Field afield, OutputObjectState os) { Object ptr = null; try { ptr = afield.get(_theObject); if (ptr == null) { os.packBoolean(false); } else { os.packBoolean(true); UidHelper.packInto(_container.getUidForHandle((T) ptr), os); } } catch (final ClassCastException ex) { System.err.println("Field " + ptr + " is not a transactional instance!"); return false; } catch (final Exception ex) { ex.printStackTrace(); return false; } return true; }
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; }
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; }
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; }
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; }
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; }