/** * Sets the list of body parts. * * @param bodyParts * the new list of <code>Entity</code> objects. */ public void setBodyParts(List<Entity> bodyParts) { this.bodyParts = bodyParts; for (Entity bodyPart : bodyParts) { bodyPart.setParent(parent); } }
/** * @see org.apache.james.mime4j.dom.Body#setParent(org.apache.james.mime4j.dom.Entity) */ public void setParent(Entity parent) { this.parent = parent; for (Entity bodyPart : bodyParts) { bodyPart.setParent(parent); } }
/** * Adds a body part to the end of the list of body parts. * * @param bodyPart * the body part. */ public void addBodyPart(Entity bodyPart) { if (bodyPart == null) throw new IllegalArgumentException(); bodyParts.add(bodyPart); bodyPart.setParent(parent); }
/** * Removes the body part at the specified position in the list of body * parts. * * @param index * index of the body part to be removed. * @return the removed body part. * @throws IndexOutOfBoundsException * if the index is out of range (index < 0 || index >= * getCount()). */ public Entity removeBodyPart(int index) { Entity bodyPart = bodyParts.remove(index); bodyPart.setParent(null); return bodyPart; }
/** * Inserts a body part at the specified position in the list of body parts. * * @param bodyPart * the body part. * @param index * index at which the specified body part is to be inserted. * @throws IndexOutOfBoundsException * if the index is out of range (index < 0 || index > * getCount()). */ public void addBodyPart(Entity bodyPart, int index) { if (bodyPart == null) throw new IllegalArgumentException(); bodyParts.add(index, bodyPart); bodyPart.setParent(parent); }
/** * Replaces the body part at the specified position in the list of body * parts with the specified body part. * * @param bodyPart * body part to be stored at the specified position. * @param index * index of body part to replace. * @return the replaced body part. * @throws IndexOutOfBoundsException * if the index is out of range (index < 0 || index >= * getCount()). */ public Entity replaceBodyPart(Entity bodyPart, int index) { if (bodyPart == null) throw new IllegalArgumentException(); Entity replacedEntity = bodyParts.set(index, bodyPart); if (bodyPart == replacedEntity) throw new IllegalArgumentException( "Cannot replace body part with itself"); bodyPart.setParent(parent); replacedEntity.setParent(null); return replacedEntity; }