/** * Adapts an element based on a key. This will find an adaptation in the * metadata and adapt to that metadata type (and element type). If no * adaptation is found this will return the source element. * * @param source the element we are narrowing from. * @param sourceMeta the source metadata to adapt from. * @param kind the kind name to lookup the adaptation for. * @return the adapted element if one was found. */ protected Element adapt(Element source, ElementMetadata<?, ?> sourceMeta, String kind) { ElementKey<?, ?> adaptorKey = sourceMeta.adapt(kind); if (adaptorKey != null) { try { return adapt(adaptorKey, source); } catch (ContentCreationException e) { // Not usable as a adaptable kind, skip. LOGGER.log(Level.SEVERE, "Unable to adapt " + source.getClass() + " to " + adaptorKey.getElementType(), e); } } return source; }
/** * Adapts an element based on a key. This will find an adaptation in the * metadata and adapt to that metadata type (and element type). If no * adaptation is found this will return the source element. * * @param source the element we are narrowing from. * @param sourceMeta the source metadata to adapt from. * @param kind the kind name to lookup the adaptation for. * @return the adapted element if one was found. */ protected Element adapt(Element source, ElementMetadata<?, ?> sourceMeta, String kind) { ElementKey<?, ?> adaptorKey = sourceMeta.adapt(kind); if (adaptorKey != null) { try { return adapt(adaptorKey, source); } catch (ContentCreationException e) { // Not usable as a adaptable kind, skip. LOGGER.log(Level.SEVERE, "Unable to adapt " + source.getClass() + " to " + adaptorKey.getElementType(), e); } } return source; }
/** * Adapts an element based on a key. This will find an adaptation in the * metadata and adapt to that metadata type (and element type). If no * adaptation is found this will return the source element. * * @param source the element we are narrowing from. * @param sourceMeta the source metadata to adapt from. * @param kind the kind name to lookup the adaptation for. * @return the adapted element if one was found. */ protected Element adapt(Element source, ElementMetadata<?, ?> sourceMeta, String kind) { ElementKey<?, ?> adaptorKey = sourceMeta.adapt(kind); if (adaptorKey != null) { try { return adapt(adaptorKey, source); } catch (ContentCreationException e) { // Not usable as a adaptable kind, skip. LOGGER.log(Level.SEVERE, "Unable to adapt " + source.getClass() + " to " + adaptorKey.getElementType(), e); } } return source; }
return adapt(narrowedKey, this); } catch (ContentCreationException e) { LOGGER.log(Level.SEVERE, "Unable to adapt " +
return adapt(narrowedKey, this); } catch (ContentCreationException e) { LOGGER.log(Level.SEVERE, "Unable to adapt " +
return adapt(narrowedKey, this); } catch (ContentCreationException e) { LOGGER.log(Level.SEVERE, "Unable to adapt " +
/** * Get child element matching the specified key. Will try to adapt the * element to the given key if it is not already an instance of the requested * class. This will fail with an exception if the adaptation was not valid. * * @param <T> the type of element to return * @param childKey the metadata key for the child element to retrieve * @return child element, or {@code null} if none was found * @throws IllegalArgumentException if the key referenced a repeating element */ public <D, T extends Element> T getElement(ElementKey<D, T> childKey) { Element child = getElement(childKey.getId()); if (child == null) { return null; } try { return adapt(childKey, child); } catch (ContentCreationException e) { throw new IllegalArgumentException("Unable to adapt to " + childKey.getElementType(), e); } }
/** * Get child element matching the specified key. Will try to adapt the * element to the given key if it is not already an instance of the requested * class. This will fail with an exception if the adaptation was not valid. * * @param <T> the type of element to return * @param childKey the metadata key for the child element to retrieve * @return child element, or {@code null} if none was found * @throws IllegalArgumentException if the key referenced a repeating element */ public <D, T extends Element> T getElement(ElementKey<D, T> childKey) { Element child = getElement(childKey.getId()); if (child == null) { return null; } try { return adapt(childKey, child); } catch (ContentCreationException e) { throw new IllegalArgumentException("Unable to adapt to " + childKey.getElementType(), e); } }
/** * Get child element matching the specified key. Will try to adapt the * element to the given key if it is not already an instance of the requested * class. This will fail with an exception if the adaptation was not valid. * * @param <T> the type of element to return * @param childKey the metadata key for the child element to retrieve * @return child element, or {@code null} if none was found * @throws IllegalArgumentException if the key referenced a repeating element */ public <D, T extends Element> T getElement(ElementKey<D, T> childKey) { Element child = getElement(childKey.getId()); if (child == null) { return null; } try { return adapt(childKey, child); } catch (ContentCreationException e) { throw new IllegalArgumentException("Unable to adapt to " + childKey.getElementType(), e); } }