jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r786295 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype: EffectiveNodeType.java NodeTypeDefStore.java NodeTypeRegistry.java
Date Thu, 18 Jun 2009 21:30:42 GMT
Author: tripod
Date: Thu Jun 18 21:30:41 2009
New Revision: 786295

URL: http://svn.apache.org/viewvc?rev=786295&view=rev
Log:
Use new Java 5 Language features where possible

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java?rev=786295&r1=786294&r2=786295&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeType.java Thu Jun 18 21:30:41 2009
@@ -29,7 +29,6 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeSet;
@@ -45,16 +44,16 @@
     private static Logger log = LoggerFactory.getLogger(EffectiveNodeType.class);
 
     // list of explicitly aggregated {i.e. merged) node types
-    private final TreeSet mergedNodeTypes;
+    private final TreeSet<Name> mergedNodeTypes;
     // list of implicitly aggregated {through inheritance) node types
-    private final TreeSet inheritedNodeTypes;
+    private final TreeSet<Name> inheritedNodeTypes;
     // list of all either explicitly (through aggregation) or implicitly
     // (through inheritance) included node types.
-    private final TreeSet allNodeTypes;
+    private final TreeSet<Name> allNodeTypes;
     // map of named item definitions (maps name to list of definitions)
-    private final HashMap namedItemDefs;
+    private final HashMap<Name, List<ItemDef>> namedItemDefs;
     // list of unnamed item definitions (i.e. residual definitions)
-    private final ArrayList unnamedItemDefs;
+    private final ArrayList<ItemDef> unnamedItemDefs;
 
     // flag indicating whether any included node type supports orderable child nodes
     private boolean orderableChildNodes;
@@ -65,11 +64,11 @@
      * private constructor.
      */
     private EffectiveNodeType() {
-        mergedNodeTypes = new TreeSet();
-        inheritedNodeTypes = new TreeSet();
-        allNodeTypes = new TreeSet();
-        namedItemDefs = new HashMap();
-        unnamedItemDefs = new ArrayList();
+        mergedNodeTypes = new TreeSet<Name>();
+        inheritedNodeTypes = new TreeSet<Name>();
+        allNodeTypes = new TreeSet<Name>();
+        namedItemDefs = new HashMap<Name, List<ItemDef>>();
+        unnamedItemDefs = new ArrayList<ItemDef>();
         orderableChildNodes = false;
         primaryItemName = null;
     }
@@ -92,7 +91,7 @@
      */
     static EffectiveNodeType create(NodeTypeDef ntd,
                                     EffectiveNodeTypeCache entCache,
-                                    Map ntdCache)
+                                    Map<Name, NodeTypeDef> ntdCache)
             throws NodeTypeConflictException, NoSuchNodeTypeException {
         // create empty effective node type instance
         EffectiveNodeType ent = new EffectiveNodeType();
@@ -105,35 +104,35 @@
         // map of all item definitions (maps id to definition)
         // used to effectively detect ambiguous child definitions where
         // ambiguity is defined in terms of definition identity
-        HashMap itemDefIds = new HashMap();
+        HashMap<Object, ItemDef> itemDefIds = new HashMap<Object, ItemDef>();
 
         NodeDef[] cnda = ntd.getChildNodeDefs();
-        for (int i = 0; i < cnda.length; i++) {
+        for (NodeDef aCnda : cnda) {
             // check if child node definition would be ambiguous within
             // this node type definition
-            if (itemDefIds.containsKey(cnda[i].getId())) {
+            if (itemDefIds.containsKey(aCnda.getId())) {
                 // conflict
                 String msg;
-                if (cnda[i].definesResidual()) {
+                if (aCnda.definesResidual()) {
                     msg = ntName + " contains ambiguous residual child node definitions";
                 } else {
                     msg = ntName + " contains ambiguous definitions for child node named "
-                            + cnda[i].getName();
+                            + aCnda.getName();
                 }
                 log.debug(msg);
                 throw new NodeTypeConflictException(msg);
             } else {
-                itemDefIds.put(cnda[i].getId(), cnda[i]);
+                itemDefIds.put(aCnda.getId(), aCnda);
             }
-            if (cnda[i].definesResidual()) {
+            if (aCnda.definesResidual()) {
                 // residual node definition
-                ent.unnamedItemDefs.add(cnda[i]);
+                ent.unnamedItemDefs.add(aCnda);
             } else {
                 // named node definition
-                Name name = cnda[i].getName();
-                List defs = (List) ent.namedItemDefs.get(name);
+                Name name = aCnda.getName();
+                List<ItemDef> defs = ent.namedItemDefs.get(name);
                 if (defs == null) {
-                    defs = new ArrayList();
+                    defs = new ArrayList<ItemDef>();
                     ent.namedItemDefs.put(name, defs);
                 }
                 if (defs.size() > 0) {
@@ -141,9 +140,8 @@
                      * there already exists at least one definition with that
                      * name; make sure none of them is auto-create
                      */
-                    for (int j = 0; j < defs.size(); j++) {
-                        ItemDef def = (ItemDef) defs.get(j);
-                        if (cnda[i].isAutoCreated() || def.isAutoCreated()) {
+                    for (ItemDef def : defs) {
+                        if (aCnda.isAutoCreated() || def.isAutoCreated()) {
                             // conflict
                             String msg = "There are more than one 'auto-create' item definitions for '"
                                     + name + "' in node type '" + ntName + "'";
@@ -152,36 +150,36 @@
                         }
                     }
                 }
-                defs.add(cnda[i]);
+                defs.add(aCnda);
             }
         }
         PropDef[] pda = ntd.getPropertyDefs();
-        for (int i = 0; i < pda.length; i++) {
+        for (PropDef aPda : pda) {
             // check if property definition would be ambiguous within
             // this node type definition
-            if (itemDefIds.containsKey(pda[i].getId())) {
+            if (itemDefIds.containsKey(aPda.getId())) {
                 // conflict
                 String msg;
-                if (pda[i].definesResidual()) {
+                if (aPda.definesResidual()) {
                     msg = ntName + " contains ambiguous residual property definitions";
                 } else {
                     msg = ntName + " contains ambiguous definitions for property named "
-                            + pda[i].getName();
+                            + aPda.getName();
                 }
                 log.debug(msg);
                 throw new NodeTypeConflictException(msg);
             } else {
-                itemDefIds.put(pda[i].getId(), pda[i]);
+                itemDefIds.put(aPda.getId(), aPda);
             }
-            if (pda[i].definesResidual()) {
+            if (aPda.definesResidual()) {
                 // residual property definition
-                ent.unnamedItemDefs.add(pda[i]);
+                ent.unnamedItemDefs.add(aPda);
             } else {
                 // named property definition
-                Name name = pda[i].getName();
-                List defs = (List) ent.namedItemDefs.get(name);
+                Name name = aPda.getName();
+                List<ItemDef> defs = ent.namedItemDefs.get(name);
                 if (defs == null) {
-                    defs = new ArrayList();
+                    defs = new ArrayList<ItemDef>();
                     ent.namedItemDefs.put(name, defs);
                 }
                 if (defs.size() > 0) {
@@ -189,9 +187,8 @@
                      * there already exists at least one definition with that
                      * name; make sure none of them is auto-create
                      */
-                    for (int j = 0; j < defs.size(); j++) {
-                        ItemDef def = (ItemDef) defs.get(j);
-                        if (pda[i].isAutoCreated() || def.isAutoCreated()) {
+                    for (ItemDef def : defs) {
+                        if (aPda.isAutoCreated() || def.isAutoCreated()) {
                             // conflict
                             String msg = "There are more than one 'auto-create' item definitions for '"
                                     + name + "' in node type '" + ntName + "'";
@@ -200,7 +197,7 @@
                         }
                     }
                 }
-                defs.add(pda[i]);
+                defs.add(aPda);
             }
         }
 
@@ -217,8 +214,8 @@
             ent.orderableChildNodes = true;
         } else {
             Name[] nta = ent.getInheritedNodeTypes();
-            for (int i = 0; i < nta.length; i++) {
-                NodeTypeDef def = (NodeTypeDef) ntdCache.get(nta[i]);
+            for (Name aNta : nta) {
+                NodeTypeDef def = ntdCache.get(aNta);
                 if (def.hasOrderableChildNodes()) {
                     ent.orderableChildNodes = true;
                     break;
@@ -231,8 +228,8 @@
             ent.primaryItemName = ntd.getPrimaryItemName();
         } else {
             Name[] nta = ent.getInheritedNodeTypes();
-            for (int i = 0; i < nta.length; i++) {
-                NodeTypeDef def = (NodeTypeDef) ntdCache.get(nta[i]);
+            for (Name aNta : nta) {
+                NodeTypeDef def = ntdCache.get(aNta);
                 if (def.getPrimaryItemName() != null) {
                     ent.primaryItemName = def.getPrimaryItemName();
                     break;
@@ -256,7 +253,8 @@
 
     /**
      * Returns true if any of the included node types supports
-     * 'orderable child nodes'; returns alse otherwise.
+     * 'orderable child nodes'; returns false otherwise.
+     * @return <code>true</code> if this effective node type has orderable child nodes
      */
     public boolean hasOrderableChildNodes() {
         return orderableChildNodes;
@@ -267,53 +265,51 @@
     }
 
     public Name[] getMergedNodeTypes() {
-        return (Name[]) mergedNodeTypes.toArray(new Name[mergedNodeTypes.size()]);
+        return mergedNodeTypes.toArray(new Name[mergedNodeTypes.size()]);
     }
 
     public Name[] getInheritedNodeTypes() {
-        return (Name[]) inheritedNodeTypes.toArray(new Name[inheritedNodeTypes.size()]);
+        return inheritedNodeTypes.toArray(new Name[inheritedNodeTypes.size()]);
     }
 
     public Name[] getAllNodeTypes() {
-        return (Name[]) allNodeTypes.toArray(new Name[allNodeTypes.size()]);
+        return allNodeTypes.toArray(new Name[allNodeTypes.size()]);
     }
 
     public ItemDef[] getAllItemDefs() {
         if (namedItemDefs.size() == 0 && unnamedItemDefs.size() == 0) {
             return ItemDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(namedItemDefs.size() + unnamedItemDefs.size());
-        Iterator iter = namedItemDefs.values().iterator();
-        while (iter.hasNext()) {
-            defs.addAll((List) iter.next());
+        ArrayList<ItemDef> defs = new ArrayList<ItemDef>(namedItemDefs.size() + unnamedItemDefs.size());
+        for (List<ItemDef> itemDefs : namedItemDefs.values()) {
+            defs.addAll(itemDefs);
         }
         defs.addAll(unnamedItemDefs);
         if (defs.size() == 0) {
             return ItemDef.EMPTY_ARRAY;
         }
-        return (ItemDef[]) defs.toArray(new ItemDef[defs.size()]);
+        return defs.toArray(new ItemDef[defs.size()]);
     }
 
     public ItemDef[] getNamedItemDefs() {
         if (namedItemDefs.size() == 0) {
             return ItemDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(namedItemDefs.size());
-        Iterator iter = namedItemDefs.values().iterator();
-        while (iter.hasNext()) {
-            defs.addAll((List) iter.next());
+        ArrayList<ItemDef> defs = new ArrayList<ItemDef>(namedItemDefs.size());
+        for (List<ItemDef> itemDefs : namedItemDefs.values()) {
+            defs.addAll(itemDefs);
         }
         if (defs.size() == 0) {
             return ItemDef.EMPTY_ARRAY;
         }
-        return (ItemDef[]) defs.toArray(new ItemDef[defs.size()]);
+        return defs.toArray(new ItemDef[defs.size()]);
     }
 
     public ItemDef[] getUnnamedItemDefs() {
         if (unnamedItemDefs.size() == 0) {
             return ItemDef.EMPTY_ARRAY;
         }
-        return (ItemDef[]) unnamedItemDefs.toArray(new ItemDef[unnamedItemDefs.size()]);
+        return unnamedItemDefs.toArray(new ItemDef[unnamedItemDefs.size()]);
     }
 
     public boolean hasNamedItemDef(Name name) {
@@ -321,99 +317,85 @@
     }
 
     public ItemDef[] getNamedItemDefs(Name name) {
-        List defs = (List) namedItemDefs.get(name);
+        List<ItemDef> defs = namedItemDefs.get(name);
         if (defs == null || defs.size() == 0) {
             return ItemDef.EMPTY_ARRAY;
         }
-        return (ItemDef[]) defs.toArray(new ItemDef[defs.size()]);
+        return defs.toArray(new ItemDef[defs.size()]);
     }
 
     public NodeDef[] getAllNodeDefs() {
         if (namedItemDefs.size() == 0 && unnamedItemDefs.size() == 0) {
             return NodeDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(namedItemDefs.size() + unnamedItemDefs.size());
-        Iterator iter = unnamedItemDefs.iterator();
-        while (iter.hasNext()) {
-            ItemDef def = (ItemDef) iter.next();
+        ArrayList<NodeDef> defs = new ArrayList<NodeDef>(namedItemDefs.size() + unnamedItemDefs.size());
+        for (ItemDef def : unnamedItemDefs) {
             if (def.definesNode()) {
-                defs.add(def);
+                defs.add((NodeDef) def);
             }
         }
-        iter = namedItemDefs.values().iterator();
-        while (iter.hasNext()) {
-            List list = (List) iter.next();
-            Iterator iter1 = list.iterator();
-            while (iter1.hasNext()) {
-                ItemDef def = (ItemDef) iter1.next();
+        for (List<ItemDef> list: namedItemDefs.values()) {
+            for (ItemDef def : list) {
                 if (def.definesNode()) {
-                    defs.add(def);
+                    defs.add((NodeDef) def);
                 }
             }
         }
         if (defs.size() == 0) {
             return NodeDef.EMPTY_ARRAY;
         }
-        return (NodeDef[]) defs.toArray(new NodeDef[defs.size()]);
+        return defs.toArray(new NodeDef[defs.size()]);
     }
 
     public NodeDef[] getNamedNodeDefs() {
         if (namedItemDefs.size() == 0) {
             return NodeDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(namedItemDefs.size());
-        Iterator iter = namedItemDefs.values().iterator();
-        while (iter.hasNext()) {
-            List list = (List) iter.next();
-            Iterator iter1 = list.iterator();
-            while (iter1.hasNext()) {
-                ItemDef def = (ItemDef) iter1.next();
+        ArrayList<NodeDef> defs = new ArrayList<NodeDef>(namedItemDefs.size());
+        for (List<ItemDef> list : namedItemDefs.values()) {
+            for (ItemDef def : list) {
                 if (def.definesNode()) {
-                    defs.add(def);
+                    defs.add((NodeDef) def);
                 }
             }
         }
         if (defs.size() == 0) {
             return NodeDef.EMPTY_ARRAY;
         }
-        return (NodeDef[]) defs.toArray(new NodeDef[defs.size()]);
+        return defs.toArray(new NodeDef[defs.size()]);
     }
 
     public NodeDef[] getNamedNodeDefs(Name name) {
-        List list = (List) namedItemDefs.get(name);
+        List<ItemDef> list = namedItemDefs.get(name);
         if (list == null || list.size() == 0) {
             return NodeDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(list.size());
-        Iterator iter = list.iterator();
-        while (iter.hasNext()) {
-            ItemDef def = (ItemDef) iter.next();
+        ArrayList<NodeDef> defs = new ArrayList<NodeDef>(list.size());
+        for (ItemDef def : list) {
             if (def.definesNode()) {
-                defs.add(def);
+                defs.add((NodeDef) def);
             }
         }
         if (defs.size() == 0) {
             return NodeDef.EMPTY_ARRAY;
         }
-        return (NodeDef[]) defs.toArray(new NodeDef[defs.size()]);
+        return defs.toArray(new NodeDef[defs.size()]);
     }
 
     public NodeDef[] getUnnamedNodeDefs() {
         if (unnamedItemDefs.size() == 0) {
             return NodeDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(unnamedItemDefs.size());
-        Iterator iter = unnamedItemDefs.iterator();
-        while (iter.hasNext()) {
-            ItemDef def = (ItemDef) iter.next();
+        ArrayList<NodeDef> defs = new ArrayList<NodeDef>(unnamedItemDefs.size());
+        for (ItemDef def : unnamedItemDefs) {
             if (def.definesNode()) {
-                defs.add(def);
+                defs.add((NodeDef) def);
             }
         }
         if (defs.size() == 0) {
             return NodeDef.EMPTY_ARRAY;
         }
-        return (NodeDef[]) defs.toArray(new NodeDef[defs.size()]);
+        return defs.toArray(new NodeDef[defs.size()]);
     }
 
     public NodeDef[] getAutoCreateNodeDefs() {
@@ -422,110 +404,92 @@
         if (namedItemDefs.size() == 0) {
             return NodeDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(namedItemDefs.size());
-        Iterator iter = namedItemDefs.values().iterator();
-        while (iter.hasNext()) {
-            List list = (List) iter.next();
-            Iterator iter1 = list.iterator();
-            while (iter1.hasNext()) {
-                ItemDef def = (ItemDef) iter1.next();
+        ArrayList<NodeDef> defs = new ArrayList<NodeDef>(namedItemDefs.size());
+        for (List<ItemDef> list : namedItemDefs.values()) {
+            for (ItemDef def : list) {
                 if (def.definesNode() && def.isAutoCreated()) {
-                    defs.add(def);
+                    defs.add((NodeDef) def);
                 }
             }
         }
         if (defs.size() == 0) {
             return NodeDef.EMPTY_ARRAY;
         }
-        return (NodeDef[]) defs.toArray(new NodeDef[defs.size()]);
+        return defs.toArray(new NodeDef[defs.size()]);
     }
 
     public PropDef[] getAllPropDefs() {
         if (namedItemDefs.size() == 0 && unnamedItemDefs.size() == 0) {
             return PropDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(namedItemDefs.size() + unnamedItemDefs.size());
-        Iterator iter = unnamedItemDefs.iterator();
-        while (iter.hasNext()) {
-            ItemDef def = (ItemDef) iter.next();
+        ArrayList<PropDef> defs = new ArrayList<PropDef>(namedItemDefs.size() + unnamedItemDefs.size());
+        for (ItemDef def : unnamedItemDefs) {
             if (!def.definesNode()) {
-                defs.add(def);
+                defs.add((PropDef) def);
             }
         }
-        iter = namedItemDefs.values().iterator();
-        while (iter.hasNext()) {
-            List list = (List) iter.next();
-            Iterator iter1 = list.iterator();
-            while (iter1.hasNext()) {
-                ItemDef def = (ItemDef) iter1.next();
+        for (List<ItemDef> list: namedItemDefs.values()) {
+            for (ItemDef def : list) {
                 if (!def.definesNode()) {
-                    defs.add(def);
+                    defs.add((PropDef) def);
                 }
             }
         }
         if (defs.size() == 0) {
             return PropDef.EMPTY_ARRAY;
         }
-        return (PropDef[]) defs.toArray(new PropDef[defs.size()]);
+        return defs.toArray(new PropDef[defs.size()]);
     }
 
     public PropDef[] getNamedPropDefs() {
         if (namedItemDefs.size() == 0) {
             return PropDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(namedItemDefs.size());
-        Iterator iter = namedItemDefs.values().iterator();
-        while (iter.hasNext()) {
-            List list = (List) iter.next();
-            Iterator iter1 = list.iterator();
-            while (iter1.hasNext()) {
-                ItemDef def = (ItemDef) iter1.next();
+        ArrayList<PropDef> defs = new ArrayList<PropDef>(namedItemDefs.size());
+        for (List<ItemDef> list : namedItemDefs.values()) {
+            for (ItemDef def : list) {
                 if (!def.definesNode()) {
-                    defs.add(def);
+                    defs.add((PropDef) def);
                 }
             }
         }
         if (defs.size() == 0) {
             return PropDef.EMPTY_ARRAY;
         }
-        return (PropDef[]) defs.toArray(new PropDef[defs.size()]);
+        return defs.toArray(new PropDef[defs.size()]);
     }
 
     public PropDef[] getNamedPropDefs(Name name) {
-        List list = (List) namedItemDefs.get(name);
+        List<ItemDef> list = namedItemDefs.get(name);
         if (list == null || list.size() == 0) {
             return PropDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(list.size());
-        Iterator iter = list.iterator();
-        while (iter.hasNext()) {
-            ItemDef def = (ItemDef) iter.next();
+        ArrayList<PropDef> defs = new ArrayList<PropDef>(list.size());
+        for (ItemDef def : list) {
             if (!def.definesNode()) {
-                defs.add(def);
+                defs.add((PropDef) def);
             }
         }
         if (defs.size() == 0) {
             return PropDef.EMPTY_ARRAY;
         }
-        return (PropDef[]) defs.toArray(new PropDef[defs.size()]);
+        return defs.toArray(new PropDef[defs.size()]);
     }
 
     public PropDef[] getUnnamedPropDefs() {
         if (unnamedItemDefs.size() == 0) {
             return PropDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(unnamedItemDefs.size());
-        Iterator iter = unnamedItemDefs.iterator();
-        while (iter.hasNext()) {
-            ItemDef def = (ItemDef) iter.next();
+        ArrayList<PropDef> defs = new ArrayList<PropDef>(unnamedItemDefs.size());
+        for (ItemDef def : unnamedItemDefs) {
             if (!def.definesNode()) {
-                defs.add(def);
+                defs.add((PropDef) def);
             }
         }
         if (defs.size() == 0) {
             return PropDef.EMPTY_ARRAY;
         }
-        return (PropDef[]) defs.toArray(new PropDef[defs.size()]);
+        return defs.toArray(new PropDef[defs.size()]);
     }
 
     public PropDef[] getAutoCreatePropDefs() {
@@ -534,22 +498,18 @@
         if (namedItemDefs.size() == 0) {
             return PropDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(namedItemDefs.size());
-        Iterator iter = namedItemDefs.values().iterator();
-        while (iter.hasNext()) {
-            List list = (List) iter.next();
-            Iterator iter1 = list.iterator();
-            while (iter1.hasNext()) {
-                ItemDef def = (ItemDef) iter1.next();
+        ArrayList<PropDef> defs = new ArrayList<PropDef>(namedItemDefs.size());
+        for (List<ItemDef> list : namedItemDefs.values()) {
+            for (ItemDef def : list) {
                 if (!def.definesNode() && def.isAutoCreated()) {
-                    defs.add(def);
+                    defs.add((PropDef) def);
                 }
             }
         }
         if (defs.size() == 0) {
             return PropDef.EMPTY_ARRAY;
         }
-        return (PropDef[]) defs.toArray(new PropDef[defs.size()]);
+        return defs.toArray(new PropDef[defs.size()]);
     }
 
     public PropDef[] getMandatoryPropDefs() {
@@ -558,22 +518,18 @@
         if (namedItemDefs.size() == 0) {
             return PropDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(namedItemDefs.size());
-        Iterator iter = namedItemDefs.values().iterator();
-        while (iter.hasNext()) {
-            List list = (List) iter.next();
-            Iterator iter1 = list.iterator();
-            while (iter1.hasNext()) {
-                ItemDef def = (ItemDef) iter1.next();
+        ArrayList<PropDef> defs = new ArrayList<PropDef>(namedItemDefs.size());
+        for (List<ItemDef> list : namedItemDefs.values()) {
+            for (ItemDef def : list) {
                 if (!def.definesNode() && def.isMandatory()) {
-                    defs.add(def);
+                    defs.add((PropDef) def);
                 }
             }
         }
         if (defs.size() == 0) {
             return PropDef.EMPTY_ARRAY;
         }
-        return (PropDef[]) defs.toArray(new PropDef[defs.size()]);
+        return defs.toArray(new PropDef[defs.size()]);
     }
 
     public NodeDef[] getMandatoryNodeDefs() {
@@ -582,22 +538,18 @@
         if (namedItemDefs.size() == 0) {
             return NodeDef.EMPTY_ARRAY;
         }
-        ArrayList defs = new ArrayList(namedItemDefs.size());
-        Iterator iter = namedItemDefs.values().iterator();
-        while (iter.hasNext()) {
-            List list = (List) iter.next();
-            Iterator iter1 = list.iterator();
-            while (iter1.hasNext()) {
-                ItemDef def = (ItemDef) iter1.next();
+        ArrayList<NodeDef> defs = new ArrayList<NodeDef>(namedItemDefs.size());
+        for (List<ItemDef> list : namedItemDefs.values()) {
+            for (ItemDef def : list) {
                 if (def.definesNode() && def.isMandatory()) {
-                    defs.add(def);
+                    defs.add((NodeDef) def);
                 }
             }
         }
         if (defs.size() == 0) {
             return NodeDef.EMPTY_ARRAY;
         }
-        return (NodeDef[]) defs.toArray(new NodeDef[defs.size()]);
+        return defs.toArray(new NodeDef[defs.size()]);
     }
 
     /**
@@ -654,13 +606,13 @@
         }
         if (values != null && values.length > 0) {
             // check value constraints on every value
-            for (int i = 0; i < values.length; i++) {
+            for (InternalValue value : values) {
                 // constraints are OR-ed together
                 boolean satisfied = false;
                 ConstraintViolationException cve = null;
-                for (int j = 0; j < constraints.length; j++) {
+                for (QValueConstraint constraint : constraints) {
                     try {
-                        constraints[j].check(values[i]);
+                        constraint.check(value);
                         satisfied = true;
                         break;
                     } catch (ConstraintViolationException e) {
@@ -743,9 +695,9 @@
 
         // try named node definitions first
         ItemDef[] defs = getNamedItemDefs(name);
-        for (int i = 0; i < defs.length; i++) {
-            if (defs[i].definesNode()) {
-                NodeDef nd = (NodeDef) defs[i];
+        for (ItemDef def : defs) {
+            if (def.definesNode()) {
+                NodeDef nd = (NodeDef) def;
                 Name[] types = nd.getRequiredPrimaryTypes();
                 // node definition with that name exists
                 if (entTarget != null && types != null) {
@@ -764,8 +716,7 @@
         // no item with that name defined;
         // try residual node definitions
         NodeDef[] nda = getUnnamedNodeDefs();
-        for (int i = 0; i < nda.length; i++) {
-            NodeDef nd = nda[i];
+        for (NodeDef nd : nda) {
             if (entTarget != null && nd.getRequiredPrimaryTypes() != null) {
                 // check 'required primary types' constraint
                 if (!entTarget.includesNodeTypes(nd.getRequiredPrimaryTypes())) {
@@ -867,37 +818,33 @@
 
     private PropDef getMatchingPropDef(PropDef[] defs, int type) {
         PropDef match = null;
-        for (int i = 0; i < defs.length; i++) {
-            ItemDef def = defs[i];
-            if (!def.definesNode()) {
-                PropDef pd = (PropDef) def;
-                int reqType = pd.getRequiredType();
-                // match type
-                if (reqType == PropertyType.UNDEFINED
-                        || type == PropertyType.UNDEFINED
-                        || reqType == type) {
-                    if (match == null) {
-                        match = pd;
+        for (PropDef pd : defs) {
+            int reqType = pd.getRequiredType();
+            // match type
+            if (reqType == PropertyType.UNDEFINED
+                    || type == PropertyType.UNDEFINED
+                    || reqType == type) {
+                if (match == null) {
+                    match = pd;
+                } else {
+                    // check if this definition is a better match than
+                    // the one we've already got
+                    if (match.getRequiredType() != pd.getRequiredType()) {
+                        if (match.getRequiredType() == PropertyType.UNDEFINED) {
+                            // found better match
+                            match = pd;
+                        }
                     } else {
-                        // check if this definition is a better match than
-                        // the one we've already got
-                        if (match.getRequiredType() != pd.getRequiredType()) {
-                            if (match.getRequiredType() == PropertyType.UNDEFINED) {
-                                // found better match
-                                match = pd;
-                            }
-                        } else {
-                            if (match.isMultiple() && !pd.isMultiple()) {
-                                // found better match
-                                match = pd;
-                            }
+                        if (match.isMultiple() && !pd.isMultiple()) {
+                            // found better match
+                            match = pd;
                         }
                     }
-                    if (match.getRequiredType() != PropertyType.UNDEFINED
-                            && !match.isMultiple()) {
-                        // found best possible match, get outta here
-                        return match;
-                    }
+                }
+                if (match.getRequiredType() != PropertyType.UNDEFINED
+                        && !match.isMultiple()) {
+                    // found best possible match, get outta here
+                    return match;
                 }
             }
         }
@@ -907,25 +854,21 @@
     private PropDef getMatchingPropDef(PropDef[] defs, int type,
                                        boolean multiValued) {
         PropDef match = null;
-        for (int i = 0; i < defs.length; i++) {
-            ItemDef def = defs[i];
-            if (!def.definesNode()) {
-                PropDef pd = (PropDef) def;
-                int reqType = pd.getRequiredType();
-                // match type
-                if (reqType == PropertyType.UNDEFINED
-                        || type == PropertyType.UNDEFINED
-                        || reqType == type) {
-                    // match multiValued flag
-                    if (multiValued == pd.isMultiple()) {
-                        // found match
-                        if (pd.getRequiredType() != PropertyType.UNDEFINED) {
-                            // found best possible match, get outta here
-                            return pd;
-                        } else {
-                            if (match == null) {
-                                match = pd;
-                            }
+        for (PropDef pd : defs) {
+            int reqType = pd.getRequiredType();
+            // match type
+            if (reqType == PropertyType.UNDEFINED
+                    || type == PropertyType.UNDEFINED
+                    || reqType == type) {
+                // match multiValued flag
+                if (multiValued == pd.isMultiple()) {
+                    // found match
+                    if (pd.getRequiredType() != PropertyType.UNDEFINED) {
+                        // found best possible match, get outta here
+                        return pd;
+                    } else {
+                        if (match == null) {
+                            match = pd;
                         }
                     }
                 }
@@ -945,11 +888,11 @@
          */
         ItemDef[] defs = getNamedItemDefs(name);
         if (defs != null) {
-            for (int i = 0; i < defs.length; i++) {
-                if (defs[i].isMandatory()) {
+            for (ItemDef def : defs) {
+                if (def.isMandatory()) {
                     throw new ConstraintViolationException("can't remove mandatory item");
                 }
-                if (defs[i].isProtected()) {
+                if (def.isProtected()) {
                     throw new ConstraintViolationException("can't remove protected item");
                 }
             }
@@ -967,11 +910,11 @@
          */
         ItemDef[] defs = getNamedNodeDefs(name);
         if (defs != null) {
-            for (int i = 0; i < defs.length; i++) {
-                if (defs[i].isMandatory()) {
+            for (ItemDef def : defs) {
+                if (def.isMandatory()) {
                     throw new ConstraintViolationException("can't remove mandatory node");
                 }
-                if (defs[i].isProtected()) {
+                if (def.isProtected()) {
                     throw new ConstraintViolationException("can't remove protected node");
                 }
             }
@@ -989,11 +932,11 @@
          */
         ItemDef[] defs = getNamedPropDefs(name);
         if (defs != null) {
-            for (int i = 0; i < defs.length; i++) {
-                if (defs[i].isMandatory()) {
+            for (ItemDef def : defs) {
+                if (def.isMandatory()) {
                     throw new ConstraintViolationException("can't remove mandatory property");
                 }
-                if (defs[i].isProtected()) {
+                if (def.isProtected()) {
                     throw new ConstraintViolationException("can't remove protected property");
                 }
             }
@@ -1011,7 +954,7 @@
     EffectiveNodeType merge(EffectiveNodeType other)
             throws NodeTypeConflictException {
         // create a clone of this instance and perform the merge on
-        // the 'clone' to avoid a potentially inconsistant state
+        // the 'clone' to avoid a potentially inconsistent state
         // of this instance if an exception is thrown during
         // the merge.
         EffectiveNodeType copy = (EffectiveNodeType) clone();
@@ -1036,10 +979,10 @@
             throws NodeTypeConflictException {
         Name[] nta = other.getAllNodeTypes();
         int includedCount = 0;
-        for (int i = 0; i < nta.length; i++) {
-            if (includesNodeType(nta[i])) {
+        for (Name aNta : nta) {
+            if (includesNodeType(aNta)) {
                 // redundant node type
-                log.debug("node type '" + nta[i] + "' is already contained.");
+                log.debug("node type '" + aNta + "' is already contained.");
                 includedCount++;
             }
         }
@@ -1050,19 +993,17 @@
 
         // named item definitions
         ItemDef[] defs = other.getNamedItemDefs();
-        for (int i = 0; i < defs.length; i++) {
-            ItemDef def = defs[i];
+        for (ItemDef def : defs) {
             if (includesNodeType(def.getDeclaringNodeType())) {
                 // ignore redundant definitions
                 continue;
             }
             Name name = def.getName();
-            List existingDefs = (List) namedItemDefs.get(name);
+            List<ItemDef> existingDefs = namedItemDefs.get(name);
             if (existingDefs != null) {
                 if (existingDefs.size() > 0) {
                     // there already exists at least one definition with that name
-                    for (int j = 0; j < existingDefs.size(); j++) {
-                        ItemDef existingDef = (ItemDef) existingDefs.get(j);
+                    for (ItemDef existingDef : existingDefs) {
                         // make sure none of them is auto-create
                         if (def.isAutoCreated() || existingDef.isAutoCreated()) {
                             // conflict
@@ -1110,7 +1051,7 @@
                     }
                 }
             } else {
-                existingDefs = new ArrayList();
+                existingDefs = new ArrayList<ItemDef>();
                 namedItemDefs.put(name, existingDefs);
             }
             existingDefs.add(def);
@@ -1118,15 +1059,12 @@
 
         // residual item definitions
         defs = other.getUnnamedItemDefs();
-        for (int i = 0; i < defs.length; i++) {
-            ItemDef def = defs[i];
+        for (ItemDef def : defs) {
             if (includesNodeType(def.getDeclaringNodeType())) {
                 // ignore redundant definitions
                 continue;
             }
-            Iterator iter = unnamedItemDefs.iterator();
-            while (iter.hasNext()) {
-                ItemDef existing = (ItemDef) iter.next();
+            for (ItemDef existing : unnamedItemDefs) {
                 // compare with existing definition
                 if (def.definesNode() == existing.definesNode()) {
                     if (!def.definesNode()) {
@@ -1168,42 +1106,33 @@
             }
             unnamedItemDefs.add(def);
         }
-        for (int i = 0; i < nta.length; i++) {
-            allNodeTypes.add(nta[i]);
-        }
+        allNodeTypes.addAll(Arrays.asList(nta));
 
         if (supertype) {
             // implicit merge as result of inheritance
 
             // add other merged node types as supertypes
             nta = other.getMergedNodeTypes();
-            for (int i = 0; i < nta.length; i++) {
-                inheritedNodeTypes.add(nta[i]);
-            }
+            inheritedNodeTypes.addAll(Arrays.asList(nta));
             // add supertypes of other merged node types as supertypes
             nta = other.getInheritedNodeTypes();
-            for (int i = 0; i < nta.length; i++) {
-                inheritedNodeTypes.add(nta[i]);
-            }
+            inheritedNodeTypes.addAll(Arrays.asList(nta));
         } else {
             // explicit merge
 
             // merge with other merged node types
             nta = other.getMergedNodeTypes();
-            for (int i = 0; i < nta.length; i++) {
-                mergedNodeTypes.add(nta[i]);
-            }
+            mergedNodeTypes.addAll(Arrays.asList(nta));
             // add supertypes of other merged node types as supertypes
             nta = other.getInheritedNodeTypes();
-            for (int i = 0; i < nta.length; i++) {
-                inheritedNodeTypes.add(nta[i]);
-            }
+            inheritedNodeTypes.addAll(Arrays.asList(nta));
         }
 
         // update 'orderable child nodes' attribute value (JCR-1947)
         if (other.hasOrderableChildNodes()) {
             orderableChildNodes = true;
         }
+
         // update 'primary item' attribute value (JCR-1947)
         if (primaryItemName == null && other.getPrimaryItemName() != null) {
             primaryItemName = other.getPrimaryItemName();
@@ -1216,11 +1145,9 @@
         clone.mergedNodeTypes.addAll(mergedNodeTypes);
         clone.inheritedNodeTypes.addAll(inheritedNodeTypes);
         clone.allNodeTypes.addAll(allNodeTypes);
-        Iterator iter = namedItemDefs.keySet().iterator();
-        while (iter.hasNext()) {
-            Object key = iter.next();
-            List list = (List) namedItemDefs.get(key);
-            clone.namedItemDefs.put(key, new ArrayList(list));
+        for (Name name : namedItemDefs.keySet()) {
+            List<ItemDef> list = namedItemDefs.get(name);
+            clone.namedItemDefs.put(name, new ArrayList<ItemDef>(list));
         }
         clone.unnamedItemDefs.addAll(unnamedItemDefs);
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java?rev=786295&r1=786294&r2=786295&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java Thu Jun 18 21:30:41 2009
@@ -34,7 +34,6 @@
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefReader;
 import org.apache.jackrabbit.spi.commons.nodetype.compact.ParseException;
-import org.apache.jackrabbit.spi.commons.nodetype.compact.QNodeTypeDefinitionsBuilderImpl;
 
 /**
  * <code>NodeTypeDefStore</code> ...
@@ -133,13 +132,13 @@
      * @return
      */
     public NodeTypeDef get(Name name) {
-        return (NodeTypeDef) ntDefs.get(name);
+        return ntDefs.get(name);
     }
 
     /**
      * @return
      */
-    public Collection all() {
+    public Collection<NodeTypeDef> all() {
         return Collections.unmodifiableCollection(ntDefs.values());
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java?rev=786295&r1=786294&r2=786295&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java Thu Jun 18 21:30:41 2009
@@ -16,34 +16,16 @@
  */
 package org.apache.jackrabbit.core.nodetype;
 
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
-import org.apache.commons.collections.map.ReferenceMap;
-import org.apache.commons.io.IOUtils;
-import org.apache.jackrabbit.core.cluster.NodeTypeEventChannel;
-import org.apache.jackrabbit.core.cluster.NodeTypeEventListener;
-import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.jackrabbit.core.fs.FileSystemException;
-import org.apache.jackrabbit.core.fs.FileSystemResource;
-import org.apache.jackrabbit.core.util.Dumpable;
-import org.apache.jackrabbit.core.value.InternalValue;
-import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.QValueConstraint;
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
-import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintStream;
-import java.io.InputStreamReader;
 import java.io.Reader;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.Stack;
@@ -55,6 +37,24 @@
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.version.OnParentVersionAction;
 
+import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.core.cluster.NodeTypeEventChannel;
+import org.apache.jackrabbit.core.cluster.NodeTypeEventListener;
+import org.apache.jackrabbit.core.fs.FileSystem;
+import org.apache.jackrabbit.core.fs.FileSystemException;
+import org.apache.jackrabbit.core.fs.FileSystemResource;
+import org.apache.jackrabbit.core.util.Dumpable;
+import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QValueConstraint;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
+
 /**
  * A <code>NodeTypeRegistry</code> ...
  */
@@ -84,15 +84,15 @@
     private EffectiveNodeTypeCache entCache;
 
     // map of node type names and node type definitions
-    private final ConcurrentReaderHashMap registeredNTDefs;
+    private final Map<Name, NodeTypeDef> registeredNTDefs;
 
     // definition of the root node
     private final NodeDef rootNodeDef;
 
     // map of id's and property definitions
-    private final ConcurrentReaderHashMap propDefs;
+    private final Map<PropDefId, PropDef> propDefs;
     // map of id's and node definitions
-    private final ConcurrentReaderHashMap nodeDefs;
+    private final Map<NodeDefId, NodeDef> nodeDefs;
 
     /**
      * namespace registry for resolving prefixes and namespace URI's;
@@ -103,7 +103,7 @@
     /**
      * Listeners (soft references)
      */
-    private final Map listeners =
+    private final Map<NodeTypeRegistryListener, NodeTypeRegistryListener> listeners =
             Collections.synchronizedMap(new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.WEAK));
 
     /**
@@ -114,10 +114,10 @@
     /**
      * Create a new <code>NodeTypeRegistry</codes>
      *
-     * @param nsReg
-     * @param ntStore
+     * @param nsReg namespace registry
+     * @param ntStore node type store
      * @return <code>NodeTypeRegistry</codes> object
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs
      */
     public static NodeTypeRegistry create(NamespaceRegistry nsReg, FileSystem ntStore)
             throws RepositoryException {
@@ -133,7 +133,7 @@
      * @return the names of all registered node types.
      */
     public Name[] getRegisteredNodeTypes() {
-        return (Name[]) registeredNTDefs.keySet().toArray(new Name[registeredNTDefs.size()]);
+        return registeredNTDefs.keySet().toArray(new Name[registeredNTDefs.size()]);
     }
 
     /**
@@ -183,7 +183,7 @@
         persistCustomNodeTypeDefs(customNTDefs);
 
         if (eventChannel != null) {
-            HashSet ntDefs = new HashSet();
+            Set<NodeTypeDef> ntDefs = new HashSet<NodeTypeDef>();
             ntDefs.add(ntd);
             eventChannel.registered(ntDefs);
         }
@@ -206,7 +206,7 @@
      * @throws InvalidNodeTypeDefException if the given node type definition is invalid.
      * @throws RepositoryException if a repository error occurs.
      */
-    public void registerNodeTypes(Collection ntDefs)
+    public void registerNodeTypes(Collection<NodeTypeDef> ntDefs)
             throws InvalidNodeTypeDefException, RepositoryException {
 
         registerNodeTypes(ntDefs, false);
@@ -220,14 +220,14 @@
      * @throws InvalidNodeTypeDefException if the given node type definition is invalid.
      * @throws RepositoryException if a repository error occurs.
      */
-    private synchronized void registerNodeTypes(Collection ntDefs, boolean external)
+    private synchronized void registerNodeTypes(Collection<NodeTypeDef> ntDefs,
+                                                boolean external)
             throws InvalidNodeTypeDefException, RepositoryException {
 
         // validate and register new node type definitions
         internalRegister(ntDefs);
         // persist new node type definitions
-        for (Iterator iter = ntDefs.iterator(); iter.hasNext();) {
-            NodeTypeDef ntDef = (NodeTypeDef) iter.next();
+        for (NodeTypeDef ntDef: ntDefs) {
             customNTDefs.add(ntDef);
         }
         persistCustomNodeTypeDefs(customNTDefs);
@@ -238,8 +238,7 @@
         }
 
         // notify listeners
-        for (Iterator iter = ntDefs.iterator(); iter.hasNext();) {
-            NodeTypeDef ntDef = (NodeTypeDef) iter.next();
+        for (NodeTypeDef ntDef : ntDefs) {
             notifyRegistered(ntDef.getName());
         }
     }
@@ -258,7 +257,7 @@
      * @throws RepositoryException if another error occurs
      * @see #unregisterNodeType(Name)
      */
-    public void unregisterNodeTypes(Collection ntNames)
+    public void unregisterNodeTypes(Collection<Name> ntNames)
             throws NoSuchNodeTypeException, RepositoryException {
 
         unregisterNodeTypes(ntNames, false);
@@ -274,12 +273,11 @@
      *                                 denote a registered node type.
      * @throws RepositoryException if another error occurs
      */
-    private synchronized void unregisterNodeTypes(Collection ntNames, boolean external)
+    private synchronized void unregisterNodeTypes(Collection<Name> ntNames, boolean external)
             throws NoSuchNodeTypeException, RepositoryException {
 
         // do some preliminary checks
-        for (Iterator iter = ntNames.iterator(); iter.hasNext();) {
-            Name ntName = (Name) iter.next();
+        for (Name ntName: ntNames) {
             if (!registeredNTDefs.containsKey(ntName)) {
                 throw new NoSuchNodeTypeException(ntName.toString());
             }
@@ -289,13 +287,13 @@
             }
             // check for node types other than those to be unregistered
             // that depend on the given node types
-            Set dependents = getDependentNodeTypes(ntName);
+            Set<Name> dependents = getDependentNodeTypes(ntName);
             dependents.removeAll(ntNames);
             if (dependents.size() > 0) {
                 StringBuffer msg = new StringBuffer();
                 msg.append(ntName).append(" can not be removed because the following node types depend on it: ");
-                for (Iterator depIter = dependents.iterator(); depIter.hasNext();) {
-                    msg.append(depIter.next());
+                for (Name dependent : dependents) {
+                    msg.append(dependent);
                     msg.append(" ");
                 }
                 throw new RepositoryException(msg.toString());
@@ -303,8 +301,7 @@
         }
 
         // make sure node types are not currently in use
-        for (Iterator iter = ntNames.iterator(); iter.hasNext();) {
-            Name ntName = (Name) iter.next();
+        for (Name ntName : ntNames) {
             checkForReferencesInContent(ntName);
         }
 
@@ -317,8 +314,7 @@
         }
 
         // persist removal of node type definitions & notify listeners
-        for (Iterator iter = ntNames.iterator(); iter.hasNext();) {
-            Name ntName = (Name) iter.next();
+        for (Name ntName : ntNames) {
             customNTDefs.remove(ntName);
             notifyUnregistered(ntName);
         }
@@ -344,7 +340,7 @@
      */
     public void unregisterNodeType(Name ntName)
             throws NoSuchNodeTypeException, RepositoryException {
-        HashSet ntNames = new HashSet();
+        HashSet<Name> ntNames = new HashSet<Name>();
         ntNames.add(ntName);
         unregisterNodeTypes(ntNames);
     }
@@ -400,7 +396,7 @@
         /**
          * build diff of current and new definition and determine type of change
          */
-        NodeTypeDef ntdOld = (NodeTypeDef) registeredNTDefs.get(name);
+        NodeTypeDef ntdOld = registeredNTDefs.get(name);
         NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntdOld, ntd);
         if (!diff.isModified()) {
             // the definition has not been modified, there's nothing to do here...
@@ -464,9 +460,9 @@
     }
 
     /**
-     * @param ntName
-     * @return
-     * @throws NoSuchNodeTypeException
+     * @param ntName name
+     * @return effective node type
+     * @throws NoSuchNodeTypeException if node type does not exist
      */
     public EffectiveNodeType getEffectiveNodeType(Name ntName)
             throws NoSuchNodeTypeException {
@@ -483,7 +479,7 @@
      * @throws NodeTypeConflictException if the given types are conflicting
      * @throws NoSuchNodeTypeException if one of the given types is not found
      */
-    public EffectiveNodeType getEffectiveNodeType(Name primary, Set mixins)
+    public EffectiveNodeType getEffectiveNodeType(Name primary, Set<Name> mixins)
             throws NodeTypeConflictException, NoSuchNodeTypeException {
         if (mixins.isEmpty()) {
             return getEffectiveNodeType(primary);
@@ -501,9 +497,9 @@
      *
      * @param nodeTypeName node type name
      * @return a set of node type <code>Name</code>s
-     * @throws NoSuchNodeTypeException
+     * @throws NoSuchNodeTypeException if node type does not exist
      */
-    public Set getDependentNodeTypes(Name nodeTypeName)
+    public Set<Name> getDependentNodeTypes(Name nodeTypeName)
             throws NoSuchNodeTypeException {
         if (!registeredNTDefs.containsKey(nodeTypeName)) {
             throw new NoSuchNodeTypeException(nodeTypeName.toString());
@@ -513,10 +509,8 @@
          * collect names of those node types that have dependencies on the given
          * node type
          */
-        HashSet names = new HashSet();
-        Iterator iter = registeredNTDefs.values().iterator();
-        while (iter.hasNext()) {
-            NodeTypeDef ntd = (NodeTypeDef) iter.next();
+        HashSet<Name> names = new HashSet<Name>();
+        for (NodeTypeDef ntd : registeredNTDefs.values()) {
             if (ntd.getDependencies().contains(nodeTypeName)) {
                 names.add(ntd.getName());
             }
@@ -534,7 +528,7 @@
      */
     public NodeTypeDef getNodeTypeDef(Name nodeTypeName)
             throws NoSuchNodeTypeException {
-        NodeTypeDef def = (NodeTypeDef) registeredNTDefs.get(nodeTypeName);
+        NodeTypeDef def = registeredNTDefs.get(nodeTypeName);
         if (def == null) {
             throw new NoSuchNodeTypeException(nodeTypeName.toString());
         }
@@ -543,7 +537,7 @@
     }
 
     /**
-     * @param nodeTypeName
+     * @param nodeTypeName node type name
      * @return <code>true</code> if the specified node type is registered;
      *         <code>false</code> otherwise.
      */
@@ -552,7 +546,7 @@
     }
 
     /**
-     * @param nodeTypeName
+     * @param nodeTypeName node type name
      * @return <code>true</code> if the specified node type is built-in;
      *         <code>false</code> otherwise.
      */
@@ -561,19 +555,19 @@
     }
 
     /**
-     * @param id
+     * @param id node def id
      * @return the node definition for the given id.
      */
     public NodeDef getNodeDef(NodeDefId id) {
-        return (NodeDef) nodeDefs.get(id);
+        return nodeDefs.get(id);
     }
 
     /**
-     * @param id
+     * @param id property def id
      * @return the property definition for the given id.
      */
     public PropDef getPropDef(PropDefId id) {
-        return (PropDef) propDefs.get(id);
+        return propDefs.get(id);
     }
 
     /**
@@ -606,77 +600,75 @@
         ps.println();
         ps.println("Registered NodeTypes:");
         ps.println();
-        Iterator iter = registeredNTDefs.values().iterator();
-        while (iter.hasNext()) {
-            NodeTypeDef ntd = (NodeTypeDef) iter.next();
+        for (NodeTypeDef ntd : registeredNTDefs.values()) {
             ps.println(ntd.getName());
             Name[] supertypes = ntd.getSupertypes();
             ps.println("\tSupertypes");
-            for (int i = 0; i < supertypes.length; i++) {
-                ps.println("\t\t" + supertypes[i]);
+            for (Name supertype : supertypes) {
+                ps.println("\t\t" + supertype);
             }
             ps.println("\tMixin\t" + ntd.isMixin());
             ps.println("\tOrderableChildNodes\t" + ntd.hasOrderableChildNodes());
             ps.println("\tPrimaryItemName\t" + (ntd.getPrimaryItemName() == null ? "<null>" : ntd.getPrimaryItemName().toString()));
             PropDef[] pd = ntd.getPropertyDefs();
-            for (int i = 0; i < pd.length; i++) {
+            for (PropDef aPd : pd) {
                 ps.print("\tPropertyDefinition");
-                ps.println(" (declared in " + pd[i].getDeclaringNodeType() + ") id=" + pd[i].getId());
-                ps.println("\t\tName\t\t" + (pd[i].definesResidual() ? "*" : pd[i].getName().toString()));
-                String type = pd[i].getRequiredType() == 0 ? "null" : PropertyType.nameFromValue(pd[i].getRequiredType());
+                ps.println(" (declared in " + aPd.getDeclaringNodeType() + ") id=" + aPd.getId());
+                ps.println("\t\tName\t\t" + (aPd.definesResidual() ? "*" : aPd.getName().toString()));
+                String type = aPd.getRequiredType() == 0 ? "null" : PropertyType.nameFromValue(aPd.getRequiredType());
                 ps.println("\t\tRequiredType\t" + type);
-                QValueConstraint[] vca = pd[i].getValueConstraints();
+                QValueConstraint[] vca = aPd.getValueConstraints();
                 StringBuffer constraints = new StringBuffer();
                 if (vca == null) {
                     constraints.append("<null>");
                 } else {
-                    for (int n = 0; n < vca.length; n++) {
+                    for (QValueConstraint aVca : vca) {
                         if (constraints.length() > 0) {
                             constraints.append(", ");
                         }
-                        constraints.append(vca[n].getString());
+                        constraints.append(aVca.getString());
                     }
                 }
                 ps.println("\t\tValueConstraints\t" + constraints.toString());
-                InternalValue[] defVals = pd[i].getDefaultValues();
+                InternalValue[] defVals = aPd.getDefaultValues();
                 StringBuffer defaultValues = new StringBuffer();
                 if (defVals == null) {
                     defaultValues.append("<null>");
                 } else {
-                    for (int n = 0; n < defVals.length; n++) {
+                    for (InternalValue defVal : defVals) {
                         if (defaultValues.length() > 0) {
                             defaultValues.append(", ");
                         }
-                        defaultValues.append(defVals[n].toString());
+                        defaultValues.append(defVal.toString());
                     }
                 }
                 ps.println("\t\tDefaultValue\t" + defaultValues.toString());
-                ps.println("\t\tAutoCreated\t" + pd[i].isAutoCreated());
-                ps.println("\t\tMandatory\t" + pd[i].isMandatory());
-                ps.println("\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(pd[i].getOnParentVersion()));
-                ps.println("\t\tProtected\t" + pd[i].isProtected());
-                ps.println("\t\tMultiple\t" + pd[i].isMultiple());
+                ps.println("\t\tAutoCreated\t" + aPd.isAutoCreated());
+                ps.println("\t\tMandatory\t" + aPd.isMandatory());
+                ps.println("\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aPd.getOnParentVersion()));
+                ps.println("\t\tProtected\t" + aPd.isProtected());
+                ps.println("\t\tMultiple\t" + aPd.isMultiple());
             }
             NodeDef[] nd = ntd.getChildNodeDefs();
-            for (int i = 0; i < nd.length; i++) {
+            for (NodeDef aNd : nd) {
                 ps.print("\tNodeDefinition");
-                ps.println(" (declared in " + nd[i].getDeclaringNodeType() + ") id=" + nd[i].getId());
-                ps.println("\t\tName\t\t" + (nd[i].definesResidual() ? "*" : nd[i].getName().toString()));
-                Name[] reqPrimaryTypes = nd[i].getRequiredPrimaryTypes();
+                ps.println(" (declared in " + aNd.getDeclaringNodeType() + ") id=" + aNd.getId());
+                ps.println("\t\tName\t\t" + (aNd.definesResidual() ? "*" : aNd.getName().toString()));
+                Name[] reqPrimaryTypes = aNd.getRequiredPrimaryTypes();
                 if (reqPrimaryTypes != null && reqPrimaryTypes.length > 0) {
-                    for (int n = 0; n < reqPrimaryTypes.length; n++) {
-                        ps.print("\t\tRequiredPrimaryType\t" + reqPrimaryTypes[n]);
+                    for (Name reqPrimaryType : reqPrimaryTypes) {
+                        ps.print("\t\tRequiredPrimaryType\t" + reqPrimaryType);
                     }
                 }
-                Name defPrimaryType = nd[i].getDefaultPrimaryType();
+                Name defPrimaryType = aNd.getDefaultPrimaryType();
                 if (defPrimaryType != null) {
                     ps.print("\n\t\tDefaultPrimaryType\t" + defPrimaryType);
                 }
-                ps.println("\n\t\tAutoCreated\t" + nd[i].isAutoCreated());
-                ps.println("\t\tMandatory\t" + nd[i].isMandatory());
-                ps.println("\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(nd[i].getOnParentVersion()));
-                ps.println("\t\tProtected\t" + nd[i].isProtected());
-                ps.println("\t\tAllowsSameNameSiblings\t" + nd[i].allowsSameNameSiblings());
+                ps.println("\n\t\tAutoCreated\t" + aNd.isAutoCreated());
+                ps.println("\t\tMandatory\t" + aNd.isMandatory());
+                ps.println("\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aNd.getOnParentVersion()));
+                ps.println("\t\tProtected\t" + aNd.isProtected());
+                ps.println("\t\tAllowsSameNameSiblings\t" + aNd.allowsSameNameSiblings());
             }
         }
         ps.println();
@@ -718,10 +710,11 @@
     /**
      * Protected constructor
      *
-     * @param nsReg
-     * @param ntStore
-     * @throws RepositoryException
+     * @param nsReg name space registry
+     * @param ntStore store
+     * @throws RepositoryException if an error occurs
      */
+    @SuppressWarnings("unchecked")
     protected NodeTypeRegistry(NamespaceRegistry nsReg, FileSystem ntStore)
             throws RepositoryException {
         this.nsReg = nsReg;
@@ -998,20 +991,16 @@
     }
 
     /**
-     * @param ntName
-     * @param entCache
-     * @param ntdCache
-     * @return
-     * @throws NoSuchNodeTypeException
+     * @param ntName node type name
      * @param entCache cache of already-built effective node types
      * @param ntdCache cache of node type definitions
-     * @return
+     * @return the effective node type
      * @throws NoSuchNodeTypeException if a node type reference (e.g. a supertype)
      *                                 could not be resolved.
      */
     static EffectiveNodeType getEffectiveNodeType(Name ntName,
                                                   EffectiveNodeTypeCache entCache,
-                                                  Map ntdCache)
+                                                  Map<Name, NodeTypeDef> ntdCache)
             throws NoSuchNodeTypeException {
         // 1. check if effective node type has already been built
         EffectiveNodeTypeCache.Key key = entCache.getKey(new Name[]{ntName});
@@ -1021,7 +1010,7 @@
         }
 
         // 2. make sure we've got the definition of the specified node type
-        NodeTypeDef ntd = (NodeTypeDef) ntdCache.get(ntName);
+        NodeTypeDef ntd = ntdCache.get(ntName);
         if (ntd == null) {
             throw new NoSuchNodeTypeException(ntName.toString());
         }
@@ -1057,7 +1046,7 @@
      */
     static EffectiveNodeType getEffectiveNodeType(Name[] ntNames,
                                                   EffectiveNodeTypeCache entCache,
-                                                  Map ntdCache)
+                                                  Map<Name, NodeTypeDef> ntdCache)
             throws NodeTypeConflictException, NoSuchNodeTypeException {
 
         EffectiveNodeTypeCache.Key key = entCache.getKey(ntNames);
@@ -1068,9 +1057,9 @@
         }
 
         // 2. make sure we've got the definitions of the specified node types
-        for (int i = 0; i < ntNames.length; i++) {
-            if (!ntdCache.containsKey(ntNames[i])) {
-                throw new NoSuchNodeTypeException(ntNames[i].toString());
+        for (Name ntName : ntNames) {
+            if (!ntdCache.containsKey(ntName)) {
+                throw new NoSuchNodeTypeException(ntName.toString());
             }
         }
 
@@ -1099,8 +1088,8 @@
                      * build aggregate of remaining node types through iteration
                      */
                     Name[] remainder = key.getNames();
-                    for (int i = 0; i < remainder.length; i++) {
-                        NodeTypeDef ntd = (NodeTypeDef) ntdCache.get(remainder[i]);
+                    for (Name aRemainder : remainder) {
+                        NodeTypeDef ntd = ntdCache.get(aRemainder);
                         EffectiveNodeType ent =
                                 EffectiveNodeType.create(ntd, entCache, ntdCache);
                         // store new effective node type
@@ -1127,11 +1116,10 @@
     }
 
     static void checkForCircularInheritance(Name[] supertypes,
-                                            Stack inheritanceChain,
-                                            Map ntDefCache)
+                                            Stack<Name> inheritanceChain,
+                                            Map<Name, NodeTypeDef> ntDefCache)
             throws InvalidNodeTypeDefException, RepositoryException {
-        for (int i = 0; i < supertypes.length; i++) {
-            Name nt = supertypes[i];
+        for (Name nt : supertypes) {
             int pos = inheritanceChain.lastIndexOf(nt);
             if (pos >= 0) {
                 StringBuffer buf = new StringBuffer();
@@ -1148,8 +1136,7 @@
             }
 
             try {
-
-                NodeTypeDef ntd = (NodeTypeDef) ntDefCache.get(nt);
+                NodeTypeDef ntd = ntDefCache.get(nt);
                 Name[] sta = ntd.getSupertypes();
                 if (sta.length > 0) {
                     // check recursively
@@ -1166,15 +1153,14 @@
     }
 
     static void checkForCircularNodeAutoCreation(EffectiveNodeType childNodeENT,
-                                                 Stack definingParentNTs,
+                                                 Stack<Name> definingParentNTs,
                                                  EffectiveNodeTypeCache anEntCache,
-                                                 Map ntDefCache)
+                                                 Map<Name, NodeTypeDef> ntDefCache)
             throws InvalidNodeTypeDefException {
         // check for circularity through default node types of auto-created child nodes
         // (node type 'a' defines auto-created child node with default node type 'a')
         Name[] childNodeNTs = childNodeENT.getAllNodeTypes();
-        for (int i = 0; i < childNodeNTs.length; i++) {
-            Name nt = childNodeNTs[i];
+        for (Name nt : childNodeNTs) {
             int pos = definingParentNTs.lastIndexOf(nt);
             if (pos >= 0) {
                 StringBuffer buf = new StringBuffer();
@@ -1195,9 +1181,9 @@
         }
 
         NodeDef[] nodeDefs = childNodeENT.getAutoCreateNodeDefs();
-        for (int i = 0; i < nodeDefs.length; i++) {
-            Name dnt = nodeDefs[i].getDefaultPrimaryType();
-            Name definingNT = nodeDefs[i].getDeclaringNodeType();
+        for (NodeDef nodeDef : nodeDefs) {
+            Name dnt = nodeDef.getDefaultPrimaryType();
+            Name definingNT = nodeDef.getDeclaringNodeType();
             try {
                 if (dnt != null) {
                     // check recursively
@@ -1208,7 +1194,7 @@
                 }
             } catch (NoSuchNodeTypeException nsnte) {
                 String msg = definingNT
-                        + " defines invalid default node type for child node " + nodeDefs[i].getName();
+                        + " defines invalid default node type for child node " + nodeDef.getName();
                 log.debug(msg);
                 throw new InvalidNodeTypeDefException(msg, nsnte);
             }
@@ -1236,12 +1222,12 @@
 
         // store property & child node definitions of new node type by id
         PropDef[] pda = ntd.getPropertyDefs();
-        for (int i = 0; i < pda.length; i++) {
-            propDefs.put(pda[i].getId(), pda[i]);
+        for (PropDef aPda : pda) {
+            propDefs.put(aPda.getId(), aPda);
         }
         NodeDef[] nda = ntd.getChildNodeDefs();
-        for (int i = 0; i < nda.length; i++) {
-            nodeDefs.put(nda[i].getId(), nda[i]);
+        for (NodeDef aNda : nda) {
+            nodeDefs.put(aNda.getId(), aNda);
         }
 
         return ent;
@@ -1256,11 +1242,11 @@
      * eventually registered.
      *
      * @param ntDefs collection of <code>NodeTypeDef</code> objects
-     * @throws InvalidNodeTypeDefException
-     * @throws RepositoryException
+     * @throws InvalidNodeTypeDefException if the node type is not valid
+     * @throws RepositoryException if an error occurs
      * @see #registerNodeType
      */
-    private void internalRegister(Collection ntDefs)
+    private void internalRegister(Collection<NodeTypeDef> ntDefs)
             throws InvalidNodeTypeDefException, RepositoryException {
         internalRegister(ntDefs, false);
     }
@@ -1275,19 +1261,18 @@
      * that can be exposed in a property definition because it is
      * system-generated (such as jcr:primaryType in nt:base).
      */
-    private void internalRegister(Collection ntDefs, boolean lenient)
+    private void internalRegister(Collection<NodeTypeDef> ntDefs, boolean lenient)
             throws InvalidNodeTypeDefException, RepositoryException {
 
         // create working copies of current ent & ntd caches:
         // cache of pre-built aggregations of node types
         EffectiveNodeTypeCache tmpENTCache = (EffectiveNodeTypeCache) entCache.clone();
         // map of node type names and node type definitions
-        Map tmpNTDefCache = new HashMap(registeredNTDefs);
+        Map<Name, NodeTypeDef> tmpNTDefCache = new HashMap<Name, NodeTypeDef>(registeredNTDefs);
 
         // temporarily register the node type definition
         // and do some preliminary checks
-        for (Iterator iter = ntDefs.iterator(); iter.hasNext();) {
-            NodeTypeDef ntd = (NodeTypeDef) iter.next();
+        for (NodeTypeDef ntd : ntDefs) {
             Name name = ntd.getName();
             if (name != null && registeredNTDefs.containsKey(name)) {
                 String msg = name + " already exists";
@@ -1298,12 +1283,9 @@
             tmpNTDefCache.put(ntd.getName(), ntd);
         }
 
-        for (Iterator iter = ntDefs.iterator(); iter.hasNext();) {
-            NodeTypeDef ntd = (NodeTypeDef) iter.next();
-
-            EffectiveNodeType ent =
-                    validateNodeTypeDef(ntd, tmpENTCache, tmpNTDefCache, nsReg,
-                            lenient);
+        for (NodeTypeDef ntd : ntDefs) {
+            EffectiveNodeType ent = validateNodeTypeDef(ntd, tmpENTCache,
+                    tmpNTDefCache, nsReg, lenient);
 
             // store new effective node type instance
             tmpENTCache.put(ent);
@@ -1311,20 +1293,18 @@
 
         // since no exception was thrown so far the definitions are assumed to
         // be valid
-        for (Iterator iter = ntDefs.iterator(); iter.hasNext();) {
-            NodeTypeDef ntd = (NodeTypeDef) iter.next();
-
+        for (NodeTypeDef ntd : ntDefs) {
             // register clone of node type definition
             ntd = (NodeTypeDef) ntd.clone();
             registeredNTDefs.put(ntd.getName(), ntd);
             // store property & child node definitions of new node type by id
             PropDef[] pda = ntd.getPropertyDefs();
-            for (int i = 0; i < pda.length; i++) {
-                propDefs.put(pda[i].getId(), pda[i]);
+            for (PropDef aPda : pda) {
+                propDefs.put(aPda.getId(), aPda);
             }
             NodeDef[] nda = ntd.getChildNodeDefs();
-            for (int i = 0; i < nda.length; i++) {
-                nodeDefs.put(nda[i].getId(), nda[i]);
+            for (NodeDef aNda : nda) {
+                nodeDefs.put(aNda.getId(), aNda);
             }
         }
 
@@ -1333,7 +1313,7 @@
     }
 
     private void internalUnregister(Name name) throws NoSuchNodeTypeException {
-        NodeTypeDef ntd = (NodeTypeDef) registeredNTDefs.get(name);
+        NodeTypeDef ntd = registeredNTDefs.get(name);
         if (ntd == null) {
             throw new NoSuchNodeTypeException(name.toString());
         }
@@ -1342,19 +1322,18 @@
 
         // remove property & child node definitions
         PropDef[] pda = ntd.getPropertyDefs();
-        for (int i = 0; i < pda.length; i++) {
-            propDefs.remove(pda[i].getId());
+        for (PropDef aPda : pda) {
+            propDefs.remove(aPda.getId());
         }
         NodeDef[] nda = ntd.getChildNodeDefs();
-        for (int i = 0; i < nda.length; i++) {
-            nodeDefs.remove(nda[i].getId());
+        for (NodeDef aNda : nda) {
+            nodeDefs.remove(aNda.getId());
         }
     }
 
-    private void internalUnregister(Collection ntNames)
+    private void internalUnregister(Collection<Name> ntNames)
             throws NoSuchNodeTypeException {
-        for (Iterator iter = ntNames.iterator(); iter.hasNext();) {
-            Name name = (Name) iter.next();
+        for (Name name : ntNames) {
             internalUnregister(name);
         }
     }
@@ -1380,18 +1359,18 @@
      * Validates the specified <code>NodeTypeDef</code> within the context of
      * the two other given collections and returns an <code>EffectiveNodeType</code>.
      *
-     * @param ntd
-     * @param entCache
+     * @param ntd node type definition
+     * @param entCache effective node type cache
      * @param ntdCache cache of 'known' node type definitions, used to resolve dependencies
      * @param nsReg    namespace registry used for validatingatch names
      * @param lenient flag governing whether validation can be lenient or has to be strict
      * @return an effective node type representation of the specified <code>NodeTypeDef</code>
-     * @throws InvalidNodeTypeDefException
+     * @throws InvalidNodeTypeDefException if the node type is not valid
      * @throws RepositoryException         if another error occurs
      */
     private static EffectiveNodeType validateNodeTypeDef(NodeTypeDef ntd,
                                                          EffectiveNodeTypeCache entCache,
-                                                         Map ntdCache,
+                                                         Map<Name, NodeTypeDef> ntdCache,
                                                          NamespaceRegistry nsReg,
                                                          boolean lenient)
             throws InvalidNodeTypeDefException, RepositoryException {
@@ -1417,21 +1396,21 @@
         // validate supertypes
         Name[] supertypes = ntd.getSupertypes();
         if (supertypes.length > 0) {
-            for (int i = 0; i < supertypes.length; i++) {
-                checkNamespace(supertypes[i], nsReg);
+            for (Name supertype : supertypes) {
+                checkNamespace(supertype, nsReg);
                 /**
                  * simple check for infinite recursion
                  * (won't trap recursion on a deeper inheritance level)
                  */
-                if (name.equals(supertypes[i])) {
+                if (name.equals(supertype)) {
                     String msg = "[" + name + "] invalid supertype: "
-                            + supertypes[i] + " (infinite recursion))";
+                            + supertype + " (infinite recursion))";
                     log.debug(msg);
                     throw new InvalidNodeTypeDefException(msg);
                 }
-                if (!ntdCache.containsKey(supertypes[i])) {
+                if (!ntdCache.containsKey(supertype)) {
                     String msg = "[" + name + "] invalid supertype: "
-                            + supertypes[i];
+                            + supertype;
                     log.debug(msg);
                     throw new InvalidNodeTypeDefException(msg);
                 }
@@ -1441,7 +1420,7 @@
              * check for circularity in inheritance chain
              * ('a' extends 'b' extends 'a')
              */
-            Stack inheritanceChain = new Stack();
+            Stack<Name> inheritanceChain = new Stack<Name>();
             inheritanceChain.push(name);
             checkForCircularInheritance(supertypes, inheritanceChain, ntdCache);
         }
@@ -1494,8 +1473,7 @@
 
         // validate property definitions
         PropDef[] pda = ntd.getPropertyDefs();
-        for (int i = 0; i < pda.length; i++) {
-            PropDef pd = pda[i];
+        for (PropDef pd : pda) {
             /**
              * sanity check:
              * make sure declaring node type matches name of node type definition
@@ -1529,11 +1507,11 @@
             InternalValue[] defVals = pd.getDefaultValues();
             if (defVals != null && defVals.length != 0) {
                 int reqType = pd.getRequiredType();
-                for (int j = 0; j < defVals.length; j++) {
+                for (InternalValue defVal : defVals) {
                     if (reqType == PropertyType.UNDEFINED) {
-                        reqType = defVals[j].getType();
+                        reqType = defVal.getType();
                     } else {
-                        if (defVals[j].getType() != reqType) {
+                        if (defVal.getType() != reqType) {
                             String msg = "[" + name + "#" + pd.getName()
                                     + "] type of default value(s) is not consistent with required property type";
                             log.debug(msg);
@@ -1559,19 +1537,18 @@
             if (constraints != null && constraints.length > 0) {
                 if (defVals != null && defVals.length > 0) {
                     // check value constraints on every value
-                    for (int j = 0; j < defVals.length; j++) {
+                    for (InternalValue defVal : defVals) {
                         // constraints are OR-ed together
                         boolean satisfied = false;
                         ConstraintViolationException cve = null;
-                        for (int k = 0; k < constraints.length; k++) {
+                        for (QValueConstraint constraint : constraints) {
                             try {
-                                constraints[k].check(defVals[j]);
+                                constraint.check(defVal);
                                 // at least one constraint is satisfied
                                 satisfied = true;
                                 break;
                             } catch (ConstraintViolationException e) {
                                 cve = e;
-                                continue;
                             }
                         }
                         if (!satisfied) {
@@ -1609,8 +1586,7 @@
 
         // validate child-node definitions
         NodeDef[] cnda = ntd.getChildNodeDefs();
-        for (int i = 0; i < cnda.length; i++) {
-            NodeDef cnd = cnda[i];
+        for (NodeDef cnd : cnda) {
             /**
              * sanity check:
              * make sure declaring node type matches name of node type definition
@@ -1679,7 +1655,7 @@
                          * of auto-created child nodes (node type 'a' defines
                          * auto-created child node with default primary type 'a')
                          */
-                        Stack definingNTs = new Stack();
+                        Stack<Name> definingNTs = new Stack<Name>();
                         definingNTs.push(name);
                         checkForCircularNodeAutoCreation(defaultENT, definingNTs, entCache, ntdCache);
                     }
@@ -1699,8 +1675,7 @@
             // check required primary types
             Name[] reqTypes = cnd.getRequiredPrimaryTypes();
             if (reqTypes != null && reqTypes.length > 0) {
-                for (int n = 0; n < reqTypes.length; n++) {
-                    Name rpt = reqTypes[n];
+                for (Name rpt : reqTypes) {
                     checkNamespace(rpt, nsReg);
                     referenceToSelf = false;
                     /**
@@ -1802,45 +1777,45 @@
 
     /**
      * Notify the listeners that a node type <code>ntName</code> has been registered.
+     * @param ntName node type name
      */
     private void notifyRegistered(Name ntName) {
         // copy listeners to array to avoid ConcurrentModificationException
-        NodeTypeRegistryListener[] la =
-                (NodeTypeRegistryListener[]) listeners.values().toArray(
+        NodeTypeRegistryListener[] la = listeners.values().toArray(
                         new NodeTypeRegistryListener[listeners.size()]);
-        for (int i = 0; i < la.length; i++) {
-            if (la[i] != null) {
-                la[i].nodeTypeRegistered(ntName);
+        for (NodeTypeRegistryListener aLa : la) {
+            if (aLa != null) {
+                aLa.nodeTypeRegistered(ntName);
             }
         }
     }
 
     /**
      * Notify the listeners that a node type <code>ntName</code> has been re-registered.
+     * @param ntName node type name
      */
     private void notifyReRegistered(Name ntName) {
         // copy listeners to array to avoid ConcurrentModificationException
-        NodeTypeRegistryListener[] la =
-                (NodeTypeRegistryListener[]) listeners.values().toArray(
+        NodeTypeRegistryListener[] la = listeners.values().toArray(
                         new NodeTypeRegistryListener[listeners.size()]);
-        for (int i = 0; i < la.length; i++) {
-            if (la[i] != null) {
-                la[i].nodeTypeReRegistered(ntName);
+        for (NodeTypeRegistryListener aLa : la) {
+            if (aLa != null) {
+                aLa.nodeTypeReRegistered(ntName);
             }
         }
     }
 
     /**
      * Notify the listeners that a node type <code>ntName</code> has been unregistered.
+     * @param ntName node type name
      */
     private void notifyUnregistered(Name ntName) {
         // copy listeners to array to avoid ConcurrentModificationException
-        NodeTypeRegistryListener[] la =
-                (NodeTypeRegistryListener[]) listeners.values().toArray(
+        NodeTypeRegistryListener[] la = listeners.values().toArray(
                         new NodeTypeRegistryListener[listeners.size()]);
-        for (int i = 0; i < la.length; i++) {
-            if (la[i] != null) {
-                la[i].nodeTypeUnregistered(ntName);
+        for (NodeTypeRegistryListener aLa : la) {
+            if (aLa != null) {
+                aLa.nodeTypeUnregistered(ntName);
             }
         }
     }



Mime
View raw message