jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r497885 [2/2] - in /jackrabbit/trunk/contrib/spi: ./ commons/ commons/src/main/java/org/apache/jackrabbit/value/ commons/src/test/java/org/apache/jackrabbit/value/ jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jcr2spi/src/main/java/o...
Date Fri, 19 Jan 2007 17:37:08 GMT
Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java Fri Jan 19 09:37:03 2007
@@ -22,7 +22,7 @@
 import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
-import org.apache.jackrabbit.value.QValue;
+import org.apache.jackrabbit.spi.QValue;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java Fri Jan 19 09:37:03 2007
@@ -28,7 +28,6 @@
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.ChildInfo;
-import org.apache.jackrabbit.value.QValue;
 import org.apache.jackrabbit.jcr2spi.WorkspaceManager;
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeConflictException;
@@ -36,17 +35,14 @@
 
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
-import javax.jcr.PropertyType;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
-import java.io.IOException;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.Collections;
 import java.util.Arrays;
 import java.util.Iterator;
-import java.util.Collection;
 
 /**
  * <code>WorkspaceItemStateFactory</code>...
@@ -213,9 +209,9 @@
         throws NoSuchItemStateException, ItemStateException {
         try {
             ChildNodeEntries entries = new ChildNodeEntries(nodeState);
-            Collection childInfos = service.getChildInfos(sessionInfo, nodeState.getNodeId());
-            for (Iterator it = childInfos.iterator(); it.hasNext();) {
-                ChildInfo ci = (ChildInfo) it.next();
+            Iterator childInfos = service.getChildInfos(sessionInfo, nodeState.getNodeId());
+            while (childInfos.hasNext()) {
+                ChildInfo ci = (ChildInfo) childInfos.next();
                 entries.add(ci.getName(), ci.getUniqueID(), ci.getIndex());
             }
             return entries;
@@ -247,22 +243,11 @@
             // build the PropertyState
             PropertyState state = new PropertyState(info.getQName(), parent,
                 def, Status.EXISTING, this, service.getIdFactory(), true);
-
-            QValue[] qValues;
-            if (info.getType() == PropertyType.BINARY) {
-                qValues = QValue.create(info.getValuesAsStream(), PropertyType.BINARY);
-            } else {
-                String[] str = info.getValues();
-                qValues = QValue.create(str, info.getType());
-            }
-
-            state.init(info.getType(), qValues);
+            state.init(info.getType(), info.getValues());
             state.addListener(cache);
             cache.created(state);
 
             return state;
-        } catch (IOException e) {
-            throw new ItemStateException(e.getMessage(), e);
         } catch (NodeTypeConflictException e) {
             String msg = "internal error: failed to build property state.";
             log.debug(msg);

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/ReferenceChangeTracker.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/ReferenceChangeTracker.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/ReferenceChangeTracker.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/ReferenceChangeTracker.java Fri Jan 19 09:37:03 2007
@@ -17,7 +17,8 @@
 package org.apache.jackrabbit.jcr2spi.util;
 
 import org.apache.jackrabbit.jcr2spi.state.PropertyState;
-import org.apache.jackrabbit.value.QValue;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -79,18 +80,19 @@
      * Returns the new UUID to which <code>oldUUID</code> has been mapped
      * or <code>null</code> if no such mapping exists.
      *
-     * @param oldReference old uuid represented by the given <code>QValue</code>
+     * @param oldReference old uuid represented by the given <code>QValue</code>.
+     * @param factory
      * @return mapped new QValue of the reference value or <code>null</code> if no such mapping exists
      * @see #mappedUUIDs(String,String)
      */
-    public QValue getMappedReference(QValue oldReference) {
+    public QValue getMappedReference(QValue oldReference, QValueFactory factory) {
         QValue remapped = null;
         if (oldReference.getType() == PropertyType.REFERENCE) {
             try {
                 String oldValue = oldReference.getString();
                 if (uuidMap.containsKey(oldValue)) {
                     String newValue = uuidMap.get(oldValue).toString();
-                    remapped = QValue.create(newValue, PropertyType.REFERENCE);
+                    remapped = factory.create(newValue, PropertyType.REFERENCE);
                 }
             } catch (RepositoryException e) {
                 log.error("Unexpected error while creating internal value.", e);

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java Fri Jan 19 09:37:03 2007
@@ -59,7 +59,7 @@
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.value.QValue;
+import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.value.ValueHelper;
 import org.apache.jackrabbit.value.ValueFormat;
 
@@ -606,7 +606,7 @@
                         Base64.decode(tv.retrieve(), baos);
                         // no need to close ByteArrayOutputStream
                         //baos.close();
-                        iv = QValue.create(baos.toByteArray());
+                        iv = session.getQValueFactory().create(baos.toByteArray());
                     } else {
                         // >= 65kb: deserialize BINARY type
                         // using Reader and temporay file
@@ -620,13 +620,13 @@
                             reader.close();
                             out.close();
                         }
-                        iv = QValue.create(tmpFile);
+                        iv = session.getQValueFactory().create(tmpFile);
                     }
                     break;
                 default:
                     // build iv using namespace context of xml document
                     Value v = ValueHelper.convert(tv.retrieve(), targetType, session.getValueFactory());
-                    iv = ValueFormat.getQValue(v, nsResolver);
+                    iv = ValueFormat.getQValue(v, nsResolver, session.getQValueFactory());
                     break;
             }
             return iv;

Modified: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/Batch.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/Batch.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/Batch.java (original)
+++ jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/Batch.java Fri Jan 19 09:37:03 2007
@@ -27,7 +27,6 @@
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.version.VersionException;
-import java.io.InputStream;
 
 /**
  * <code>Batch</code>...
@@ -63,7 +62,6 @@
      * @param parentId
      * @param propertyName Name of the property to be created
      * @param value
-     * @param propertyType
      * @throws ValueFormatException
      * @throws VersionException
      * @throws LockException
@@ -85,13 +83,12 @@
      * @see javax.jcr.Session#importXML(String, java.io.InputStream, int)
      * @see javax.jcr.query.Query#storeAsNode(String)
      */
-    public void addProperty(NodeId parentId, QName propertyName, String value, int propertyType) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException;
+    public void addProperty(NodeId parentId, QName propertyName, QValue value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException;
 
     /**
      * @param parentId
      * @param propertyName Name of the property to be created
      * @param values
-     * @param propertyType the property type
      * @throws javax.jcr.ValueFormatException
      * @throws javax.jcr.version.VersionException
      * @throws javax.jcr.lock.LockException
@@ -107,57 +104,12 @@
      * @see javax.jcr.Node#setProperty(String, String[], int)
      * @see javax.jcr.Session#importXML(String, java.io.InputStream, int)
      */
-    public void addProperty(NodeId parentId, QName propertyName, String[] values, int propertyType) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException;
-
-    /**
-     *
-     * @param parentId
-     * @param propertyName Name of the property to be created
-     * @param value
-     * @param propertyType
-     * @throws ValueFormatException
-     * @throws VersionException
-     * @throws LockException
-     * @throws ConstraintViolationException
-     * @throws PathNotFoundException
-     * @throws ItemExistsException
-     * @throws AccessDeniedException
-     * @throws UnsupportedRepositoryOperationException
-     * @throws RepositoryException
-     * @see javax.jcr.Node#setProperty(String, javax.jcr.Value, int)
-     * @see javax.jcr.Node#setProperty(String, String, int)
-     * @see javax.jcr.Node#setProperty(String, java.io.InputStream)
-     * @see javax.jcr.Session#importXML(String, java.io.InputStream, int)
-     */
-    public void addProperty(NodeId parentId, QName propertyName, InputStream value, int propertyType) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException;
-
-    /**
-     * @param parentId
-     * @param propertyName Name of the property to be created
-     * @param values
-     * @param propertyType the property type
-     * @throws javax.jcr.ValueFormatException
-     * @throws javax.jcr.version.VersionException
-     * @throws javax.jcr.lock.LockException
-     * @throws javax.jcr.nodetype.ConstraintViolationException
-     * @throws javax.jcr.PathNotFoundException
-     * @throws javax.jcr.ItemExistsException
-     * @throws javax.jcr.AccessDeniedException
-     * @throws javax.jcr.UnsupportedRepositoryOperationException
-     * @throws javax.jcr.RepositoryException
-     * @see javax.jcr.Node#setProperty(String, javax.jcr.Value[])
-     * @see javax.jcr.Node#setProperty(String, javax.jcr.Value[], int)
-     * @see javax.jcr.Node#setProperty(String, String[])
-     * @see javax.jcr.Node#setProperty(String, String[], int)
-     * @see javax.jcr.Session#importXML(String, java.io.InputStream, int)
-     */
-    public void addProperty(NodeId parentId, QName propertyName, InputStream[] values, int propertyType) throws RepositoryException;
+    public void addProperty(NodeId parentId, QName propertyName, QValue[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException;
 
     /**
      *
      * @param propertyId
      * @param value
-     * @param propertyType
      * @throws ValueFormatException
      * @throws VersionException
      * @throws LockException
@@ -173,12 +125,11 @@
      * @see javax.jcr.Property#setValue(boolean)
      * @see javax.jcr.Property#setValue(javax.jcr.Node)
      */
-    public void setValue(PropertyId propertyId, String value, int propertyType) throws RepositoryException;
+    public void setValue(PropertyId propertyId, QValue value) throws RepositoryException;
 
     /**
      * @param propertyId
      * @param values
-     * @param propertyType the type of the property
      * @throws javax.jcr.ValueFormatException
      * @throws javax.jcr.version.VersionException
      * @throws javax.jcr.lock.LockException
@@ -189,39 +140,7 @@
      * @see javax.jcr.Property#setValue(javax.jcr.Value[])
      * @see javax.jcr.Property#setValue(String[])
      */
-    public void setValue(PropertyId propertyId, String[] values, int propertyType) throws RepositoryException;
-
-    /**
-     *
-     * @param propertyId
-     * @param value
-     * @param propertyType
-     * @throws ValueFormatException
-     * @throws VersionException
-     * @throws LockException
-     * @throws ConstraintViolationException
-     * @throws AccessDeniedException
-     * @throws UnsupportedRepositoryOperationException
-     * @throws RepositoryException
-     * @see javax.jcr.Property#setValue(javax.jcr.Value)
-     * @see javax.jcr.Property#setValue(java.io.InputStream)
-     */
-    public void setValue(PropertyId propertyId, InputStream value, int propertyType) throws RepositoryException;
-
-    /**
-     * @param propertyId
-     * @param values
-     * @param propertyType the type of the property
-     * @throws javax.jcr.ValueFormatException
-     * @throws javax.jcr.version.VersionException
-     * @throws javax.jcr.lock.LockException
-     * @throws javax.jcr.nodetype.ConstraintViolationException
-     * @throws javax.jcr.AccessDeniedException
-     * @throws javax.jcr.UnsupportedRepositoryOperationException
-     * @throws javax.jcr.RepositoryException
-     * @see javax.jcr.Property#setValue(javax.jcr.Value[])
-     */
-    public void setValue(PropertyId propertyId, InputStream[] values, int propertyType) throws RepositoryException;
+    public void setValue(PropertyId propertyId, QValue[] values) throws RepositoryException;
 
     /**
      * @param itemId
@@ -279,4 +198,4 @@
      * @see javax.jcr.Session#move(String, String)
      */
     public void move(NodeId srcNodeId, NodeId destParentNodeId, QName destName) throws RepositoryException;
-}
\ No newline at end of file
+}

Modified: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/PropertyInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/PropertyInfo.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/PropertyInfo.java (original)
+++ jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/PropertyInfo.java Fri Jan 19 09:37:03 2007
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.spi;
 
-import java.io.InputStream;
-
 /**
  * <code>PropertyInfo</code>...
  */
@@ -31,7 +29,10 @@
     public PropertyId getId();
 
     /**
-     * @return
+     * @return The {@link javax.jcr.PropertyType type} of the <code>Property</code>
+     * base on this <code>PropertyInfo</code>. Note, that
+     * {@link javax.jcr.PropertyType#UNDEFINED} will never be returned as the
+     * value of a <code>Property</code> always has a defined type.
      * @see javax.jcr.PropertyType
      */
     public int getType();
@@ -44,12 +45,7 @@
     public boolean isMultiValued();
 
     /**
-     * @return String representation of the property value(s)
-     */
-    public String[] getValues();
-
-    /**
-     * @return InputStream representation of the property value(s)
+     * @return Qualified values present on this <code>PropertyInfo</code>.
      */
-    public InputStream[] getValuesAsStream();
-}
\ No newline at end of file
+    public QValue[] getValues();
+}

Modified: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QPropertyDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QPropertyDefinition.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QPropertyDefinition.java (original)
+++ jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QPropertyDefinition.java Fri Jan 19 09:37:03 2007
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.spi;
 
 import javax.jcr.nodetype.PropertyDefinition;
-import java.io.InputStream;
 
 /**
  * <code>QPropertyDefinition</code> is the qualified SPI representation of
@@ -46,18 +45,12 @@
     String[] getValueConstraints();
 
     /**
-     * Returns the array of default values.
+     * Returns the array of default values or <code>null</code> if no default
+     * values are defined.
      *
-     * @return the array of default values.
+     * @return the array of default values or <code>null</code>
      */
-    String[] getDefaultValues();
-
-    /**
-     * Returns the array of default values.
-     *
-     * @return the array of default values.
-     */
-    InputStream[] getDefaultValuesAsStream();
+    QValue[] getDefaultValues();
 
     /**
      * Reports whether this property can have multiple values.

Added: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValue.java?view=auto&rev=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValue.java (added)
+++ jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValue.java Fri Jan 19 09:37:03 2007
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi;
+
+import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.name.QName;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.PropertyType;
+import javax.jcr.Property;
+import java.io.InputStream;
+
+/**
+ * <code>QValue</code>...
+ */
+public interface QValue {
+
+    public static final QValue[] EMPTY_ARRAY = new QValue[0];
+
+    /**
+     * Returns the <code>PropertyType</code> of this <code>QValue</code> object.
+     * It may be either of the value property types defined by the JSR 170:
+     * <ul>
+     * <li>{@link PropertyType#BINARY<li>
+     * <li>{@link PropertyType#BOOLEAN<li>
+     * <li>{@link PropertyType#DATE<li>
+     * <li>{@link PropertyType#DOUBLE<li>
+     * <li>{@link PropertyType#LONG<li>
+     * <li>{@link PropertyType#NAME<li>
+     * <li>{@link PropertyType#PATH<li>
+     * <li>{@link PropertyType#REFERENCE<li>
+     * <li>{@link PropertyType#STRING<li>
+     * </ul>
+     *
+     * @return
+     */
+    public int getType();
+
+    /**
+     * Returns the length of the internal value.<br>
+     * NOTE: for {@link PropertyType#NAME} and {@link PropertyType#PATH} the
+     * length of the internal value must not be used for indicating the length
+     * of a property such as retrieved by calling {@link Property#getLength()}
+     * and {@link Property#getLengths()}.
+     *
+     * @return length of the internal value.
+     */
+    public long getLength() throws RepositoryException;
+
+    /**
+     *
+     * @return
+     */
+    public String getString() throws RepositoryException;
+
+    /**
+     *
+     * @return
+     * @throws RepositoryException
+     */
+    public InputStream getStream() throws RepositoryException;
+
+    /**
+     * Returns a <code>QName</code> representation of this value.
+     *
+     * @return A <code>QName</code> representation of this value.
+     * @throws RepositoryException if an error occurs.
+     */
+    public QName getQName() throws RepositoryException;
+
+    /**
+     * Returns a <code>Path</code> representation of this value.
+     *
+     * @return A <code>Path</code> representation of this value.
+     * @throws RepositoryException if an error occurs.
+     */
+    public Path getPath() throws RepositoryException;
+
+    /**
+     * Frees temporarily allocated resources such as temporary file, buffer, etc.
+     */
+    public void discard();
+}

Propchange: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValue.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValueFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValueFactory.java?view=auto&rev=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValueFactory.java (added)
+++ jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValueFactory.java Fri Jan 19 09:37:03 2007
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi;
+
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.Path;
+
+import java.io.IOException;
+import java.io.File;
+import java.io.InputStream;
+import java.util.Calendar;
+
+/**
+ * <code>QValueFactory</code>...
+ */
+public interface QValueFactory {
+
+    /**
+     * @param value
+     * @return
+     */
+    public QValue create(String value, int type);
+
+    /**
+     * @param value
+     * @return
+     */
+    public QValue create(Calendar value);
+
+    /**
+     * @param value
+     * @return
+     */
+    public QValue create(QName value);
+
+    /**
+     * @param value
+     * @return
+     */
+    public QValue create(Path value);
+
+
+    /**
+     * @param value
+     * @return
+     */
+    public QValue create(byte[] value);
+
+    /**
+     * @param value
+     * @return
+     * @throws IOException
+     */
+    public QValue create(InputStream value) throws IOException;
+
+    /**
+     * @param value
+     * @return
+     * @throws IOException
+     */
+    public QValue create(File value) throws IOException;
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValueFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValueFactory.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java (original)
+++ jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java Fri Jan 19 09:37:03 2007
@@ -36,10 +36,10 @@
     public double getScore();
     
     /**
-     * @return an array of String representing the values present in this result row
+     * @return an array of <code>QValue</code> representing the values present
+     * in this result row.
      * @see javax.jcr.query.Row#getValue(String)
      * @see javax.jcr.query.Row#getValues()
-     * TODO: switch type to QValue[] when available
      */
-    public String[] getValues(); 
+    public QValue[] getValues();
 }

Modified: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java (original)
+++ jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java Fri Jan 19 09:37:03 2007
@@ -42,6 +42,7 @@
 import javax.jcr.query.InvalidQueryException;
 import java.util.Map;
 import java.util.Collection;
+import java.util.Iterator;
 import java.io.InputStream;
 
 /**
@@ -50,12 +51,19 @@
 public interface RepositoryService {
 
     /**
-     * Return the <code>IdFactory</code>
+     * Return the <code>IdFactory</code>.
      *
      * @return
      */
     public IdFactory getIdFactory();
 
+    /**
+     * Return the <code>QValueFactory</code> defined with this SPI implementation.
+     *
+     * @return
+     */
+    public QValueFactory getQValueFactory();
+
     //--------------------------------------------------------------------------
     /**
      * @return key-value pairs for repository descriptor keys and values.
@@ -197,7 +205,7 @@
      * @throws ItemNotFoundException
      * @throws RepositoryException
      */
-    public Collection getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws ItemNotFoundException, RepositoryException;
+    public Iterator getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws ItemNotFoundException, RepositoryException;
 
     /**
      * @param sessionInfo

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/PropertyInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/PropertyInfoImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/PropertyInfoImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/PropertyInfoImpl.java Fri Jan 19 09:37:03 2007
@@ -26,6 +26,8 @@
 import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.spi.PropertyInfo;
 import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -33,9 +35,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
-import java.io.InputStream;
-import java.io.ByteArrayInputStream;
-import java.io.UnsupportedEncodingException;
+import java.io.IOException;
 
 /**
  * <code>PropertyInfoImpl</code>...
@@ -48,11 +48,12 @@
 
     private int type;
     private boolean isMultiValued;
-    private Object[] values;
+    private QValue[] values;
 
     public PropertyInfoImpl(PropertyId id, NodeId parentId, DavPropertySet propSet,
-                            NamespaceResolver nsResolver, ValueFactory valueFactory)
-        throws RepositoryException, DavException {
+                            NamespaceResolver nsResolver, ValueFactory valueFactory,
+                            QValueFactory qValueFactory)
+        throws RepositoryException, DavException, IOException {
 
         super(parentId);
         // set id
@@ -62,29 +63,32 @@
         String typeName = propSet.get(ItemResourceConstants.JCR_TYPE).getValue().toString();
         type = PropertyType.valueFromName(typeName);
 
+        // values from jcr-server must be converted to qualified values.
         if (propSet.contains(ItemResourceConstants.JCR_VALUE)) {
-            // TODO: jcr-server sends jcr values not qualified
             ValuesProperty vp = new ValuesProperty(propSet.get(ItemResourceConstants.JCR_VALUE), type, valueFactory);
             Value jcrValue = vp.getJcrValue(type, valueFactory);
-            if (type == PropertyType.BINARY) {
-                values = (jcrValue == null) ?  new InputStream[0] : new InputStream[] {jcrValue.getStream()};
+            if (jcrValue == null) {
+                // TODO: should never occur. since 'null' single values are not allowed. rather throw?
+                values = QValue.EMPTY_ARRAY;
             } else {
-                String vStr = (jcrValue == null) ? "" : ValueFormat.getQValue(jcrValue, nsResolver).getString();
-                values = new String[] {vStr};
+                QValue qv;
+                if (type == PropertyType.BINARY) {
+                    qv = qValueFactory.create(jcrValue.getStream());
+                } else {
+                    qv = ValueFormat.getQValue(jcrValue, nsResolver, qValueFactory);
+                }
+                values = new QValue[] {qv};
             }
         } else {
             isMultiValued = true;
             ValuesProperty vp = new ValuesProperty(propSet.get(ItemResourceConstants.JCR_VALUES), type, valueFactory);
             Value[] jcrValues = vp.getJcrValues(type, valueFactory);
-            if (type == PropertyType.BINARY) {
-                values = new InputStream[jcrValues.length];
-                for (int i = 0; i < jcrValues.length; i++) {
-                    values[i] = jcrValues[i].getStream();
-                }
-            } else {
-                values = new String[jcrValues.length];
-                for (int i = 0; i < jcrValues.length; i++) {
-                    values[i] = ValueFormat.getQValue(jcrValues[i], nsResolver).getString();
+            values = new QValue[jcrValues.length];
+            for (int i = 0; i < jcrValues.length; i++) {
+                if (type == PropertyType.BINARY) {
+                    values[i] = qValueFactory.create(jcrValues[i].getStream());
+                } else {
+                    values[i] = ValueFormat.getQValue(jcrValues[i], nsResolver, qValueFactory);
                 }
             }
         }
@@ -112,29 +116,7 @@
         return isMultiValued;
     }
 
-    public String[] getValues() {
-        if (values instanceof InputStream[]) {
-            // TODO
-            throw new UnsupportedOperationException("use getValueAsStream");
-        } else {
-            return (String[])values;
-        }
-    }
-
-    public InputStream[] getValuesAsStream() {
-        if (values instanceof InputStream[]) {
-            return (InputStream[]) values;
-        } else {
-            InputStream[] ins = new InputStream[values.length];
-            for (int i = 0; i < values.length; i++) {
-                String v = (String)values[i];
-                try {
-                    ins[i] = (v != null) ? new ByteArrayInputStream(v.getBytes("UTF-8")) : null;
-                } catch (UnsupportedEncodingException e) {
-                    log.error("Error while converting values", e);
-                }
-            }
-            return ins;
-        }
+    public QValue[] getValues() {
+        return values;
     }
-}
\ No newline at end of file
+}

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java Fri Jan 19 09:37:03 2007
@@ -27,6 +27,7 @@
 import org.apache.jackrabbit.name.NameFormat;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QValueFactory;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -58,7 +59,8 @@
     /**
      * Default constructor.
      */
-    public QNodeTypeDefinitionImpl(Element ntdElement, NamespaceResolver nsResolver)
+    public QNodeTypeDefinitionImpl(Element ntdElement, NamespaceResolver nsResolver,
+                                   QValueFactory qValueFactory)
         throws RepositoryException {
         // TODO: webdav-server currently sends jcr-names -> conversion needed
         // NOTE: the server should send the namespace-mappings as addition ns-defininitions
@@ -111,7 +113,7 @@
         it = DomUtil.getChildren(ntdElement, PROPERTYDEFINITION_ELEMENT, null);
         itemDefs = new ArrayList();
         while (it.hasNext()) {
-            itemDefs.add(new QPropertyDefinitionImpl(name, it.nextElement(), nsResolver));
+            itemDefs.add(new QPropertyDefinitionImpl(name, it.nextElement(), nsResolver, qValueFactory));
         }
         propDefs = (QPropertyDefinition[]) itemDefs.toArray(new QPropertyDefinition[itemDefs.size()]);
         } catch (NameException e) {

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QPropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QPropertyDefinitionImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QPropertyDefinitionImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QPropertyDefinitionImpl.java Fri Jan 19 09:37:03 2007
@@ -20,19 +20,20 @@
 import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.webdav.xml.DomUtil;
 import org.apache.jackrabbit.webdav.xml.ElementIterator;
 import org.apache.jackrabbit.value.ValueFormat;
-import org.apache.jackrabbit.value.QValue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 import java.util.Arrays;
 import java.util.List;
 import java.util.ArrayList;
-import java.io.InputStream;
 
 /**
  * This class implements the <code>QPropertyDefinition</code> interface and additionally
@@ -68,7 +69,8 @@
     /**
      * Default constructor.
      */
-    QPropertyDefinitionImpl(QName declaringNodeType, Element pdefElement, NamespaceResolver nsResolver)
+    QPropertyDefinitionImpl(QName declaringNodeType, Element pdefElement,
+                            NamespaceResolver nsResolver, QValueFactory qValueFactory)
         throws RepositoryException {
         // TODO: webdav server sends jcr names -> nsResolver required. improve this.
         // NOTE: the server should send the namespace-mappings as addition ns-defininitions
@@ -88,12 +90,21 @@
 
         Element child = DomUtil.getChildElement(pdefElement, DEFAULTVALUES_ELEMENT, null);
         if (child == null) {
-            defaultValues = new QValue[0];
+            // No default value defined at all.
+            defaultValues = null;
         } else {
             List vs = new ArrayList();
             ElementIterator it = DomUtil.getChildren(child, DEFAULTVALUE_ELEMENT, null);
             while (it.hasNext()) {
-                QValue qValue = ValueFormat.getQValue(DomUtil.getText(it.nextElement()), requiredType, nsResolver);
+                String jcrVal = DomUtil.getText(it.nextElement());
+                QValue qValue;
+                if (requiredType == PropertyType.BINARY) {
+                    // TODO: improve
+                    Value v = ValueFactoryImpl.getInstance().createValue(jcrVal, requiredType);
+                    qValue = ValueFormat.getQValue(v, nsResolver, qValueFactory);
+                } else {
+                    qValue = ValueFormat.getQValue(jcrVal, requiredType, nsResolver, qValueFactory);
+                }
                 vs.add(qValue);
             }
             defaultValues = (QValue[]) vs.toArray(new QValue[vs.size()]);
@@ -108,8 +119,10 @@
             while (it.hasNext()) {
                 int constType = (requiredType == PropertyType.REFERENCE) ?  PropertyType.NAME : requiredType;
                 String qValue = DomUtil.getText(it.nextElement());
+                // in case of name and path constraint, the value must be
+                // converted to be in qualified format
                 if (constType == PropertyType.NAME || constType == PropertyType.PATH) {
-                   qValue = ValueFormat.getQValue(qValue, constType, nsResolver).getString();
+                   qValue = ValueFormat.getQValue(qValue, constType, nsResolver, qValueFactory).getString();
                 }
                 vc.add(qValue);
             }
@@ -135,28 +148,8 @@
     /**
      * {@inheritDoc}
      */
-    public String[] getDefaultValues() {
-        String[] strs = new String[defaultValues.length];
-        for (int i = 0; i < defaultValues.length; i++) {
-            try {
-                strs[i] = defaultValues[i].getString();
-            } catch (RepositoryException e) {
-                log.error("Internal error while retrieving default values.", e);
-            }
-        }
-        return strs;
-    }
-
-    public InputStream[] getDefaultValuesAsStream() {
-        InputStream[] ins = new InputStream[defaultValues.length];
-        for (int i = 0; i < defaultValues.length; i++) {
-            try {
-                ins[i] = defaultValues[i].getStream();
-            } catch (RepositoryException e) {
-                log.error("Internal error while retrieving default values.", e);
-            }
-        }
-        return ins;
+    public QValue[] getDefaultValues() {
+        return defaultValues;
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java Fri Jan 19 09:37:03 2007
@@ -16,13 +16,13 @@
  */
 package org.apache.jackrabbit.spi2dav;
 
-import java.util.AbstractCollection;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFactory;
+import javax.jcr.Value;
 
 import org.apache.jackrabbit.name.NameException;
 import org.apache.jackrabbit.name.NameFormat;
@@ -32,6 +32,9 @@
 import org.apache.jackrabbit.spi.QueryInfo;
 import org.apache.jackrabbit.spi.QueryResultRowIterator;
 import org.apache.jackrabbit.spi.SessionInfo;
+import org.apache.jackrabbit.spi.QValueFactory;
+import org.apache.jackrabbit.spi.QueryResultRow;
+import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.util.ISO9075;
 import org.apache.jackrabbit.webdav.DavServletResponse;
 import org.apache.jackrabbit.webdav.MultiStatus;
@@ -39,6 +42,7 @@
 import org.apache.jackrabbit.webdav.jcr.search.SearchResultProperty;
 import org.apache.jackrabbit.webdav.property.DavProperty;
 import org.apache.jackrabbit.webdav.property.DavPropertySet;
+import org.apache.jackrabbit.value.ValueFormat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,15 +56,16 @@
      */
     private static final Logger log = LoggerFactory.getLogger(QueryInfoImpl.class);
 
-    private final Map results = new LinkedHashMap();
+    private static final double UNDEFINED_SCORE = -1;
 
     private final QName[] columnNames;
-    private final NamespaceResolver nsResolver;
+    private int scoreIndex = -1;
+    private final Map results = new LinkedHashMap();
 
     public QueryInfoImpl(MultiStatus ms, SessionInfo sessionInfo, URIResolver uriResolver,
-                         NamespaceResolver nsResolver, ValueFactory valueFactory)
+                         NamespaceResolver nsResolver, ValueFactory valueFactory,
+                         QValueFactory qValueFactory)
         throws RepositoryException {
-        this.nsResolver = nsResolver;
 
         String responseDescription = ms.getResponseDescription();
         if (responseDescription != null) {
@@ -70,6 +75,9 @@
                 String jcrColumnNames = ISO9075.decode(cn[i]);
                 try {
                     columnNames[i] = NameFormat.parse(jcrColumnNames, nsResolver);
+                    if (QName.JCR_SCORE.equals(columnNames[i])) {
+                        scoreIndex = i;
+                    }
                 } catch (NameException e) {
                     throw new RepositoryException(e);
                 }
@@ -86,73 +94,107 @@
 
             DavProperty davProp = okSet.get(SearchResultProperty.SEARCH_RESULT_PROPERTY);
             SearchResultProperty resultProp = new SearchResultProperty(davProp, valueFactory);
+            Value[] values = resultProp.getValues();
+            QValue[] qValues = new QValue[values.length];
+            for (int j = 0; j < values.length; j++) {
+                try {
+                    qValues[j] = (values[j] == null) ?  null : ValueFormat.getQValue(values[j], nsResolver, qValueFactory);
+                } catch (RepositoryException e) {
+                    // should not occur
+                    log.error("Malformed value: " + values[j].toString());
+                }
+            }
 
             NodeId nodeId = uriResolver.getNodeId(href, sessionInfo);
-            this.results.put(nodeId, resultProp);
+            results.put(nodeId, qValues);
         }
     }
 
+    /**
+     * @see QueryInfo#getRows()
+     */
     public QueryResultRowIterator getRows() {
-      // TODO: objects need to implement QueryResultRow
-      
-      return new IteratorHelper(new AbstractCollection() {
-            public int size() {
-                return results.size();
-            }
-
-            public Iterator iterator() {
-                return results.keySet().iterator();
-            }
-        });
+        return new QueryResultRowIteratorImpl();
     }
 
+    /**
+     * @see QueryInfo#getColumnNames()
+     */
     public QName[] getColumnNames() {
         return columnNames;
     }
 
-//    public String[] getValues(NodeId nodeId) {
-//        SearchResultProperty prop = (SearchResultProperty) results.get(nodeId);
-//        if (prop == null) {
-//            throw new NoSuchElementException();
-//        } else {
-//            Value[] values = prop.getValues();
-//            String[] ret = new String[values.length];
-//            for (int i = 0; i < values.length; i++) {
-//                try {
-//                    QValue qValue = (values[i] == null) ?  null : ValueFormat.getQValue(values[i], nsResolver);
-//                    ret[i] = qValue.getString();
-//                } catch (RepositoryException e) {
-//                    // should not occur
-//                    log.error("malformed value: " + values[i].toString());
-//                }
-//            }
-//            return ret;
-//        }
-//    }
-//
-//    public InputStream[] getValuesAsStream(NodeId nodeId) {
-//        SearchResultProperty prop = (SearchResultProperty) results.get(nodeId);
-//        if (prop == null) {
-//            throw new NoSuchElementException();
-//        } else {
-//            Value[] values = prop.getValues();
-//            InputStream[] ret = new InputStream[values.length];
-//            for (int i = 0; i < ret.length; i++) {
-//                try {
-//                    // make sure we return the qualified value if the type is
-//                    // name or path.
-//                    if (values[i].getType() == PropertyType.NAME || values[i].getType() == PropertyType.PATH) {
-//                        ret[i] = ValueFormat.getQValue(values[i], nsResolver).getStream();
-//                    } else {
-//                        ret[i] = values[i].getStream();
-//                    }
-//                } catch (RepositoryException e) {
-//                    // ignore this value
-//                    log.warn("unable to get stream value: " + values[i].toString());
-//                }
-//            }
-//            return ret;
-//        }
-//    }
+    private class QueryResultRowIteratorImpl implements QueryResultRowIterator {
 
+        private final Iterator keyIterator;
+        private long pos = 0;
+
+        private QueryResultRowIteratorImpl() {
+            keyIterator = results.keySet().iterator();
+        }
+
+        public QueryResultRow nextQueryResultRow() {
+            final NodeId nId = (NodeId) keyIterator.next();
+            final QValue[] qValues = (QValue[]) results.get(nId);
+            pos++;
+
+            return new QueryResultRow() {
+                /**
+                 * @see QueryResultRow#getNodeId()
+                 */
+                public NodeId getNodeId() {
+                    return nId;
+                }
+
+                /**
+                 * @see QueryResultRow#getScore()
+                 */
+                public double getScore() {
+                    if (scoreIndex != -1 && qValues[scoreIndex] != null) {
+                        try {
+                            return Double.parseDouble(qValues[scoreIndex].getString());
+                        } catch (RepositoryException e) {
+                            log.error("Error while building query score", e);
+                        }   return UNDEFINED_SCORE;
+                    } else {
+                        log.error("Cannot determined jcr:score from query results.");
+                        return UNDEFINED_SCORE;
+                    }
+                }
+
+                /**
+                 * @see QueryResultRow#getValues()
+                 */
+                public QValue[] getValues() {
+                    return qValues;
+                }
+            };
+        }
+
+        public void skip(long skipNum) {
+            while (skipNum-- > 0) {
+                nextQueryResultRow();
+            }
+        }
+
+        public long getSize() {
+            return results.size();
+        }
+
+        public long getPosition() {
+            return pos;
+        }
+
+        public void remove() {
+            throw new UnsupportedOperationException("Remove not implemented");
+        }
+
+        public boolean hasNext() {
+            return keyIterator.hasNext();
+        }
+
+        public Object next() {
+            return nextQueryResultRow();
+        }
+    }
 }

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java Fri Jan 19 09:37:03 2007
@@ -22,6 +22,7 @@
 import org.apache.commons.httpclient.URIException;
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.HttpConnectionManager;
 import org.apache.commons.httpclient.auth.AuthScope;
 import org.apache.commons.httpclient.methods.HeadMethod;
 import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
@@ -122,10 +123,12 @@
 import org.apache.jackrabbit.spi.EventFilter;
 import org.apache.jackrabbit.spi.Event;
 import org.apache.jackrabbit.spi.ChildInfo;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.util.Text;
 import org.apache.jackrabbit.uuid.UUID;
 import org.apache.jackrabbit.value.ValueFormat;
-import org.apache.jackrabbit.value.QValue;
+import org.apache.jackrabbit.value.QValueFactoryImpl;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 import org.w3c.dom.Element;
@@ -268,10 +271,10 @@
     }
 
     HttpClient getClient(SessionInfo sessionInfo) throws RepositoryException {
-        if (clients.containsKey(sessionInfo)) {
-            return (HttpClient) clients.get(sessionInfo);
-        } else {
-            HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager());
+        HttpClient client = (HttpClient) clients.get(sessionInfo);
+        if (client == null) {
+            HttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
+            client = new HttpClient(connMgr);
             client.setHostConfiguration(hostConfig);
             // always send authentication not waiting for 401
             client.getParams().setAuthenticationPreemptive(true);
@@ -283,10 +286,18 @@
                 creds = ((SessionInfoImpl) sessionInfo).getCredentials().getCredentials();
             }
             client.getState().setCredentials(AuthScope.ANY, creds);
-
             clients.put(sessionInfo, client);
-            return client;
+            log.debug("Created Client " + client + " for SessionInfo " + sessionInfo);
+        }
+        return client;
+    }
+
+    private void removeClient(SessionInfo sessionInfo) {
+        HttpClient cl = (HttpClient) clients.remove(sessionInfo);
+        if (cl != null) {
+            ((MultiThreadedHttpConnectionManager) cl.getHttpConnectionManager()).shutdown();
         }
+        log.debug("Removed Client " + cl + " for SessionInfo " + sessionInfo);
     }
 
     private String getItemUri(ItemId itemId, SessionInfo sessionInfo) throws RepositoryException {
@@ -383,6 +394,10 @@
         return idFactory;
     }
 
+    public QValueFactory getQValueFactory() {
+        return QValueFactoryImpl.getInstance();
+    }
+
     /**
      * @see RepositoryService#getRepositoryDescriptors()
      */
@@ -492,6 +507,7 @@
             String rootUri = uriResolver.getRootItemUri(sessionInfo.getWorkspaceName());
             unsubscribe(rootUri, subscriptionId, sessionInfo);
         }
+        removeClient(sessionInfo);
     }
 
     /**
@@ -639,7 +655,7 @@
                     if (itemId.denotesNode()) {
                         definition = new QNodeDefinitionImpl(null, idfElem, nsResolver);
                     } else {
-                        definition = new QPropertyDefinitionImpl(null, idfElem, nsResolver);
+                        definition = new QPropertyDefinitionImpl(null, idfElem, nsResolver, getQValueFactory());
                     }
                 }
             }
@@ -764,7 +780,7 @@
     /**
      * @see RepositoryService#getChildInfos(SessionInfo, NodeId)
      */
-    public Collection getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws ItemNotFoundException, RepositoryException {
+    public Iterator getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws ItemNotFoundException, RepositoryException {
         // set of properties to be retrieved
         DavPropertyNameSet nameSet = new DavPropertyNameSet();
         nameSet.add(ItemResourceConstants.JCR_NAME);
@@ -788,10 +804,10 @@
                 throw new ItemNotFoundException("Unable to retrieve the node with id " + parentId);
             } else if (responses.length == 1) {
                 // no child nodes nor properties
-                return Collections.EMPTY_LIST;
+                return Collections.EMPTY_LIST.iterator();
             }
 
-            Set childEntries = new HashSet();
+            List childEntries = new ArrayList();
             for (int i = 0; i < responses.length; i++) {
                 if (!isSameResource(uri, responses[i])) {
                     MultiStatusResponse resp = responses[i];
@@ -808,7 +824,7 @@
                     } // else: property -> ignore
                 } // else: ignore the response related to the parent
             }
-            return childEntries;
+            return childEntries.iterator();
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -850,7 +866,7 @@
             NodeId parentId = getParentId(propSet, sessionInfo);
             PropertyId id = uriResolver.buildPropertyId(parentId, responses[0], sessionInfo.getWorkspaceName());
 
-            PropertyInfo pInfo = new PropertyInfoImpl(id, parentId, propSet, nsResolver, valueFactory);
+            PropertyInfo pInfo = new PropertyInfoImpl(id, parentId, propSet, nsResolver, valueFactory, getQValueFactory());
             return pInfo;
         } catch (IOException e) {
             throw new RepositoryException(e);
@@ -1248,7 +1264,7 @@
 
             MultiStatus ms = method.getResponseBodyAsMultiStatus();
             return new QueryInfoImpl(ms, sessionInfo, uriResolver,
-                nsResolver, valueFactory);
+                nsResolver, valueFactory, getQValueFactory());
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -1588,7 +1604,7 @@
             ElementIterator it = DomUtil.getChildren(reportDoc.getDocumentElement(), NodeTypeConstants.NODETYPE_ELEMENT, null);
             List ntDefs = new ArrayList();
             while (it.hasNext()) {
-                ntDefs.add(new QNodeTypeDefinitionImpl(it.nextElement(), nsResolver));
+                ntDefs.add(new QNodeTypeDefinitionImpl(it.nextElement(), nsResolver, getQValueFactory()));
             }
             // refresh node type definitions map
             synchronized (nodeTypeDefinitions) {
@@ -1753,63 +1769,28 @@
         }
 
         /**
-         * @see Batch#addProperty(NodeId, QName, String, int)
+         * @see Batch#addProperty(NodeId, QName, QValue)
          */
-        public void addProperty(NodeId parentId, QName propertyName, String value, int propertyType) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
+        public void addProperty(NodeId parentId, QName propertyName, QValue value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
             checkConsumed();
-            QValue qV = QValue.create(value, propertyType);
-            Value jcrValue = ValueFormat.getJCRValue(qV, nsResolver, valueFactory);
+            Value jcrValue = ValueFormat.getJCRValue(value, nsResolver, valueFactory);
             ValuesProperty vp = new ValuesProperty(jcrValue);
             internalAddProperty(parentId, propertyName, vp);
         }
 
         /**
-         * @see Batch#addProperty(NodeId, QName, String[], int)
+         * @see Batch#addProperty(NodeId, QName, QValue[])
          */
-        public void addProperty(NodeId parentId, QName propertyName, String[] values, int propertyType) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
+        public void addProperty(NodeId parentId, QName propertyName, QValue[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
             checkConsumed();
             Value[] jcrValues = new Value[values.length];
             for (int i = 0; i < values.length; i++) {
-                QValue v = QValue.create(values[i], propertyType);
-                jcrValues[i] = ValueFormat.getJCRValue(v, nsResolver, valueFactory);
+                jcrValues[i] = ValueFormat.getJCRValue(values[i], nsResolver, valueFactory);
             }
             ValuesProperty vp = new ValuesProperty(jcrValues);
             internalAddProperty(parentId, propertyName, vp);
         }
 
-        /**
-         * @see Batch#addProperty(NodeId, QName, InputStream, int)
-         */
-        public void addProperty(NodeId parentId, QName propertyName, InputStream value, int propertyType) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
-            checkConsumed();
-            try {
-                QValue qV = QValue.create(value, propertyType);
-                Value jcrValue = ValueFormat.getJCRValue(qV, nsResolver, valueFactory);
-                ValuesProperty vp = new ValuesProperty(jcrValue);
-                internalAddProperty(parentId, propertyName, vp);
-            } catch (IOException e) {
-                throw new ValueFormatException(e);
-            }
-        }
-
-        /**
-         * @see Batch#addProperty(NodeId, QName, InputStream[], int)
-         */
-        public void addProperty(NodeId parentId, QName propertyName, InputStream[] values, int propertyType) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
-            checkConsumed();
-            try {
-                Value[] jcrValues = new Value[values.length];
-                for (int i = 0; i < values.length; i++) {
-                    QValue qV = QValue.create(values[i], propertyType);
-                    jcrValues[i] = ValueFormat.getJCRValue(qV, nsResolver, valueFactory);
-                }
-                ValuesProperty vp = new ValuesProperty(jcrValues);
-                internalAddProperty(parentId, propertyName, vp);
-            } catch (IOException e) {
-                throw new ValueFormatException(e);
-            }
-        }
-
         private void internalAddProperty(NodeId parentId, QName propertyName, ValuesProperty vp) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
             try {
                 String uri = getItemUri(parentId, propertyName, sessionInfo);
@@ -1824,9 +1805,9 @@
         }
 
         /**
-         * @see Batch#setValue(PropertyId, String, int)
+         * @see Batch#setValue(PropertyId, QValue)
          */
-        public void setValue(PropertyId propertyId, String value, int propertyType) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
+        public void setValue(PropertyId propertyId, QValue value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
             checkConsumed();
             DavPropertySet setProperties = new DavPropertySet();
             if (value == null) {
@@ -1834,8 +1815,7 @@
                 remove(propertyId);
             } else {
                 // qualified value must be converted to jcr value
-                QValue qV = QValue.create(value, propertyType);
-                Value jcrValue = ValueFormat.getJCRValue(qV, nsResolver, valueFactory);
+                Value jcrValue = ValueFormat.getJCRValue(value, nsResolver, valueFactory);
                 ValuesProperty vp = new ValuesProperty(jcrValue);
                 setProperties.add(vp);
             }
@@ -1843,9 +1823,9 @@
         }
 
         /**
-         * @see Batch#setValue(PropertyId, String[], int)
+         * @see Batch#setValue(PropertyId, QValue[])
          */
-        public void setValue(PropertyId propertyId, String[] values, int propertyType) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
+        public void setValue(PropertyId propertyId, QValue[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
             checkConsumed();
             DavPropertySet setProperties = new DavPropertySet();
             if (values == null) {
@@ -1855,60 +1835,11 @@
                 // qualified values must be converted to jcr values
                 Value[] jcrValues = new Value[values.length];
                 for (int i = 0; i < values.length; i++) {
-                    QValue qV = QValue.create(values[i], propertyType);
-                    jcrValues[i] = ValueFormat.getJCRValue(qV, nsResolver, valueFactory);
+                    jcrValues[i] = ValueFormat.getJCRValue(values[i], nsResolver, valueFactory);
                 }
                 setProperties.add(new ValuesProperty(jcrValues));
             }
             internalSetValue(propertyId, setProperties);
-        }
-
-        /**
-         * @see Batch#setValue(PropertyId, InputStream, int)
-         */
-        public void setValue(PropertyId propertyId, InputStream value, int propertyType) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
-            checkConsumed();
-            try {
-                DavPropertySet setProperties = new DavPropertySet();
-                if (value == null) {
-                    // setting property value to 'null' is identical to a removal
-                    remove(propertyId);
-                } else {
-                    // qualified value must be converted to jcr value
-                    QValue qV = QValue.create(value, propertyType);
-                    Value jcrValue = ValueFormat.getJCRValue(qV, nsResolver, valueFactory);
-                    ValuesProperty vp = new ValuesProperty(jcrValue);
-                    setProperties.add(vp);
-                }
-                internalSetValue(propertyId, setProperties);
-            } catch (IOException e) {
-                throw new ValueFormatException(e);
-            }
-        }
-
-        /**
-         * @see Batch#setValue(PropertyId, InputStream[], int)
-         */
-        public void setValue(PropertyId propertyId, InputStream[] values, int propertyType) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
-            checkConsumed();
-            try {
-                DavPropertySet setProperties = new DavPropertySet();
-                if (values == null) {
-                    // setting property value to 'null' is identical to a removal
-                    remove(propertyId);
-                } else {
-                    // qualified values must be converted to jcr values
-                    Value[] jcrValues = new Value[values.length];
-                    for (int i = 0; i < values.length; i++) {
-                        QValue qV = QValue.create(values[i], propertyType);
-                        jcrValues[i] = ValueFormat.getJCRValue(qV, nsResolver, valueFactory);
-                    }
-                    setProperties.add(new ValuesProperty(jcrValues));
-                }
-                internalSetValue(propertyId, setProperties);
-            }   catch (IOException e) {
-                throw new ValueFormatException(e);
-            }
         }
 
         /**



Mime
View raw message