Index: src/main/java/org/apache/pdfbox/pdmodel/PDDestinationNameTreeNode.java
===================================================================
--- src/main/java/org/apache/pdfbox/pdmodel/PDDestinationNameTreeNode.java	(Revision 1609073)
+++ src/main/java/org/apache/pdfbox/pdmodel/PDDestinationNameTreeNode.java	(Arbeitskopie)
@@ -32,7 +32,7 @@
  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
  * @version $Revision: 1.2 $
  */
-public class PDDestinationNameTreeNode extends PDNameTreeNode
+public class PDDestinationNameTreeNode extends PDNameTreeNode<PDPageDestination>
 {

     /**
@@ -56,7 +56,7 @@
     /**
      * {@inheritDoc}
      */
-    protected COSObjectable convertCOSToPD( COSBase base ) throws IOException
+    protected PDPageDestination convertCOSToPD( COSBase base ) throws IOException
     {
         COSBase destination = base;
         if( base instanceof COSDictionary )
@@ -66,13 +66,13 @@
             //it for now
             destination = ((COSDictionary)base).getDictionaryObject( COSName.D );
         }
-        return PDDestination.create( destination );
+        return (PDPageDestination) PDDestination.create( destination );
     }

     /**
      * {@inheritDoc}
      */
-    protected PDNameTreeNode createChildNode( COSDictionary dic )
+    protected PDNameTreeNode<PDPageDestination> createChildNode( COSDictionary dic )
     {
         return new PDDestinationNameTreeNode(dic);
     }
Index: src/main/java/org/apache/pdfbox/pdmodel/PDEmbeddedFilesNameTreeNode.java
===================================================================
--- src/main/java/org/apache/pdfbox/pdmodel/PDEmbeddedFilesNameTreeNode.java	(Revision 1609073)
+++ src/main/java/org/apache/pdfbox/pdmodel/PDEmbeddedFilesNameTreeNode.java	(Arbeitskopie)
@@ -30,7 +30,7 @@
  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
  * @version $Revision: 1.3 $
  */
-public class PDEmbeddedFilesNameTreeNode extends PDNameTreeNode
+public class PDEmbeddedFilesNameTreeNode extends PDNameTreeNode<PDComplexFileSpecification>
 {
     /**
      * Constructor.
@@ -53,7 +53,7 @@
     /**
      * {@inheritDoc}
      */
-    protected COSObjectable convertCOSToPD( COSBase base ) throws IOException
+    protected PDComplexFileSpecification convertCOSToPD( COSBase base ) throws IOException
     {
         return new PDComplexFileSpecification( (COSDictionary)base );
     }
@@ -61,7 +61,7 @@
     /**
      * {@inheritDoc}
      */
-    protected PDNameTreeNode createChildNode( COSDictionary dic )
+    protected PDNameTreeNode<PDComplexFileSpecification> createChildNode( COSDictionary dic )
     {
         return new PDEmbeddedFilesNameTreeNode(dic);
     }
Index: src/main/java/org/apache/pdfbox/pdmodel/PDJavascriptNameTreeNode.java
===================================================================
--- src/main/java/org/apache/pdfbox/pdmodel/PDJavascriptNameTreeNode.java	(Revision 1609073)
+++ src/main/java/org/apache/pdfbox/pdmodel/PDJavascriptNameTreeNode.java	(Arbeitskopie)
@@ -32,7 +32,7 @@
  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
  * @version $Revision: 1.1 $
  */
-public class PDJavascriptNameTreeNode extends PDNameTreeNode
+public class PDJavascriptNameTreeNode extends PDNameTreeNode<PDTextStream>
 {
     /**
      * Constructor.
@@ -55,7 +55,7 @@
     /**
      * {@inheritDoc}
      */
-    protected COSObjectable convertCOSToPD( COSBase base ) throws IOException
+    protected PDTextStream convertCOSToPD( COSBase base ) throws IOException
     {
         PDTextStream stream = null;
         if( base instanceof COSString )
@@ -77,7 +77,7 @@
     /**
      * {@inheritDoc}
      */
-    protected PDNameTreeNode createChildNode( COSDictionary dic )
+    protected PDNameTreeNode<PDTextStream> createChildNode( COSDictionary dic )
     {
         return new PDJavascriptNameTreeNode(dic);
     }
Index: src/main/java/org/apache/pdfbox/pdmodel/common/PDNameTreeNode.java
===================================================================
--- src/main/java/org/apache/pdfbox/pdmodel/common/PDNameTreeNode.java	(Revision 1609073)
+++ src/main/java/org/apache/pdfbox/pdmodel/common/PDNameTreeNode.java	(Arbeitskopie)
@@ -17,6 +17,7 @@
 package org.apache.pdfbox.pdmodel.common;

 import java.io.IOException;
+import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedHashMap;
@@ -36,14 +37,16 @@
  * for more details.
  *
  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
+ *         <a href="mailto:dtubach@web.de">Dominic Tubach</a>
  * @version $Revision: 1.4 $
+ * @param <T> The type of values in the tree.
  */
-public class PDNameTreeNode implements COSObjectable
+public class PDNameTreeNode<T extends COSObjectable> implements COSObjectable
 {
     private static final Log LOG = LogFactory.getLog(PDNameTreeNode.class);
     private COSDictionary node;
-    private Class<? extends COSObjectable> valueType = null;
-    private PDNameTreeNode parent = null;
+    private Class<? extends T> valueType = null;
+    private PDNameTreeNode<T> parent = null;

     /**
      * Constructor.
@@ -50,7 +53,7 @@
      *
      * @param valueClass The PD Model type of object that is the value.
      */
-    public PDNameTreeNode( Class<? extends COSObjectable> valueClass )
+    public PDNameTreeNode( Class<? extends T> valueClass )
     {
         node = new COSDictionary();
         valueType = valueClass;
@@ -62,7 +65,7 @@
      * @param dict The dictionary that holds the name information.
      * @param valueClass The PD Model type of object that is the value.
      */
-    public PDNameTreeNode( COSDictionary dict, Class<? extends COSObjectable> valueClass )
+    public PDNameTreeNode( COSDictionary dict, Class<? extends T> valueClass )
     {
         node = dict;
         valueType = valueClass;
@@ -93,7 +96,7 @@
      *
      * @return parent node
      */
-    public PDNameTreeNode getParent()
+    public PDNameTreeNode<T> getParent()
     {
         return parent;
     }
@@ -103,7 +106,7 @@
      *
      * @param parentNode the node to be set as parent
      */
-    public void setParent(PDNameTreeNode parentNode)
+    public void setParent(PDNameTreeNode<T> parentNode)
     {
         parent = parentNode;
         calculateLimits();
@@ -123,19 +126,19 @@
      *
      * @return The list of children or null if there are no children.
      */
-    public List<PDNameTreeNode> getKids()
+    public List<PDNameTreeNode<T>> getKids()
     {

-        List<PDNameTreeNode> retval = null;
+        List<PDNameTreeNode<T>> retval = null;
         COSArray kids = (COSArray)node.getDictionaryObject( COSName.KIDS );
         if( kids != null )
         {
-            List<PDNameTreeNode> pdObjects = new ArrayList<PDNameTreeNode>();
+            List<PDNameTreeNode<T>> pdObjects = new ArrayList<PDNameTreeNode<T>>();
             for( int i=0; i<kids.size(); i++ )
             {
                 pdObjects.add( createChildNode( (COSDictionary)kids.getObject(i) ) );
             }
-            retval = new COSArrayList<PDNameTreeNode>(pdObjects,kids);
+            retval = new COSArrayList<PDNameTreeNode<T>>(pdObjects, kids);
         }

         return retval;
@@ -146,11 +149,11 @@
      *
      * @param kids The children of this named tree.
      */
-    public void setKids( List<? extends PDNameTreeNode> kids )
+    public void setKids( List<? extends PDNameTreeNode<T>> kids )
     {
         if (kids != null && kids.size() > 0)
         {
-            for (PDNameTreeNode kidsNode : kids)
+            for (PDNameTreeNode<T> kidsNode : kids)
                 kidsNode.setParent(this);
             node.setItem( COSName.KIDS, COSArrayList.converterToCOSArray( kids ) );
             // root nodes with kids don't have Names
@@ -177,11 +180,11 @@
         }
         else
         {
-            List<PDNameTreeNode> kids = getKids();
+            List<PDNameTreeNode<T>> kids = getKids();
             if (kids != null && kids.size() > 0)
             {
-                PDNameTreeNode firstKid = kids.get(0);
-                PDNameTreeNode lastKid = kids.get(kids.size() - 1);
+                PDNameTreeNode<T> firstKid = kids.get(0);
+                PDNameTreeNode<T> lastKid = kids.get(kids.size() - 1);
                 String lowerLimit = firstKid.getLowerLimit();
                 setLowerLimit(lowerLimit);
                 String upperLimit = lastKid.getUpperLimit();
@@ -191,7 +194,7 @@
             {
                 try
                 {
-                    Map<String, COSObjectable> names = getNames();
+                    Map<String, T> names = getNames();
                     if (names != null && names.size() > 0)
                     {
                         Object[] keys = names.keySet().toArray();
@@ -222,10 +225,10 @@
      *
      * @throws IOException If an there is a problem creating the destinations.
      */
-    public Object getValue( String name ) throws IOException
+    public T getValue( String name ) throws IOException
     {
-        Object retval = null;
-        Map<String, COSObjectable> names = getNames();
+        T retval = null;
+        Map<String, T> names = getNames();
         if( names != null )
         {
             retval = names.get( name );
@@ -232,12 +235,12 @@
         }
         else
         {
-            List<PDNameTreeNode> kids = getKids();
+            List<PDNameTreeNode<T>> kids = getKids();
             if (kids != null)
             {
                 for( int i=0; i<kids.size() && retval == null; i++ )
                 {
-                    PDNameTreeNode childNode = kids.get( i );
+                    PDNameTreeNode<T> childNode = kids.get( i );
                     if( childNode.getLowerLimit().compareTo( name ) <= 0 &&
                         childNode.getUpperLimit().compareTo( name ) >= 0 )
                     {
@@ -258,16 +261,16 @@
      * This will return a map of names. The key will be a string, and the
      * value will depend on where this class is being used.
      *
-     * @return ordered map of cos objects or <code>null</code> if dictionary
-     *         contains no 'Names' entry
+     * @return ordered map of PD objects or <code>null</code> if dictionary
+     *         contains no 'Names' entry.
      * @throws IOException If there is an error while creating the sub types.
      */
-    public Map<String, COSObjectable> getNames() throws IOException
+    public Map<String, T> getNames() throws IOException
     {
         COSArray namesArray = (COSArray)node.getDictionaryObject( COSName.NAMES );
         if( namesArray != null )
         {
-            Map<String, COSObjectable> names = new LinkedHashMap<String, COSObjectable>();
+            Map<String, T> names = new LinkedHashMap<String, T>();
             for( int i=0; i<namesArray.size(); i+=2 )
             {
                 COSString key = (COSString)namesArray.getObject(i);
@@ -283,17 +286,30 @@
     }

     /**
-     * Method to convert the COS value in the name tree to the PD Model object. The
-     * default implementation will simply return the given COSBase object.
-     * Subclasses should do something specific.
+     * Method to convert the COS value in the number tree to the PD Model object. The
+     * default implementation will simply use reflection to create the correct object
+     * type. Subclasses can do whatever they want.
      *
      * @param base The COS object to convert.
      * @return The converted PD Model object.
      * @throws IOException If there is an error during creation.
      */
-    protected COSObjectable convertCOSToPD( COSBase base ) throws IOException
+    protected T convertCOSToPD( COSBase base ) throws IOException
     {
-        return base;
+        if ( valueType.isAssignableFrom( base.getClass() )) {
+            // T is COSBase or a subclass
+            return (T) base;
+        }
+
+        try
+        {
+            Constructor<? extends T> ctor = valueType.getConstructor( base.getClass() );
+            return ctor.newInstance( base );
+        }
+        catch ( Exception e )
+        {
+            throw new IOException( "Error while trying to create value in number tree: " + e.getMessage(), e );
+        }
     }

     /**
@@ -302,19 +318,18 @@
      * @param dic The dictionary for the child node object to refer to.
      * @return The new child node object.
      */
-    protected PDNameTreeNode createChildNode( COSDictionary dic )
+    protected PDNameTreeNode<T> createChildNode( COSDictionary dic )
     {
-        return new PDNameTreeNode(dic,valueType);
+        return new PDNameTreeNode<T>(dic, valueType);
     }

     /**
-     * Set the names of for this node.  The keys should be java.lang.String and the
-     * values must be a COSObjectable.  This method will set the appropriate upper and lower
+     * Set the names of for this node. This method will set the appropriate upper and lower
      * limits based on the keys in the map.
      *
-     * @param names map of names to objects, or <code>null</code>
+     * @param names map of names to objects, or <code>null</code>.
      */
-    public void setNames( Map<String, ? extends COSObjectable> names )
+    public void setNames( Map<String, T> names )
     {
         if( names == null )
         {
Index: src/main/java/org/apache/pdfbox/pdmodel/common/PDNumberTreeNode.java
===================================================================
--- src/main/java/org/apache/pdfbox/pdmodel/common/PDNumberTreeNode.java	(Revision 1609073)
+++ src/main/java/org/apache/pdfbox/pdmodel/common/PDNumberTreeNode.java	(Arbeitskopie)
@@ -38,14 +38,16 @@
  *
  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>,
  *         <a href="igor.podolskiy@ievvwi.uni-stuttgart.de">Igor Podolskiy</a>
+ *         <a href="mailto:dtubach@web.de">Dominic Tubach</a>
  * @version $Revision: 1.4 $
+ * @param <T> The type of values in the tree.
  */
-public class PDNumberTreeNode implements COSObjectable
+public class PDNumberTreeNode<T extends COSObjectable> implements COSObjectable
 {
     private static final Log LOG = LogFactory.getLog( PDNumberTreeNode.class );

     private COSDictionary node;
-    private Class<? extends COSObjectable> valueType = null;
+    private Class<? extends T> valueType = null;

     /**
      * Constructor.
@@ -52,7 +54,7 @@
      *
      * @param valueClass The PD Model type of object that is the value.
      */
-    public PDNumberTreeNode( Class<? extends COSObjectable> valueClass )
+    public PDNumberTreeNode( Class<T> valueClass )
     {
         node = new COSDictionary();
         valueType = valueClass;
@@ -61,10 +63,10 @@
     /**
      * Constructor.
      *
-     * @param dict The dictionary that holds the name information.
+     * @param dict The dictionary that holds the number information.
      * @param valueClass The PD Model type of object that is the value.
      */
-    public PDNumberTreeNode( COSDictionary dict, Class<? extends COSObjectable> valueClass )
+    public PDNumberTreeNode( COSDictionary dict, Class<? extends T> valueClass )
     {
         node = dict;
         valueType = valueClass;
@@ -95,18 +97,18 @@
      *
      * @return The list of children or null if there are no children.
      */
-    public List<PDNumberTreeNode> getKids()
+    public List<PDNumberTreeNode<T>> getKids()
     {
-        List<PDNumberTreeNode> retval = null;
+        List<PDNumberTreeNode<T>> retval = null;
         COSArray kids = (COSArray)node.getDictionaryObject( COSName.KIDS );
         if( kids != null )
         {
-            List<PDNumberTreeNode> pdObjects = new ArrayList<PDNumberTreeNode>();
+            List<PDNumberTreeNode<T>> pdObjects = new ArrayList<PDNumberTreeNode<T>>();
             for( int i=0; i<kids.size(); i++ )
             {
                 pdObjects.add( createChildNode( (COSDictionary)kids.getObject(i) ) );
             }
-            retval = new COSArrayList<PDNumberTreeNode>(pdObjects,kids);
+            retval = new COSArrayList<PDNumberTreeNode<T>>(pdObjects, kids);
         }

         return retval;
@@ -117,12 +119,12 @@
      *
      * @param kids The children of this number tree.
      */
-    public void setKids( List<? extends PDNumberTreeNode> kids )
+    public void setKids( List<? extends PDNumberTreeNode<T>> kids )
     {
         if (kids != null && kids.size() > 0)
         {
-            PDNumberTreeNode firstKid = kids.get(0);
-            PDNumberTreeNode lastKid = kids.get(kids.size() - 1);
+            PDNumberTreeNode<T> firstKid = kids.get(0);
+            PDNumberTreeNode<T> lastKid = kids.get(kids.size() - 1);
             Integer lowerLimit = firstKid.getLowerLimit();
             this.setLowerLimit(lowerLimit);
             Integer upperLimit = lastKid.getUpperLimit();
@@ -145,22 +147,22 @@
      *
      * @throws IOException If there is a problem creating the values.
      */
-    public Object getValue( Integer index ) throws IOException
+    public T getValue( Integer index ) throws IOException
     {
-        Object retval = null;
-        Map<Integer,COSObjectable> names = getNumbers();
-        if( names != null )
+        T retval = null;
+        Map<Integer, T> numbers = getNumbers();
+        if( numbers != null )
         {
-            retval = names.get( index );
+            retval = numbers.get( index );
         }
         else
         {
-            List<PDNumberTreeNode> kids = getKids();
+            List<PDNumberTreeNode<T>> kids = getKids();
             if ( kids != null )
             {
                 for( int i=0; i<kids.size() && retval == null; i++ )
                 {
-                    PDNumberTreeNode childNode = kids.get( i );
+                    PDNumberTreeNode<T> childNode = kids.get( i );
                     if( childNode.getLowerLimit().compareTo( index ) <= 0 &&
                         childNode.getUpperLimit().compareTo( index ) >= 0 )
                     {
@@ -181,22 +183,23 @@
      * This will return a map of numbers.  The key will be a java.lang.Integer, the value will
      * depend on where this class is being used.
      *
-     * @return A map of COS objects.
+     * @return A map of PD objects or <code>null</code> if dictionary
+     *         contains no 'Nums' entry.
      *
      * @throws IOException If there is a problem creating the values.
      */
-    public Map<Integer,COSObjectable> getNumbers()  throws IOException
+    public Map<Integer, T> getNumbers()  throws IOException
     {
-        Map<Integer, COSObjectable> indices = null;
-        COSArray namesArray = (COSArray)node.getDictionaryObject( COSName.NUMS );
-        if( namesArray != null )
+        Map<Integer, T> indices = null;
+        COSArray numbersArray = (COSArray)node.getDictionaryObject( COSName.NUMS );
+        if( numbersArray != null )
         {
-            indices = new HashMap<Integer,COSObjectable>();
-            for( int i=0; i<namesArray.size(); i+=2 )
+            indices = new HashMap<Integer, T>();
+            for( int i=0; i<numbersArray.size(); i+=2 )
             {
-                COSInteger key = (COSInteger)namesArray.getObject(i);
-                COSBase cosValue = namesArray.getObject( i+1 );
-                COSObjectable pdValue = convertCOSToPD( cosValue );
+                COSInteger key = (COSInteger)numbersArray.getObject(i);
+                COSBase cosValue = numbersArray.getObject( i+1 );
+                T pdValue = convertCOSToPD( cosValue );
                 indices.put( Integer.valueOf(key.intValue()), pdValue );
             }
             indices = Collections.unmodifiableMap(indices);
@@ -205,28 +208,30 @@
     }

     /**
-     * Method to convert the COS value in the name tree to the PD Model object.  The
+     * Method to convert the COS value in the number tree to the PD Model object. The
      * default implementation will simply use reflection to create the correct object
-     * type.  Subclasses can do whatever they want.
+     * type. Subclasses can do whatever they want.
      *
      * @param base The COS object to convert.
      * @return The converted PD Model object.
      * @throws IOException If there is an error during creation.
      */
-    protected COSObjectable convertCOSToPD( COSBase base ) throws IOException
+    protected T convertCOSToPD( COSBase base ) throws IOException
     {
-        COSObjectable retval = null;
+        if ( valueType.isAssignableFrom( base.getClass() )) {
+            // T is COSBase or a subclass
+            return (T) base;
+        }
+
         try
         {
-            Constructor<? extends COSObjectable> ctor = valueType.getConstructor( new Class[] { base.getClass() } );
-            retval = ctor.newInstance( new Object[] { base } );
+            Constructor<? extends T> ctor = valueType.getConstructor( base.getClass() );
+            return ctor.newInstance( base );
         }
-        catch( Throwable t )
+        catch ( Exception e )
         {
-            throw new IOException( "Error while trying to create value in number tree:" + t.getMessage());
-
+            throw new IOException( "Error while trying to create value in number tree: " + e.getMessage(), e );
         }
-        return retval;
     }

     /**
@@ -235,19 +240,18 @@
      * @param dic The dictionary for the child node object to refer to.
      * @return The new child node object.
      */
-    protected PDNumberTreeNode createChildNode( COSDictionary dic )
+    protected PDNumberTreeNode<T> createChildNode( COSDictionary dic )
     {
-        return new PDNumberTreeNode(dic,valueType);
+        return new PDNumberTreeNode<T>(dic, valueType);
     }

     /**
-     * Set the names of for this node.  The keys should be java.lang.String and the
-     * values must be a COSObjectable.  This method will set the appropriate upper and lower
+     * Set the numbers of for this node. This method will set the appropriate upper and lower
      * limits based on the keys in the map.
      *
-     * @param numbers The map of names to objects.
+     * @param numbers The map of numbers to objects, or <code>null</code>.
      */
-    public void setNumbers( Map<Integer, ? extends COSObjectable> numbers )
+    public void setNumbers( Map<Integer, T> numbers )
     {
         if( numbers == null )
         {
@@ -263,7 +267,7 @@
             {
                 Integer key = keys.get(i);
                 array.add( COSInteger.get( key ) );
-                COSObjectable obj = (COSObjectable)numbers.get( key );
+                COSObjectable obj = numbers.get( key );
                 array.add( obj );
             }
             Integer lower = null;
@@ -270,8 +274,8 @@
             Integer upper = null;
             if( keys.size() > 0 )
             {
-                lower = (Integer)keys.get( 0 );
-                upper = (Integer)keys.get( keys.size()-1 );
+                lower = keys.get( 0 );
+                upper = keys.get( keys.size()-1 );
             }
             setUpperLimit( upper );
             setLowerLimit( lower );
@@ -280,7 +284,7 @@
     }

     /**
-     * Get the highest value for a key in the name map.
+     * Get the highest value for a key in the number map.
      *
      * @return The highest value for a key in the map.
      */
@@ -321,7 +325,7 @@
     }

     /**
-     * Get the lowest value for a key in the name map.
+     * Get the lowest value for a key in the number map.
      *
      * @return The lowest value for a key in the map.
      */
Index: src/main/java/org/apache/pdfbox/pdmodel/common/PDPageLabels.java
===================================================================
--- src/main/java/org/apache/pdfbox/pdmodel/common/PDPageLabels.java	(Revision 1609073)
+++ src/main/java/org/apache/pdfbox/pdmodel/common/PDPageLabels.java	(Arbeitskopie)
@@ -94,16 +94,16 @@
         {
             return;
         }
-        PDNumberTreeNode root = new PDNumberTreeNode(dict, COSDictionary.class);
+        PDNumberTreeNode<COSDictionary> root = new PDNumberTreeNode<COSDictionary>(dict, COSDictionary.class);
         findLabels(root);
     }

-    private void findLabels(PDNumberTreeNode node) throws IOException
+    private void findLabels(PDNumberTreeNode<COSDictionary> node) throws IOException
     {
         if (node.getKids() != null)
         {
-            List<PDNumberTreeNode> kids = node.getKids();
-            for (PDNumberTreeNode kid : kids)
+            List<PDNumberTreeNode<COSDictionary>> kids = node.getKids();
+            for (PDNumberTreeNode<COSDictionary> kid : kids)
             {
                 findLabels(kid);
             }
@@ -110,12 +110,12 @@
         }
         else if (node.getNumbers() != null)
         {
-            Map<Integer, COSObjectable> numbers = node.getNumbers();
-            for (Entry<Integer, COSObjectable> i : numbers.entrySet())
+            Map<Integer, COSDictionary> numbers = node.getNumbers();
+            for (Entry<Integer, COSDictionary> i : numbers.entrySet())
             {
                 if(i.getKey() >= 0)
                 {
-                    labels.put(i.getKey(), new PDPageLabelRange((COSDictionary)i.getValue()));
+                    labels.put(i.getKey(), new PDPageLabelRange(i.getValue()));
                 }
             }
         }
Index: src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureTreeRoot.java
===================================================================
--- src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureTreeRoot.java	(Revision 1609073)
+++ src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureTreeRoot.java	(Arbeitskopie)
@@ -118,12 +118,12 @@
      *
      * @return the ID tree
      */
-    public PDNameTreeNode getIDTree()
+    public PDNameTreeNode<PDStructureElement> getIDTree()
     {
         COSDictionary idTreeDic = (COSDictionary) this.getCOSDictionary().getDictionaryObject(COSName.ID_TREE);
         if (idTreeDic != null)
         {
-            return new PDNameTreeNode(idTreeDic, PDStructureElement.class);
+            return new PDNameTreeNode<PDStructureElement>(idTreeDic, PDStructureElement.class);
         }
         return null;
     }
@@ -133,7 +133,7 @@
      *
      * @param idTree the ID tree
      */
-    public void setIDTree(PDNameTreeNode idTree)
+    public void setIDTree(PDNameTreeNode<PDStructureElement> idTree)
     {
         this.getCOSDictionary().setItem(COSName.ID_TREE, idTree);
     }
@@ -143,12 +143,12 @@
      *
      * @return the parent tree
      */
-    public PDNumberTreeNode getParentTree()
+    public PDNumberTreeNode<COSBase> getParentTree()
     {
         COSDictionary parentTreeDic = (COSDictionary) this.getCOSDictionary().getDictionaryObject(COSName.PARENT_TREE);
         if (parentTreeDic != null)
         {
-            return new PDNumberTreeNode(parentTreeDic, COSBase.class);
+            return new PDNumberTreeNode<COSBase>(parentTreeDic, COSBase.class);
         }
         return null;
     }
@@ -158,7 +158,7 @@
      *
      * @param parentTree the parent tree
      */
-    public void setParentTree(PDNumberTreeNode parentTree)
+    public void setParentTree(PDNumberTreeNode<COSBase> parentTree)
     {
         this.getCOSDictionary().setItem(COSName.PARENT_TREE, parentTree);
     }
Index: src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.java
===================================================================
--- src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.java	(Revision 1609073)
+++ src/main/java/org/apache/pdfbox/pdmodel/interactive/documentnavigation/outline/PDOutlineItem.java	(Arbeitskopie)
@@ -239,7 +239,7 @@
                 PDDestinationNameTreeNode destsTree = namesDict.getDests();
                 if( destsTree != null )
                 {
-                    pageDestination = (PDPageDestination)destsTree.getValue( namedDest.getNamedDestination() );
+                    pageDestination = destsTree.getValue( namedDest.getNamedDestination() );
                 }
                 else
                 {
Index: src/test/java/org/apache/pdfbox/pdmodel/common/TestPDNameTreeNode.java
===================================================================
--- src/test/java/org/apache/pdfbox/pdmodel/common/TestPDNameTreeNode.java	(Revision 1609073)
+++ src/test/java/org/apache/pdfbox/pdmodel/common/TestPDNameTreeNode.java	(Arbeitskopie)
@@ -20,7 +20,9 @@
 import java.util.List;
 import java.util.SortedMap;
 import java.util.TreeMap;
+
 import junit.framework.TestCase;
+
 import org.apache.pdfbox.cos.COSInteger;
 import org.junit.Assert;

@@ -28,21 +30,22 @@
  * A test case for PDNameTreeNode.
  *
  * @author Koch
+ *         <a href="mailto:dtubach@web.de">Dominic Tubach</a>
  */
 public class TestPDNameTreeNode extends TestCase
 {

-    private PDNameTreeNode node1;
-    private PDNameTreeNode node2;
-    private PDNameTreeNode node4;
-    private PDNameTreeNode node5;
-    private PDNameTreeNode node24;
+    private PDNameTreeNode<COSInteger> node1;
+    private PDNameTreeNode<COSInteger> node2;
+    private PDNameTreeNode<COSInteger> node4;
+    private PDNameTreeNode<COSInteger> node5;
+    private PDNameTreeNode<COSInteger> node24;

     @Override
     protected void setUp() throws Exception
     {
-        this.node5 = new PDNameTreeNode(COSInteger.class);
-        SortedMap<String, COSObjectable> names = new TreeMap<String, COSObjectable>();
+        this.node5 = new PDNameTreeNode<COSInteger>(COSInteger.class);
+        SortedMap<String, COSInteger> names = new TreeMap<String, COSInteger>();
         names.put("Actinium", COSInteger.get(89));
         names.put("Aluminum", COSInteger.get(13));
         names.put("Americium", COSInteger.get(95));
@@ -52,8 +55,8 @@
         names.put("Astatine", COSInteger.get(85));
         this.node5.setNames(names);

-        this.node24 = new PDNameTreeNode(COSInteger.class);
-        names = new TreeMap<String, COSObjectable>();
+        this.node24 = new PDNameTreeNode<COSInteger>(COSInteger.class);
+        names = new TreeMap<String, COSInteger>();
         names.put("Xenon", COSInteger.get(54));
         names.put("Ytterbium", COSInteger.get(70));
         names.put("Yttrium", COSInteger.get(39));
@@ -61,29 +64,29 @@
         names.put("Zirconium", COSInteger.get(40));
         this.node24.setNames(names);

-        this.node2 = new PDNameTreeNode(COSInteger.class);
-        List<PDNameTreeNode> kids = this.node2.getKids();
+        this.node2 = new PDNameTreeNode<COSInteger>(COSInteger.class);
+        List<PDNameTreeNode<COSInteger>> kids = this.node2.getKids();
         if (kids == null)
         {
-            kids = new COSArrayList<PDNameTreeNode>();
+            kids = new COSArrayList<PDNameTreeNode<COSInteger>>();
         }
         kids.add(this.node5);
         this.node2.setKids(kids);

-        this.node4 = new PDNameTreeNode(COSInteger.class);
+        this.node4 = new PDNameTreeNode<COSInteger>(COSInteger.class);
         kids = this.node4.getKids();
         if (kids == null)
         {
-            kids = new COSArrayList<PDNameTreeNode>();
+            kids = new COSArrayList<PDNameTreeNode<COSInteger>>();
         }
         kids.add(this.node24);
         this.node4.setKids(kids);

-        this.node1 = new PDNameTreeNode(COSInteger.class);
+        this.node1 = new PDNameTreeNode<COSInteger>(COSInteger.class);
         kids = this.node1.getKids();
         if (kids == null)
         {
-            kids = new COSArrayList<PDNameTreeNode>();
+            kids = new COSArrayList<PDNameTreeNode<COSInteger>>();
         }
         kids.add(this.node2);
         kids.add(this.node4);
Index: src/test/java/org/apache/pdfbox/pdmodel/common/TestPDNumberTreeNode.java
===================================================================
--- src/test/java/org/apache/pdfbox/pdmodel/common/TestPDNumberTreeNode.java	(Revision 1609073)
+++ src/test/java/org/apache/pdfbox/pdmodel/common/TestPDNumberTreeNode.java	(Arbeitskopie)
@@ -34,20 +34,20 @@
  */
 public class TestPDNumberTreeNode extends TestCase
 {
-
-    private PDNumberTreeNode node1;
-    private PDNumberTreeNode node2;
-    private PDNumberTreeNode node4;
-    private PDNumberTreeNode node5;
-    private PDNumberTreeNode node24;

-    public static class PDTest implements COSObjectable {
+    private PDNumberTreeNode<PDTest> node1;
+    private PDNumberTreeNode<PDTest> node2;
+    private PDNumberTreeNode<PDTest> node4;
+    private PDNumberTreeNode<PDTest> node5;
+    private PDNumberTreeNode<PDTest> node24;
+
+    private static class PDTest implements COSObjectable {
         private int value;

         public PDTest(int value) {
             this.value = value;
         }
-
+
         public PDTest(COSInteger cosInt) {
             this.value = cosInt.intValue();
         }
@@ -83,7 +83,7 @@
     @Override
     protected void setUp() throws Exception
     {
-        this.node5 = new PDNumberTreeNode(PDTest.class);
+        this.node5 = new PDNumberTreeNode<PDTest>(PDTest.class);
         Map<Integer,PDTest> Numbers = new TreeMap<Integer, PDTest>();
         Numbers.put( 1, new PDTest( 89 ) );
         Numbers.put( 2, new PDTest( 13 ) );
@@ -94,7 +94,7 @@
         Numbers.put( 7, new PDTest( 85 ) );
         this.node5.setNumbers( Numbers );

-        this.node24 = new PDNumberTreeNode( PDTest.class );
+        this.node24 = new PDNumberTreeNode<PDTest>( PDTest.class );
         Numbers = new TreeMap<Integer, PDTest>();
         Numbers.put( 8, new PDTest( 54 ) );
         Numbers.put( 9, new PDTest( 70 ) );
@@ -103,29 +103,29 @@
         Numbers.put( 12, new PDTest( 40 ) );
         this.node24.setNumbers( Numbers );

-        this.node2 = new PDNumberTreeNode( PDTest.class );
-        List<PDNumberTreeNode> kids = this.node2.getKids();
+        this.node2 = new PDNumberTreeNode<PDTest>( PDTest.class );
+        List<PDNumberTreeNode<PDTest>> kids = this.node2.getKids();
         if ( kids == null)
         {
-            kids = new COSArrayList<PDNumberTreeNode>();
+            kids = new COSArrayList<PDNumberTreeNode<PDTest>>();
         }
         kids.add( this.node5 );
         this.node2.setKids( kids );

-        this.node4 = new PDNumberTreeNode( PDTest.class );
+        this.node4 = new PDNumberTreeNode<PDTest>( PDTest.class );
         kids = this.node4.getKids();
         if ( kids == null)
         {
-            kids = new COSArrayList<PDNumberTreeNode>();
+            kids = new COSArrayList<PDNumberTreeNode<PDTest>>();
         }
         kids.add( this.node24 );
         this.node4.setKids( kids );

-        this.node1 = new PDNumberTreeNode( PDTest.class );
+        this.node1 = new PDNumberTreeNode<PDTest>( PDTest.class );
         kids = this.node1.getKids();
         if ( kids == null)
         {
-            kids = new COSArrayList<PDNumberTreeNode>();
+            kids = new COSArrayList<PDNumberTreeNode<PDTest>>();
         }
         kids.add( this.node2 );
         kids.add( this.node4 );
@@ -151,7 +151,7 @@

         Assert.assertEquals(Integer.valueOf( 12 ), this.node1.getUpperLimit());

-        this.node24.setNumbers( new HashMap<Integer, COSObjectable>() );
+        this.node24.setNumbers( new HashMap<Integer, PDTest>() );
         Assert.assertNull( this.node24.getUpperLimit() );

         this.node5.setNumbers( null );
@@ -171,7 +171,7 @@

         Assert.assertEquals(Integer.valueOf( 1 ), this.node1.getLowerLimit());

-        this.node24.setNumbers( new HashMap<Integer, COSObjectable>() );
+        this.node24.setNumbers( new HashMap<Integer, PDTest>() );
         Assert.assertNull( this.node24.getLowerLimit() );

         this.node5.setNumbers( null );
