1 7 8 package org.dom4j.tree; 9 10 import java.util.List ; 11 12 import org.dom4j.Branch; 13 import org.dom4j.Document; 14 import org.dom4j.Element; 15 import org.dom4j.Namespace; 16 import org.dom4j.QName; 17 18 27 public class BaseElement extends AbstractElement { 28 29 private QName qname; 30 31 37 private Branch parentBranch; 38 39 40 protected List content; 41 42 43 protected List attributes; 44 45 public BaseElement(String name) { 46 this.qname = getDocumentFactory().createQName(name); 47 } 48 49 public BaseElement(QName qname) { 50 this.qname = qname; 51 } 52 53 public BaseElement(String name, Namespace namespace) { 54 this.qname = getDocumentFactory().createQName(name, namespace); 55 } 56 57 public Element getParent() { 58 Element result = null; 59 60 if (parentBranch instanceof Element) { 61 result = (Element) parentBranch; 62 } 63 64 return result; 65 } 66 67 public void setParent(Element parent) { 68 if (parentBranch instanceof Element || (parent != null)) { 69 parentBranch = parent; 70 } 71 } 72 73 public Document getDocument() { 74 if (parentBranch instanceof Document) { 75 return (Document) parentBranch; 76 } else if (parentBranch instanceof Element) { 77 Element parent = (Element) parentBranch; 78 79 return parent.getDocument(); 80 } 81 82 return null; 83 } 84 85 public void setDocument(Document document) { 86 if (parentBranch instanceof Document || (document != null)) { 87 parentBranch = document; 88 } 89 } 90 91 public boolean supportsParent() { 92 return true; 93 } 94 95 public QName getQName() { 96 return qname; 97 } 98 99 public void setQName(QName name) { 100 this.qname = name; 101 } 102 103 public void clearContent() { 104 contentList().clear(); 105 } 106 107 public void setContent(List content) { 108 this.content = content; 109 110 if (content instanceof ContentListFacade) { 111 this.content = ((ContentListFacade) content).getBackingList(); 112 } 113 } 114 115 public void setAttributes(List attributes) { 116 this.attributes = attributes; 117 118 if (attributes instanceof ContentListFacade) { 119 this.attributes = ((ContentListFacade) attributes).getBackingList(); 120 } 121 } 122 123 protected List contentList() { 126 if (content == null) { 127 content = createContentList(); 128 } 129 130 return content; 131 } 132 133 protected List attributeList() { 134 if (attributes == null) { 135 attributes = createAttributeList(); 136 } 137 138 return attributes; 139 } 140 141 protected List attributeList(int size) { 142 if (attributes == null) { 143 attributes = createAttributeList(size); 144 } 145 146 return attributes; 147 } 148 149 protected void setAttributeList(List attributeList) { 150 this.attributes = attributeList; 151 } 152 } 153 154 190 | Popular Tags |