public <K> AttributeMetadata<K> bindAttribute(AttributeKey<K> key) { return delegate().bindAttribute(key); }
public <K> AttributeMetadata<K> bindAttribute(AttributeKey<K> key) { return delegate().bindAttribute(key); }
public <K> AttributeMetadata<K> bindAttribute(AttributeKey<K> key) { return delegate().bindAttribute(key); }
/** * 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 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 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; }
/** * Conditionally adds a new attribute path step. For absolute paths, it will * be added if the {@link QName} matches a valid child attribute type for * the current selected element. If the path is relative a new * {@link ElementKey} step corresponding to the name will be unconditionally * added. * * @param id qualified name of child attribute step to add * @return {@code true} if added successfully, {@code false} otherwise. * @throws PathException if this path is an attribute path. Once a path has * an attribute key no more steps may be added. */ public boolean addIfAttribute(QName id) { AttributeKey<?> attrKey; if (selectedElement != null) { attrKey = selectedElement.findAttribute(id); if (attrKey == null) { return false; } selectedAttribute = selectedElement.bindAttribute(attrKey); } else { attrKey = AttributeKey.of(id); } addToStepList(attrKey); return true; }
/** * Conditionally adds a new attribute path step. For absolute paths, it will * be added if the {@link QName} matches a valid child attribute type for * the current selected element. If the path is relative a new * {@link ElementKey} step corresponding to the name will be unconditionally * added. * * @param id qualified name of child attribute step to add * @return {@code true} if added successfully, {@code false} otherwise. * @throws PathException if this path is an attribute path. Once a path has * an attribute key no more steps may be added. */ public boolean addIfAttribute(QName id) { AttributeKey<?> attrKey; if (selectedElement != null) { attrKey = selectedElement.findAttribute(id); if (attrKey == null) { return false; } selectedAttribute = selectedElement.bindAttribute(attrKey); } else { attrKey = AttributeKey.of(id); } addToStepList(attrKey); return true; }
/** * Conditionally adds a new attribute path step. For absolute paths, it will * be added if the {@link QName} matches a valid child attribute type for * the current selected element. If the path is relative a new * {@link ElementKey} step corresponding to the name will be unconditionally * added. * * @param id qualified name of child attribute step to add * @return {@code true} if added successfully, {@code false} otherwise. * @throws PathException if this path is an attribute path. Once a path has * an attribute key no more steps may be added. */ public boolean addIfAttribute(QName id) { AttributeKey<?> attrKey; if (selectedElement != null) { attrKey = selectedElement.findAttribute(id); if (attrKey == null) { return false; } selectedAttribute = selectedElement.bindAttribute(attrKey); } else { attrKey = AttributeKey.of(id); } addToStepList(attrKey); return true; }
/** * 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 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 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; }
private static void addReferencedNamespaces(ElementMetadata<?, ?> metadata, ImmutableSet.Builder<XmlNamespace> builder, Set<ElementKey<?, ?>> added) { // Avoid recursive looping if (added.contains(metadata.getKey())) { return; } added.add(metadata.getKey()); // Add namespace for this element (if any) XmlNamespace elemNs = metadata.getName().getNs(); if (elemNs != null) { builder.add(elemNs); } // Add namespace for all attributes (if any) for (AttributeKey<?> attrKey : metadata.getAttributes()) { AttributeMetadata<?> attrMetadata = metadata.bindAttribute(attrKey); XmlNamespace attrNs = attrMetadata.getName().getNs(); if (attrNs != null) { builder.add(attrNs); } } // Add namespace for all child elements (recursively) for (ElementKey<?, ?> elemKey : metadata.getElements()) { ElementMetadata<?, ?> childMetadata = metadata.bindElement(elemKey); addReferencedNamespaces(childMetadata, builder, added); } }
private static void addReferencedNamespaces(ElementMetadata<?, ?> metadata, ImmutableSet.Builder<XmlNamespace> builder, Set<ElementKey<?, ?>> added) { // Avoid recursive looping if (added.contains(metadata.getKey())) { return; } added.add(metadata.getKey()); // Add namespace for this element (if any) XmlNamespace elemNs = metadata.getName().getNs(); if (elemNs != null) { builder.add(elemNs); } // Add namespace for all attributes (if any) for (AttributeKey<?> attrKey : metadata.getAttributes()) { AttributeMetadata<?> attrMetadata = metadata.bindAttribute(attrKey); XmlNamespace attrNs = attrMetadata.getName().getNs(); if (attrNs != null) { builder.add(attrNs); } } // Add namespace for all child elements (recursively) for (ElementKey<?, ?> elemKey : metadata.getElements()) { ElementMetadata<?, ?> childMetadata = metadata.bindElement(elemKey); addReferencedNamespaces(childMetadata, builder, added); } }
private static void addReferencedNamespaces(ElementMetadata<?, ?> metadata, ImmutableSet.Builder<XmlNamespace> builder, Set<ElementKey<?, ?>> added) { // Avoid recursive looping if (added.contains(metadata.getKey())) { return; } added.add(metadata.getKey()); // Add namespace for this element (if any) XmlNamespace elemNs = metadata.getName().getNs(); if (elemNs != null) { builder.add(elemNs); } // Add namespace for all attributes (if any) for (AttributeKey<?> attrKey : metadata.getAttributes()) { AttributeMetadata<?> attrMetadata = metadata.bindAttribute(attrKey); XmlNamespace attrNs = attrMetadata.getName().getNs(); if (attrNs != null) { builder.add(attrNs); } } // Add namespace for all child elements (recursively) for (ElementKey<?, ?> elemKey : metadata.getElements()) { ElementMetadata<?, ?> childMetadata = metadata.bindElement(elemKey); addReferencedNamespaces(childMetadata, builder, added); } }
/** * For parsing, we always parse directly into the first source. */ public void parse(Element element, ElementMetadata<?, ?> metadata, Object value) throws ParseException { if (sources.isEmpty()) { return; } MetadataKey<?> source = sources.get(0); if (source instanceof ElementKey<?, ?>) { ElementKey<?, ?> childKey = (ElementKey<?, ?>) source; ElementMetadata<?, ?> childMeta = metadata.bindElement(childKey); Element child = element.getElement(childKey); if (child == null) { try { child = childMeta.createElement(); } catch (ContentCreationException e) { throw new ParseException(e); } element.addElement(childKey, child); } childMeta.parseValue(child, childMeta, value); } else { AttributeKey<?> attKey = (AttributeKey<?>) source; AttributeMetadata<?> attMeta = metadata.bindAttribute(attKey); attMeta.parseValue(element, metadata, value); } } }
/** * For parsing, we always parse directly into the first source. */ public void parse(Element element, ElementMetadata<?, ?> metadata, Object value) throws ParseException { if (sources.isEmpty()) { return; } MetadataKey<?> source = sources.get(0); if (source instanceof ElementKey<?, ?>) { ElementKey<?, ?> childKey = (ElementKey<?, ?>) source; ElementMetadata<?, ?> childMeta = metadata.bindElement(childKey); Element child = element.getElement(childKey); if (child == null) { try { child = childMeta.createElement(); } catch (ContentCreationException e) { throw new ParseException(e); } element.addElement(childKey, child); } childMeta.parseValue(child, childMeta, value); } else { AttributeKey<?> attKey = (AttributeKey<?>) source; AttributeMetadata<?> attMeta = metadata.bindAttribute(attKey); attMeta.parseValue(element, metadata, value); } } }
/** * For parsing, we always parse directly into the first source. */ public void parse(Element element, ElementMetadata<?, ?> metadata, Object value) throws ParseException { if (sources.isEmpty()) { return; } MetadataKey<?> source = sources.get(0); if (source instanceof ElementKey<?, ?>) { ElementKey<?, ?> childKey = (ElementKey<?, ?>) source; ElementMetadata<?, ?> childMeta = metadata.bindElement(childKey); Element child = element.getElement(childKey); if (child == null) { try { child = childMeta.createElement(); } catch (ContentCreationException e) { throw new ParseException(e); } element.addElement(childKey, child); } childMeta.parseValue(child, childMeta, value); } else { AttributeKey<?> attKey = (AttributeKey<?>) source; AttributeMetadata<?> attMeta = metadata.bindAttribute(attKey); attMeta.parseValue(element, metadata, value); } } }
/** * Calculate the namespaces on an element using the given visitor to store * the namespaces. We cheat by using an attribute visitor for even visiting * the element names, because all we're doing with the visitor is adding a * QName. */ private static void calculateNamespaces(Map<String, XmlNamespace> namespaces, Element e, ElementMetadata<?, ?> metadata) { QName name = (metadata == null) ? e.getElementId() : metadata.getName(); addNamespace(namespaces, name); Iterator<Attribute> attIter = e.getAttributeIterator(metadata); while (attIter.hasNext()) { Attribute att = attIter.next(); AttributeKey<?> attKey = att.getAttributeKey(); AttributeMetadata<?> attMeta = (metadata == null) ? null : metadata.bindAttribute(attKey); name = (attMeta == null) ? attKey.getId() : attMeta.getName(); addNamespace(namespaces, name); } Iterator<Element> childIter = e.getElementIterator(metadata); while (childIter.hasNext()) { Element child = childIter.next(); ElementMetadata<?, ?> childMeta = (metadata == null) ? null : metadata.bindElement(child.getElementKey()); calculateNamespaces(namespaces, child, childMeta); } }
/** * Calculate the namespaces on an element using the given visitor to store * the namespaces. We cheat by using an attribute visitor for even visiting * the element names, because all we're doing with the visitor is adding a * QName. */ private static void calculateNamespaces(Map<String, XmlNamespace> namespaces, Element e, ElementMetadata<?, ?> metadata) { QName name = (metadata == null) ? e.getElementId() : metadata.getName(); addNamespace(namespaces, name); Iterator<Attribute> attIter = e.getAttributeIterator(metadata); while (attIter.hasNext()) { Attribute att = attIter.next(); AttributeKey<?> attKey = att.getAttributeKey(); AttributeMetadata<?> attMeta = (metadata == null) ? null : metadata.bindAttribute(attKey); name = (attMeta == null) ? attKey.getId() : attMeta.getName(); addNamespace(namespaces, name); } Iterator<Element> childIter = e.getElementIterator(metadata); while (childIter.hasNext()) { Element child = childIter.next(); ElementMetadata<?, ?> childMeta = (metadata == null) ? null : metadata.bindElement(child.getElementKey()); calculateNamespaces(namespaces, child, childMeta); } }