Author: stillalex
Date: Tue Sep 19 09:19:20 2017
New Revision: 1808848

URL: http://svn.apache.org/viewvc?rev=1808848&view=rev
Log:
OAK-6681 Remove PropInfo dependecy on EffectiveNodeType


Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/PropInfo.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java?rev=1808848&r1=1808847&r2=1808848&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java
 Tue Sep 19 09:19:20 2017
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 
 import javax.annotation.Nonnull;
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
@@ -362,6 +363,44 @@ public class EffectiveNodeType {
    }
 
     /**
+     * Calculates the applicable definition for the property with the specified
+     * characteristics under a parent with this effective type.
+     *
+     * @param name The internal oak name of the property for which the 
definition should be retrieved.
+     * @param type The target type of the property.
+     * @param unknownMultiple {@code true} if the target property has an 
unknown type, {@code false} if it is known to be a multi-valued property.
+     * @return the applicable definition for the target property or {@code 
null} if no matching definition can be found.
+     */
+    public PropertyDefinition getPropertyDefinition(String name, int type, 
boolean unknownMultiple) {
+        // TODO check multivalue handling
+        Iterable<PropertyDefinition> definitions = 
getNamedPropertyDefinitions(name);
+
+        for (PropertyDefinition def : definitions) {
+            int requiredType = def.getRequiredType();
+            if ((requiredType == PropertyType.UNDEFINED || type == 
PropertyType.UNDEFINED || requiredType == type)
+                    && (def.isMultiple() || unknownMultiple)) {
+                return def;
+            }
+        }
+        definitions = getResidualPropertyDefinitions();
+        for (PropertyDefinition def : definitions) {
+            int requiredType = def.getRequiredType();
+            if ((requiredType == PropertyType.UNDEFINED || type == 
PropertyType.UNDEFINED || requiredType == type)
+                    && !def.isMultiple() && unknownMultiple) {
+                return def;
+            }
+        }
+        for (PropertyDefinition def : definitions) {
+            int requiredType = def.getRequiredType();
+            if ((requiredType == PropertyType.UNDEFINED || type == 
PropertyType.UNDEFINED || requiredType == type)
+                    && def.isMultiple()) {
+                return def;
+            }
+        }
+        return null;
+    }
+
+    /**
      *
      * @param childName The internal oak name of the target node.
      * @param childEffective

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/PropInfo.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/PropInfo.java?rev=1808848&r1=1808847&r2=1808848&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/PropInfo.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/PropInfo.java
 Tue Sep 19 09:19:20 2017
@@ -31,7 +31,6 @@ import com.google.common.collect.Immutab
 import com.google.common.collect.Lists;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
-import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeType;
 
 /**
  * Information about a property being imported. This class is used
@@ -134,6 +133,10 @@ public class PropInfo {
         return type;
     }
 
+    public boolean isUnknownMultiple() {
+        return multipleStatus == MultipleStatus.UNKNOWN;
+    }
+
     @Nonnull
     public TextValue getTextValue() throws RepositoryException {
         if (multipleStatus == MultipleStatus.MULTIPLE) {
@@ -168,35 +171,6 @@ public class PropInfo {
         }
     }
 
-    //TODO check multivalue handling
-    public PropertyDefinition getPropertyDef(EffectiveNodeType ent) {
-        Iterable<PropertyDefinition> definitions = 
ent.getNamedPropertyDefinitions(getName());
-        int knownType = getType();
-        for (PropertyDefinition def : definitions) {
-            int requiredType = def.getRequiredType();
-            if ((requiredType == PropertyType.UNDEFINED || knownType == 
PropertyType.UNDEFINED || requiredType == knownType)
-                    && (def.isMultiple() || multipleStatus == 
MultipleStatus.UNKNOWN)) {
-                return def;
-            }
-        }
-        definitions = ent.getResidualPropertyDefinitions();
-        for (PropertyDefinition def : definitions) {
-            int requiredType = def.getRequiredType();
-            if ((requiredType == PropertyType.UNDEFINED || knownType == 
PropertyType.UNDEFINED || requiredType == knownType)
-                    && !def.isMultiple() && multipleStatus == 
MultipleStatus.UNKNOWN) {
-                return def;
-            }
-        }
-        for (PropertyDefinition def : definitions) {
-            int requiredType = def.getRequiredType();
-            if ((requiredType == PropertyType.UNDEFINED || knownType == 
PropertyType.UNDEFINED || requiredType == knownType)
-                    && def.isMultiple()) {
-                return def;
-            }
-        }
-        return null;
-    }
-
     public PropertyState asPropertyState(@Nonnull PropertyDefinition 
propertyDefinition) throws RepositoryException {
         List<Value> vs = getValues(getTargetType(propertyDefinition));
         PropertyState propertyState;

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java?rev=1808848&r1=1808847&r2=1808848&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
 Tue Sep 19 09:19:20 2017
@@ -59,6 +59,7 @@ import org.apache.jackrabbit.oak.jcr.ses
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.plugins.nodetype.DefinitionProvider;
+import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeTypeProvider;
 import 
org.apache.jackrabbit.oak.spi.security.authorization.permission.Permissions;
 import org.apache.jackrabbit.oak.spi.xml.Importer;
@@ -268,7 +269,8 @@ public class ImporterImpl implements Imp
         for (PropInfo pi : propInfos) {
             // find applicable definition
             //TODO find better heuristics?
-            PropertyDefinition def = 
pi.getPropertyDef(effectiveNodeTypeProvider.getEffectiveNodeType(tree));
+            EffectiveNodeType ent = 
effectiveNodeTypeProvider.getEffectiveNodeType(tree);
+            PropertyDefinition def = ent.getPropertyDefinition(pi.getName(), 
pi.getType(), pi.isUnknownMultiple());
             if (def.isProtected()) {
                 // skip protected property
                 log.debug("Protected property {}", pi.getName());


Reply via email to