/** * Returns a reference to the current node handler. The handler is obtained * from the parent pointer. * * @return the node handler */ private NodeHandler<T> getNodeHandler() { return getParentPointer().getNodeHandler(); } }
/** * Returns the node handler for the managed nodes. This is a convenience * method. * * @return the node handler */ protected NodeHandler<T> getNodeHandler() { return getParent().getNodeHandler(); }
/** * Creates the {@code JXPathContext} to be used for executing a query. This * method delegates to the context factory. * * @param root the configuration root node * @param handler the node handler * @return the new context */ private <T> JXPathContext createContext(final T root, final NodeHandler<T> handler) { return getContextFactory().createContext(root, handler); }
/** * Returns the current node pointer. * * @return the current pointer in this iteration */ @Override public NodePointer getNodePointer() { if (getPosition() < 1 && !setPosition(1)) { return null; } return createNodePointer(positionToIndex(getPosition())); }
/** * Creates the configuration node pointer for the current position. * * @param position the current position in the iteration * @return the node pointer */ @Override protected NodePointer createNodePointer(final int position) { return new ConfigurationNodePointer<>(getParent(), subNodes .get(position), getNodeHandler()); }
/** * Creates a node pointer for the specified bean. If the bean is a * configuration node (indicated by a wrapper object), a corresponding * pointer is returned. * * @param name the name of the node * @param bean the bean * @param locale the locale * @return a pointer for a configuration node if the bean is such a node */ @Override @SuppressWarnings("unchecked") /* Type casts are safe here; because of the way the NodeWrapper was constructed the node handler must be compatible with the node. */ public NodePointer createNodePointer(final QName name, final Object bean, final Locale locale) { if (bean instanceof NodeWrapper) { final NodeWrapper<?> wrapper = (NodeWrapper<?>) bean; return new ConfigurationNodePointer(wrapper.getNode(), locale, wrapper.getNodeHandler()); } return null; }
/** * Returns the maximum position for this iterator. * * @return the maximum allowed position */ protected int getMaxPosition() { return reverse ? getStartOffset() + 1 : size() - getStartOffset(); }
/** * Returns an iterator for the children of this pointer that match the given * test object. * * @param test the test object * @param reverse the reverse flag * @param startWith the start value of the iteration */ @Override public NodeIterator childIterator(final NodeTest test, final boolean reverse, final NodePointer startWith) { return new ConfigurationNodeIteratorChildren<>(this, test, reverse, castPointer(startWith)); }
/** * Returns the value of this node. * * @return the represented node's value */ @Override public Object getValue() { return getNodeHandler().getValue(node); }
/** * Returns an iterator for the attributes that match the given name. * * @param name the attribute name * @return the iterator for the attributes */ @Override public NodeIterator attributeIterator(final QName name) { return new ConfigurationNodeIteratorAttribute<>(this, name); }
/** * Returns the base value. We return the value. * * @return the base value */ @Override public Object getBaseValue() { return getValue(); }
/** * Creates a new instance of {@code XPathExpressionEngine} with default * settings. */ public XPathExpressionEngine() { this(new XPathContextFactory()); }
/** * Creates a new instance of {@code ConfigurationNodeIteratorAttribute}. * @param parent the parent node pointer * @param name the name of the selected attribute */ public ConfigurationNodeIteratorAttribute( final ConfigurationNodePointer<T> parent, final QName name) { super(parent, false); parentPointer = parent; attributeNames = createAttributeDataList(parent, name); }
/** * Returns the index in the data list for the given position. This method * also checks the reverse flag. * * @param pos the position (1-based) * @return the corresponding list index */ protected int positionToIndex(final int pos) { return (reverse ? 1 - pos : pos - 1) + getStartOffset(); }
/** * Sets the position of the iteration. * * @param pos the new position * @return a flag if this is a valid position */ @Override public boolean setPosition(final int pos) { position = pos; return pos >= 1 && pos <= getMaxPosition(); }
/** * Returns a reference to the parent node pointer. * * @return the parent pointer */ public ConfigurationNodePointer<T> getParentPointer() { // safe to cast because the constructor only expects pointers of this // type @SuppressWarnings("unchecked") final ConfigurationNodePointer<T> configurationNodePointer = (ConfigurationNodePointer<T>) getParent(); return configurationNodePointer; }
/** * Creates a node wrapper for the specified node and its handler. This * wrapper has to be passed to the JXPath context instead of the original * node. * * @param <T> the type of the node * @param node the node * @param handler the corresponding node handler * @return a wrapper for this node */ public static <T> Object wrapNode(final T node, final NodeHandler<T> handler) { return new NodeWrapper<>(node, handler); }
/** * Creates a pointer for the node at the specified position. * * @param position the desired position * @return a pointer for the attribute at this position */ @Override protected NodePointer createNodePointer(final int position) { return new ConfigurationAttributePointer<>(parentPointer, attributeNames.get(position)); }
/** * Returns the value of this node. * * @return this node's value */ @Override public Object getValue() { return attributeResult.getAttributeValue(getNodeHandler()); }
/** * Returns a flag whether this node is a leaf. This is the case if there are * no child nodes. * * @return a flag if this node is a leaf */ @Override public boolean isLeaf() { return getNodeHandler().getChildrenCount(node, null) < 1; }