You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2009/09/18 15:49:18 UTC

svn commit: r816632 - in /jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype: EffectiveNodeTypeProvider.java NodeTypeRegistryImpl.java

Author: reschke
Date: Fri Sep 18 13:49:17 2009
New Revision: 816632

URL: http://svn.apache.org/viewvc?rev=816632&view=rev
Log:
JCR-2087: parametrize generic types

Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java?rev=816632&r1=816631&r2=816632&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java Fri Sep 18 13:49:17 2009
@@ -58,7 +58,7 @@
      * @throws ConstraintViolationException
      * @throws NoSuchNodeTypeException
      */
-    public EffectiveNodeType getEffectiveNodeType(Name[] ntNames, Map ntdMap)
+    public EffectiveNodeType getEffectiveNodeType(Name[] ntNames, Map<Name, QNodeTypeDefinition> ntdMap)
             throws ConstraintViolationException, NoSuchNodeTypeException;
 
     /**
@@ -74,6 +74,6 @@
      * @throws NoSuchNodeTypeException
      */
     public EffectiveNodeType getEffectiveNodeType(QNodeTypeDefinition ntd,
-                                                  Map ntdMap)
+                                                  Map<Name, QNodeTypeDefinition> ntdMap)
             throws ConstraintViolationException, NoSuchNodeTypeException;
 }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java?rev=816632&r1=816631&r2=816632&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java Fri Sep 18 13:49:17 2009
@@ -65,9 +65,9 @@
     private final NodeTypeDefinitionMap registeredNTDefs;
 
     // set of property definitions
-    private final Set propDefs;
+    private final Set<QPropertyDefinition> propDefs;
     // set of node definitions
-    private final Set nodeDefs;
+    private final Set<QNodeDefinition> nodeDefs;
 
     /**
      * Object used to persist new nodetypes and modified nodetype definitions.
@@ -121,8 +121,8 @@
         //registeredNTDefs = new ConcurrentReaderHashMap();
         registeredNTDefs = new NodeTypeDefinitionMap();
 
-        propDefs = new HashSet();
-        nodeDefs = new HashSet();
+        propDefs = new HashSet<QPropertyDefinition>();
+        nodeDefs = new HashSet<QNodeDefinition>();
     }
 
     //---------------------------------------------------< NodeTypeRegistry >---
@@ -146,8 +146,8 @@
      * @see NodeTypeRegistry#getRegisteredNodeTypes()
      */
     public Name[] getRegisteredNodeTypes() throws RepositoryException {
-        Set qNames = registeredNTDefs.keySet();
-        return (Name[]) qNames.toArray(new Name[registeredNTDefs.size()]);
+        Set<Name> qNames = registeredNTDefs.keySet();
+        return qNames.toArray(new Name[registeredNTDefs.size()]);
     }
 
 
@@ -174,7 +174,7 @@
         }
 
         // validate new nodetype definitions
-        Map defMap = validator.validateNodeTypeDefs(ntDefs, registeredNTDefs);
+        Map<QNodeTypeDefinition, EffectiveNodeType> defMap = validator.validateNodeTypeDefs(ntDefs, registeredNTDefs);
         storage.registerNodeTypes(ntDefs.toArray(new QNodeTypeDefinition[ntDefs.size()]), allowUpdate);
 
         // update internal cache:
@@ -201,12 +201,12 @@
         for (Name ntName : nodeTypeNames) {
             // Best effort check for node types other than those to be
             // unregistered that depend on the given node types
-            Set dependents = registeredNTDefs.getDependentNodeTypes(ntName);
+            Set<Name> dependents = registeredNTDefs.getDependentNodeTypes(ntName);
             dependents.removeAll(nodeTypeNames);
             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();) {
+                for (Iterator<Name> depIter = dependents.iterator(); depIter.hasNext();) {
                     msg.append(depIter.next());
                     msg.append(" ");
                 }
@@ -223,8 +223,8 @@
         internalUnregister(nodeTypeNames);
 
         // notify listeners
-        for (Iterator iter = nodeTypeNames.iterator(); iter.hasNext();) {
-            Name ntName = (Name) iter.next();
+        for (Iterator<Name> iter = nodeTypeNames.iterator(); iter.hasNext();) {
+            Name ntName = iter.next();
             notifyUnregistered(ntName);
         }
     }
@@ -258,24 +258,24 @@
     }
 
     /**
-     * @see EffectiveNodeTypeProvider#getEffectiveNodeType(Name[], Map)
+     * @see EffectiveNodeTypeProvider#getEffectiveNodeType(Name[], Map<Name, QNodeTypeDefinition>)
      */
-    public EffectiveNodeType getEffectiveNodeType(Name[] ntNames, Map ntdMap)
+    public EffectiveNodeType getEffectiveNodeType(Name[] ntNames, Map<Name, QNodeTypeDefinition> ntdMap)
         throws ConstraintViolationException, NoSuchNodeTypeException {
         return getEffectiveNodeType(ntNames, entCache, ntdMap);
     }
 
     /**
-     * @see EffectiveNodeTypeProvider#getEffectiveNodeType(QNodeTypeDefinition, Map)
+     * @see EffectiveNodeTypeProvider#getEffectiveNodeType(QNodeTypeDefinition, Map<Name, QNodeTypeDefinition>)
      */
-    public EffectiveNodeType getEffectiveNodeType(QNodeTypeDefinition ntd, Map ntdMap)
+    public EffectiveNodeType getEffectiveNodeType(QNodeTypeDefinition ntd, Map<Name, QNodeTypeDefinition> ntdMap)
             throws ConstraintViolationException, NoSuchNodeTypeException {
-        TreeSet mergedNodeTypes = new TreeSet();
-        TreeSet inheritedNodeTypes = new TreeSet();
-        TreeSet allNodeTypes = new TreeSet();
-        Map namedItemDefs = new HashMap();
-        List unnamedItemDefs = new ArrayList();
-        Set supportedMixins = null;
+        TreeSet<Name> mergedNodeTypes = new TreeSet<Name>();
+        TreeSet<Name> inheritedNodeTypes = new TreeSet<Name>();
+        TreeSet<Name> allNodeTypes = new TreeSet<Name>();
+        Map<Name, List<QItemDefinition>> namedItemDefs = new HashMap<Name, List<QItemDefinition>>();
+        List<QItemDefinition> unnamedItemDefs = new ArrayList<QItemDefinition>();
+        Set<Name> supportedMixins = null;
 
         Name ntName = ntd.getName();
         // prepare new instance
@@ -285,7 +285,7 @@
         Name[] smixins = ntd.getSupportedMixinTypes();
 
         if (smixins != null) {
-            supportedMixins = new HashSet();
+            supportedMixins = new HashSet<Name>();
             for (int i = 0; i < smixins.length; i++) {
                 supportedMixins.add(smixins[i]);
             }
@@ -294,7 +294,7 @@
         // 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
-        Set itemDefIds = new HashSet();
+        Set<QItemDefinition> itemDefIds = new HashSet<QItemDefinition>();
 
         QNodeDefinition[] cnda = ntd.getChildNodeDefs();
         for (int i = 0; i < cnda.length; i++) {
@@ -320,9 +320,9 @@
             } else {
                 // named node definition
                 Name name = cnda[i].getName();
-                List defs = (List) namedItemDefs.get(name);
+                List<QItemDefinition> defs = namedItemDefs.get(name);
                 if (defs == null) {
-                    defs = new ArrayList();
+                    defs = new ArrayList<QItemDefinition>();
                     namedItemDefs.put(name, defs);
                 }
                 if (defs.size() > 0) {
@@ -331,7 +331,7 @@
                      * name; make sure none of them is auto-create
                      */
                     for (int j = 0; j < defs.size(); j++) {
-                        QItemDefinition qDef = (QItemDefinition) defs.get(j);
+                        QItemDefinition qDef = defs.get(j);
                         if (cnda[i].isAutoCreated() || qDef.isAutoCreated()) {
                             // conflict
                             String msg = "There are more than one 'auto-create' item definitions for '"
@@ -368,9 +368,9 @@
             } else {
                 // named property definition
                 Name name = pda[i].getName();
-                List defs = (List) namedItemDefs.get(name);
+                List<QItemDefinition> defs = namedItemDefs.get(name);
                 if (defs == null) {
-                    defs = new ArrayList();
+                    defs = new ArrayList<QItemDefinition>();
                     namedItemDefs.put(name, defs);
                 }
                 if (defs.size() > 0) {
@@ -379,7 +379,7 @@
                      * name; make sure none of them is auto-create
                      */
                     for (int j = 0; j < defs.size(); j++) {
-                        QItemDefinition qDef = (QItemDefinition) defs.get(j);
+                        QItemDefinition qDef = defs.get(j);
                         if (pda[i].isAutoCreated() || qDef.isAutoCreated()) {
                             // conflict
                             String msg = "There are more than one 'auto-create' item definitions for '"
@@ -417,7 +417,7 @@
      */
     private EffectiveNodeType getEffectiveNodeType(Name ntName,
                                                    EffectiveNodeTypeCache entCache,
-                                                   Map ntdCache)
+                                                   Map<Name, QNodeTypeDefinition> ntdCache)
         throws NoSuchNodeTypeException {
         // 1. check if effective node type has already been built
         EffectiveNodeTypeCache.Key key = entCache.getKey(new Name[]{ntName});
@@ -427,7 +427,7 @@
         }
 
         // 2. make sure we've got the definition of the specified node type
-        QNodeTypeDefinition ntd = (QNodeTypeDefinition) ntdCache.get(ntName);
+        QNodeTypeDefinition ntd = ntdCache.get(ntName);
         if (ntd == null) {
             throw new NoSuchNodeTypeException(ntName.toString());
         }
@@ -458,7 +458,7 @@
      */
     private EffectiveNodeType getEffectiveNodeType(Name[] ntNames,
                                                    EffectiveNodeTypeCache entCache,
-                                                   Map ntdCache)
+                                                   Map<Name, QNodeTypeDefinition> ntdCache)
         throws ConstraintViolationException, NoSuchNodeTypeException {
 
         EffectiveNodeTypeCache.Key key = entCache.getKey(ntNames);
@@ -500,7 +500,7 @@
                      */
                     Name[] remainder = key.getNames();
                     for (int i = 0; i < remainder.length; i++) {
-                        QNodeTypeDefinition ntd = (QNodeTypeDefinition) ntdCache.get(remainder[i]);
+                        QNodeTypeDefinition ntd = ntdCache.get(remainder[i]);
                         EffectiveNodeType ent = getEffectiveNodeType(ntd, ntdCache);
                         // store new effective node type
                         entCache.put(ent);
@@ -581,11 +581,10 @@
         }
     }
 
-    private void internalRegister(Map defMap) {
-        for (Iterator it = defMap.entrySet().iterator(); it.hasNext(); ) {
-            Map.Entry entry = (Map.Entry)it.next();
-            QNodeTypeDefinition ntd = (QNodeTypeDefinition)entry.getKey();
-            internalRegister(ntd, (EffectiveNodeTypeImpl)entry.getValue());
+    private void internalRegister(Map<QNodeTypeDefinition, EffectiveNodeType> defMap) {
+        for (Map.Entry<QNodeTypeDefinition, EffectiveNodeType> entry : defMap.entrySet()) {
+            QNodeTypeDefinition ntd = entry.getKey();
+            internalRegister(ntd, entry.getValue());
         }
     }