Collection<Element> elements, ElementMetadata<?, ?> metadata) throws ParseException { Preconditions.checkState(path.selectsElement(), "An attribute path cannot be used to parse elements.");
/** * Generate multiple elements based on this path. This only allows a single * multiple cardinality element in the path, but that multiple cardinality * element can be anywhere in the path. Once found we only follow single * cardinality children after that point. * * cardinality along the path. */ public Collection<? extends Element> generateMultiple(Element parent, ElementMetadata<?, ?> parentMetadata, ElementMetadata<?, ?> metadata) { Preconditions.checkState(path.selectsElement(), "An attribute path cannot be used to generate elements."); Collection<? extends Element> elements = getFinalElements(path, parent); if (elements.isEmpty()) { return elements; } List<Element> result = Lists.newArrayListWithCapacity(elements.size()); for (Element e : elements) { try { ElementKey<?, ?> realKey = mergeKeys( e.getElementKey(), metadata.getKey()); result.add(Element.createElement(realKey, e)); } catch (ContentCreationException ex) { throw new IllegalArgumentException("Invalid metadata", ex); } } return result; }
Collection<Element> elements, ElementMetadata<?, ?> metadata) throws ParseException { Preconditions.checkState(path.selectsElement(), "An attribute path cannot be used to parse elements.");
Collection<Element> elements, ElementMetadata<?, ?> metadata) throws ParseException { Preconditions.checkState(path.selectsElement(), "An attribute path cannot be used to parse elements.");
/** * Generate multiple elements based on this path. This only allows a single * multiple cardinality element in the path, but that multiple cardinality * element can be anywhere in the path. Once found we only follow single * cardinality children after that point. * * cardinality along the path. */ public Collection<? extends Element> generateMultiple(Element parent, ElementMetadata<?, ?> parentMetadata, ElementMetadata<?, ?> metadata) { Preconditions.checkState(path.selectsElement(), "An attribute path cannot be used to generate elements."); Collection<? extends Element> elements = getFinalElements(path, parent); if (elements.isEmpty()) { return elements; } List<Element> result = Lists.newArrayListWithCapacity(elements.size()); for (Element e : elements) { try { ElementKey<?, ?> realKey = mergeKeys( e.getElementKey(), metadata.getKey()); result.add(Element.createElement(realKey, e)); } catch (ContentCreationException ex) { throw new IllegalArgumentException("Invalid metadata", ex); } } return result; }
/** * Generate multiple elements based on this path. This only allows a single * multiple cardinality element in the path, but that multiple cardinality * element can be anywhere in the path. Once found we only follow single * cardinality children after that point. * * cardinality along the path. */ public Collection<? extends Element> generateMultiple(Element parent, ElementMetadata<?, ?> parentMetadata, ElementMetadata<?, ?> metadata) { Preconditions.checkState(path.selectsElement(), "An attribute path cannot be used to generate elements."); Collection<? extends Element> elements = getFinalElements(path, parent); if (elements.isEmpty()) { return elements; } List<Element> result = Lists.newArrayListWithCapacity(elements.size()); for (Element e : elements) { try { ElementKey<?, ?> realKey = mergeKeys( e.getElementKey(), metadata.getKey()); result.add(Element.createElement(realKey, e)); } catch (ContentCreationException ex) { throw new IllegalArgumentException("Invalid metadata", ex); } } return result; }
/** * Returns the element creator at the end of the path by looking it up * directly in the registry (not traversing). */ private ElementCreatorImpl getElementCreator(Path path) { Preconditions.checkArgument(path.selectsElement(), "Must be an element path"); ElementKey<?, ?> parent = path.getParentKey(); if (parent == null) { parent = elementKey; } ElementKey<?, ?> selected = path.getSelectedElementKey(); return (ElementCreatorImpl) registry.build( parent, selected, transformKey.getContext()); }
/** * Returns the element creator at the end of the path by looking it up * directly in the registry (not traversing). */ private ElementCreatorImpl getElementCreator(Path path) { Preconditions.checkArgument(path.selectsElement(), "Must be an element path"); ElementKey<?, ?> parent = path.getParentKey(); if (parent == null) { parent = elementKey; } ElementKey<?, ?> selected = path.getSelectedElementKey(); return (ElementCreatorImpl) registry.build( parent, selected, transformKey.getContext()); }
/** * Generates a single element on the parent by using this path. This * will follow the path to its end, and then use that same element content * as the returned element, after wrapping it with the correct key (id). * * elements along it. */ public Element generateSingle(Element parent, ElementMetadata<?, ?> parentMetadata, ElementMetadata<?, ?> metadata) { Preconditions.checkState(path.selectsElement(), "An attribute path cannot be used to generate elements."); Element element = getFinalElement(path, parent); if (element == null) { return null; } try { ElementKey<?, ?> realKey = mergeKeys( element.getElementKey(), metadata.getKey()); return Element.createElement(realKey, element); } catch (ContentCreationException e) { throw new IllegalArgumentException("Invalid metadata", e); } }
/** * Returns the element creator at the end of the path by looking it up * directly in the registry (not traversing). */ private ElementCreatorImpl getElementCreator(Path path) { Preconditions.checkArgument(path.selectsElement(), "Must be an element path"); ElementKey<?, ?> parent = path.getParentKey(); if (parent == null) { parent = elementKey; } ElementKey<?, ?> selected = path.getSelectedElementKey(); return (ElementCreatorImpl) registry.build( parent, selected, transformKey.getContext()); }
/** * Generates a single element on the parent by using this path. This * will follow the path to its end, and then use that same element content * as the returned element, after wrapping it with the correct key (id). * * elements along it. */ public Element generateSingle(Element parent, ElementMetadata<?, ?> parentMetadata, ElementMetadata<?, ?> metadata) { Preconditions.checkState(path.selectsElement(), "An attribute path cannot be used to generate elements."); Element element = getFinalElement(path, parent); if (element == null) { return null; } try { ElementKey<?, ?> realKey = mergeKeys( element.getElementKey(), metadata.getKey()); return Element.createElement(realKey, element); } catch (ContentCreationException e) { throw new IllegalArgumentException("Invalid metadata", e); } }
/** * Generates a single element on the parent by using this path. This * will follow the path to its end, and then use that same element content * as the returned element, after wrapping it with the correct key (id). * * elements along it. */ public Element generateSingle(Element parent, ElementMetadata<?, ?> parentMetadata, ElementMetadata<?, ?> metadata) { Preconditions.checkState(path.selectsElement(), "An attribute path cannot be used to generate elements."); Element element = getFinalElement(path, parent); if (element == null) { return null; } try { ElementKey<?, ?> realKey = mergeKeys( element.getElementKey(), metadata.getKey()); return Element.createElement(realKey, element); } catch (ContentCreationException e) { throw new IllegalArgumentException("Invalid metadata", e); } }
/** * Adds a virtual element, which marks the source element as moved and creates * a new virtual child element with the source path. */ public ElementCreator moveElement(ElementKey<?, ?> childKey, Path path) { Preconditions.checkArgument(path.selectsElement(), "Path must refer to an element."); ElementCreatorImpl dest = replaceElement(childKey); ElementCreatorImpl source = getElementCreator(path); dest.setSource(path, source.getTransformKey()); source.moved(); return dest; }
/** * Adds a virtual element, which marks the source element as moved and creates * a new virtual child element with the source path. */ public ElementCreator moveElement(ElementKey<?, ?> childKey, Path path) { Preconditions.checkArgument(path.selectsElement(), "Path must refer to an element."); ElementCreatorImpl dest = replaceElement(childKey); ElementCreatorImpl source = getElementCreator(path); dest.setSource(path, source.getTransformKey()); source.moved(); return dest; }
/** * Adds a virtual element, which marks the source element as moved and creates * a new virtual child element with the source path. */ public ElementCreator moveElement(ElementKey<?, ?> childKey, Path path) { Preconditions.checkArgument(path.selectsElement(), "Path must refer to an element."); ElementCreatorImpl dest = replaceElement(childKey); ElementCreatorImpl source = getElementCreator(path); dest.setSource(path, source.getTransformKey()); source.moved(); return dest; }
/** * Parses a single element using this path. This will follow the path until * the second to last element on the path, and then parse into the final * element using the real parent instead of the path's parent. * * elements along it. */ public void parse(Element parent, ElementMetadata<?, ?> parentMetadata, Element element, ElementMetadata<?, ?> metadata) throws ParseException { Preconditions.checkState(path.selectsElement(), "An attribute path cannot be used to parse elements."); parent = createParentElement(path, parent); ElementKey<?, ?> lastKey = path.getSelectedElementKey(); try { Element child = Element.createElement(lastKey, element); parent.addElement(child); } catch (ContentCreationException e) { throw new ParseException(e); } }
/** * Parses a single element using this path. This will follow the path until * the second to last element on the path, and then parse into the final * element using the real parent instead of the path's parent. * * elements along it. */ public void parse(Element parent, ElementMetadata<?, ?> parentMetadata, Element element, ElementMetadata<?, ?> metadata) throws ParseException { Preconditions.checkState(path.selectsElement(), "An attribute path cannot be used to parse elements."); parent = createParentElement(path, parent); ElementKey<?, ?> lastKey = path.getSelectedElementKey(); try { Element child = Element.createElement(lastKey, element); parent.addElement(child); } catch (ContentCreationException e) { throw new ParseException(e); } }
/** * Parses a single element using this path. This will follow the path until * the second to last element on the path, and then parse into the final * element using the real parent instead of the path's parent. * * elements along it. */ public void parse(Element parent, ElementMetadata<?, ?> parentMetadata, Element element, ElementMetadata<?, ?> metadata) throws ParseException { Preconditions.checkState(path.selectsElement(), "An attribute path cannot be used to parse elements."); parent = createParentElement(path, parent); ElementKey<?, ?> lastKey = path.getSelectedElementKey(); try { Element child = Element.createElement(lastKey, element); parent.addElement(child); } catch (ContentCreationException e) { throw new ParseException(e); } }