| Method from org.dom4j.swing.BranchTreeNode Detail: |
public Enumeration children() {
return new Enumeration() {
private int index = -1;
public boolean hasMoreElements() {
return (index + 1) < getChildCount();
}
public Object nextElement() {
return getChildAt(++index);
}
};
}
|
protected List createChildList() {
// add attributes and content as children?
Branch branch = getXmlBranch();
int size = branch.nodeCount();
List childList = new ArrayList(size);
for (int i = 0; i < size; i++) {
Node node = branch.node(i);
// ignore whitespace text nodes
if (node instanceof CharacterData) {
String text = node.getText();
if (text == null) {
continue;
}
text = text.trim();
if (text.length() < = 0) {
continue;
}
}
childList.add(createChildTreeNode(node));
}
return childList;
}
Factory method to create List of children TreeNodes |
protected TreeNode createChildTreeNode(Node xmlNode) {
if (xmlNode instanceof Branch) {
return new BranchTreeNode(this, (Branch) xmlNode);
} else {
return new LeafTreeNode(this, xmlNode);
}
}
Factory method to create child tree nodes for a given XML node type |
public boolean getAllowsChildren() {
return true;
}
|
public TreeNode getChildAt(int childIndex) {
return (TreeNode) getChildList().get(childIndex);
}
|
public int getChildCount() {
return getChildList().size();
}
|
protected List getChildList() {
// for now lets just create the children once, the first time they
// are asked for.
// XXXX - we may wish to detect inconsistencies here....
if (children == null) {
children = createChildList();
}
return children;
}
Uses Lazy Initialization pattern to create a List of children |
public int getIndex(TreeNode node) {
return getChildList().indexOf(node);
}
|
protected Branch getXmlBranch() {
return (Branch) xmlNode;
}
|
public boolean isLeaf() {
return getXmlBranch().nodeCount() < = 0;
}
|
public String toString() {
return xmlNode.getName();
}
|