/** * Helper method that constructs a new {@link Element} instance of the type * defined by the type parameter {@code E}. * * @param key the element key to create the element from * @return element that was created * @throws ContentCreationException if content cannot be created */ public static <E extends Element> E createElement( ElementKey<?, E> key) throws ContentCreationException { return createElement(key, null); }
/** * Helper method that constructs a new {@link Element} instance of the type * defined by the type parameter {@code E}. * * @param key the element key to create the element from * @return element that was created * @throws ContentCreationException if content cannot be created */ public static <E extends Element> E createElement( ElementKey<?, E> key) throws ContentCreationException { return createElement(key, null); }
public E createElement() throws ContentCreationException { return Element.createElement(elemKey); }
/** * Helper method that constructs a new {@link Element} instance of the type * defined by the type parameter {@code E}. * * @param key the element key to create the element from * @return element that was created * @throws ContentCreationException if content cannot be created */ public static <E extends Element> E createElement( ElementKey<?, E> key) throws ContentCreationException { return createElement(key, null); }
public E createElement() throws ContentCreationException { return Element.createElement(elemKey); }
public E createElement() throws ContentCreationException { return Element.createElement(elemKey); }
/** * Creates a new entry for the feed. */ public <E extends Entry> E createEntry(ElementKey<?, E> entryKey) { E entry; try { entry = Element.createElement(entryKey); } catch (ContentCreationException cce) { throw new IllegalStateException(cce); } // Propagate the associated service (if any) if (feedState.service != null) { entry.setService(feedState.service); } return entry; }
/** * Creates a new entry for the feed. */ public <E extends Entry> E createEntry(ElementKey<?, E> entryKey) { E entry; try { entry = Element.createElement(entryKey); } catch (ContentCreationException cce) { throw new IllegalStateException(cce); } // Propagate the associated service (if any) if (feedState.service != null) { entry.setService(feedState.service); } return entry; }
/** * Creates a new entry for the feed. */ public <E extends Entry> E createEntry(ElementKey<?, E> entryKey) { E entry; try { entry = Element.createElement(entryKey); } catch (ContentCreationException cce) { throw new IllegalStateException(cce); } // Propagate the associated service (if any) if (feedState.service != null) { entry.setService(feedState.service); } return entry; }
/** * Gets an existing child from the parent or creates it if needed. */ private static Element getOrCreateChild( Element parent, ElementKey<?, ?> childKey) throws ParseException { Element child = parent.getElement(childKey); if (child != null) { return child; } try { child = Element.createElement(childKey); parent.addElement(child); return child; } catch (ContentCreationException e) { throw new ParseException(e); } }
/** * Gets an existing child from the parent or creates it if needed. */ private static Element getOrCreateChild( Element parent, ElementKey<?, ?> childKey) throws ParseException { Element child = parent.getElement(childKey); if (child != null) { return child; } try { child = Element.createElement(childKey); parent.addElement(child); return child; } catch (ContentCreationException e) { throw new ParseException(e); } }
/** * Gets an existing child from the parent or creates it if needed. */ private static Element getOrCreateChild( Element parent, ElementKey<?, ?> childKey) throws ParseException { Element child = parent.getElement(childKey); if (child != null) { return child; } try { child = Element.createElement(childKey); parent.addElement(child); return child; } catch (ContentCreationException e) { throw new ParseException(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); } }
/** * 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); } }
/** * 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); } }
/** * 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 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); } }
/** * 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; }