/** * Return this child's owning document or null if the branch containing * this child is currently not attached to a document. * * @return this child's owning document or null if none */ public Document getDocument() { if (parent == null) return null; return parent.getDocument(); }
protected Content setParent(Parent parent) { // Save previous owning document (if any). Document prevDoc = this.getDocument(); Document newDoc = (parent != null)? parent.getDocument(): null; // Attach to new parent element. super.setParent(parent); if (newDoc != prevDoc) { // New and previous owning documents are different. // => Remove all the IDs for the subtree this element is the root // of from the previous owning document's lookup table and // insert them into the new owning document's lookup table. transferIds(prevDoc, newDoc); } return this; }
protected Attribute setParent(Element parent) { Parent oldParent = this.getParent(); super.setParent(parent); if (this.getAttributeType() == Attribute.ID_TYPE) { Document doc; // Udpate the owning document's lookup table. if (oldParent != null) { doc = oldParent.getDocument(); if (doc instanceof IdDocument) { ((IdDocument)doc).removeId(this.getValue()); } } doc = this.getDocument(); if (doc instanceof IdDocument) { ((IdDocument)doc).addId(this.getValue(), this.getParent()); } } return this; }