/** * Adds a new attribute to the list. * * <p> Note: The importance parameter should not be null. The current * implementation allows null values for loadind old attributes persisted on * client side. The null check will be enabled in a future release. * * @param attributeId the id for this attribute * @param importance attribute importance, may be null if no importance is * defined * @throws NullPointerException if name is null * @throws IllegalArgumentException if an attribute with the same name and * type has already been added */ public void addAttribute(GoogleBaseAttributeId attributeId, GmAttribute.Importance importance) { if (attributeIds.contains(attributeId)) { throw new IllegalArgumentException("Attribute id already registered " + "in the attributes group " + attributeId); } attributes.add(new GmAttribute(attributeId, importance)); attributeIds.add(attributeId); }
/** Generate the XML representation for this tag. */ public void generate(XmlWriter w, ExtensionProfile extProfile) throws IOException { if (attributes.isEmpty()) { // Nothing to write return; } w.startElement(GoogleBaseNamespaces.GM, "attributes", null, null); w.startRepeatingElement(); for (GmAttribute attribute : attributes) { List<XmlWriter.Attribute> attributes = new ArrayList<XmlWriter.Attribute>(); GoogleBaseAttributeId id = attribute.getAttributeId(); attributes.add(new XmlWriter.Attribute("name", id.getName())); if (id.getType() != null) { attributes.add(new XmlWriter.Attribute("type", id.getType().getName())); } if (attribute.getImportance() != null) { attributes.add(new XmlWriter.Attribute("importance", attribute.getImportance().getXmlValue())); } w.simpleElement(GoogleBaseNamespaces.GM, "attribute", attributes, null); } w.endRepeatingElement(); w.endElement(); }
/** Generate the XML representation for this tag. */ public void generate(XmlWriter w, ExtensionProfile extProfile) throws IOException { if (attributes.isEmpty()) { // Nothing to write return; } w.startElement(GoogleBaseNamespaces.GM, "attributes", null, null); w.startRepeatingElement(); for (GmAttribute attribute : attributes) { List<XmlWriter.Attribute> attributes = new ArrayList<XmlWriter.Attribute>(); GoogleBaseAttributeId id = attribute.getAttributeId(); attributes.add(new XmlWriter.Attribute("name", id.getName())); if (id.getType() != null) { attributes.add(new XmlWriter.Attribute("type", id.getType().getName())); } if (attribute.getImportance() != null) { attributes.add(new XmlWriter.Attribute("importance", attribute.getImportance().getXmlValue())); } w.simpleElement(GoogleBaseNamespaces.GM, "attribute", attributes, null); } w.endRepeatingElement(); w.endElement(); }
/** * Adds a new attribute to the list. * * <p> Note: The importance parameter should not be null. The current * implementation allows null values for loadind old attributes persisted on * client side. The null check will be enabled in a future release. * * @param attributeId the id for this attribute * @param importance attribute importance, may be null if no importance is * defined * @throws NullPointerException if name is null * @throws IllegalArgumentException if an attribute with the same name and * type has already been added */ public void addAttribute(GoogleBaseAttributeId attributeId, GmAttribute.Importance importance) { if (attributeIds.contains(attributeId)) { throw new IllegalArgumentException("Attribute id already registered " + "in the attributes group " + attributeId); } attributes.add(new GmAttribute(attributeId, importance)); attributeIds.add(attributeId); }