public ElementKey<?, ?> adapt(String kind) { return delegate().adapt(kind); }
public ElementMetadata<D, E> bind(MetadataContext context) { return delegate().bind(context); }
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); } }
/** * 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; }
/** * Checks that a particular piece of metadata is not multiple cardinality. * * @throws IllegalStateException if the metadata is multiple cardinality */ private static void checkNotMultiple(ElementMetadata<?, ?> meta) { if (meta != null && meta.getCardinality() != Cardinality.SINGLE) { throw new IllegalStateException("Metadata for key " + meta.getKey() + " represents a multiple-cardinality element." + " The path cannot contain more than one multiple-cardinality" + " element."); } }
public void validate(ValidationContext vc, Element e, ElementMetadata<?, ?> metadata) { ElementKey<?, ?> key = metadata.getKey(); && metadata.isContentRequired()) { vc.addError(e, CoreErrorDomain.ERR.missingTextContent.withInternalReason( "Element " + key.getId() + " must contain a text content value.")); for (AttributeKey<?> attributeKey : metadata.getAttributes()) { AttributeMetadata<?> attMeta = metadata.bindAttribute(attributeKey); if (attMeta.isRequired() && e.getAttributeValue(attributeKey) == null) { vc.addError(e, CoreErrorDomain.ERR.missingAttribute.withInternalReason( for (ElementKey<?, ?> childKey : metadata.getElements()) { ElementMetadata<?, ?> childMeta = metadata.bindElement(childKey); if (childMeta.isRequired() && !e.hasElement(childKey)) { vc.addError(e, CoreErrorDomain.ERR.missingExtensionElement.withInternalReason(
/** * 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); } } }
ElementMetadata<?, ?> childMeta = metadata.bindElement(nextKey); if (!childMeta.isVisible()) { continue; childMeta.getSingleVirtualElement(); if (singleVirtual != null) { Element generated = childMeta.getMultipleVirtualElement(); if (multipleVirtual != null) { Collection<? extends Element> virtualElements =
/** * 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); } }
if (child != null) { ElementMetadata<?, ?> childMeta = (metadata == null) ? null : metadata.bindElement(childKey); Object value = (childMeta == null) ? child.getTextValue() : childMeta.generateValue(child, childMeta); if (value != null) { return value; AttributeKey<?> attKey = (AttributeKey<?>) source; AttributeMetadata<?> attMeta = (metadata == null) ? null : metadata.bindAttribute(attKey); Object value = (attMeta == null) ? element.getAttributeValue(attKey) : attMeta.generateValue(element, metadata);
/** * 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; }
ElementKey<?, ?> childKey = (ElementKey<?, ?>) steps.get(i); ElementMetadata<?, ?> childMetadata = (parentMetadata == null) ? null : parentMetadata.bindElement(childKey); || childMetadata.getCardinality() == Cardinality.SINGLE) { Element child = getOrCreateChild(parent, childKey); parent = child;
/** * Generates the text value for a given key and metadata. If the metadata is * null this will just return the text value, but if the metadata is not null * it will have the metadata generate the value. */ static Object generateTextValue( Element element, ElementMetadata<?, ?> metadata) { if (metadata != null) { return metadata.generateValue(element, metadata); } return element.getTextValue(); }
public <K, L extends Element> ElementMetadata<K, L> bindElement( ElementKey<K, L> key) { return delegate().bindElement(key); }
public Cardinality getCardinality() { return delegate().getCardinality(); }
public <K> AttributeMetadata<K> bindAttribute(AttributeKey<K> key) { return delegate().bindAttribute(key); }
AttributeIterator(Element element, ElementMetadata<?, ?> metadata, Map<QName, Attribute> attributes) { this.element = element; this.metadata = metadata; this.metadataIterator = (metadata == null) ? null : metadata.getAttributes().iterator(); this.attributeIterator = (attributes == null) ? null : attributes.entrySet().iterator(); nextAttribute = findNextAttribute(); }
public E createElement() throws ContentCreationException { return delegate().createElement(); }
public AttributeKey<?> findAttribute(QName id) { return delegate().findAttribute(id); }
public ElementKey<?, ?> findElement(QName id) { return delegate().findElement(id); }