jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r515598 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: nodetype/EffectiveNodeType.java nodetype/EffectiveNodeTypeImpl.java state/WorkspaceItemStateFactory.java
Date Wed, 07 Mar 2007 15:11:38 GMT
Author: reschke
Date: Wed Mar  7 07:11:37 2007
New Revision: 515598

URL: http://svn.apache.org/viewvc?view=rev&rev=515598
Log:
JCR-741: ask the SPI server if an effective node type has multiple matching property definitions

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java?view=diff&rev=515598&r1=515597&r2=515598
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java
Wed Mar  7 07:11:37 2007
@@ -103,6 +103,16 @@
             throws ConstraintViolationException;
 
     /**
+     * Returns all applicable property definitions for a property with the
+     * specified name, type and multiValued characteristics.
+     * @throws ConstraintViolationException if no applicable property definition
+     *                                      could be found
+     */
+    public QPropertyDefinition[] getApplicablePropertyDefinitions(QName name, int type,
+                                                                  boolean multiValued)
+            throws ConstraintViolationException;
+
+    /**
      * Returns the applicable property definition for a property with the
      * specified name and type. The multiValued flag is not taken into account
      * in the selection algorithm. Other than

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java?view=diff&rev=515598&r1=515597&r2=515598
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
Wed Mar  7 07:11:37 2007
@@ -28,6 +28,7 @@
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -561,6 +562,32 @@
     /**
      * @inheritDoc
      */
+    public QPropertyDefinition[] getApplicablePropertyDefinitions(QName name, int type, boolean
multiValued) throws ConstraintViolationException {
+      
+        QPropertyDefinition named[] = getNamedPropDefs(name);
+        QPropertyDefinition unnamed[] = getUnnamedPropDefs();
+        QPropertyDefinition all[] = new QPropertyDefinition[named.length + unnamed.length];
+        for (int i = 0; i < all.length; i++) {
+            if (i < named.length) {
+                all[i] = named[i]; 
+            }
+            else {
+                all[i] = unnamed[i - named.length];
+            }
+        }
+      
+        QPropertyDefinition result[] = getMatchingPropDefs(all, type, multiValued);
+        if (result.length == 0) {
+            throw new ConstraintViolationException("no matching property definition found
for " + name);
+        }
+        else {
+            return result;
+        }
+    }
+
+    /**
+     * @inheritDoc
+     */
     public QPropertyDefinition getApplicablePropertyDefinition(QName name, int type)
             throws ConstraintViolationException {
         // try named property definitions first
@@ -734,6 +761,35 @@
             }
         }
         return match;
+    }
+
+    private QPropertyDefinition[] getMatchingPropDefs(QPropertyDefinition[] defs, int type,
boolean multiValued) {
+        List result = Collections.EMPTY_LIST;
+    
+        for (int i = 0; i < defs.length; i++) {
+            QItemDefinition qDef = defs[i];
+            if (!qDef.definesNode()) {
+                QPropertyDefinition pd = (QPropertyDefinition)qDef;
+                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 (result.isEmpty()) {
+                            result = Collections.singletonList(pd);
+                        }
+                        else {
+                            if (result.size() == 1) {
+                                result = new ArrayList(result);
+                            }
+                            result.add(pd);
+                        }
+                    }
+                }
+            }
+        }
+        return (QPropertyDefinition[])result.toArray(QPropertyDefinition.EMPTY_ARRAY);
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java?view=diff&rev=515598&r1=515597&r2=515598
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
Wed Mar  7 07:11:37 2007
@@ -342,7 +342,13 @@
             try {
                 parentState = entry.getParent().getNodeState();
                 EffectiveNodeType ent = wspManager.getNodeTypeRegistry().getEffectiveNodeType(parentState.getNodeTypeNames());
-                definition = ent.getApplicablePropertyDefinition(info.getQName(), info.getType(),
info.isMultiValued());
+                QPropertyDefinition defs[] = ent.getApplicablePropertyDefinitions(info.getQName(),
info.getType(), info.isMultiValued());
+                if (defs.length == 1) {
+                    definition = defs[0];
+                }
+                else {
+                    definition = service.getPropertyDefinition(sessionInfo, entry.getId());
+                }
             } catch (ItemStateException e) {
                 // should not get here
                 log.warn("Internal error", e);



Mime
View raw message