jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r590762 - in /jackrabbit/trunk: jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/ jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/
Date Wed, 31 Oct 2007 17:31:21 GMT
Author: reschke
Date: Wed Oct 31 10:31:20 2007
New Revision: 590762

URL: http://svn.apache.org/viewvc?rev=590762&view=rev
Log:
JCR-1200: add QValueFactory.computeAutoValues(), use it in jcr2spi SessionItemStateManager
and spi-commons QValueFactoryImpl.

Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QValueFactory.java

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?rev=590762&r1=590761&r2=590762&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
Wed Oct 31 10:31:20 2007
@@ -54,7 +54,6 @@
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
-import org.apache.jackrabbit.uuid.UUID;
 import org.apache.jackrabbit.name.NameConstants;
 
 import javax.jcr.InvalidItemStateException;
@@ -74,7 +73,6 @@
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.lock.LockException;
 import java.util.Iterator;
-import java.util.Calendar;
 import java.io.InputStream;
 
 /**
@@ -712,31 +710,18 @@
             // properties without default values
             Name declaringNT = def.getDeclaringNodeType();
             Name name = def.getName();
-            if (NameConstants.MIX_REFERENCEABLE.equals(declaringNT) && NameConstants.JCR_UUID.equals(name))
{
-                // mix:referenceable node type defines jcr:uuid
-                genValues = getQValues(parent.getUniqueID(), qValueFactory);
-            } else if (NameConstants.NT_BASE.equals(declaringNT)) {
-                // nt:base node type
-                if (NameConstants.JCR_PRIMARYTYPE.equals(name)) {
-                    // jcr:primaryType property
-                    genValues = new QValue[]{qValueFactory.create(parent.getNodeTypeName())};
-                } else if (NameConstants.JCR_MIXINTYPES.equals(name)) {
-                    // jcr:mixinTypes property
-                    Name[] mixins = parent.getMixinTypeNames();
-                    genValues = getQValues(mixins, qValueFactory);
-                }
-            } else if (NameConstants.NT_HIERARCHYNODE.equals(declaringNT) && NameConstants.JCR_CREATED.equals(name))
{
-                // nt:hierarchyNode node type defines jcr:created property
-                genValues = new QValue[]{qValueFactory.create(Calendar.getInstance())};
-            } else if (NameConstants.NT_RESOURCE.equals(declaringNT) && NameConstants.JCR_LASTMODIFIED.equals(name))
{
-                // nt:resource node type defines jcr:lastModified property
-                genValues = new QValue[]{qValueFactory.create(Calendar.getInstance())};
-            } else if (NameConstants.NT_VERSION.equals(declaringNT) && NameConstants.JCR_CREATED.equals(name))
{
-                // nt:version node type defines jcr:created property
-                genValues = new QValue[]{qValueFactory.create(Calendar.getInstance())};
-            } else {
-                // TODO: TOBEFIXED. other nodetype -> build some default value
-                log.warn("Missing implementation. Nodetype " + def.getDeclaringNodeType()
+ " defines autocreated property " + def.getName() + " without default value.");
+
+            if (NameConstants.NT_BASE.equals(declaringNT) && NameConstants.JCR_PRIMARYTYPE.equals(name))
{
+                // jcr:primaryType property
+                genValues = new QValue[]{qValueFactory.create(parent.getNodeTypeName())};
+            } else if (NameConstants.NT_BASE.equals(declaringNT) && NameConstants.JCR_MIXINTYPES.equals(name))
{
+                // jcr:mixinTypes property
+                Name[] mixins = parent.getMixinTypeNames();
+                genValues = getQValues(mixins, qValueFactory);
+            }
+            else {
+                // ask the SPI implementation for advice
+                genValues = qValueFactory.computeAutoValues(def);
             }
         }
         return genValues;
@@ -756,9 +741,6 @@
     }
 
     private static QValue[] getQValues(String uniqueID, QValueFactory factory) throws RepositoryException
{
-        if (uniqueID == null) {
-            uniqueID = UUID.randomUUID().toString();
-        }
         return new QValue[] {factory.create(uniqueID, PropertyType.STRING)};
     }
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java?rev=590762&r1=590761&r2=590762&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
Wed Oct 31 10:31:20 2007
@@ -16,16 +16,19 @@
  */
 package org.apache.jackrabbit.value;
 
+import org.apache.jackrabbit.name.NameConstants;
 import org.apache.jackrabbit.name.PathFactoryImpl;
 import org.apache.jackrabbit.name.NameFactoryImpl;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.PathFactory;
 import org.apache.jackrabbit.spi.NameFactory;
 import org.apache.jackrabbit.util.TransientFileFactory;
 import org.apache.jackrabbit.util.ISO8601;
+import org.apache.jackrabbit.uuid.UUID;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFormatException;
@@ -185,6 +188,24 @@
             throw new IllegalArgumentException("Cannot create QValue from null value.");
         }
         return new BinaryQValue(value);
+    }
+
+    /**
+     * @see QValueFactory#computeAutoValues(QPropertyDefinition)
+     */
+    public QValue[] computeAutoValues(QPropertyDefinition propertyDefinition) throws RepositoryException
{
+        Name nodeType = propertyDefinition.getDeclaringNodeType();
+        Name name = propertyDefinition.getName();
+
+        if (NameConstants.NT_HIERARCHYNODE.equals(nodeType) && NameConstants.JCR_CREATED.equals(name))
{
+            return new QValue[] { create(Calendar.getInstance()) };
+        } else if (NameConstants.NT_RESOURCE.equals(nodeType) && NameConstants.JCR_LASTMODIFIED.equals(name))
{
+            return new QValue[] { create(Calendar.getInstance()) };
+        } else if (NameConstants.MIX_REFERENCEABLE.equals(nodeType) && NameConstants.JCR_UUID.equals(name))
{
+            return new QValue[] { create(UUID.randomUUID().toString(), PropertyType.STRING)
};
+        } else {
+            throw new RepositoryException("createFromDefinition not implemented for: " +
name);
+        }
     }
 
     //--------------------------------------------------------< Inner Class >---

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QValueFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QValueFactory.java?rev=590762&r1=590761&r2=590762&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QValueFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QValueFactory.java
Wed Oct 31 10:31:20 2007
@@ -114,4 +114,15 @@
      * @throws IOException
      */
     public QValue create(File value) throws RepositoryException, IOException;
+    
+    /**
+     * Given the <code>QPropertyDefinition</code> of an <em>autocreated</em>
+     * property, compute suitable values to be used in transient space until
+     * the newly created node gets saved.
+     * 
+     * @param propertyDefinition definition of property for which values should be created
+     * @return computed value
+     * @throws RepositoryException
+     */
+    public QValue[] computeAutoValues(QPropertyDefinition propertyDefinition) throws RepositoryException;
 }



Mime
View raw message