jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r792142 [18/35] - in /jackrabbit/sandbox/JCR-1456: ./ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/ jackrabbit-core/ jackrabbit-core/src/main/java/org/apache/jackrab...
Date Wed, 08 Jul 2009 13:57:46 GMT
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java Wed Jul  8 13:57:13 2009
@@ -52,22 +52,6 @@
     }
 
     /**
-     * Same as {@link #convert(String, int, ValueFactory)} using
-     * <code>ValueFactoryImpl</code>.
-     *
-     * @param srcValue
-     * @param targetType
-     * @throws ValueFormatException
-     * @throws IllegalArgumentException
-     * @deprecated Use {@link #convert(String, int, ValueFactory)} instead.
-     * @see #convert(Value, int, ValueFactory)
-     */
-    public static Value convert(String srcValue, int targetType)
-            throws ValueFormatException, IllegalArgumentException {
-        return convert(srcValue, targetType, ValueFactoryImpl.getInstance());
-    }
-
-    /**
      * @param srcValue
      * @param targetType
      * @param factory
@@ -85,21 +69,6 @@
     }
 
     /**
-     * Same as {@link #convert(InputStream, int, ValueFactory)} using
-     * <code>ValueFactoryImpl</code>.
-     *
-     * @param srcValue
-     * @param targetType
-     * @throws ValueFormatException
-     * @throws IllegalArgumentException
-     * @deprecated Use {@link #convert(InputStream, int, ValueFactory)} instead.
-     */
-    public static Value convert(InputStream srcValue, int targetType)
-            throws ValueFormatException, IllegalArgumentException {
-        return convert(srcValue, targetType, ValueFactoryImpl.getInstance());
-    }
-
-    /**
      * @param srcValue
      * @param targetType
      * @param factory
@@ -123,22 +92,6 @@
      * @param targetType
      * @throws ValueFormatException
      * @throws IllegalArgumentException
-     * @deprecated Use {@link #convert(String[], int, ValueFactory)} instead.
-     * @see #convert(Value, int, ValueFactory)
-     */
-    public static Value[] convert(String[] srcValues, int targetType)
-            throws ValueFormatException, IllegalArgumentException {
-        return convert(srcValues, targetType, ValueFactoryImpl.getInstance());
-    }
-
-    /**
-     * Same as {@link #convert(String[], int, ValueFactory)} using
-     * <code>ValueFactoryImpl</code>.
-     *
-     * @param srcValues
-     * @param targetType
-     * @throws ValueFormatException
-     * @throws IllegalArgumentException
      * @see #convert(Value, int, ValueFactory)
      */
     public static Value[] convert(String[] srcValues, int targetType, ValueFactory factory)
@@ -174,22 +127,6 @@
     }
 
     /**
-     * Same as {@link #convert(Value[], int, ValueFactory)} using
-     * <code>ValueFactoryImpl</code>.
-     *
-     * @param srcValues
-     * @param targetType
-     * @throws ValueFormatException
-     * @throws IllegalArgumentException
-     * @deprecated Use {@link #convert(Value[], int, ValueFactory)} instead.
-     * @see #convert(Value, int, ValueFactory)
-     */
-    public static Value[] convert(Value[] srcValues, int targetType)
-        throws ValueFormatException, IllegalArgumentException {
-        return convert(srcValues, targetType, ValueFactoryImpl.getInstance());
-    }
-
-    /**
      * @param srcValues
      * @param targetType
      * @param factory
@@ -226,24 +163,6 @@
     }
 
     /**
-     * Same as {@link #convert(Value, int, ValueFactory)} using
-     * <code>ValueFactoryImpl</code>.
-
-     * @param srcValue
-     * @param targetType
-     * @throws ValueFormatException
-     * @throws IllegalStateException
-     * @throws IllegalArgumentException
-     * @deprecated Use {@link #convert(Value, int, ValueFactory)} instead.
-     * @see #convert(Value, int, ValueFactory)
-     */
-    public static Value convert(Value srcValue, int targetType)
-        throws ValueFormatException, IllegalStateException,
-        IllegalArgumentException {
-        return convert(srcValue, targetType, ValueFactoryImpl.getInstance());
-    }
-
-    /**
      * Converts the given value to a value of the specified target type.
      * The conversion is performed according to the rules described in
      * "3.6.4 Property Type Conversion" in the JSR 283 specification.
@@ -285,7 +204,7 @@
             case PropertyType.BINARY:
                 // convert to BINARY
                 try {
-                    val = factory.createValue(srcValue.getStream());
+                    val = factory.createValue(srcValue.getBinary());
                 } catch (RepositoryException re) {
                     throw new ValueFormatException("conversion failed: "
                             + PropertyType.nameFromValue(srcType) + " to "
@@ -369,6 +288,8 @@
                             throw new ValueFormatException("failed to convert source value to PATH value",
                                     re);
                         }
+                        // the following call will throw ValueFormatException
+                        // if p is not a valid PATH
                         val = factory.createValue(path, targetType);
                         break;
 
@@ -391,6 +312,8 @@
                             p = p.substring(2);
                         }
 
+                        // the following call will throw ValueFormatException
+                        // if p is not a valid PATH
                         val = factory.createValue(p, targetType);
                         break;
 
@@ -431,9 +354,35 @@
                             throw new ValueFormatException("failed to convert source value to NAME value",
                                     re);
                         }
+                        // the following call will throw ValueFormatException
+                        // if p is not a valid NAME
                         val = factory.createValue(name, targetType);
                         break;
 
+                    case PropertyType.URI:
+                        URI uri;
+                        try {
+                            uri = URI.create(srcValue.getString());
+                        } catch (RepositoryException re) {
+                            // should never happen
+                            throw new ValueFormatException("failed to convert source value to NAME value",
+                                    re);
+                        }
+                        if (uri.isAbsolute()) {
+                            // uri contains scheme...
+                            throw new ValueFormatException("failed to convert URI value to NAME value");
+                        }
+                        String p = uri.getPath();
+
+                        if (p.startsWith("./")) {
+                            p = p.substring(2);
+                        }
+
+                        // the following call will throw ValueFormatException
+                        // if p is not a valid NAME
+                        val = factory.createValue(p, targetType);
+                        break;
+
                     case PropertyType.BOOLEAN:
                     case PropertyType.DATE:
                     case PropertyType.DOUBLE:
@@ -479,6 +428,7 @@
                     case PropertyType.LONG:
                     case PropertyType.DECIMAL:
                     case PropertyType.PATH:
+                    case PropertyType.URI:
                     case PropertyType.NAME:
                         throw new ValueFormatException("conversion failed: "
                                 + PropertyType.nameFromValue(srcType) + " to "
@@ -517,6 +467,7 @@
                     case PropertyType.DOUBLE:
                     case PropertyType.LONG:
                     case PropertyType.DECIMAL:
+                    case PropertyType.URI:
                     case PropertyType.PATH:
                     case PropertyType.NAME:
                         throw new ValueFormatException("conversion failed: "
@@ -603,17 +554,6 @@
     }
 
     /**
-     * Same as {@link #copy(Value, ValueFactory)} using <code>ValueFactoryImpl</code>.
-     *
-     * @param srcValue
-     * @throws IllegalStateException
-     * @deprecated Use {@link #copy(Value, ValueFactory)} instead.
-     */
-    public static Value copy(Value srcValue) throws IllegalStateException {
-        return copy(srcValue, ValueFactoryImpl.getInstance());
-    }
-
-    /**
      *
      * @param srcValue
      * @param factory
@@ -671,17 +611,6 @@
     }
 
     /**
-     * Same as {@link #copy(Value[], ValueFactory)} using <code>ValueFactoryImpl</code>.
-     *
-     * @param srcValues
-     * @throws IllegalStateException
-     * @deprecated Use {@link #copy(Value[], ValueFactory)} instead.
-     */
-    public static Value[] copy(Value[] srcValues) throws IllegalStateException {
-        return copy(srcValues, ValueFactoryImpl.getInstance());
-    }
-
-    /**
      * @param srcValues
      * @param factory
      * @throws IllegalStateException
@@ -725,15 +654,6 @@
     }
 
     /**
-     * @deprecated use {@link #serialize(Value, boolean, boolean, Writer)} instead
-     */
-    public static void serialize(Value value, boolean encodeBlanks,
-        Writer writer)
-        throws IllegalStateException, IOException, RepositoryException {
-        serialize(value, encodeBlanks, false, writer);
-    }
-
-      /**
      * Outputs the serialized value to a <code>Writer</code>. The serialization
      * format is the same as used by Document & System View XML, i.e.
      * binary values will be Base64-encoded whereas for all others
@@ -786,30 +706,6 @@
 
     /**
      * Deserializes the given string to a <code>Value</code> of the given type.
-     * Same as {@link #deserialize(String, int, boolean, ValueFactory)} using
-     * <code>ValueFactoryImpl</code>.
-     *
-     * @param value        string to be deserialized
-     * @param type         type of value
-     * @param decodeBlanks if <code>true</code> <code>"_x0020_"</code>
-     *                     character sequences will be decoded to single space
-     *                     characters each.
-     * @return the deserialized <code>Value</code>
-     * @throws ValueFormatException if the string data is not of the required
-     *                              format
-     * @throws RepositoryException  if an error occured during the
-     *                              deserialization.
-     * @deprecated Use {@link #deserialize(String, int, boolean, ValueFactory)}
-     * instead.
-     */
-    public static Value deserialize(String value, int type,
-                                    boolean decodeBlanks)
-            throws ValueFormatException, RepositoryException {
-        return deserialize(value, type, decodeBlanks, ValueFactoryImpl.getInstance());
-    }
-
-    /**
-     * Deserializes the given string to a <code>Value</code> of the given type.
      *
      * @param value        string to be deserialized
      * @param type         type of value
@@ -854,33 +750,6 @@
 
     /**
      * Deserializes the string data read from the given reader to a
-     * <code>Value</code> of the given type. Same as
-     * {@link #deserialize(Reader, int, boolean, ValueFactory)} using
-     * <code>ValueFactoryImpl</code>.
-     *
-     * @param reader       reader for the string data to be deserialized
-     * @param type         type of value
-     * @param decodeBlanks if <code>true</code> <code>"_x0020_"</code>
-     *                     character sequences will be decoded to single space
-     *                     characters each.
-     * @return the deserialized <code>Value</code>
-     * @throws IOException          if an i/o error occured during the
-     *                              serialization
-     * @throws ValueFormatException if the string data is not of the required
-     *                              format
-     * @throws RepositoryException  if an error occured during the
-     *                              deserialization.
-     * @deprecated Use {@link #deserialize(Reader, int, boolean, ValueFactory)}
-     * instead.
-     */
-    public static Value deserialize(Reader reader, int type,
-                                    boolean decodeBlanks)
-            throws IOException, ValueFormatException, RepositoryException {
-        return deserialize(reader, type, decodeBlanks, ValueFactoryImpl.getInstance());
-    }
-
-    /**
-     * Deserializes the string data read from the given reader to a
      * <code>Value</code> of the given type.
      *
      * @param reader       reader for the string data to be deserialized

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/WeakReferenceValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/WeakReferenceValue.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/WeakReferenceValue.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/WeakReferenceValue.java Wed Jul  8 13:57:13 2009
@@ -24,6 +24,7 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.ValueFormatException;
 import java.util.Calendar;
+import java.math.BigDecimal;
 
 /**
  * A <code>WeakReferenceValue</code> provides an implementation
@@ -184,4 +185,15 @@
 
         throw new ValueFormatException("conversion to double failed: inconvertible types");
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public BigDecimal getDecimal()
+            throws ValueFormatException, IllegalStateException,
+            RepositoryException {
+        setValueConsumed();
+
+        throw new ValueFormatException("conversion to Decimal failed: inconvertible types");
+    }
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/ISO9075Test.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/ISO9075Test.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/ISO9075Test.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/ISO9075Test.java Wed Jul  8 13:57:13 2009
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.util;
 
-import org.apache.jackrabbit.name.QName;
 import junit.framework.TestCase;
 
 /**
@@ -61,37 +60,4 @@
         assertEquals("year/_x0032_007", ISO9075.encodePath("year/2007"));
         assertEquals("year/_x0032_007[2]", ISO9075.encodePath("year/2007[2]"));
     }
-
-    /**
-     * This is a disabled brute force test. It tests permutations of characters:
-     * <code>' ', '_', 'x', '0', '2', 'a', 'b', '{'</code>, encodes and decodes
-     * the sequences and test whether the initial sequence equals the resulting
-     * sequence that went through the encoding / decoding process.
-     * </p>
-     * The test takes about 30 seconds on my 1.2G P3.
-     * </p>
-     * To enable the test remove the 'disabled_' refix from the method name.
-     */
-    public void disabled_testBrute() {
-        char[] chars = new char[] {' ', '_', 'x', '0', '2', 'a', 'b', '{'};
-        long start = Long.parseLong("1000000", 8);
-        long end = Long.parseLong("7777777", 8);
-        for (long i = start; i < end; i++) {
-            String s = Long.toString(i, chars.length);
-            StringBuffer b = new StringBuffer(s.length());
-            for (int j = 0; j < s.length(); j++) {
-                b.append(chars[s.charAt(j) - '0']);
-            }
-            // encode and decode
-            QName initial = new QName("", b.toString());
-            if ((i % 100000) == 0) {
-                System.out.println(initial);
-            }
-            QName encoded = ISO9075.encode(initial);
-            assertTrue(XMLChar.isValidName(encoded.getLocalName()));
-            QName decoded = ISO9075.decode(encoded);
-            assertEquals(initial, decoded);
-        }
-    }
-
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/util/TextTest.java Wed Jul  8 13:57:13 2009
@@ -22,9 +22,6 @@
 
 import junit.framework.TestCase;
 
-import org.apache.jackrabbit.name.IllegalNameException;
-import org.apache.jackrabbit.name.NameFormat;
-
 /**
  * Test cases for the Text utility class.
  */
@@ -32,11 +29,6 @@
 
     private void checkEscape(String name) {
         String escaped = Text.escapeIllegalJcrChars(name);
-        try {
-            NameFormat.checkFormat(escaped);
-        } catch (IllegalNameException e) {
-            fail("Illegal name: " + escaped);
-        }
         assertEquals(name, Text.unescapeIllegalJcrChars(escaped));
     }
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultIOManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultIOManager.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultIOManager.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultIOManager.java Wed Jul  8 13:57:13 2009
@@ -37,18 +37,6 @@
     }
 
     /**
-     * Creates a new <code>DefaultIOManager</code>. The if the flag is set to
-     * false no <code>IOHandler</code>s are added to the internal list.
-     *
-     * @deprecated Use {@link IOManagerImpl} instead.
-     */
-    protected DefaultIOManager(boolean initDefaults) {
-        if (initDefaults) {
-           init();
-        }
-    }
-
-    /**
      * Add the predefined <code>IOHandler</code>s to this manager. This includes
      * <ul>
      * <li>{@link VersionHistoryHandler}</li>

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java Wed Jul  8 13:57:13 2009
@@ -106,6 +106,8 @@
 
             if (JcrConstants.JCR_MIXINTYPES.equals(propName)) {
                 setMixins(parent, extractValuesFromRequest(targetPath));
+            } else if (JcrConstants.JCR_PRIMARYTYPE.equals(propName)) {
+                setPrimaryType(parent, extractValuesFromRequest(targetPath));
             } else {
                 if (diffValue == null || diffValue.length() == 0) {
                     // single valued property with value present in multipart.
@@ -347,6 +349,17 @@
         return n;
     }
 
+    private static void setPrimaryType(Node n, Value[] values) throws RepositoryException, DiffException {
+        if (values.length == 1) {
+            String ntName = values[0].getString();
+            if (!ntName.equals(n.getPrimaryNodeType().getName())) {
+                n.setPrimaryType(ntName);
+            } // else: same primaryType as before -> nothing to do.
+        } else {
+            throw new DiffException("Invalid diff: jcr:primarytype cannot have multiple values, nor can it's value be removed.");
+        }
+    }
+
     private static void setMixins(Node n, Value[] values) throws RepositoryException {
         if (values.length == 0) {
             // remove all mixins

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java Wed Jul  8 13:57:13 2009
@@ -48,8 +48,6 @@
 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
 import org.apache.jackrabbit.webdav.property.HrefProperty;
 import org.apache.jackrabbit.webdav.property.ResourceType;
-import org.apache.jackrabbit.webdav.property.DavPropertyNameIterator;
-import org.apache.jackrabbit.webdav.property.DavPropertyIterator;
 import org.apache.jackrabbit.webdav.search.QueryGrammerSet;
 import org.apache.jackrabbit.webdav.search.SearchInfo;
 import org.apache.jackrabbit.webdav.search.SearchResource;
@@ -223,31 +221,6 @@
     }
 
     /**
-     * Builds a single List from the properties to set and the properties to
-     * remove and delegates the list to {@link AbstractResource#alterProperties(List)};
-     *
-     * @see DavResource#alterProperties(org.apache.jackrabbit.webdav.property.DavPropertySet, org.apache.jackrabbit.webdav.property.DavPropertyNameSet)
-     */
-    public MultiStatusResponse alterProperties(DavPropertySet setProperties,
-                                               DavPropertyNameSet removePropertyNames)
-            throws DavException {
-        List changeList = new ArrayList();
-        if (removePropertyNames != null) {
-            DavPropertyNameIterator it = removePropertyNames.iterator();
-            while (it.hasNext()) {
-                changeList.add(it.next());
-            }
-        }
-        if (setProperties != null) {
-            DavPropertyIterator it = setProperties.iterator();
-            while (it.hasNext()) {
-                changeList.add(it.next());
-            }
-        }
-        return alterProperties(changeList);
-    }
-
-    /**
      * Throws {@link DavServletResponse#SC_METHOD_NOT_ALLOWED}
      *
      * @see DavResource#alterProperties(List)
@@ -736,7 +709,13 @@
      */
     class EListener implements EventListener {
 
-        private static final int ALL_EVENTS = Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED;
+        private static final int ALL_EVENTS = Event.NODE_ADDED
+                | Event.NODE_REMOVED
+                | Event.PROPERTY_ADDED
+                | Event.PROPERTY_CHANGED
+                | Event.PROPERTY_REMOVED
+                | Event.NODE_MOVED
+                | Event.PERSIST;
 
         private final DavPropertyNameSet propNameSet;
         private MultiStatus ms;

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java Wed Jul  8 13:57:13 2009
@@ -80,8 +80,6 @@
 import org.apache.jackrabbit.webdav.ordering.Position;
 import org.apache.jackrabbit.webdav.property.DavProperty;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
-import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
-import org.apache.jackrabbit.webdav.property.DavPropertySet;
 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
 import org.apache.jackrabbit.webdav.property.HrefProperty;
 import org.apache.jackrabbit.webdav.xml.DomUtil;
@@ -220,14 +218,14 @@
      * @param property
      * @throws DavException
      * @see #setProperty(DavProperty)
-     * @see #alterProperties(DavPropertySet, DavPropertyNameSet)
      */
     private void internalSetProperty(DavProperty property) throws DavException {
         if (!exists()) {
             throw new DavException(DavServletResponse.SC_NOT_FOUND);
         }
-        if (property.getName().equals(JCR_MIXINNODETYPES)) {
-            Node n = (Node)item;
+        DavPropertyName propName = property.getName();
+        if (JCR_MIXINNODETYPES.equals(propName)) {
+            Node n = (Node) item;
             try {
                 NodeType[] existingMixin = n.getMixinNodeTypes();
                 NodeTypeProperty mix = new NodeTypeProperty(property);
@@ -252,8 +250,23 @@
             } catch (RepositoryException e) {
                 throw new JcrDavException(e);
             }
+        } else if (JCR_PRIMARYNODETYPE.equals(propName)) {
+            Node n = (Node) item;
+            try {
+                NodeTypeProperty ntProp = new NodeTypeProperty(property);
+                Set names = ntProp.getNodeTypeNames();
+                if (names.size() == 1) {
+                    String ntName = names.iterator().next().toString();
+                    n.setPrimaryType(ntName);
+                } else {
+                    // only a single node type can be primary node type.
+                    throw new DavException(DavServletResponse.SC_BAD_REQUEST);
+                }
+            } catch (RepositoryException e) {
+                throw new JcrDavException(e);
+            }
         } else {
-            // all props except for mixinnodetypes are read-only
+            // all props except for mixinnodetypes and primaryType are read-only
             throw new DavException(DavServletResponse.SC_CONFLICT);
         }
     }
@@ -278,7 +291,6 @@
      * @param propertyName
      * @throws DavException
      * @see #removeProperty(DavPropertyName)
-     * @see #alterProperties(DavPropertySet, DavPropertyNameSet)
      */
     private void internalRemoveProperty(DavPropertyName propertyName) throws DavException {
         if (!exists()) {
@@ -315,7 +327,6 @@
      * @param changeList
      * @return
      * @throws DavException
-     * @see DavResource#alterProperties(org.apache.jackrabbit.webdav.property.DavPropertySet, org.apache.jackrabbit.webdav.property.DavPropertyNameSet)
      */
     public MultiStatusResponse alterProperties(List changeList) throws DavException {
         Iterator it = changeList.iterator();
@@ -882,11 +893,12 @@
                 properties.add(new NodeTypeProperty(JCR_MIXINNODETYPES, n.getMixinNodeTypes(), false));
                 properties.add(new DefaultDavProperty(JCR_INDEX, new Integer(n.getIndex()), true));
                 addHrefProperty(JCR_REFERENCES, n.getReferences(), true);
+                addHrefProperty(JCR_WEAK_REFERENCES, n.getWeakReferences(), true);
                 if (n.isNodeType(JcrConstants.MIX_REFERENCEABLE)) {
                     properties.add(new DefaultDavProperty(JCR_UUID, n.getUUID(), true));
                 }
             } catch (RepositoryException e) {
-                log.error("Failed to retrieve primary nodetype property: " + e.getMessage());
+                log.error("Failed to retrieve node-specific property: " + e);
             }
             try {
                 Item primaryItem = n.getPrimaryItem();

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java Wed Jul  8 13:57:13 2009
@@ -122,12 +122,17 @@
     public static final DavPropertyName JCR_ISNEW = DavPropertyName.create("isnew", NAMESPACE);
     public static final DavPropertyName JCR_ISMODIFIED = DavPropertyName.create("ismodified", NAMESPACE);
     public static final DavPropertyName JCR_DEFINITION = DavPropertyName.create("definition", NAMESPACE);
+    public static final DavPropertyName JCR_SELECTOR_NAME = DavPropertyName.create("selectorName", NAMESPACE);
 
     // property names used for resources representing jcr-nodes
     public static final DavPropertyName JCR_PRIMARYNODETYPE = DavPropertyName.create(XML_PRIMARYNODETYPE, NAMESPACE);
     public static final DavPropertyName JCR_MIXINNODETYPES = DavPropertyName.create("mixinnodetypes", NAMESPACE);
     public static final DavPropertyName JCR_INDEX = DavPropertyName.create("index", NAMESPACE);
     public static final DavPropertyName JCR_REFERENCES = DavPropertyName.create("references", NAMESPACE);
+    /**
+     * @since JCR 2.0
+     */
+    public static final DavPropertyName JCR_WEAK_REFERENCES = DavPropertyName.create("weakreferences", NAMESPACE);
     public static final DavPropertyName JCR_UUID = DavPropertyName.create("uuid", NAMESPACE);
     public static final DavPropertyName JCR_PRIMARYITEM = DavPropertyName.create("primaryitem", NAMESPACE);
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/observation/SubscriptionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/observation/SubscriptionImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/observation/SubscriptionImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/observation/SubscriptionImpl.java Wed Jul  8 13:57:13 2009
@@ -34,6 +34,7 @@
 import org.apache.jackrabbit.webdav.observation.SubscriptionInfo;
 import org.apache.jackrabbit.webdav.observation.DefaultEventType;
 import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.apache.jackrabbit.webdav.xml.Namespace;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -48,6 +49,7 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 /**
  * The <code>Subscription</code> class encapsulates a single subscription with
@@ -92,6 +94,18 @@
      */
     private static final String EVENT_PROPERTYCHANGED = "propertychanged";
 
+    /**
+     * Element representing the 'nodemoved' event type.
+     * @see javax.jcr.observation.Event#NODE_MOVED
+     */
+    private static final String EVENT_NODEMOVED = "nodemoved";
+
+    /**
+     * Element representing the 'persist' event type.
+     * @see javax.jcr.observation.Event#PERSIST
+     */
+    private static final String EVENT_PERSIST = "persist";
+
     private SubscriptionInfo info;
     private long expirationTime;
 
@@ -383,6 +397,8 @@
      * <li>{@link Event#PROPERTY_ADDED}</li>
      * <li>{@link Event#PROPERTY_REMOVED}</li>
      * <li>{@link Event#PROPERTY_CHANGED}</li>
+     * <li>{@link Event#NODE_MOVED}</li>
+     * <li>{@link Event#PERSIST}</li>
      * </ul>
      */
     public static EventType getEventType(int jcrEventType) {
@@ -403,6 +419,12 @@
             case Event.PROPERTY_REMOVED:
                 localName = EVENT_PROPERTYREMOVED;
                 break;
+            case Event.NODE_MOVED:
+                localName = EVENT_NODEMOVED;
+                break;
+            case Event.PERSIST:
+                localName = EVENT_PERSIST;
+                break;
             default: // no default
                 throw new IllegalArgumentException("Invalid JCR event type: " + jcrEventType);
         }
@@ -423,6 +445,8 @@
      * <li>{@link Event#PROPERTY_ADDED}</li>
      * <li>{@link Event#PROPERTY_REMOVED}</li>
      * <li>{@link Event#PROPERTY_CHANGED}</li>
+     * <li>{@link Event#NODE_MOVED}</li>
+     * <li>{@link Event#PERSIST}</li>
      * </ul>
      * @throws DavException if the given event type does not define a valid
      * JCR event type, such as returned by {@link #getEventType(int)}.
@@ -443,6 +467,10 @@
             eType = Event.PROPERTY_CHANGED;
         } else if (EVENT_PROPERTYREMOVED.equals(eventName)) {
             eType = Event.PROPERTY_REMOVED;
+        } else if (EVENT_NODEMOVED.equals(eventName)) {
+            eType = Event.NODE_MOVED;
+        } else if (EVENT_PERSIST.equals(eventName)) {
+            eType = Event.PERSIST;
         } else {
             throw new DavException(DavServletResponse.SC_UNPROCESSABLE_ENTITY, "Invalid event type: "+eventName);
         }
@@ -495,6 +523,42 @@
                 eType.appendChild(getEventType(event.getType()).toXml(document));
                 // user id
                 DomUtil.addChildElement(eventElem, XML_EVENTUSERID, NAMESPACE, event.getUserID());
+
+                // Additional JCR 2.0 event information
+                // userdata
+                try {
+                    DomUtil.addChildElement(eventElem, XML_EVENTUSERDATA, NAMESPACE, event.getUserData());
+                } catch (RepositoryException e) {
+                    log.error("Internal error while retrieving event user data.", e.getMessage());
+                }
+                // timestamp
+                try {
+                    DomUtil.addChildElement(eventElem, XML_EVENTDATE, NAMESPACE, String.valueOf(event.getDate()));
+                } catch (RepositoryException e) {
+                    log.error("Internal error while retrieving event date.", e.getMessage());
+                }
+                // identifier
+                try {
+                    DomUtil.addChildElement(eventElem, XML_EVENTIDENTIFIER, NAMESPACE, event.getIdentifier());
+                } catch (RepositoryException e) {
+                    log.error("Internal error while retrieving event identifier.", e.getMessage());
+                }
+                // info
+                Element info = DomUtil.addChildElement(eventElem, XML_EVENTINFO, NAMESPACE);
+                try {
+                    Map m = event.getInfo();
+                    for (Iterator it = m.keySet().iterator(); it.hasNext();) {
+                        String key = it.next().toString();
+                        Object value = m.get(key);
+                        if (value != null) {
+                            DomUtil.addChildElement(info, key, Namespace.EMPTY_NAMESPACE, value.toString());
+                        } else {
+                            DomUtil.addChildElement(info, key, Namespace.EMPTY_NAMESPACE);
+                        }
+                    }
+                } catch (RepositoryException e) {
+                    log.error("Internal error while retrieving event info.", e.getMessage());
+                }
             }
             return bundle;
         }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java Wed Jul  8 13:57:13 2009
@@ -37,14 +37,24 @@
 import javax.jcr.Session;
 import javax.jcr.Value;
 import javax.jcr.NamespaceRegistry;
+import javax.jcr.ValueFactory;
+import javax.jcr.PropertyType;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.Row;
 import javax.jcr.query.RowIterator;
+import javax.jcr.query.qom.Source;
+import javax.jcr.query.qom.Join;
+import javax.jcr.query.qom.Selector;
+import javax.jcr.query.qom.QueryObjectModel;
+
 import java.util.Map;
 import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
 
 /**
  * <code>SearchResourceImpl</code>...
@@ -70,9 +80,9 @@
         try {
             QueryManager qMgr = getRepositorySession().getWorkspace().getQueryManager();
             String[] langs = qMgr.getSupportedQueryLanguages();
-            for (int i = 0; i < langs.length; i++) {
+            for (String lang : langs) {
                 // todo: define proper namespace
-                qgs.addQueryLanguage(langs[i], Namespace.EMPTY_NAMESPACE);
+                qgs.addQueryLanguage(lang, Namespace.EMPTY_NAMESPACE);
             }
         } catch (RepositoryException e) {
             log.debug(e.getMessage());
@@ -87,9 +97,7 @@
      */
     public MultiStatus search(SearchInfo sInfo) throws DavException {
         try {
-            Query q = getQuery(sInfo);
-            QueryResult qR = q.execute();
-            return queryResultToMultiStatus(qR);
+            return queryResultToMultiStatus(getQuery(sInfo));
 
         } catch (RepositoryException e) {
             throw new JcrDavException(e);
@@ -138,18 +146,24 @@
         Query q;
         if (sInfo != null) {
             // apply namespace mappings to session
-            Map namespaces = sInfo.getNamespaces();
+            Map<String, String> namespaces = sInfo.getNamespaces();
             try {
-                for (Iterator it = namespaces.keySet().iterator(); it.hasNext(); ) {
-                    String prefix = (String) it.next();
-                    String uri = (String) namespaces.get(prefix);
+                for (Map.Entry<String, String> entry : namespaces.entrySet()) {
+                    String prefix = entry.getKey();
+                    String uri = entry.getValue();
                     session.setNamespacePrefix(prefix, uri);
                 }
                 q = qMgr.createQuery(sInfo.getQuery(), sInfo.getLanguageName());
+
+                if (SearchInfo.NRESULTS_UNDEFINED != sInfo.getNumberResults()) {
+                    q.setLimit(sInfo.getNumberResults());
+                }
+                if (SearchInfo.OFFSET_UNDEFINED != sInfo.getOffset()) {
+                    q.setOffset(sInfo.getOffset());
+                }
             } finally {
                 // reset namespace mappings
-                for (Iterator it = namespaces.values().iterator(); it.hasNext(); ) {
-                    String uri = (String) it.next();
+                for (String uri : namespaces.values()) {
                     try {
                         session.setNamespacePrefix(nsReg.getPrefix(uri), uri);
                     } catch (RepositoryException e) {
@@ -168,7 +182,7 @@
                 q.storeAsNode(itemPath);
             } catch (RepositoryException e) {
                 // ItemExistsException should never occur.
-                new JcrDavException(e);
+                throw new JcrDavException(e);
             }
         }
         return q;
@@ -177,49 +191,212 @@
     /**
      * Build a <code>MultiStatus</code> object from the specified query result.
      *
-     * @param qResult <code>QueryResult</code> as obtained from {@link javax.jcr.query.Query#execute()}.
+     * @param query the query to execute.
      * @return <code>MultiStatus</code> object listing the query result in
      * Webdav compatible form.
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs.
      */
-    private MultiStatus queryResultToMultiStatus(QueryResult qResult)
+    private MultiStatus queryResultToMultiStatus(Query query)
             throws RepositoryException {
+        QueryResult qResult = query.execute();
         MultiStatus ms = new MultiStatus();
 
-        String[] columnNames = qResult.getColumnNames();
+        List<String> columnNames = new ArrayList<String>();
+        columnNames.addAll(Arrays.asList(qResult.getColumnNames()));
         StringBuffer responseDescription = new StringBuffer();
         String delim = "";
-        for (int i = 0; i < columnNames.length; i++) {
+        for (String columnName : columnNames) {
             responseDescription.append(delim);
-            responseDescription.append(ISO9075.encode(columnNames[i]));
+            responseDescription.append(ISO9075.encode(columnName));
             delim = " ";
         }
         ms.setResponseDescription(responseDescription.toString());
 
+        ValueFactory vf = getRepositorySession().getValueFactory();
+        List<RowValue> descr = new ArrayList<RowValue>();
+        for (Iterator<String> it = columnNames.iterator(); it.hasNext(); ) {
+            String columnName = it.next();
+            if (!isPathOrScore(columnName)) {
+                descr.add(new PlainValue(columnName, null, vf));
+            } else {
+                it.remove();
+            }
+        }
+        // add path and score for each selector
+        List<String> sn = new ArrayList<String>();
+        collectSelectorNames(query, qResult, sn);
+        for (String selectorName : sn) {
+            descr.add(new PathValue(JcrConstants.JCR_PATH, selectorName, vf));
+            columnNames.add(JcrConstants.JCR_PATH);
+            descr.add(new ScoreValue(JcrConstants.JCR_SCORE, selectorName, vf));
+            columnNames.add(JcrConstants.JCR_SCORE);
+        }
+        String[] selectorNames = createSelectorNames(descr);
+        String[] colNames = columnNames.toArray(new String[columnNames.size()]);
         RowIterator rowIter = qResult.getRows();
         while (rowIter.hasNext()) {
             Row row = rowIter.nextRow();
-            Value[] values = row.getValues();
+            List<Value> values = new ArrayList<Value>();
+            for (RowValue rv : descr) {
+                values.add(rv.getValue(row));
+            }
 
-            // get the jcr:path column indicating the node path and build
+            // get the path for the first selector and build
             // a webdav compliant resource path of it.
-            String itemPath = row.getValue(JcrConstants.JCR_PATH).getString();
+            String itemPath = row.getPath();
             // create a new ms-response for this row of the result set
             DavResourceLocator loc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), itemPath, false);
             String href = loc.getHref(true);
             MultiStatusResponse resp = new MultiStatusResponse(href, null);
             // build the s-r-property
-            SearchResultProperty srp = new SearchResultProperty(columnNames, values);
+            SearchResultProperty srp = new SearchResultProperty(colNames,
+                    selectorNames, values.toArray(new Value[values.size()]));
             resp.add(srp);
             ms.addResponse(resp);
         }
         return ms;
     }
 
+    private static String[] createSelectorNames(Iterable<RowValue> rows)
+            throws RepositoryException {
+        List<String> sn = new ArrayList<String>();
+        for (RowValue rv : rows) {
+            sn.add(rv.getSelectorName());
+        }
+        return sn.toArray(new String[sn.size()]);
+    }
+
+    /**
+     * @param columnName a column name.
+     * @return <code>true</code> if <code>columnName</code> is either
+     *         <code>jcr:path</code> or <code>jcr:score</code>;
+     *         <code>false</code> otherwise.
+     */
+    private static boolean isPathOrScore(String columnName) {
+        return JcrConstants.JCR_PATH.equals(columnName)
+                || JcrConstants.JCR_SCORE.equals(columnName);
+    }
+
     /**
-     * @return
+     * @return the session associated with this resource.
      */
     private Session getRepositorySession() {
         return session.getRepositorySession();
     }
+
+    private interface RowValue {
+
+        public Value getValue(Row row) throws RepositoryException;
+
+        public String getColumnName() throws RepositoryException;
+
+        public String getSelectorName() throws RepositoryException;
+    }
+
+    private static final class PlainValue extends SelectorValue {
+
+        public PlainValue(String columnName,
+                          String selectorName,
+                          ValueFactory vf) {
+            super(columnName, selectorName, vf);
+        }
+
+        public Value getValue(Row row) throws RepositoryException {
+            return row.getValue(columnName);
+        }
+    }
+
+    private static abstract class SelectorValue implements RowValue {
+
+        protected final String columnName;
+
+        protected final String selectorName;
+
+        protected final ValueFactory vf;
+
+        public SelectorValue(String columnName,
+                             String selectorName,
+                             ValueFactory vf) {
+            this.columnName = columnName;
+            this.selectorName = selectorName;
+            this.vf = vf;
+        }
+
+        public String getColumnName() throws RepositoryException {
+            return columnName;
+        }
+
+        public String getSelectorName() throws RepositoryException {
+            return selectorName;
+        }
+    }
+
+    private static final class ScoreValue extends SelectorValue {
+
+        public ScoreValue(String columnName,
+                          String selectorName,
+                          ValueFactory vf) {
+            super(columnName, selectorName, vf);
+        }
+
+        public Value getValue(Row row) throws RepositoryException {
+            double score;
+            if (selectorName != null) {
+                score = row.getScore(selectorName);
+            } else {
+                score = row.getScore();
+            }
+            return vf.createValue(score);
+        }
+    }
+
+    private static final class PathValue extends SelectorValue {
+
+        public PathValue(String columnName,
+                         String selectorName,
+                         ValueFactory vf) {
+            super(columnName, selectorName, vf);
+        }
+
+        public Value getValue(Row row) throws RepositoryException {
+            String path;
+            if (selectorName != null) {
+                path = row.getPath(selectorName);
+            } else {
+                path = row.getPath();
+            }
+            return vf.createValue(path, PropertyType.PATH);
+        }
+    }
+
+    private static void collectSelectorNames(Query query,
+                                             QueryResult result,
+                                             List<String> sn) {
+        if (query instanceof QueryObjectModel) {
+            QueryObjectModel qom = (QueryObjectModel) query;
+            collectSelectorNames(qom.getSource(), sn);
+        } else {
+            // TODO
+            // sn.addAll(Arrays.asList(qResult.getSelectorNames()));
+            // TODO: remove once getSelectorNames() is available
+            sn.add(null); // default selector
+        }
+    }
+
+    private static void collectSelectorNames(Source source, List<String> sn) {
+        if (source instanceof Join) {
+            collectSelectorNames((Join) source, sn);
+        } else {
+            collectSelectorNames((Selector) source, sn);
+        }
+    }
+
+    private static void collectSelectorNames(Join join, List<String> sn) {
+        collectSelectorNames(join.getLeft(), sn);
+        collectSelectorNames(join.getRight(), sn);
+    }
+
+    private static void collectSelectorNames(Selector s, List<String> sn) {
+        sn.add(s.getSelectorName());
+    }
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResultProperty.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResultProperty.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResultProperty.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResultProperty.java Wed Jul  8 13:57:13 2009
@@ -33,7 +33,6 @@
 import javax.jcr.ValueFormatException;
 import javax.jcr.ValueFactory;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -48,18 +47,24 @@
     private static final String COLUMN = "column";
 
     private final String[] columnNames;
+    private final String[] selectorNames;
     private final Value[] values;
 
     /**
      * Creates a new <code>SearchResultProperty</code>.
      *
-     * @param columnNames the column names of the search row represented by this
-     * dav property.
-     * @param values the values present in the columns
-     */
-    public SearchResultProperty(String[] columnNames, Value[] values) {
+     * @param columnNames   the column names of the search row represented by
+     *                      this dav property.
+     * @param selectorNames the selecotr names of the row represented by this
+     *                      dav property.
+     * @param values        the values present in the columns
+     */
+    public SearchResultProperty(String[] columnNames,
+                                String[] selectorNames,
+                                Value[] values) {
         super(SEARCH_RESULT_PROPERTY, true);
         this.columnNames = columnNames;
+        this.selectorNames = selectorNames;
         this.values = values;
     }
 
@@ -79,35 +84,39 @@
 	    throw new IllegalArgumentException("SearchResultProperty may only be created from a property named " + SEARCH_RESULT_PROPERTY.toString());
 	}
 
-        List colList = new ArrayList();
-        List valList = new ArrayList();
+        List<String> colList = new ArrayList<String>();
+        List<String> selList = new ArrayList<String>();
+        List<Value> valList = new ArrayList<Value>();
         Object propValue = property.getValue();
         if (propValue instanceof List) {
-            Iterator elemIt = ((List)propValue).iterator();
-            while (elemIt.hasNext()) {
-                Object el = elemIt.next();
-                if (el instanceof Element) {
-                    parseColumnElement((Element)el, colList, valList, valueFactory);
+            for (Object o : ((List) propValue)) {
+                if (o instanceof Element) {
+                    parseColumnElement((Element) o, colList, selList, valList, valueFactory);
                 }
             }
         } else if (propValue instanceof Element) {
-            parseColumnElement((Element)property.getValue(), colList, valList, valueFactory);
+            parseColumnElement((Element)property.getValue(), colList, selList, valList, valueFactory);
         } else {
             throw new IllegalArgumentException("SearchResultProperty requires a list of 'dcr:column' xml elements.");
         }
 
-        columnNames = (String[]) colList.toArray(new String[colList.size()]);
-        values = (Value[]) valList.toArray(new Value[valList.size()]);
+        columnNames = colList.toArray(new String[colList.size()]);
+        selectorNames = selList.toArray(new String[selList.size()]);
+        values = valList.toArray(new Value[valList.size()]);
     }
 
-    private void parseColumnElement(Element columnElement, List columnNames,
-                                    List values, ValueFactory valueFactory)
+    private void parseColumnElement(Element columnElement,
+                                    List<String> columnNames,
+                                    List<String> selectorNames,
+                                    List<Value> values,
+                                    ValueFactory valueFactory)
         throws ValueFormatException, RepositoryException {
         if (!DomUtil.matches(columnElement, COLUMN, ItemResourceConstants.NAMESPACE)) {
             log.debug("dcr:column element expected within search result.");
             return;
         }
         columnNames.add(DomUtil.getChildText(columnElement, JCR_NAME.getName(), JCR_NAME.getNamespace()));
+        selectorNames.add(DomUtil.getChildText(columnElement, JCR_SELECTOR_NAME.getName(), JCR_SELECTOR_NAME.getNamespace()));
 
         Value jcrValue;
         Element valueElement = DomUtil.getChildElement(columnElement, JCR_VALUE.getName(), JCR_VALUE.getNamespace());
@@ -132,6 +141,13 @@
     }
 
     /**
+     * @return the selector name for each of the columns in the result property.
+     */
+    public String[] getSelectorNames() {
+        return selectorNames;
+    }
+
+    /**
      * Return the values representing the values of that row in the search
      * result table.
      *
@@ -154,7 +170,8 @@
 
     /**
      * Return the xml representation of this webdav property. For every value in
-     * the query result row a dcr:name, dcr:value and dcr:type element is created.
+     * the query result row a dcr:name, dcr:value, dcr:type and an optional
+     * dcr:selectorName element is created.
      * Example:
      * <pre>
      * -----------------------------------------------------------
@@ -162,6 +179,7 @@
      * -----------------------------------------------------------
      *   value     |   xxx   |   111   |  /aNode    |    1
      *   type      |    1    |    3    |     8      |    3
+     *   sel-name  |         |         |     S      |    S
      * -----------------------------------------------------------
      * </pre>
      * results in:
@@ -178,10 +196,12 @@
      *    &lt;dcr:column&gt;
      *       &lt;dcr:name&gt;jcr:path&lt;dcr:name/&gt;
      *       &lt;dcr:value dcr:type="Path"&gt;/aNode&lt;dcr:value/&gt;
+     *       &lt;dcr:selectorName&gt;S&lt;dcr:selectorName/&gt;
      *    &lt;/dcr:column&gt;
      *    &lt;dcr:column&gt;
      *       &lt;dcr:name&gt;jcr:score&lt;dcr:name/&gt;
      *       &lt;dcr:value dcr:type="Long"&gt;1&lt;dcr:value/&gt;
+     *       &lt;dcr:selectorName&gt;S&lt;dcr:selectorName/&gt;
      *    &lt;/dcr:column&gt;
      * &lt;/dcr:search-result-property&gt;
      * </pre>
@@ -192,6 +212,7 @@
         Element elem = getName().toXml(document);
         for (int i = 0; i < columnNames.length; i++) {
             String propertyName = columnNames[i];
+            String selectorName = selectorNames[i];
             Value propertyValue = values[i];
 
             Element columnEl = DomUtil.addChildElement(elem, COLUMN, ItemResourceConstants.NAMESPACE);
@@ -206,6 +227,9 @@
                     log.error(e.toString());
                 }
             }
+            if (selectorName != null) {
+                DomUtil.addChildElement(columnEl, JCR_SELECTOR_NAME.getName(), JCR_SELECTOR_NAME.getNamespace(), selectorName);
+            }
         }
         return elem;
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java Wed Jul  8 13:57:13 2009
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.webdav.simple;
 
 import org.apache.jackrabbit.JcrConstants;
-import org.apache.jackrabbit.uuid.UUID;
 import org.apache.jackrabbit.server.io.AbstractExportContext;
 import org.apache.jackrabbit.server.io.DefaultIOListener;
 import org.apache.jackrabbit.server.io.ExportContext;
@@ -30,6 +29,7 @@
 import org.apache.jackrabbit.server.io.PropertyExportContext;
 import org.apache.jackrabbit.server.io.PropertyImportContext;
 import org.apache.jackrabbit.util.Text;
+import org.apache.jackrabbit.uuid.UUID;
 import org.apache.jackrabbit.webdav.DavCompliance;
 import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.DavResource;
@@ -42,8 +42,8 @@
 import org.apache.jackrabbit.webdav.MultiStatusResponse;
 import org.apache.jackrabbit.webdav.bind.BindConstants;
 import org.apache.jackrabbit.webdav.bind.BindableResource;
-import org.apache.jackrabbit.webdav.bind.ParentSet;
 import org.apache.jackrabbit.webdav.bind.ParentElement;
+import org.apache.jackrabbit.webdav.bind.ParentSet;
 import org.apache.jackrabbit.webdav.io.InputContext;
 import org.apache.jackrabbit.webdav.io.OutputContext;
 import org.apache.jackrabbit.webdav.jcr.JcrDavException;
@@ -57,10 +57,7 @@
 import org.apache.jackrabbit.webdav.lock.SupportedLock;
 import org.apache.jackrabbit.webdav.lock.Type;
 import org.apache.jackrabbit.webdav.property.DavProperty;
-import org.apache.jackrabbit.webdav.property.DavPropertyIterator;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
-import org.apache.jackrabbit.webdav.property.DavPropertyNameIterator;
-import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
 import org.apache.jackrabbit.webdav.property.DavPropertySet;
 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
 import org.apache.jackrabbit.webdav.property.HrefProperty;
@@ -81,11 +78,11 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.HashSet;
 
 /**
  * DavResourceImpl implements a DavResource.
@@ -128,42 +125,6 @@
      * @param locator
      * @param factory
      * @param session
-     * @deprecated
-     */
-    public DavResourceImpl(DavResourceLocator locator, DavResourceFactory factory,
-                           DavSession session, ResourceConfig config) throws DavException {
-        JcrDavSession.checkImplementation(session);
-        this.session = (JcrDavSession)session;
-        this.factory = factory;
-        this.locator = locator;
-        this.config = config;
-
-        if (locator != null && locator.getRepositoryPath() != null) {
-            try {
-                Item item = getJcrSession().getItem(locator.getRepositoryPath());
-                if (item != null && item.isNode()) {
-                    node = (Node) item;
-                    // define what is a collection in webdav
-                    isCollection = config.isCollectionResource(node);
-                    initRfc4122Uri();
-                }
-            } catch (PathNotFoundException e) {
-                // ignore: exists field evaluates to false
-            } catch (RepositoryException e) {
-                // some other error
-                throw new JcrDavException(e);
-            }
-        } else {
-            throw new DavException(DavServletResponse.SC_NOT_FOUND);
-        }
-    }
-
-    /**
-     * Create a new {@link DavResource}.
-     *
-     * @param locator
-     * @param factory
-     * @param session
      * @param config
      * @param isCollection
      * @throws DavException
@@ -259,17 +220,6 @@
     }
 
     /**
-     * Package protected method that allows to define whether this resource
-     * represents a collection or not.
-     *
-     * @param isCollection
-     * @deprecated Use the constructor taking a boolean flag instead.
-     */
-    void setIsCollection(boolean isCollection) {
-        this.isCollection = isCollection;
-    }
-
-    /**
      * @see org.apache.jackrabbit.webdav.DavResource#getLocator()
      */
     public DavResourceLocator getLocator() {
@@ -456,28 +406,6 @@
         }
     }
 
-    /**
-     * @see DavResource#alterProperties(DavPropertySet, DavPropertyNameSet)
-     */
-    public MultiStatusResponse alterProperties(DavPropertySet setProperties,
-                                               DavPropertyNameSet removePropertyNames)
-            throws DavException {
-        List changeList = new ArrayList();
-        if (removePropertyNames != null) {
-            DavPropertyNameIterator it = removePropertyNames.iterator();
-            while (it.hasNext()) {
-                changeList.add(it.next());
-            }
-        }
-        if (setProperties != null) {
-            DavPropertyIterator it = setProperties.iterator();
-            while (it.hasNext()) {
-                changeList.add(it.next());
-            }
-        }
-        return alterProperties(changeList);
-    }
-
     public MultiStatusResponse alterProperties(List changeList) throws DavException {
         if (isLocked(this)) {
             throw new DavException(DavServletResponse.SC_LOCKED);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionHistoryResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionHistoryResourceImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionHistoryResourceImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionHistoryResourceImpl.java Wed Jul  8 13:57:13 2009
@@ -31,8 +31,6 @@
 import org.apache.jackrabbit.webdav.property.ResourceType;
 import org.apache.jackrabbit.webdav.property.DavProperty;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
-import org.apache.jackrabbit.webdav.property.DavPropertySet;
-import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
 import org.apache.jackrabbit.webdav.version.VersionHistoryResource;
 import org.apache.jackrabbit.webdav.version.VersionResource;
 import org.slf4j.Logger;
@@ -156,15 +154,6 @@
     /**
      * Version storage is read-only -> fails with 403.
      *
-     * @see DavResource#alterProperties(DavPropertySet, DavPropertyNameSet)
-     */
-    public MultiStatusResponse alterProperties(DavPropertySet setProperties, DavPropertyNameSet removePropertyNames) throws DavException {
-        throw new DavException(DavServletResponse.SC_FORBIDDEN);
-    }
-
-    /**
-     * Version storage is read-only -> fails with 403.
-     *
      * @see DavResource#alterProperties(List)
      */
     public MultiStatusResponse alterProperties(List changeList) throws DavException {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionResourceImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionResourceImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionResourceImpl.java Wed Jul  8 13:57:13 2009
@@ -32,8 +32,6 @@
 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
 import org.apache.jackrabbit.webdav.property.HrefProperty;
 import org.apache.jackrabbit.webdav.property.DavProperty;
-import org.apache.jackrabbit.webdav.property.DavPropertySet;
-import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
 import org.apache.jackrabbit.webdav.version.LabelInfo;
 import org.apache.jackrabbit.webdav.version.LabelSetProperty;
 import org.apache.jackrabbit.webdav.version.VersionHistoryResource;
@@ -138,15 +136,6 @@
     /**
      * Version storage is read-only -> fails with 403.
      *
-     * @see DavResource#alterProperties(DavPropertySet, DavPropertyNameSet)
-     */
-    public MultiStatusResponse alterProperties(DavPropertySet setProperties, DavPropertyNameSet removePropertyNames) throws DavException {
-        throw new DavException(DavServletResponse.SC_FORBIDDEN);
-    }
-
-    /**
-     * Version storage is read-only -> fails with 403.
-     *
      * @see DavResource#alterProperties(List)
      */
     public MultiStatusResponse alterProperties(List changeList) throws DavException {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/pom.xml?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/pom.xml (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/pom.xml Wed Jul  8 13:57:13 2009
@@ -58,8 +58,8 @@
         </configuration>
       </plugin>
       <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>rat-maven-plugin</artifactId>
+        <groupId>org.apache.rat</groupId>
+        <artifactId>apache-rat-plugin</artifactId>
         <configuration>
           <excludes>
             <exclude>**/nodetype/spec/*.txt</exclude>

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java Wed Jul  8 13:57:13 2009
@@ -49,9 +49,9 @@
 public abstract class AbstractJCRTest extends JUnitTest {
 
     /**
-     * Helper object to access repository transparently
+     * Pool of helper objects to access repository transparently
      */
-    public static RepositoryHelper helper = new RepositoryHelper();
+    private static final RepositoryHelperPool HELPER_POOL = new RepositoryHelperPoolImpl();
 
     /**
      * Namespace URI for jcr prefix.
@@ -74,6 +74,11 @@
     public static final String NS_SV_URI = "http://www.jcp.org/jcr/sv/1.0";
 
     /**
+     * The repository helper for this test.
+     */
+    private RepositoryHelper helper;
+
+    /**
      * JCR Name jcr:primaryType using the namespace resolver of the current session.
      */
     protected String jcrPrimaryType;
@@ -104,6 +109,11 @@
     protected String jcrVersionHistory;
 
     /**
+     * JCR Name jcr:copiedFrom using the namespace resolver of the current session.
+     */
+    protected String jcrCopiedFrom;
+
+    /**
      * JCR Name jcr:frozenNode using the namespace resolver of the current session.
      */
     protected String jcrFrozenNode;
@@ -279,6 +289,11 @@
      */
     protected Node testRootNode;
 
+    /**
+     * The value factory for {@link #superuser}.
+     */
+    protected ValueFactory vf;
+
     protected void setUp() throws Exception {
         super.setUp();
         testRoot = getProperty(RepositoryStub.PROP_TESTROOT);
@@ -320,7 +335,7 @@
             fail("Property '" + RepositoryStub.PROP_WORKSPACE_NAME + "' is not defined.");
         }
 
-        superuser = helper.getSuperuserSession();
+        superuser = getHelper().getSuperuserSession();
 
         // setup some common names
         jcrPrimaryType = superuser.getNamespacePrefix(NS_JCR_URI) + ":primaryType";
@@ -329,6 +344,7 @@
         jcrSuccessors = superuser.getNamespacePrefix(NS_JCR_URI) + ":successors";
         jcrCreated = superuser.getNamespacePrefix(NS_JCR_URI) + ":created";
         jcrVersionHistory = superuser.getNamespacePrefix(NS_JCR_URI) + ":versionHistory";
+        jcrCopiedFrom = superuser.getNamespacePrefix(NS_JCR_URI) + ":copiedFrom";
         jcrFrozenNode = superuser.getNamespacePrefix(NS_JCR_URI) + ":frozenNode";
         jcrFrozenUuid = superuser.getNamespacePrefix(NS_JCR_URI) + ":frozenUuid";
         jcrRootVersion = superuser.getNamespacePrefix(NS_JCR_URI) + ":rootVersion";
@@ -369,6 +385,7 @@
                     }
                 }
             }
+            vf = superuser.getValueFactory();
         }
 
         if (isReadOnly) {
@@ -384,7 +401,7 @@
         } else if (isSupported(Repository.LEVEL_2_SUPPORTED)) {
             testRootNode = cleanUpTestRoot(superuser);
             // also clean second workspace
-            Session s = helper.getSuperuserSession(workspaceName);
+            Session s = getHelper().getSuperuserSession(workspaceName);
             try {
                 cleanUpTestRoot(s);
             } finally {
@@ -407,6 +424,7 @@
             } finally {
                 superuser.logout();
                 superuser = null;
+                vf = null;
             }
         }
         testRootNode = null;
@@ -426,7 +444,24 @@
      * @param testResult the test result.
      */
     public void run(TestResult testResult) {
-        super.run(new JCRTestResult(testResult, log));
+        try {
+            helper = HELPER_POOL.borrowHelper();
+            try {
+                super.run(new JCRTestResult(testResult, log));
+            } finally {
+                HELPER_POOL.returnHelper(helper);
+                helper = null;
+            }
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * @return the repository helper instance that is associated with this test.
+     */
+    protected RepositoryHelper getHelper() {
+        return helper;
     }
 
     /**
@@ -462,28 +497,28 @@
         }
 
         // 1) test case specific property first
-        String value = helper.getProperty(RepositoryStub.PROP_PREFIX + "."
+        String value = getHelper().getProperty(RepositoryStub.PROP_PREFIX + "."
                 + testClassName + "." + testCaseName + "." + propName);
         if (value != null) {
             return value;
         }
 
         // 2) check test class property
-        value = helper.getProperty(RepositoryStub.PROP_PREFIX + "."
+        value = getHelper().getProperty(RepositoryStub.PROP_PREFIX + "."
                 + testClassName + "." + propName);
         if (value != null) {
             return value;
         }
 
         // 3) check package property
-        value = helper.getProperty(RepositoryStub.PROP_PREFIX + "."
+        value = getHelper().getProperty(RepositoryStub.PROP_PREFIX + "."
                 + testPackName + "." + propName);
         if (value != null) {
             return value;
         }
 
         // finally try global property
-        return helper.getProperty(RepositoryStub.PROP_PREFIX + "." + propName);
+        return getHelper().getProperty(RepositoryStub.PROP_PREFIX + "." + propName);
     }
 
     /**
@@ -548,6 +583,21 @@
     }
 
     /**
+     * Returns the local name for the given <code>name</code>.
+     *
+     * @param name the name.
+     * @return the local name part.
+     */
+    protected static String getLocalName(String name) {
+        int idx = name.indexOf(':');
+        if (idx != -1) {
+            return name.substring(idx + 1);
+        } else {
+            return name;
+        }
+    }
+
+    /**
      * Returns the name of a workspace that is not accessible from
      * <code>session</code>.
      * @param session the session.
@@ -593,7 +643,7 @@
      * @throws RepositoryException if an error occurs.
      */
     protected boolean isSupported(String descriptorKey) throws RepositoryException {
-        return "true".equals(helper.getRepository().getDescriptor(descriptorKey));
+        return "true".equals(getHelper().getRepository().getDescriptor(descriptorKey));
     }
 
     /**
@@ -605,7 +655,7 @@
      * @throws NotExecutableException If the feature is not supported.
      */
     protected void checkSupportedOption(String descriptorKey) throws RepositoryException, NotExecutableException {
-        String value = helper.getRepository().getDescriptor(descriptorKey);
+        String value = getHelper().getRepository().getDescriptor(descriptorKey);
         if (value == null || ! Boolean.valueOf(value).booleanValue()) {
             throw new NotExecutableException (
                     "Repository feature not supported: " + descriptorKey);
@@ -708,7 +758,28 @@
             throw new NotExecutableException("Repository does not support node type " + nodetype);
         }
     }
-    
+
+    /**
+     * Ensures that the given <code>node</code> is of the given mixin type.
+     *
+     * @param node  a node.
+     * @param mixin the name of a mixin type.
+     * @throws NotExecutableException if the node is not of type mixin and the
+     *                                mixin cannot be added.
+     * @throws RepositoryException    if an error occurs.
+     */
+    protected void ensureMixinType(Node node, String mixin)
+            throws NotExecutableException, RepositoryException {
+        if (!node.isNodeType(mixin)) {
+            if (node.canAddMixin(mixin)) {
+                node.addMixin(mixin);
+            } else {
+                throw new NotExecutableException(node.getPath() +
+                        " does not support adding " + mixin);
+            }
+        }
+    }
+
     /**
      * Checks whether the node already has the specified mixin node type
      */

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/JCRTestSuite.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/JCRTestSuite.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/JCRTestSuite.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/JCRTestSuite.java Wed Jul  8 13:57:13 2009
@@ -16,12 +16,10 @@
  */
 package org.apache.jackrabbit.test;
 
-import junit.framework.TestSuite;
-
 /**
  * Test suite that includes all the JCR API tests
  */
-public class JCRTestSuite extends TestSuite {
+public class JCRTestSuite extends ConcurrentTestSuite {
 
     public JCRTestSuite() {
         super("JCR API tests");

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryStub.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryStub.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryStub.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/RepositoryStub.java Wed Jul  8 13:57:13 2009
@@ -170,7 +170,7 @@
      * @return a <code>RepositoryStub</code> implementation.
      * @throws RepositoryStubException
      */
-    static synchronized RepositoryStub getInstance(Map configuration)
+    public static synchronized RepositoryStub getInstance(Map configuration)
         throws RepositoryStubException {
         Properties props = null;
         RepositoryStub stub = null;

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractPropertyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractPropertyTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractPropertyTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractPropertyTest.java Wed Jul  8 13:57:13 2009
@@ -59,7 +59,7 @@
     protected void setUp() throws Exception {
         isReadOnly = true;
         super.setUp();
-        session = helper.getReadOnlySession();
+        session = getHelper().getReadOnlySession();
 
         prop = PropertyUtil.searchProp(session, session.getRootNode().getNode(testPath), getPropertyType(), getPropertyIsMultivalued());
         if (prop == null) {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyBetweenTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyBetweenTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyBetweenTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractWorkspaceCopyBetweenTest.java Wed Jul  8 13:57:13 2009
@@ -66,8 +66,8 @@
 
         // init second workspace
         String otherWspName = getOtherWorkspaceName();
-        superuserW2 = helper.getSuperuserSession(otherWspName);
-        rwSessionW2 = helper.getReadWriteSession(otherWspName);
+        superuserW2 = getHelper().getSuperuserSession(otherWspName);
+        rwSessionW2 = getHelper().getReadWriteSession(otherWspName);
         workspaceW2 = superuserW2.getWorkspace();
 
         initNodesW2();

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractWorkspaceReferenceableTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractWorkspaceReferenceableTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractWorkspaceReferenceableTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractWorkspaceReferenceableTest.java Wed Jul  8 13:57:13 2009
@@ -53,11 +53,10 @@
      * @param node
      * @return referenceable node.
      */
-    protected Node addMixinReferenceableToNode(Node node) throws RepositoryException {
-        if (!node.isNodeType(mixReferenceable)) {
-            node.addMixin(mixReferenceable);
-            node.save();
-        }
+    protected Node addMixinReferenceableToNode(Node node) throws RepositoryException,
+            NotExecutableException {
+        ensureMixinType(node, mixReferenceable);
+        node.save();
         return node;
     }
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractWorkspaceVersionableTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractWorkspaceVersionableTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractWorkspaceVersionableTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractWorkspaceVersionableTest.java Wed Jul  8 13:57:13 2009
@@ -52,11 +52,9 @@
     /**
      * add the mix:versionable mixin type to a node.
      */
-    protected Node addMixinVersionableToNode(Node parent, Node node) throws RepositoryException {
-        NodeType nodetype = node.getPrimaryNodeType();
-        if (!nodetype.isNodeType(mixVersionable)) {
-            node.addMixin(mixVersionable);
-        }
+    protected Node addMixinVersionableToNode(Node parent, Node node) throws RepositoryException,
+            NotExecutableException {
+        ensureMixinType(node, mixVersionable);
         parent.save();
 
         return node;

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AddNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AddNodeTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AddNodeTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AddNodeTest.java Wed Jul  8 13:57:13 2009
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.test.api;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Node;
@@ -24,6 +25,9 @@
 import javax.jcr.ItemExistsException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.Session;
 
 /**
@@ -92,6 +96,49 @@
     }
 
     /**
+     * Tests if addNode() throws a ConstraintViolationException in case
+     * of an abstract node type.
+     */
+    public void testAbstractNodeType() throws RepositoryException {
+        NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
+        NodeTypeIterator nts = ntMgr.getPrimaryNodeTypes();
+        while (nts.hasNext()) {
+            NodeType nt = nts.nextNodeType();
+            if (nt.isAbstract()) {
+                try {
+                    testRootNode.addNode(nodeName1, nt.getName());
+                    superuser.save();
+                    fail("Expected ConstraintViolationException.");
+                } catch (ConstraintViolationException e) {
+                    // correct.
+                } finally {
+                    superuser.refresh(false);
+                }
+            }
+        }
+    }
+
+    /**
+     * Tests if addNode() throws a ConstraintViolationException in case
+     * of an mixin node type.
+     */
+    public void testMixinNodeType() throws RepositoryException, NotExecutableException {
+        NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
+        NodeTypeIterator nts = ntMgr.getMixinNodeTypes();
+        if (nts.hasNext()) {
+            try {
+                testRootNode.addNode(nodeName1, nts.nextNodeType().getName());
+                superuser.save();
+                fail("Expected ConstraintViolationException.");
+            } catch (ConstraintViolationException e) {
+                // correct.
+            }
+        } else {
+            throw new NotExecutableException("no mixins.");
+        }
+    }
+
+    /**
      * Tests if the path of the created node is correct.
      */
     public void testPath() throws RepositoryException {
@@ -164,7 +211,7 @@
         defaultRootNode.save();
 
         // use a different session to verify if the node is there
-        Session session = helper.getReadOnlySession();
+        Session session = getHelper().getReadOnlySession();
         try {
             session.getItem(testNode.getPath());
         } finally {
@@ -188,7 +235,7 @@
         superuser.save();
 
         // use a different session to verify if the node is there
-        Session session = helper.getReadOnlySession();
+        Session session = getHelper().getReadOnlySession();
         try {
             session.getItem(testNode.getPath());
         } finally {



Mime
View raw message