@Override public String toXML() { if ((items == null) || (items.size() == 0)) { return super.toXML(); } else { StringBuilder builder = new StringBuilder("<"); builder.append(getElementName()); builder.append(" node='"); builder.append(getNode()); if (notify != null) { builder.append("' "); builder.append(type.getElementAttribute()); builder.append("='"); builder.append(notify.equals(Boolean.TRUE) ? 1 : 0); builder.append("'>"); } else { builder.append("'>"); for (PacketExtension item : items) { builder.append(item.toXML()); } } builder.append("</"); builder.append(getElementName()); builder.append(">"); return builder.toString(); } }
/** * Construct an instance with a list representing items that have been published or deleted. * * <p>Valid scenarios are: * <li>Request items from node - itemsType = {@link ItemsElementType#items}, items = list of * {@link Item} and an optional value for the <b>max_items</b> attribute. * <li>Request to delete items - itemsType = {@link ItemsElementType#retract}, items = list of * {@link Item} containing only id's and an optional value for the <b>notify</b> attribute. * <li>Items published event - itemsType = {@link ItemsElementType#items}, items = list of {@link * Item} and attributeValue = <code>null</code> * <li>Items deleted event - itemsType = {@link ItemsElementType#items}, items = list of {@link * RetractItem} and attributeValue = <code>null</code> * * @param itemsType Type of representation * @param nodeId The node to which the items are being sent or deleted * @param items The list of {@link Item} or {@link RetractItem} * @param attributeValue The value of the <b>max_items</b> */ public ItemsExtension( ItemsElementType itemsType, String nodeId, List<? extends PacketExtension> items) { super(itemsType.getNodeElement(), nodeId); type = itemsType; this.items = items; }