private static void mergeBeans(Map nodeMap, BaseBean bean, BaseBean patternBean) { if (bean.binding != null && patternBean.binding != null) { Node node = bean. binding.getNode(); Node otherNode = patternBean.binding.getNode(); if (node != null && otherNode != null) { mergeNode(nodeMap, node, otherNode); } } }
/** * 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; }
public void writeNode(java.io.Writer out) throws IOException { if (graphManager == null) { throw new IllegalStateException(Common. getMessage("CantWriteBeanNotInDOMTree_msg")); } Node myNode = binding.getNode(); try { graphManager.write(out, myNode); } catch (Schema2BeansException e) { // This exception does not make sense for our signature. throw new RuntimeException(e); } }
/** * @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; }
Node getParentNode() { // If we are the root, there is no parent node if (this.isRoot) { return null; } Node n = null; DOMBinding b = this.bean.domBinding(); if (b != null) { n = b.getNode(); } if (n == null) { throw new IllegalStateException(Common.getMessage("ParentNodeCantBeNull_msg")); } else { return n; } }
/** * Merge "unsupported" elements - elements which are not represented * in model (whitespaces, comments, unknown atributes and tags), * but they should be merged to DOMBinding * * @param patternBean */ public static void mergeUnsupportedElements(BaseBean bean, BaseBean patternBean) { Map nodeMap = new HashMap(); List l = new LinkedList(); l.add(bean); bean.childBeans(true, l); l.add(patternBean); patternBean.childBeans(true, l); for (Iterator it = l.iterator(); it.hasNext();) { BaseBean baseBean = (BaseBean) it.next(); DOMBinding binding = baseBean.binding; if (binding != null) { nodeMap.put(binding.getNode(), baseBean); } } mergeNode(nodeMap, getOwnerDocument(bean.binding.getNode()), getOwnerDocument(patternBean.binding.getNode())); }
if (patternBean != null) { foundBean = takeEqualBean(nodeMap, children, patternBean); foundChild = foundBean == null ? null : foundBean.binding.getNode(); } else { foundBean = null;
d1.moveBefore(this, db.getNode());