public void expandNode(PdfObjectTreeNode node) {
   if (node.getChildCount() > 0) {
     return;
   }
   PdfObject object = node.getPdfObject();
   PdfObjectTreeNode leaf;
   switch (object.type()) {
     case PdfObject.INDIRECT:
       PdfIndirectReference ref = (PdfIndirectReference) object;
       leaf = getNode(ref.getNumber());
       addNodes(node, leaf);
       if (leaf instanceof PdfPagesTreeNode) expandNode(leaf);
       return;
     case PdfObject.ARRAY:
       PdfArray array = (PdfArray) object;
       for (Iterator<PdfObject> it = array.listIterator(); it.hasNext(); ) {
         leaf = PdfObjectTreeNode.getInstance(it.next());
         addNodes(node, leaf);
         expandNode(leaf);
       }
       return;
     case PdfObject.DICTIONARY:
     case PdfObject.STREAM:
       PdfDictionary dict = (PdfDictionary) object;
       for (Iterator<PdfName> it = dict.getKeys().iterator(); it.hasNext(); ) {
         leaf = PdfObjectTreeNode.getInstance(dict, it.next());
         addNodes(node, leaf);
         expandNode(leaf);
       }
       return;
   }
 }
 public TreeNodeFactory(IndirectObjectFactory objects) {
   this.objects = objects;
   for (int i = 0; i < objects.size(); i++) {
     int ref = objects.getRefByIndex(i);
     nodes.add(PdfObjectTreeNode.getInstance(PdfNull.PDFNULL, ref));
   }
 }
 public PdfObjectTreeNode getNode(int ref) {
   int idx = objects.getIndexByRef(ref);
   PdfObjectTreeNode node = nodes.get(idx);
   if (node.getPdfObject().isNull()) {
     node = PdfObjectTreeNode.getInstance(objects.loadObjectByReference(ref), ref);
     nodes.set(idx, node);
   }
   return node;
 }