Add explicit support for bag in java backend

Still testing. Not ready for review.