/** * The new comment will be added to the first of the bean's children. * @return the newly added Comment * @throws NullPointerException if this is a nonroot bean that is * not part of a rooted graph yet. */ public org.w3c.dom.Comment addComment(String comment) { if (graphManager == null) { // ? } Document doc = graphManager.getXmlDocument(); org.w3c.dom.Comment commentNode = doc.createComment(comment); Node node = binding.getNode(); Node firstChild = node.getFirstChild(); if (firstChild == null) { node.appendChild(commentNode); } else { node.insertBefore(commentNode, firstChild); } return commentNode; }
/** * @return all Comment nodes found in this particular bean. * If there are no comments, then a 0 sized array will be * returned. null will never be returned. * If you want to change a comment, use Comment.setData(). */ public org.w3c.dom.Comment[] comments() { if (graphManager == null) return new org.w3c.dom.Comment[0]; Document doc = graphManager.getXmlDocument(); Node node = binding.getNode(); NodeList children = node.getChildNodes(); List foundComments = new LinkedList(); for (int i = 0; i < children.getLength(); ++i) { Node child = children.item(i); if (child instanceof org.w3c.dom.Comment) { foundComments.add(child); } } org.w3c.dom.Comment[] result = new org.w3c.dom.Comment[foundComments.size()]; result = (org.w3c.dom.Comment[]) foundComments.toArray(result); return result; }