}
private pn_atom_t convertToAtom(Object o)
{
pn_atom_t atom = new pn_atom_t();
//PN_NULL
if(o == null)
{
atom.setType(pn_type_t.PN_NULL);
}
//PN_BOOL
else if(o instanceof Boolean)
{
atom.setType(pn_type_t.PN_BOOL);
atom.getU().setAs_bool((Boolean)o);
}
//PN_UBYTE
else if(o instanceof UnsignedByte)
{
atom.setType(pn_type_t.PN_UBYTE);
atom.getU().setAs_ubyte(((UnsignedByte) o).shortValue());
}
//PN_BYTE
else if(o instanceof Byte)
{
atom.setType(pn_type_t.PN_BYTE);
atom.getU().setAs_byte((Byte) o);
}
//PN_USHORT
else if(o instanceof UnsignedShort)
{
atom.setType(pn_type_t.PN_USHORT);
atom.getU().setAs_ushort(((UnsignedShort) o).intValue());
}
//PN_SHORT
else if(o instanceof Short)
{
atom.setType(pn_type_t.PN_SHORT);
atom.getU().setAs_short((Short) o);
}
//PN_UINT
else if(o instanceof UnsignedInteger)
{
atom.setType(pn_type_t.PN_UINT);
atom.getU().setAs_uint(((UnsignedInteger) o).longValue());
}
//PN_INT
else if(o instanceof Integer)
{
atom.setType(pn_type_t.PN_INT);
atom.getU().setAs_int((Integer) o);
}
//PN_CHAR
else if(o instanceof Character)
{
atom.setType(pn_type_t.PN_CHAR);
atom.getU().setAs_char((Character) o);
}
//PN_ULONG
else if(o instanceof UnsignedLong)
{
atom.setType(pn_type_t.PN_ULONG);
atom.getU().setAs_ulong(((UnsignedLong) o).bigIntegerValue());
}
//PN_LONG
else if(o instanceof Long)
{
atom.setType(pn_type_t.PN_LONG);
atom.getU().setAs_long((Long) o);
}
//PN_TIMESTAMP
else if(o instanceof Date)
{
atom.setType(pn_type_t.PN_TIMESTAMP);
atom.getU().setAs_timestamp(((Date)o).getTime());
}
//PN_FLOAT
else if(o instanceof Float)
{
atom.setType(pn_type_t.PN_FLOAT);
atom.getU().setAs_float((Float) o);
}
//PN_DOUBLE
else if(o instanceof Double)
{
atom.setType(pn_type_t.PN_DOUBLE);
atom.getU().setAs_double((Double) o);
}
//PN_DECIMAL32
// TODO
//PN_DECIMAL64
// TODO
//PN_DECIMAL128
// TODO
//PN_UUID
else if (o instanceof UUID)
{
byte[] bytes = new byte[16];
ByteBuffer buf = ByteBuffer.wrap(bytes);
UUID uuid = (UUID) o;
buf.putLong(uuid.getMostSignificantBits());
buf.putLong(uuid.getLeastSignificantBits());
atom.setType(pn_type_t.PN_UUID);
pn_bytes_t val = new pn_bytes_t();
Proton.pn_bytes_from_array(val, bytes);
atom.getU().setAs_bytes(val);
val.delete();
}
//PN_BINARY
else if(o instanceof byte[] || o instanceof Binary)
{
byte[] bytes = (o instanceof byte[]) ? (byte[])o : ((Binary)o).getArray();
atom.setType(pn_type_t.PN_BINARY);
pn_bytes_t val = new pn_bytes_t();
Proton.pn_bytes_from_array(val, bytes);
atom.getU().setAs_bytes(val);
val.delete();
}
//PN_STRING
else if(o instanceof String)
{
byte[] bytes = ((String)o).getBytes(UTF8_CHARSET);
atom.setType(pn_type_t.PN_STRING);
pn_bytes_t val = new pn_bytes_t();
Proton.pn_bytes_from_array(val, bytes);
atom.getU().setAs_bytes(val);
val.delete();
}
//PN_SYMBOL
else if(o instanceof Symbol)
{
byte[] bytes = ((Symbol)o).toString().getBytes(ASCII_CHARSET);
atom.setType(pn_type_t.PN_STRING);
pn_bytes_t val = new pn_bytes_t();
Proton.pn_bytes_from_array(val, bytes);
atom.getU().setAs_bytes(val);
val.delete();
}
//PN_DESCRIBED
// TODO
//PN_ARRAY