/** * 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 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; }
/** * 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; }