/** * 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()); }
/** * 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)); }
/** * Helper method for checking whether an attribute is defined and adding it * to the list of attributes to iterate over. * * @param parent the parent node pointer * @param result the result list * @param name the name of the current attribute */ private void addAttributeData(final ConfigurationNodePointer<T> parent, final List<String> result, final String name) { if (parent.getNodeHandler().getAttributeValue( parent.getConfigurationNode(), name) != null) { result.add(name); } } }
/** * 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 a new instance of {@code ConfigurationAttributePointer}. * * @param parent the parent node pointer * @param attrName the name of the managed attribute */ public ConfigurationAttributePointer(final ConfigurationNodePointer<T> parent, final String attrName) { super(parent); attributeResult = QueryResult.createAttributeResult( parent.getConfigurationNode(), attrName); }
/** * 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; }
/** * Creates a new instance of {@code ConfigurationNodeIteratorChildren} and * initializes it. * * @param parent the parent pointer * @param nodeTest the test selecting the sub nodes * @param reverse the reverse flag * @param startsWith the first element of the iteration */ public ConfigurationNodeIteratorChildren( final ConfigurationNodePointer<T> parent, final NodeTest nodeTest, final boolean reverse, final ConfigurationNodePointer<T> startsWith) { super(parent, reverse); final T root = parent.getConfigurationNode(); subNodes = createSubNodeList(root, nodeTest); if (startsWith != null) { setStartOffset(findStartIndex(subNodes, startsWith.getConfigurationNode())); } else { if (reverse) { setStartOffset(size()); } } }
new LinkedHashSet<>(parent.getNodeHandler() .getAttributes(parent.getConfigurationNode())); final String prefix = (name.getPrefix() != null) ? prefixName(name.getPrefix(),
/** * Returns the value of this node. * * @return the represented node's value */ @Override public Object getValue() { return getNodeHandler().getValue(node); }
/** * 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 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(); } }
/** * Creates a node pointer for the specified bean. If the bean is a * configuration node, a corresponding pointer is returned. * * @param parent the parent node * @param name the name * @param bean the bean * @return a pointer for a configuration node if the bean is such a node */ @Override @SuppressWarnings("unchecked") /* Type casts are safe here, see above. Also, the hierarchy of node pointers is consistent, so a parent is compatible to a child. */ public NodePointer createNodePointer(final NodePointer parent, final QName name, final Object bean) { if (bean instanceof NodeWrapper) { final NodeWrapper<?> wrapper = (NodeWrapper<?>) bean; return new ConfigurationNodePointer((ConfigurationNodePointer) parent, wrapper.getNode(), wrapper.getNodeHandler()); } return null; }
/** * Returns this node's name. * * @return the name */ @Override public QName getName() { return new QName(null, getNodeHandler().nodeName(node)); }
/** * Compares two child node pointers. * * @param pointer1 one pointer * @param pointer2 another pointer * @return a flag, which pointer should be sorted first */ @Override public int compareChildNodePointers(final NodePointer pointer1, final NodePointer pointer2) { final Object node1 = pointer1.getBaseValue(); final Object node2 = pointer2.getBaseValue(); // sort based on the occurrence in the sub node list for (final T child : getNodeHandler().getChildren(node)) { if (child == node1) { return -1; } else if (child == node2) { return 1; } } return 0; // should not happen }