/** * Finds the next valid undeclared attribute in the map. */ private Attribute findNextUndeclaredAttribute() { if (attributeIterator != null) { while (attributeIterator.hasNext()) { Entry<QName, Attribute> entry = attributeIterator.next(); Attribute attribute = entry.getValue(); if (isUndeclared(attribute.getAttributeKey())) { return entry.getValue(); } } // No more attributes, turn the iterator off. attributeIterator = null; } // Go back and check for any remaining declared attributes if needed. mode = metadataIterator != null && metadataIterator.hasNext() ? Mode.DECLARED : Mode.DONE; return null; }
/** * Get the value of an attribute by id. */ public Object getAttributeValue(QName id) { if (state.attributes == null) { return null; } Attribute attribute = state.attributes.get(id); return (attribute == null) ? null : attribute.getValue(); }
/** * Construct an attribute using the given key and value. * * @param key the key to this attribute, contains the id and datatype. * @param value the attribute value * @throws IllegalArgumentException if the key is invalid for the * value (incompatible datatype). * @throws NullPointerException if the key or value is null */ Attribute(AttributeKey<?> key, Object value) { this.key = Preconditions.checkNotNull(key, "key"); setValue(value); }
/** * Get a list of attributes for the given element. */ protected List<XmlWriter.Attribute> getAttributes(Element e, ElementMetadata<?, ?> metadata) { List<XmlWriter.Attribute> attrs = null; Iterator<Attribute> attributeIterator = e.getAttributeIterator(metadata); if (attributeIterator.hasNext()) { ElementKey<?, ?> key = e.getElementKey(); attrs = new ArrayList<XmlWriter.Attribute>(); while (attributeIterator.hasNext()) { Attribute attribute = attributeIterator.next(); AttributeKey<?> attKey = attribute.getAttributeKey(); AttributeMetadata<?> attMeta = (metadata == null) ? null : metadata.bindAttribute(attKey); QName qName = attMeta != null ? attMeta.getName() : attKey.getId(); String alias = (qName.getNs() != null) ? qName.getNs().getAlias() : null; attrs.add(new XmlWriter.Attribute(alias, qName.getLocalName(), attribute.getValue().toString())); } } return attrs; }
/** * Add attribute by value. If the value is {@code null} the value will be * removed. * * @param key attribute key that is being added * @param attrValue attribute value or {@code null} to remove */ public Element setAttributeValue(AttributeKey<?> key, Object attrValue) { if (attrValue == null) { removeAttributeValue(key); } else { setAttribute(key, new Attribute(key, attrValue)); } return this; }
/** * Locks this element. A locked element cannot have any changes made to its * content or its attributes or child elements. This will also lock all * attributes and child elements as well. Once this method has been called, * this element can be safely published to other threads. */ public Element lock() { state.locked = true; if (state.attributes != null) { for (Attribute att : state.attributes.values()) { att.lock(); } } if (state.elements != null) { for (Object childObj : state.elements.values()) { if (childObj instanceof Element) { ((Element) childObj).lock(); } else { for (Element child : castElementCollection(childObj)) { child.lock(); } } } } return this; }
/** * Get a list of attributes for the given element. */ protected List<XmlWriter.Attribute> getAttributes(Element e, ElementMetadata<?, ?> metadata) { List<XmlWriter.Attribute> attrs = null; Iterator<Attribute> attributeIterator = e.getAttributeIterator(metadata); if (attributeIterator.hasNext()) { ElementKey<?, ?> key = e.getElementKey(); attrs = new ArrayList<XmlWriter.Attribute>(); while (attributeIterator.hasNext()) { Attribute attribute = attributeIterator.next(); AttributeKey<?> attKey = attribute.getAttributeKey(); AttributeMetadata<?> attMeta = (metadata == null) ? null : metadata.bindAttribute(attKey); QName qName = attMeta != null ? attMeta.getName() : attKey.getId(); String alias = (qName.getNs() != null) ? qName.getNs().getAlias() : null; attrs.add(new XmlWriter.Attribute(alias, qName.getLocalName(), attribute.getValue().toString())); } } return attrs; }
/** * Add attribute by value. If the value is {@code null} the value will be * removed. * * @param key attribute key that is being added * @param attrValue attribute value or {@code null} to remove */ public Element setAttributeValue(AttributeKey<?> key, Object attrValue) { if (attrValue == null) { removeAttributeValue(key); } else { setAttribute(key, new Attribute(key, attrValue)); } return this; }
/** * Locks this element. A locked element cannot have any changes made to its * content or its attributes or child elements. This will also lock all * attributes and child elements as well. Once this method has been called, * this element can be safely published to other threads. */ public Element lock() { state.locked = true; if (state.attributes != null) { for (Attribute att : state.attributes.values()) { att.lock(); } } if (state.elements != null) { for (Object childObj : state.elements.values()) { if (childObj instanceof Element) { ((Element) childObj).lock(); } else { for (Element child : castElementCollection(childObj)) { child.lock(); } } } } return this; }
/** * Get a list of attributes for the given element. */ protected List<XmlWriter.Attribute> getAttributes(Element e, ElementMetadata<?, ?> metadata) { List<XmlWriter.Attribute> attrs = null; Iterator<Attribute> attributeIterator = e.getAttributeIterator(metadata); if (attributeIterator.hasNext()) { ElementKey<?, ?> key = e.getElementKey(); attrs = new ArrayList<XmlWriter.Attribute>(); while (attributeIterator.hasNext()) { Attribute attribute = attributeIterator.next(); AttributeKey<?> attKey = attribute.getAttributeKey(); AttributeMetadata<?> attMeta = (metadata == null) ? null : metadata.bindAttribute(attKey); QName qName = attMeta != null ? attMeta.getName() : attKey.getId(); String alias = (qName.getNs() != null) ? qName.getNs().getAlias() : null; attrs.add(new XmlWriter.Attribute(alias, qName.getLocalName(), attribute.getValue().toString())); } } return attrs; }
/** * Get the value of an attribute by id. */ public Object getAttributeValue(QName id) { if (state.attributes == null) { return null; } Attribute attribute = state.attributes.get(id); return (attribute == null) ? null : attribute.getValue(); }
/** * Add attribute by value. If the value is {@code null} the value will be * removed. * * @param key attribute key that is being added * @param attrValue attribute value or {@code null} to remove */ public Element setAttributeValue(AttributeKey<?> key, Object attrValue) { if (attrValue == null) { removeAttributeValue(key); } else { setAttribute(key, new Attribute(key, attrValue)); } return this; }
/** * Finds the next valid undeclared attribute in the map. */ private Attribute findNextUndeclaredAttribute() { if (attributeIterator != null) { while (attributeIterator.hasNext()) { Entry<QName, Attribute> entry = attributeIterator.next(); Attribute attribute = entry.getValue(); if (isUndeclared(attribute.getAttributeKey())) { return entry.getValue(); } } // No more attributes, turn the iterator off. attributeIterator = null; } // Go back and check for any remaining declared attributes if needed. mode = metadataIterator != null && metadataIterator.hasNext() ? Mode.DECLARED : Mode.DONE; return null; }
/** * Construct an attribute using the given key and value. * * @param key the key to this attribute, contains the id and datatype. * @param value the attribute value * @throws IllegalArgumentException if the key is invalid for the * value (incompatible datatype). * @throws NullPointerException if the key or value is null */ Attribute(AttributeKey<?> key, Object value) { this.key = Preconditions.checkNotNull(key, "key"); setValue(value); }
/** * Locks this element. A locked element cannot have any changes made to its * content or its attributes or child elements. This will also lock all * attributes and child elements as well. Once this method has been called, * this element can be safely published to other threads. */ public Element lock() { state.locked = true; if (state.attributes != null) { for (Attribute att : state.attributes.values()) { att.lock(); } } if (state.elements != null) { for (Object childObj : state.elements.values()) { if (childObj instanceof Element) { ((Element) childObj).lock(); } else { for (Element child : castElementCollection(childObj)) { child.lock(); } } } } return this; }
@Override public String toString() { ToStringHelper helper = Objects.toStringHelper(this); helper.addValue(getElementId() + "@" + Integer.toHexString(hashCode())); Iterator<Attribute> aIter = getAttributeIterator(); while (aIter.hasNext()) { Attribute att = aIter.next(); helper.add(att.getAttributeKey().getId().toString(), att.getValue()); } if (hasTextValue()) { helper.addValue(getTextValue()); } return helper.toString(); } }
/** * Get the value of an attribute by id. */ public Object getAttributeValue(QName id) { if (state.attributes == null) { return null; } Attribute attribute = state.attributes.get(id); return (attribute == null) ? null : attribute.getValue(); }
/** * Finds the next declared attribute, or null if no more exist. */ private Attribute findNextDeclaredAttribute() { if (metadataIterator != null) { while (metadataIterator.hasNext()) { AttributeKey<?> nextKey = metadataIterator.next(); if (ElementCreatorImpl.ATTRIBUTE_MARKER == nextKey) { mode = Mode.UNDECLARED; return null; } AttributeMetadata<?> attMeta = metadata.bindAttribute(nextKey); if (!attMeta.isVisible()) { continue; } Object value = attMeta.generateValue(element, metadata); if (value != null) { return new Attribute(nextKey, value); } } // No more declared attributes, turn the iterator off. metadataIterator = null; } // Check undeclared next. mode = Mode.UNDECLARED; return null; }
/** * Finds the next valid undeclared attribute in the map. */ private Attribute findNextUndeclaredAttribute() { if (attributeIterator != null) { while (attributeIterator.hasNext()) { Entry<QName, Attribute> entry = attributeIterator.next(); Attribute attribute = entry.getValue(); if (isUndeclared(attribute.getAttributeKey())) { return entry.getValue(); } } // No more attributes, turn the iterator off. attributeIterator = null; } // Go back and check for any remaining declared attributes if needed. mode = metadataIterator != null && metadataIterator.hasNext() ? Mode.DECLARED : Mode.DONE; return null; }
/** * Construct an attribute using the given key and value. * * @param key the key to this attribute, contains the id and datatype. * @param value the attribute value * @throws IllegalArgumentException if the key is invalid for the * value (incompatible datatype). * @throws NullPointerException if the key or value is null */ Attribute(AttributeKey<?> key, Object value) { this.key = Preconditions.checkNotNull(key, "key"); setValue(value); }