code: public BagObject getBagObject (int index) {
          Object object = getObject (index);
          try {
              return (BagObject) object;
          } catch (ClassCastException exception) {
              log.warn ("Cannot cast value type (" + object.getClass ().getName () + ") to BagObject for index (" + index + ")");
          }
          return null;
      }
docs: Retrieve an indexed element and return it as a BagObject.
  
  @param index An integer value specifying the offset from the beginning of the array.
  @return The element as a BagObject, or null if the element is not found.