public <K, L extends Element> ElementMetadata<K, L> bindElement( ElementKey<K, L> key) { return delegate().bindElement(key); }
/** * Returns the appropriate metadata to use for the given qualified name. */ protected ElementMetadata<?, ?> findMetadata(QName qName) { if (metadata == null) { return null; } ElementKey<?, ?> childKey = metadata.findElement(qName); if (childKey == null) { return null; } ElementMetadata<?, ?> childMeta = metadata.bindElement(childKey); return childMeta; }
public <K, L extends Element> ElementMetadata<K, L> bindElement( ElementKey<K, L> key) { return delegate().bindElement(key); }
public <K, L extends Element> ElementMetadata<K, L> bindElement( ElementKey<K, L> key) { return delegate().bindElement(key); }
/** * Returns the appropriate metadata to use for the given qualified name. */ protected ElementMetadata<?, ?> findMetadata(QName qName) { if (metadata == null) { return null; } ElementKey<?, ?> childKey = metadata.findElement(qName); if (childKey == null) { return null; } ElementMetadata<?, ?> childMeta = metadata.bindElement(childKey); return childMeta; }
/** * Returns the appropriate metadata to use for the given qualified name. */ protected ElementMetadata<?, ?> findMetadata(QName qName) { if (metadata == null) { return null; } ElementKey<?, ?> childKey = metadata.findElement(qName); if (childKey == null) { return null; } ElementMetadata<?, ?> childMeta = metadata.bindElement(childKey); return childMeta; }
/** * Visit all of the children of this element, calling the element visitor * with the child element and child metadata for each child. */ private void visitChildren(ElementVisitor ev, ElementMetadata<?, ?> meta) throws ElementVisitor.StoppedException { // Visit children Iterator<Element> childIterator = getElementIterator(meta); while (childIterator.hasNext()) { Element child = childIterator.next(); ElementMetadata<?, ?> childMeta = (meta == null) ? null : meta.bindElement(child.getElementKey()); child.visit(ev, this, childMeta); } }
/** * Visit all of the children of this element, calling the element visitor * with the child element and child metadata for each child. */ private void visitChildren(ElementVisitor ev, ElementMetadata<?, ?> meta) throws ElementVisitor.StoppedException { // Visit children Iterator<Element> childIterator = getElementIterator(meta); while (childIterator.hasNext()) { Element child = childIterator.next(); ElementMetadata<?, ?> childMeta = (meta == null) ? null : meta.bindElement(child.getElementKey()); child.visit(ev, this, childMeta); } }
/** * Visit all of the children of this element, calling the element visitor * with the child element and child metadata for each child. */ private void visitChildren(ElementVisitor ev, ElementMetadata<?, ?> meta) throws ElementVisitor.StoppedException { // Visit children Iterator<Element> childIterator = getElementIterator(meta); while (childIterator.hasNext()) { Element child = childIterator.next(); ElementMetadata<?, ?> childMeta = (meta == null) ? null : meta.bindElement(child.getElementKey()); child.visit(ev, this, childMeta); } }
/** * Conditionally adds a new element path step. For absolute paths, it will * be added if the {@link QName} matches a valid child element 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 element 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 addIfElement(QName id) { ElementKey<?, ?> elemKey; if (selectedElement != null) { elemKey = selectedElement.findElement(id); if (elemKey == null) { return false; } selectedElement = selectedElement.bindElement(elemKey); } else { elemKey = ElementKey.of(id); } addToStepList(elemKey); return true; }
/** * Conditionally adds a new element path step. For absolute paths, it will * be added if the {@link QName} matches a valid child element 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 element 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 addIfElement(QName id) { ElementKey<?, ?> elemKey; if (selectedElement != null) { elemKey = selectedElement.findElement(id); if (elemKey == null) { return false; } selectedElement = selectedElement.bindElement(elemKey); } else { elemKey = ElementKey.of(id); } addToStepList(elemKey); return true; }
/** * Conditionally adds a new element path step. For absolute paths, it will * be added if the {@link QName} matches a valid child element 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 element 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 addIfElement(QName id) { ElementKey<?, ?> elemKey; if (selectedElement != null) { elemKey = selectedElement.findElement(id); if (elemKey == null) { return false; } selectedElement = selectedElement.bindElement(elemKey); } else { elemKey = ElementKey.of(id); } addToStepList(elemKey); return true; }
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); } } }
/** * 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); } }
/** * 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); } }