diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java index 5e741af118..6240c1cb08 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeType.java @@ -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 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 diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/PropInfo.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/PropInfo.java index bb44e358e1..48d16be322 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/PropInfo.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/PropInfo.java @@ -31,7 +31,6 @@ import com.google.common.collect.ImmutableList; 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 isUnknwownMultiple() { + 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 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 vs = getValues(getTargetType(propertyDefinition)); PropertyState propertyState; diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java index 3bf9b61fe9..9df0fbe25a 100644 --- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java +++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java @@ -59,6 +59,7 @@ import org.apache.jackrabbit.oak.jcr.session.WorkspaceImpl; 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 Importer { 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.isUnknwownMultiple()); if (def.isProtected()) { // skip protected property log.debug("Protected property {}", pi.getName());