/** * Returns the last element along the path, starting with the given root * element. If at any point there is no valid element this method will return * {@code null}. If the path ends in an attribute key this will return the * parent of that attribute, if it ends in an element key it will return that * element. * * @throws NullPointerException if the root or path is null. * @throws IllegalArgumentException if there are any repeating elements along * the path. */ static Element getFinalElement(Path path, Element rootElement) { Element parent = getParentElement(path, rootElement); if (path.selectsAttribute() || parent == null) { return parent; } return parent.getElement(path.getSelectedElementKey()); }
/** * Returns the last element along the path, starting with the given root * element. If at any point there is no valid element this method will return * {@code null}. If the path ends in an attribute key this will return the * parent of that attribute, if it ends in an element key it will return that * element. * * @throws NullPointerException if the root or path is null. * @throws IllegalArgumentException if there are any repeating elements along * the path. */ static Element getFinalElement(Path path, Element rootElement) { Element parent = getParentElement(path, rootElement); if (path.selectsAttribute() || parent == null) { return parent; } return parent.getElement(path.getSelectedElementKey()); }
/** * Returns the last element along the path, starting with the given root * element. If at any point there is no valid element this method will return * {@code null}. If the path ends in an attribute key this will return the * parent of that attribute, if it ends in an element key it will return that * element. * * @throws NullPointerException if the root or path is null. * @throws IllegalArgumentException if there are any repeating elements along * the path. */ static Element getFinalElement(Path path, Element rootElement) { Element parent = getParentElement(path, rootElement); if (path.selectsAttribute() || parent == null) { return parent; } return parent.getElement(path.getSelectedElementKey()); }
/** * Returns the attribute creator at the end of the path by looking it up * directly in the registry. */ private AttributeCreatorImpl getAttributeCreator(Path path) { Preconditions.checkArgument(path.selectsAttribute(), "Must be an attribute path"); ElementKey<?, ?> parent = path.getParentKey(); if (parent == null) { parent = elementKey; } AttributeKey<?> selected = path.getSelectedAttributeKey(); return (AttributeCreatorImpl) registry.build( parent, selected, transformKey.getContext()); }
/** * Returns the attribute creator at the end of the path by looking it up * directly in the registry. */ private AttributeCreatorImpl getAttributeCreator(Path path) { Preconditions.checkArgument(path.selectsAttribute(), "Must be an attribute path"); ElementKey<?, ?> parent = path.getParentKey(); if (parent == null) { parent = elementKey; } AttributeKey<?> selected = path.getSelectedAttributeKey(); return (AttributeCreatorImpl) registry.build( parent, selected, transformKey.getContext()); }
/** * Returns the attribute creator at the end of the path by looking it up * directly in the registry. */ private AttributeCreatorImpl getAttributeCreator(Path path) { Preconditions.checkArgument(path.selectsAttribute(), "Must be an attribute path"); ElementKey<?, ?> parent = path.getParentKey(); if (parent == null) { parent = elementKey; } AttributeKey<?> selected = path.getSelectedAttributeKey(); return (AttributeCreatorImpl) registry.build( parent, selected, transformKey.getContext()); }
/** * Adds a virtual attribute, which marks the source attribute as moved and * creates a new virtual attribute in this element with the source path. */ public AttributeCreator moveAttribute(AttributeKey<?> attKey, Path path) { Preconditions.checkArgument(path.selectsAttribute(), "Path must refer to an attribute."); AttributeCreatorImpl dest = replaceAttribute(attKey); AttributeCreatorImpl source = getAttributeCreator(path); dest.setSource(path, source.getTransformKey()); source.moved(); return dest; }
/** * Adds a virtual attribute, which marks the source attribute as moved and * creates a new virtual attribute in this element with the source path. */ public AttributeCreator moveAttribute(AttributeKey<?> attKey, Path path) { Preconditions.checkArgument(path.selectsAttribute(), "Path must refer to an attribute."); AttributeCreatorImpl dest = replaceAttribute(attKey); AttributeCreatorImpl source = getAttributeCreator(path); dest.setSource(path, source.getTransformKey()); source.moved(); return dest; }
/** * Adds a virtual attribute, which marks the source attribute as moved and * creates a new virtual attribute in this element with the source path. */ public AttributeCreator moveAttribute(AttributeKey<?> attKey, Path path) { Preconditions.checkArgument(path.selectsAttribute(), "Path must refer to an attribute."); AttributeCreatorImpl dest = replaceAttribute(attKey); AttributeCreatorImpl source = getAttributeCreator(path); dest.setSource(path, source.getTransformKey()); source.moved(); return dest; }
/** * Travels along the path, creating any elements that don't exist until it * gets to the final key. If the final key is an element, it creates that * element if necessary and returns it. If the final key is an attribute, it * returns the parent of that attribute. */ static Element createFinalElement(Path path, Element rootElement) throws ParseException { Element parent = createParentElement(path, rootElement); if (path.selectsAttribute() || parent == null) { return parent; } ElementKey<?, ?> childKey = path.getSelectedElementKey(); Element child = parent.getElement(childKey); if (child == null) { try { child = Element.createElement(childKey); parent.addElement(child); } catch (ContentCreationException e) { throw new ParseException(e); } } return child; }
/** * Travels along the path, creating any elements that don't exist until it * gets to the final key. If the final key is an element, it creates that * element if necessary and returns it. If the final key is an attribute, it * returns the parent of that attribute. */ static Element createFinalElement(Path path, Element rootElement) throws ParseException { Element parent = createParentElement(path, rootElement); if (path.selectsAttribute() || parent == null) { return parent; } ElementKey<?, ?> childKey = path.getSelectedElementKey(); Element child = parent.getElement(childKey); if (child == null) { try { child = Element.createElement(childKey); parent.addElement(child); } catch (ContentCreationException e) { throw new ParseException(e); } } return child; }
/** * Travels along the path, creating any elements that don't exist until it * gets to the final key. If the final key is an element, it creates that * element if necessary and returns it. If the final key is an attribute, it * returns the parent of that attribute. */ static Element createFinalElement(Path path, Element rootElement) throws ParseException { Element parent = createParentElement(path, rootElement); if (path.selectsAttribute() || parent == null) { return parent; } ElementKey<?, ?> childKey = path.getSelectedElementKey(); Element child = parent.getElement(childKey); if (child == null) { try { child = Element.createElement(childKey); parent.addElement(child); } catch (ContentCreationException e) { throw new ParseException(e); } } return child; }
/** * Parses a value through a path. This will find the element or attribute * that is at the end of the path, and parse the value into the element's * text content or the attribute's value as appropriate. */ public void parse(Element element, ElementMetadata<?, ?> metadata, Object value) throws ParseException { Path bound = path.toAbsolute(metadata); element = createFinalElement(path, element); if (bound.selectsAttribute()) { parseAttributeValue(element, bound.getSelectedElement(), bound.getSelectedAttributeKey(), bound.getSelectedAttribute(), value); } else { parseTextValue(element, bound.getSelectedElement(), value); } } }
/** * Generate a text value through the path. If the path ends in an element, * the value will be the text content of the final element. If the path * ends in an attribute, the value will be the value of that attribute. */ public Object generate(Element element, ElementMetadata<?, ?> metadata) { Path bound = path.toAbsolute(metadata); element = getFinalElement(bound, element); if (element == null) { return null; } // Generate the value at the end of the path. if (bound.selectsAttribute()) { return generateAttributeValue(element, bound.getSelectedElement(), bound.getSelectedAttributeKey(), bound.getSelectedAttribute()); } else { return generateTextValue(element, bound.getSelectedElement()); } }
/** * Generate a text value through the path. If the path ends in an element, * the value will be the text content of the final element. If the path * ends in an attribute, the value will be the value of that attribute. */ public Object generate(Element element, ElementMetadata<?, ?> metadata) { Path bound = path.toAbsolute(metadata); element = getFinalElement(bound, element); if (element == null) { return null; } // Generate the value at the end of the path. if (bound.selectsAttribute()) { return generateAttributeValue(element, bound.getSelectedElement(), bound.getSelectedAttributeKey(), bound.getSelectedAttribute()); } else { return generateTextValue(element, bound.getSelectedElement()); } }
/** * Generate a text value through the path. If the path ends in an element, * the value will be the text content of the final element. If the path * ends in an attribute, the value will be the value of that attribute. */ public Object generate(Element element, ElementMetadata<?, ?> metadata) { Path bound = path.toAbsolute(metadata); element = getFinalElement(bound, element); if (element == null) { return null; } // Generate the value at the end of the path. if (bound.selectsAttribute()) { return generateAttributeValue(element, bound.getSelectedElement(), bound.getSelectedAttributeKey(), bound.getSelectedAttribute()); } else { return generateTextValue(element, bound.getSelectedElement()); } }
/** * Parses a value through a path. This will find the element or attribute * that is at the end of the path, and parse the value into the element's * text content or the attribute's value as appropriate. */ public void parse(Element element, ElementMetadata<?, ?> metadata, Object value) throws ParseException { Path bound = path.toAbsolute(metadata); element = createFinalElement(path, element); if (bound.selectsAttribute()) { parseAttributeValue(element, bound.getSelectedElement(), bound.getSelectedAttributeKey(), bound.getSelectedAttribute(), value); } else { parseTextValue(element, bound.getSelectedElement(), value); } } }
/** * Parses a value through a path. This will find the element or attribute * that is at the end of the path, and parse the value into the element's * text content or the attribute's value as appropriate. */ public void parse(Element element, ElementMetadata<?, ?> metadata, Object value) throws ParseException { Path bound = path.toAbsolute(metadata); element = createFinalElement(path, element); if (bound.selectsAttribute()) { parseAttributeValue(element, bound.getSelectedElement(), bound.getSelectedAttributeKey(), bound.getSelectedAttribute(), value); } else { parseTextValue(element, bound.getSelectedElement(), value); } } }