jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r497885 [1/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
Author: angela
Date: Fri Jan 19 09:37:03 2007
New Revision: 497885

URL: http://svn.apache.org/viewvc?view=rev&rev=497885
Log:
work in progress

- SPI: replace String/Stream for values by QValue interface
- SPI: add factory for QValue
  > adjust commons and add implementation
  > adjust usages of former QValue object with jcr2spi, spi2dav
- RepositoryService.getChildInfos returns Iterator instead of Collection
- spi2dav: add implementation for new query interfaces

- TODO: 
  improve conversion of jcr-value to q-value and vice-versa



Added:
    jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java   (with props)
    jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValue.java   (with props)
    jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QValueFactory.java   (with props)
Removed:
    jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/QValue.java
Modified:
    jackrabbit/trunk/contrib/spi/TODO.txt
    jackrabbit/trunk/contrib/spi/commons/project.xml
    jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/ValueFormat.java
    jackrabbit/trunk/contrib/spi/commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistry.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/PropertyDefinitionImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ValueConstraint.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddProperty.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/ReferenceChangeTracker.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java
    jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/Batch.java
    jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/PropertyInfo.java
    jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QPropertyDefinition.java
    jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java
    jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/PropertyInfoImpl.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QNodeTypeDefinitionImpl.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QPropertyDefinitionImpl.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java

Modified: jackrabbit/trunk/contrib/spi/TODO.txt
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/TODO.txt?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/TODO.txt (original)
+++ jackrabbit/trunk/contrib/spi/TODO.txt Fri Jan 19 09:37:03 2007
@@ -6,7 +6,7 @@
       Minor known issues and problems are marked throughout the code with TODO.
 
 
-1) RepositoryService  (missing)
+1) RepositoryServiceImpl in Spi2Dav  (missing)
    
    missing implementation for:
    > Clone
@@ -17,20 +17,12 @@
    > UnregisterNodeType
    
    
-2) RepositoryService  (improve)
+2) SPI: interfaces  (improve)
 
-   param consistency
-   while in the very first draft ids, values and names were represented
-   by String and Stream only, we currently have a inconsistent mixture
-   of separate interfaces/classes for ids and names, while values are
-   still represented by String/Stream only mentioning in the comments
-   that values are meant to be in a qualified form in case of property
-   type Name and Path.
-   Second it seems inconsistent that an interface is defined for ItemId,
-   while the QName class from jackrabbit commons is used (see also FAQ).
+   > review usage of jackrabbit-commons classes (QName, Path)
 
 
-3) RepositoryService, Batch (improve)
+3) SPI: RepositoryService, Batch (improve)
 
    > check consistency of throw clauses.
 

Modified: jackrabbit/trunk/contrib/spi/commons/project.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/commons/project.xml?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/commons/project.xml (original)
+++ jackrabbit/trunk/contrib/spi/commons/project.xml Fri Jan 19 09:37:03 2007
@@ -35,6 +35,11 @@
             <artifactId>jackrabbit-jcr-commons</artifactId>
             <version>${jackrabbit.build.version.jackrabbit}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-spi</artifactId>
+            <version>${jackrabbit.build.version.spi}</version>
+        </dependency>
         <!-- external dependencies -->
         <dependency>
             <groupId>jsr170</groupId>

Added: jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java?view=auto&rev=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java (added)
+++ jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java Fri Jan 19 09:37:03 2007
@@ -0,0 +1,645 @@
+/*
+ * 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.value;
+
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.util.TransientFileFactory;
+import org.apache.jackrabbit.util.ISO8601;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFormatException;
+import javax.jcr.PropertyType;
+import java.util.Calendar;
+import java.util.Arrays;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.File;
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
+/**
+ * <code>QValueFactoryImpl</code>...
+ */
+public final class QValueFactoryImpl implements QValueFactory {
+
+    private static final QValueFactory instance = new QValueFactoryImpl();
+
+    private QValueFactoryImpl() {
+    }
+
+    public static QValueFactory getInstance() {
+        return instance;
+    }
+
+    //------------------------------------------------------< QValueFactory >---
+    /**
+     * @see QValueFactory#create(String, int)
+     */
+    public QValue create(String value, int type) {
+        if (value == null) {
+            throw new IllegalArgumentException("Cannot create QValue from null value.");
+        }
+        switch (type) {
+            case PropertyType.BOOLEAN:
+                return new QValueImpl(Boolean.valueOf(value));
+            case PropertyType.DATE:
+                return new QValueImpl(ISO8601.parse(value));
+            case PropertyType.DOUBLE:
+                return new QValueImpl(Double.valueOf(value));
+            case PropertyType.LONG:
+                return new QValueImpl(Long.valueOf(value));
+            case PropertyType.PATH:
+                return new QValueImpl(Path.valueOf(value));
+            case PropertyType.NAME:
+                return new QValueImpl(QName.valueOf(value));
+            case PropertyType.STRING:
+            case PropertyType.REFERENCE:
+                return new QValueImpl(value, type);
+            case PropertyType.BINARY:
+                throw new IllegalArgumentException("this method does not support the type PropertyType.BINARY");
+            default:
+                throw new IllegalArgumentException("illegal type");
+        }
+    }
+
+    /**
+     * @see QValueFactory#create(Calendar)
+     */
+    public QValue create(Calendar value) {
+        if (value == null) {
+            throw new IllegalArgumentException("Cannot create QValue from null value.");
+        }
+        return new QValueImpl(value);
+    }
+
+    /**
+     * @see QValueFactory#create(QName)
+     */
+    public QValue create(QName value) {
+        if (value == null) {
+            throw new IllegalArgumentException("Cannot create QValue from null value.");
+        }
+        return new QValueImpl(value);
+    }
+
+    /**
+     * @see QValueFactory#create(Path)
+     */
+    public QValue create(Path value) {
+        if (value == null) {
+            throw new IllegalArgumentException("Cannot create QValue from null value.");
+        }
+        return new QValueImpl(value);
+    }
+
+    /**
+     * @see QValueFactory#create(byte[])
+     */
+    public QValue create(byte[] value) {
+        if (value == null) {
+            throw new IllegalArgumentException("Cannot create QValue from null value.");
+        }
+        return new BinaryQValue(value);
+    }
+
+    /**
+     * @see QValueFactory#create(InputStream)
+     */
+    public QValue create(InputStream value) throws IOException {
+        if (value == null) {
+            throw new IllegalArgumentException("Cannot create QValue from null value.");
+        }
+        return new BinaryQValue(value);
+    }
+
+    /**
+     * @see QValueFactory#create(File)
+     */
+    public QValue create(File value) throws IOException {
+        if (value == null) {
+            throw new IllegalArgumentException("Cannot create QValue from null value.");
+        }
+        return new BinaryQValue(value);
+    }
+
+    //--------------------------------------------------------< Inner Class >---
+    /**
+     * <code>QValue</code> implementation for all valid <code>PropertyType</code>s
+     * except for BINARY.
+     * @see QValueFactoryImpl.BinaryQValue
+     */
+    private static class QValueImpl implements QValue {
+        /**
+         * the default encoding
+         */
+        private static final String DEFAULT_ENCODING = "UTF-8";
+
+        private final Object val;
+        private final int type;
+
+        private QValueImpl(String value, int type) {
+            if (!(type == PropertyType.STRING || type == PropertyType.REFERENCE)) {
+                throw new IllegalArgumentException();
+            }
+            val = value;
+            this.type = type;
+        }
+
+        private QValueImpl(Long value) {
+            val = value;
+            type = PropertyType.LONG;
+        }
+
+        private QValueImpl(Double value) {
+            val = value;
+            type = PropertyType.DOUBLE;
+        }
+
+        private QValueImpl(Calendar value) {
+            val = ISO8601.format(value);
+            type = PropertyType.DATE;
+        }
+
+        private QValueImpl(Boolean value) {
+            val = value;
+            type = PropertyType.BOOLEAN;
+        }
+
+        private QValueImpl(QName value) {
+            val = value;
+            type = PropertyType.NAME;
+        }
+
+        private QValueImpl(Path value) {
+            val = value;
+            type = PropertyType.PATH;
+        }
+
+        //---------------------------------------------------------< QValue >---
+        /**
+         * @see QValue#getType()
+         */
+        public int getType() {
+            return type;
+        }
+
+        /**
+         * @see QValue#getLength()
+         */
+        public long getLength() throws RepositoryException {
+            return getString().length();
+        }
+
+        /**
+         * @see QValue#getString()
+         */
+        public String getString() throws RepositoryException {
+            return val.toString();
+        }
+
+        /**
+         * @see QValue#getStream()
+         */
+        public InputStream getStream() throws RepositoryException {
+            try {
+                // convert via string
+                return new ByteArrayInputStream(getString().getBytes(QValueImpl.DEFAULT_ENCODING));
+            } catch (UnsupportedEncodingException e) {
+                throw new RepositoryException(QValueImpl.DEFAULT_ENCODING + " is not supported encoding on this platform", e);
+            }
+        }
+
+        /**
+         * @see QValue#getQName()
+         */
+        public QName getQName() throws RepositoryException {
+            if (type == PropertyType.NAME) {
+                return (QName) val;
+            } else {
+                return QName.valueOf(getString());
+            }
+        }
+
+        /**
+         * @see QValue#getPath()
+         */
+        public Path getPath() throws RepositoryException {
+            if (type == PropertyType.PATH) {
+                return (Path) val;
+            } else {
+                return Path.valueOf(getString());
+            }
+        }
+
+        /**
+         * @see QValue#discard()
+         */
+        public void discard() {
+            // nothing to do
+        }
+
+        //---------------------------------------------------------< Object >---
+        /**
+         * Returns the string representation of this internal value.
+         *
+         * @return string representation of this internal value
+         */
+        public String toString() {
+            return val.toString();
+        }
+
+        /**
+         *
+         * @param obj
+         * @return
+         * @see Object#equals(Object)
+         */
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj instanceof QValueImpl) {
+                QValueImpl other = (QValueImpl) obj;
+                return val.equals(other.val) && type == other.type;
+            }
+            return false;
+        }
+
+        /**
+         * @return the hashCode of the internal value object.
+         * @see Object#hashCode()
+         */
+        public int hashCode() {
+            return val.hashCode();
+        }
+    }
+
+
+    //--------------------------------------------------------< Inner Class >---
+    /**
+     * <code>BinaryQValue</code> represents a binary <code>Value</code> which is
+     * backed by a resource or byte[]. Unlike <code>BinaryValue</code> it has no
+     * state, i.e. the <code>getStream()</code> method always returns a fresh
+     * <code>InputStream</code> instance.
+     */
+    private static class BinaryQValue implements QValue {
+        /**
+         * empty array
+         */
+        private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+
+        /**
+         * max size for keeping tmp data in memory
+         */
+        private static final int MAX_BUFFER_SIZE = 0x10000;
+
+        /**
+         * underlying file
+         */
+        private final File file;
+
+        /**
+         * flag indicating if this instance represents a <i>temporary</i> value
+         * whose dynamically allocated resources can be explicitly freed on
+         * {@link #discard()}.
+         */
+        private final boolean temp;
+
+        /**
+         * Buffer for small-sized data
+         */
+        private byte[] buffer = BinaryQValue.EMPTY_BYTE_ARRAY;
+
+        /**
+         * Converted text
+         */
+        private String text = null;
+
+        /**
+         * Creates a new <code>BinaryQValue</code> instance from an
+         * <code>InputStream</code>. The contents of the stream is spooled
+         * to a temporary file or to a byte buffer if its size is smaller than
+         * {@link #MAX_BUFFER_SIZE}.
+         * <p/>
+         * The new instance represents a <i>temporary</i> value whose dynamically
+         * allocated resources will be freed explicitly on {@link #discard()}.
+         *
+         * @param in stream to be represented as a <code>BinaryQValue</code> instance
+         * @throws IOException if an error occurs while reading from the stream or
+         *                     writing to the temporary file
+         */
+        private BinaryQValue(InputStream in) throws IOException {
+            this(in, true);
+        }
+
+        /**
+         * Creates a new <code>BinaryQValue</code> instance from an
+         * <code>InputStream</code>. The contents of the stream is spooled
+         * to a temporary file or to a byte buffer if its size is smaller than
+         * {@link #MAX_BUFFER_SIZE}.
+         * <p/>
+         * The <code>temp</code> parameter governs whether dynamically allocated
+         * resources will be freed explicitly on {@link #discard()}. Note that any
+         * dynamically allocated resources (temp file/buffer) will be freed
+         * implicitly once this instance has been gc'ed.
+         *
+         * @param in stream to be represented as a <code>BinaryQValue</code> instance
+         * @param temp flag indicating whether this instance represents a
+         *             <i>temporary</i> value whose resources can be explicitly freed
+         *             on {@link #discard()}.
+         * @throws IOException if an error occurs while reading from the stream or
+         *                     writing to the temporary file
+         */
+        private BinaryQValue(InputStream in, boolean temp) throws IOException {
+            byte[] spoolBuffer = new byte[0x2000];
+            int read;
+            int len = 0;
+            OutputStream out = null;
+            File spoolFile = null;
+            try {
+                while ((read = in.read(spoolBuffer)) > 0) {
+                    if (out != null) {
+                        // spool to temp file
+                        out.write(spoolBuffer, 0, read);
+                        len += read;
+                    } else if (len + read > BinaryQValue.MAX_BUFFER_SIZE) {
+                        // threshold for keeping data in memory exceeded;
+                        // create temp file and spool buffer contents
+                        TransientFileFactory fileFactory = TransientFileFactory.getInstance();
+                        spoolFile = fileFactory.createTransientFile("bin", null, null);
+                        out = new FileOutputStream(spoolFile);
+                        out.write(buffer, 0, len);
+                        out.write(spoolBuffer, 0, read);
+                        buffer = null;
+                        len += read;
+                    } else {
+                        // reallocate new buffer and spool old buffer contents
+                        byte[] newBuffer = new byte[len + read];
+                        System.arraycopy(buffer, 0, newBuffer, 0, len);
+                        System.arraycopy(spoolBuffer, 0, newBuffer, len, read);
+                        buffer = newBuffer;
+                        len += read;
+                    }
+                }
+            } finally {
+                if (out != null) {
+                    out.close();
+                }
+            }
+
+            // init vars
+            file = spoolFile;
+            this.temp = temp;
+            // buffer is EMPTY_BYTE_ARRAY (default value)
+        }
+
+        /**
+         * Creates a new <code>BinaryQValue</code> instance from a
+         * <code>byte[]</code> array.
+         *
+         * @param bytes byte array to be represented as a <code>BinaryQValue</code>
+         *              instance
+         */
+        private BinaryQValue(byte[] bytes) {
+            buffer = bytes;
+            file = null;
+            // this instance is not backed by a temporarily allocated buffer
+            temp = false;
+        }
+
+        /**
+         * Creates a new <code>BinaryQValue</code> instance from a <code>File</code>.
+         *
+         * @param file file to be represented as a <code>BinaryQValue</code> instance
+         * @throws IOException if the file can not be read
+         */
+        private BinaryQValue(File file) throws IOException {
+            String path = file.getCanonicalPath();
+            if (!file.isFile()) {
+                throw new IOException(path + ": the specified file does not exist");
+            }
+            if (!file.canRead()) {
+                throw new IOException(path + ": the specified file can not be read");
+            }
+            // this instance is backed by a 'real' file
+            this.file = file;
+            // this instance is not backed by temporarily allocated resource/buffer
+            temp = false;
+            // buffer is EMPTY_BYTE_ARRAY (default value)
+        }
+
+        //---------------------------------------------------------< QValue >---
+        /**
+         * @see QValue#getType()
+         */
+        public int getType() {
+            return PropertyType.BINARY;
+        }
+
+        /**
+         * Returns the length of this <code>BinaryQValue</code>.
+         *
+         * @return The length, in bytes, of this <code>BinaryQValue</code>,
+         *         or -1L if the length can't be determined.
+         * @see QValue#getLength()
+         */
+        public long getLength() {
+            if (file != null) {
+                // this instance is backed by a 'real' file
+                if (file.exists()) {
+                    return file.length();
+                } else {
+                    return -1;
+                }
+            } else {
+                // this instance is backed by an in-memory buffer
+                return buffer.length;
+            }
+        }
+
+        /**
+         * @see QValue#getString()
+         */
+        public String getString() throws RepositoryException {
+            if (text == null) {
+                ByteArrayOutputStream out = new ByteArrayOutputStream();
+                try {
+                    spool(out);
+                    byte[] data = out.toByteArray();
+                    text = new String(data, QValueImpl.DEFAULT_ENCODING);
+                } catch (UnsupportedEncodingException e) {
+                    throw new RepositoryException(QValueImpl.DEFAULT_ENCODING
+                        + " not supported on this platform", e);
+                } catch (IOException e) {
+                    throw new ValueFormatException("conversion from stream to string failed", e);
+                } finally {
+                    try {
+                        out.close();
+                    } catch (IOException e) {
+                        // ignore
+                    }
+                }
+            }
+            return text;
+        }
+
+        /**
+         * @see QValue#getStream()
+         */
+        public InputStream getStream() throws RepositoryException {
+            // always return a 'fresh' stream
+            if (file != null) {
+                // this instance is backed by a 'real' file
+                try {
+                    return new FileInputStream(file);
+                } catch (FileNotFoundException fnfe) {
+                    throw new RepositoryException("file backing binary value not found",
+                        fnfe);
+                }
+            } else {
+                return new ByteArrayInputStream(buffer);
+            }
+        }
+
+        /**
+         * @see QValue#getQName()
+         */
+        public QName getQName() throws RepositoryException {
+            throw new UnsupportedOperationException();
+        }
+
+        /**
+         * @see QValue#getPath()
+         */
+        public Path getPath() throws RepositoryException {
+            throw new UnsupportedOperationException();
+        }
+
+        /**
+         * Frees temporarily allocated resources such as temporary file, buffer, etc.
+         * If this <code>BinaryQValue</code> is backed by a persistent resource
+         * calling this method will have no effect.
+         * @see QValue#discard()
+         */
+        public void discard() {
+            if (!temp) {
+                // do nothing if this instance is not backed by temporarily
+                // allocated resource/buffer
+                return;
+            }
+            if (file != null) {
+                // this instance is backed by a temp file
+                file.delete();
+            } else if (buffer != null) {
+                // this instance is backed by an in-memory buffer
+                buffer = EMPTY_BYTE_ARRAY;
+            }
+        }
+
+        //-----------------------------------------------< java.lang.Object >---
+        /**
+         * Returns a string representation of this <code>BinaryQValue</code>
+         * instance. The string representation of a resource backed value is
+         * the path of the underlying resource. If this instance is backed by an
+         * in-memory buffer the generic object string representation of the byte
+         * array will be used instead.
+         *
+         * @return A string representation of this <code>BinaryQValue</code> instance.
+         */
+        public String toString() {
+            if (file != null) {
+                // this instance is backed by a 'real' file
+                return file.toString();
+            } else {
+                // this instance is backed by an in-memory buffer
+                return buffer.toString();
+            }
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj instanceof BinaryQValue) {
+                BinaryQValue other = (BinaryQValue) obj;
+                return ((file == null ? other.file == null : file.equals(other.file))
+                    && Arrays.equals(buffer, other.buffer));
+            }
+            return false;
+        }
+
+        /**
+         * Returns zero to satisfy the Object equals/hashCode contract.
+         * This class is mutable and not meant to be used as a hash key.
+         *
+         * @return always zero
+         * @see Object#hashCode()
+         */
+        public int hashCode() {
+            return 0;
+        }
+
+        //----------------------------------------------------------------------
+        /**
+         * Spools the contents of this <code>BinaryQValue</code> to the given
+         * output stream.
+         *
+         * @param out output stream
+         * @throws RepositoryException if the input stream for this
+         *                             <code>BinaryQValue</code> could not be obtained
+         * @throws IOException         if an error occurs while while spooling
+         */
+        private void spool(OutputStream out) throws RepositoryException, IOException {
+            InputStream in;
+            if (file != null) {
+                // this instance is backed by a 'real' file
+                try {
+                    in = new FileInputStream(file);
+                } catch (FileNotFoundException fnfe) {
+                    throw new RepositoryException("file backing binary value not found",
+                        fnfe);
+                }
+            } else {
+                // this instance is backed by an in-memory buffer
+                in = new ByteArrayInputStream(buffer);
+            }
+            try {
+                byte[] buffer = new byte[0x2000];
+                int read;
+                while ((read = in.read(buffer)) > 0) {
+                    out.write(buffer, 0, read);
+                }
+            } finally {
+                try {
+                    in.close();
+                } catch (IOException ignore) {
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

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

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

Modified: jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/ValueFormat.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/ValueFormat.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/ValueFormat.java (original)
+++ jackrabbit/trunk/contrib/spi/commons/src/main/java/org/apache/jackrabbit/value/ValueFormat.java Fri Jan 19 09:37:03 2007
@@ -23,6 +23,8 @@
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.PathFormat;
 import org.apache.jackrabbit.name.NameFormat;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.PropertyType;
@@ -37,35 +39,65 @@
  */
 public class ValueFormat {
 
-    public static QValue getQValue(Value jcrValue, NamespaceResolver nsResolver) throws RepositoryException {
+    /**
+     *
+     * @param jcrValue
+     * @param nsResolver
+     * @param factory
+     * @return
+     * @throws RepositoryException
+     */
+    public static QValue getQValue(Value jcrValue, NamespaceResolver nsResolver,
+                                   QValueFactory factory) throws RepositoryException {
         if (jcrValue == null) {
             throw new IllegalArgumentException("null value");
         }
         if (jcrValue.getType() == PropertyType.BINARY) {
             try {
-                return QValue.create(jcrValue.getStream());
+                return factory.create(jcrValue.getStream());
             } catch (IOException e) {
                 throw new RepositoryException(e);
             }
         } else {
-            return getQValue(jcrValue.getString(), jcrValue.getType(), nsResolver);
+            return getQValue(jcrValue.getString(), jcrValue.getType(), nsResolver, factory);
         }
     }
 
-    public static QValue[] getQValues(Value[] jcrValues, NamespaceResolver nsResolver) throws RepositoryException {
+    /**
+     *
+     * @param jcrValues
+     * @param nsResolver
+     * @param factory
+     * @return
+     * @throws RepositoryException
+     */
+    public static QValue[] getQValues(Value[] jcrValues,
+                                      NamespaceResolver nsResolver,
+                                      QValueFactory factory) throws RepositoryException {
         if (jcrValues == null) {
             throw new IllegalArgumentException("null value");
         }
         List qValues = new ArrayList();
         for (int i = 0; i < jcrValues.length; i++) {
             if (jcrValues[i] != null) {
-                qValues.add(getQValue(jcrValues[i], nsResolver));
+                qValues.add(getQValue(jcrValues[i], nsResolver, factory));
             }
         }
         return (QValue[]) qValues.toArray(new QValue[qValues.size()]);
     }
 
-    public static QValue getQValue(String jcrValue, int propertyType, NamespaceResolver nsResolver) throws RepositoryException {
+    /**
+     * 
+     * @param jcrValue
+     * @param propertyType
+     * @param nsResolver
+     * @param factory
+     * @return
+     * @throws RepositoryException
+     */
+    public static QValue getQValue(String jcrValue, int propertyType,
+                                   NamespaceResolver nsResolver,
+                                   QValueFactory factory) throws RepositoryException {
         QValue qValue;
         switch (propertyType) {
             case PropertyType.STRING:
@@ -74,15 +106,15 @@
             case PropertyType.LONG:
             case PropertyType.DATE:
             case PropertyType.REFERENCE:
-                qValue = QValue.create(jcrValue, propertyType);
+                qValue = factory.create(jcrValue, propertyType);
                 break;
             case PropertyType.BINARY:
-                qValue = QValue.create(jcrValue.getBytes());
+                qValue = factory.create(jcrValue.getBytes());
                 break;
             case PropertyType.NAME:
                 try {
                     QName qName = NameFormat.parse(jcrValue, nsResolver);
-                    qValue = QValue.create(qName);
+                    qValue = factory.create(qName);
                 } catch (NameException e) {
                     throw new RepositoryException(e);
                 }
@@ -90,7 +122,7 @@
             case PropertyType.PATH:
                 try {
                     Path qPath = PathFormat.parse(jcrValue, nsResolver).getNormalizedPath();
-                    qValue = QValue.create(qPath);
+                    qValue = factory.create(qPath);
                 } catch (NameException e) {
                     throw new RepositoryException(e);
                 }
@@ -108,8 +140,7 @@
      */
     public static Value getJCRValue(QValue qualifiedValue,
                                     NamespaceResolver nsResolver,
-                                    ValueFactory factory)
-        throws RepositoryException {
+                                    ValueFactory factory) throws RepositoryException {
         Value jcrValue;
         int propertyType = qualifiedValue.getType();
         switch (propertyType) {

Modified: jackrabbit/trunk/contrib/spi/commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java (original)
+++ jackrabbit/trunk/contrib/spi/commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java Fri Jan 19 09:37:03 2007
@@ -29,6 +29,8 @@
 import org.apache.jackrabbit.uuid.UUID;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
 
 /**
  * <code>QValueTest</code>...
@@ -38,34 +40,18 @@
     private final Calendar CALENDAR = Calendar.getInstance();
     private static final String REFERENCE = UUID.randomUUID().toString();
 
+    private static final QValueFactory factory = QValueFactoryImpl.getInstance();
+
     //---------------------------------------------------------------< DATE >---
     public void testNullDateValue() throws IOException {
         try {
-            QValue.create((Calendar) null);
-            fail();
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
-        try {
-            QValue.create((String) null, PropertyType.DATE);
-            fail();
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
-        try {
-            QValue.create(new String[] {null}, PropertyType.DATE);
+            factory.create((Calendar) null);
             fail();
         } catch (IllegalArgumentException e) {
             // ok
         }
         try {
-            QValue.create((InputStream) null, PropertyType.DATE);
-            fail();
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
-        try {
-            QValue.create(new InputStream[] {null}, PropertyType.DATE);
+            factory.create((String) null, PropertyType.DATE);
             fail();
         } catch (IllegalArgumentException e) {
             // ok
@@ -73,63 +59,31 @@
     }
 
     public void testDateValueType() {
-        QValue v = QValue.create(CALENDAR);
+        QValue v = factory.create(CALENDAR);
         assertTrue("Type of a date value must be PropertyType.DATE", v.getType() == PropertyType.DATE);
     }
     public void testDateValueEquality() {
-        QValue v = QValue.create(CALENDAR);
-        QValue otherV = QValue.create(CALENDAR);
+        QValue v = factory.create(CALENDAR);
+        QValue otherV = factory.create(CALENDAR);
         assertEquals("Equality of qualified date value must be calculated based on their String representation.", v, otherV);
     }
 
     public void testDateValueEquality2() throws RepositoryException {
-        QValue v = QValue.create(CALENDAR);
-        QValue otherV = QValue.create(v.getString(), PropertyType.DATE);
+        QValue v = factory.create(CALENDAR);
+        QValue otherV = factory.create(v.getString(), PropertyType.DATE);
         assertEquals("Equality of qualified date value must be calculated based on their String representation.", v, otherV);
     }
 
     public void testDateValueStringRepresentation() throws RepositoryException {
-        QValue v = QValue.create(CALENDAR);
+        QValue v = factory.create(CALENDAR);
         String s = ISO8601.format(CALENDAR);
         assertEquals("Expected String representation of qualified date value to be ISO8601 compliant.", s, v.getString());
     }
 
-    public void testDateValueCopy() throws RepositoryException {
-        QValue v = QValue.create(CALENDAR);
-        QValue copy = v.createCopy();
-        assertTrue(copy.getType() == PropertyType.DATE);
-        assertNotSame(v, copy);
-        assertEquals(v, copy);
-    }
-
     //----------------------------------------------------------< REFERENCE >---
     public void testNullReferenceValue() throws IOException {
         try {
-            QValue.create((UUID) null);
-            fail();
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
-        try {
-            QValue.create((String) null, PropertyType.REFERENCE);
-            fail();
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
-        try {
-            QValue.create(new String[] {null}, PropertyType.REFERENCE);
-            fail();
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
-        try {
-            QValue.create((InputStream) null, PropertyType.REFERENCE);
-            fail();
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
-        try {
-            QValue.create(new InputStream[] {null}, PropertyType.REFERENCE);
+            factory.create((String) null, PropertyType.REFERENCE);
             fail();
         } catch (IllegalArgumentException e) {
             // ok
@@ -137,27 +91,19 @@
     }
 
     public void testReferenceValueType() {
-        QValue v = QValue.create(REFERENCE, PropertyType.REFERENCE);
+        QValue v = factory.create(REFERENCE, PropertyType.REFERENCE);
         assertTrue("Type of a date value must be PropertyType.REFERENCE.", v.getType() == PropertyType.REFERENCE);
     }
 
     public void testReferenceValueEquality() {
-        QValue v = QValue.create(REFERENCE, PropertyType.REFERENCE);
-        QValue otherV = QValue.create(REFERENCE, PropertyType.REFERENCE);
+        QValue v = factory.create(REFERENCE, PropertyType.REFERENCE);
+        QValue otherV = factory.create(REFERENCE, PropertyType.REFERENCE);
         assertEquals("Qualified ref values created from the same string must be equal.", v, otherV);
     }
 
-    public void testReferenceValueCopy() throws RepositoryException {
-        QValue v = QValue.create(REFERENCE, PropertyType.REFERENCE);
-        QValue copy = v.createCopy();
-        assertTrue(copy.getType() == PropertyType.REFERENCE);
-        assertNotSame(v, copy);
-        assertEquals(v, copy);
-    }
-
     public void testEqualityDifferentTypes() {
-        QValue v = QValue.create(REFERENCE, PropertyType.REFERENCE);
-        QValue v2 = QValue.create(REFERENCE, PropertyType.STRING);
+        QValue v = factory.create(REFERENCE, PropertyType.REFERENCE);
+        QValue v2 = factory.create(REFERENCE, PropertyType.STRING);
         assertFalse(v.equals(v2));
     }
 
@@ -165,13 +111,7 @@
     //--------------------------------------------------------------< QName >---
     public void testNullQNameValue() throws IOException {
         try {
-            QValue.create((QName) null);
-            fail();
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
-        try {
-            QValue.create(new QName[] {null});
+            factory.create((QName) null);
             fail();
         } catch (IllegalArgumentException e) {
             // ok
@@ -179,16 +119,27 @@
     }
 
     public void testQNameValueType() throws IOException {
-        QValue v = QValue.create(QName.JCR_DATA);
+        QValue v = factory.create(QName.JCR_DATA);
         assertTrue(v.getType() == PropertyType.NAME);
-        v = QValue.create(QName.JCR_DATA.toString(), PropertyType.NAME);
+        v = factory.create(QName.JCR_DATA.toString(), PropertyType.NAME);
         assertTrue(v.getType() == PropertyType.NAME);
     }
 
+    public void testQNameValueEquality() throws IOException {
+        QValue v = factory.create(QName.JCR_DATA);
+        QValue v2 = factory.create(QName.JCR_DATA.toString(), PropertyType.NAME);
+        assertTrue(v.equals(v2));
+    }
+
+    public void testQNameValueGetString() throws IOException, RepositoryException {
+        QValue v = factory.create(QName.JCR_DATA);
+        assertTrue(v.getString().equals(QName.JCR_DATA.toString()));
+    }
+
     //--------------------------------------------------------------< QPath >---
     public void testNullPathValue() throws IOException {
         try {
-            QValue.create((Path) null);
+            factory.create((Path) null);
             fail();
         } catch (IllegalArgumentException e) {
             // ok
@@ -196,28 +147,40 @@
     }
 
     public void testPathValueType() throws IOException {
-        QValue v = QValue.create(Path.ROOT);
+        QValue v = factory.create(Path.ROOT);
         assertTrue(v.getType() == PropertyType.PATH);
-        v = QValue.create(Path.ROOT.toString(), PropertyType.PATH);
+        v = factory.create(Path.ROOT.toString(), PropertyType.PATH);
         assertTrue(v.getType() == PropertyType.PATH);
     }
 
+
+    public void testPathValueEquality() throws IOException {
+        QValue v = factory.create(Path.ROOT);
+        QValue v2 = factory.create(Path.ROOT.toString(), PropertyType.PATH);
+        assertTrue(v.equals(v2));
+    }
+
+    public void testPathValueGetString() throws IOException, RepositoryException {
+        QValue v = factory.create(Path.ROOT);
+        assertTrue(v.getString().equals(Path.ROOT.toString()));
+    }
+
     //-------------------------------------------------------------< BINARY >---
     public void testNullBinaryValue() throws IOException {
         try {
-            QValue.create((byte[]) null);
+            factory.create((byte[]) null);
             fail();
         } catch (IllegalArgumentException e) {
             // ok
         }
         try {
-            QValue.create((InputStream) null);
+            factory.create((InputStream) null);
             fail();
         } catch (IllegalArgumentException e) {
             // ok
         }
         try {
-            QValue.create((File) null);
+            factory.create((File) null);
             fail();
         } catch (IllegalArgumentException e) {
             // ok
@@ -225,7 +188,7 @@
     }
 
     public void testBinaryValueType() throws IOException {
-        QValue v = QValue.create(new byte[] {'a', 'b', 'c'});
+        QValue v = factory.create(new byte[] {'a', 'b', 'c'});
         assertTrue(v.getType() == PropertyType.BINARY);
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java Fri Jan 19 09:37:03 2007
@@ -20,7 +20,6 @@
 import org.apache.jackrabbit.util.IteratorHelper;
 import org.apache.jackrabbit.value.ValueHelper;
 import org.apache.jackrabbit.value.ValueFormat;
-import org.apache.jackrabbit.value.QValue;
 import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.jackrabbit.name.NameException;
@@ -53,6 +52,7 @@
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.IdIterator;
 import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.QValue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -1384,11 +1384,11 @@
         }
         QValue qvs;
         if (targetType == PropertyType.UNDEFINED) {
-            qvs = ValueFormat.getQValue(value, session.getNamespaceResolver());
+            qvs = ValueFormat.getQValue(value, session.getNamespaceResolver(), session.getQValueFactory());
             targetType = qvs.getType();
         } else {
             Value targetValue = ValueHelper.convert(value, targetType, session.getValueFactory());
-            qvs = ValueFormat.getQValue(targetValue, session.getNamespaceResolver());
+            qvs = ValueFormat.getQValue(targetValue, session.getNamespaceResolver(), session.getQValueFactory());
         }
         return createProperty(qName, targetType, def, new QValue[] {qvs});
     }
@@ -1428,7 +1428,7 @@
             }
         }
         Value[] targetValues = ValueHelper.convert(values, targetType, session.getValueFactory());
-        QValue[] qvs = ValueFormat.getQValues(targetValues, session.getNamespaceResolver());
+        QValue[] qvs = ValueFormat.getQValues(targetValues, session.getNamespaceResolver(), session.getQValueFactory());
         return createProperty(qName, targetType, def, qvs);
     }
 

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java Fri Jan 19 09:37:03 2007
@@ -23,7 +23,7 @@
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.NameFormat;
 import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.value.QValue;
+import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.value.ValueFormat;
 import org.apache.jackrabbit.value.ValueHelper;
 import org.slf4j.LoggerFactory;
@@ -153,7 +153,7 @@
         QValue[] qValues = null;
         if (values != null) {
             Value[] vs = ValueHelper.convert(values, targetType, session.getValueFactory());
-            qValues = ValueFormat.getQValues(vs, session.getNamespaceResolver());
+            qValues = ValueFormat.getQValues(vs, session.getNamespaceResolver(), session.getQValueFactory());
         }
         setInternalValues(qValues, targetType);
     }
@@ -189,10 +189,10 @@
                     if (reqType != PropertyType.STRING) {
                         // type conversion required
                         Value v = ValueHelper.convert(string, reqType, session.getValueFactory());
-                        qValue = ValueFormat.getQValue(v, session.getNamespaceResolver());
+                        qValue = ValueFormat.getQValue(v, session.getNamespaceResolver(), session.getQValueFactory());
                     } else {
                         // no type conversion required
-                        qValue = QValue.create(string);
+                        qValue = session.getQValueFactory().create(string, PropertyType.STRING);
                     }
                 }
                 qValues[i] = qValue;
@@ -264,7 +264,7 @@
             setInternalValues(null, reqType);
         } else {
             checkValidReference(value, reqType, session.getNamespaceResolver());
-            QValue qValue = QValue.create(value.getUUID(), PropertyType.REFERENCE);
+            QValue qValue = session.getQValueFactory().create(value.getUUID(), PropertyType.REFERENCE);
             setInternalValues(new QValue[]{qValue}, reqType);
         }
     }
@@ -506,10 +506,10 @@
         if (requiredType != value.getType()) {
             // type conversion required
             Value v = ValueHelper.convert(value, requiredType, session.getValueFactory());
-            qValue = ValueFormat.getQValue(v, session.getNamespaceResolver());
+            qValue = ValueFormat.getQValue(v, session.getNamespaceResolver(), session.getQValueFactory());
         } else {
             // no type conversion required
-            qValue = ValueFormat.getQValue(value, session.getNamespaceResolver());
+            qValue = ValueFormat.getQValue(value, session.getNamespaceResolver(), session.getQValueFactory());
         }
         setInternalValues(new QValue[]{qValue}, requiredType);
     }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java Fri Jan 19 09:37:03 2007
@@ -50,6 +50,7 @@
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.spi.XASessionInfo;
+import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.commons.collections.map.ReferenceMap;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -136,7 +137,7 @@
         nsMappings = new LocalNamespaceMappings(workspace.getNamespaceRegistryImpl());
 
         // build nodetype manager
-        ntManager = new NodeTypeManagerImpl(workspace.getNodeTypeRegistry(), getNamespaceResolver(), internalGetValueFactory());
+        ntManager = new NodeTypeManagerImpl(workspace.getNodeTypeRegistry(), getNamespaceResolver(), internalGetValueFactory(), getQValueFactory());
 
         validator = new ItemStateValidator(workspace.getNodeTypeRegistry(), this);
 
@@ -677,8 +678,8 @@
         return new WorkspaceImpl(sessionInfo.getWorkspaceName(), this, config, sessionInfo);
     }
 
-    protected SessionItemStateManager createSessionItemStateManager(UpdatableItemStateManager workspaceStateManager) {
-        return new SessionItemStateManager(workspaceStateManager, getIdFactory(), getValidator());
+    protected SessionItemStateManager createSessionItemStateManager(UpdatableItemStateManager workspaceStateManager) throws RepositoryException {
+        return new SessionItemStateManager(workspaceStateManager, getIdFactory(), getValidator(), getQValueFactory());
     }
 
     protected HierarchyManager createHierarchyManager() {
@@ -742,6 +743,10 @@
     // TODO public for SessionImport only. review
     public IdFactory getIdFactory() {
         return workspace.getIdFactory();
+    }
+
+    public QValueFactory getQValueFactory() throws RepositoryException {
+        return config.getRepositoryService().getQValueFactory();
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java Fri Jan 19 09:37:03 2007
@@ -76,7 +76,7 @@
 import org.apache.jackrabbit.spi.EventFilter;
 import org.apache.jackrabbit.spi.IdIterator;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
-import org.apache.jackrabbit.value.QValue;
+import org.apache.jackrabbit.spi.QValue;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -86,7 +86,6 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.AccessDeniedException;
 import javax.jcr.PathNotFoundException;
-import javax.jcr.PropertyType;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.ItemExistsException;
@@ -709,27 +708,10 @@
             QName propertyName = operation.getPropertyName();
             int type = operation.getPropertyType();
             if (operation.isMultiValued()) {
-                QValue[] values = operation.getValues();
-                if (type == PropertyType.BINARY) {
-                    InputStream[] ins = new InputStream[values.length];
-                    for (int i = 0; i < values.length; i++) {
-                        ins[i] = values[i].getStream();
-                    }
-                    batch.addProperty(parentId, propertyName, ins, type);
-                } else {
-                    String[] strs = new String[values.length];
-                    for (int i = 0; i < values.length; i++) {
-                        strs[i] = values[i].getString();
-                    }
-                    batch.addProperty(parentId, propertyName, strs, type);
-                }
+                batch.addProperty(parentId, propertyName, operation.getValues());
             } else {
                 QValue value = operation.getValues()[0];
-                if (type == PropertyType.BINARY) {
-                    batch.addProperty(parentId, propertyName, value.getStream(), type);
-                } else {
-                    batch.addProperty(parentId, propertyName, value.getString(), type);
-                }
+                batch.addProperty(parentId, propertyName, value);
             }
         }
 
@@ -800,29 +782,10 @@
         public void visit(SetPropertyValue operation) throws RepositoryException {
             PropertyState pState = operation.getPropertyState();
             PropertyId id = pState.getPropertyId();
-            int type = operation.getPropertyType();
             if (pState.isMultiValued()) {
-                QValue[] values = operation.getValues();
-                if (type == PropertyType.BINARY) {
-                    InputStream[] ins = new InputStream[values.length];
-                    for (int i = 0; i < values.length; i++) {
-                        ins[i] = values[i].getStream();
-                    }
-                    batch.setValue(id, ins, type);
-                } else {
-                    String[] strs = new String[values.length];
-                    for (int i = 0; i < values.length; i++) {
-                        strs[i] = values[i].getString();
-                    }
-                    batch.setValue(id, strs, type);
-                }
+                batch.setValue(id, operation.getValues());
             } else {
-                QValue value = operation.getValues()[0];
-                if (operation.getPropertyType() == PropertyType.BINARY) {
-                    batch.setValue(id, value.getStream(), type);
-                } else {
-                    batch.setValue(id, value.getString(), type);
-                }
+                batch.setValue(id, operation.getValues()[0]);
             }
         }
 

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java Fri Jan 19 09:37:03 2007
@@ -20,7 +20,7 @@
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 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;
 
@@ -35,8 +35,6 @@
 import java.util.HashMap;
 import java.util.ArrayList;
 import java.util.Iterator;
-import java.io.InputStream;
-import java.io.IOException;
 
 /**
  * <code>DefinitionValidator</code>...
@@ -246,7 +244,7 @@
              * Note: default internal values are built from the required type,
              * thus check for match with pd.getRequiredType is redundant.
              */
-            QValue[] defVals = getQValues(pd);
+            QValue[] defVals = pd.getDefaultValues();
 
             /* check that default values satisfy value constraints.
              * Note however, that no check is performed if autocreated property-
@@ -562,37 +560,5 @@
             // make sure namespace uri denotes a registered namespace
             nsRegistry.getPrefix(name.getNamespaceURI());
         }
-    }
-
-    private static QValue[] getQValues(QPropertyDefinition propDef) throws RepositoryException {
-        int reqType = propDef.getRequiredType();
-        // if no default values are specified, need to return null.
-        QValue[] ivs = null;
-        if (reqType == PropertyType.BINARY) {
-            InputStream[] dfv = propDef.getDefaultValuesAsStream();
-            if (dfv != null) {
-                ivs = new QValue[dfv.length];
-                for (int i = 0; i < dfv.length; i++) {
-                    try {
-                        ivs[i] = QValue.create(dfv[i]);
-                    } catch (IOException e) {
-                        String msg = "[" + propDef.getQName() + "] error while reading binary default values.";
-                        throw new RepositoryException(msg);
-                    }
-                }
-            }
-        } else {
-            String[] dfv = propDef.getDefaultValues();
-            if (dfv != null) {
-                ivs = new QValue[dfv.length];
-                if (reqType == PropertyType.UNDEFINED) {
-                    reqType = PropertyType.STRING;
-                }
-                for (int i = 0; i < dfv.length; i++) {
-                    ivs[i] = QValue.create(dfv[i], reqType);
-                }
-            }
-        }
-        return ivs;
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java Fri Jan 19 09:37:03 2007
@@ -26,7 +26,8 @@
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
-import org.apache.jackrabbit.value.QValue;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.value.ValueHelper;
 import org.apache.jackrabbit.value.ValueFormat;
 import org.slf4j.LoggerFactory;
@@ -65,6 +66,11 @@
      * @see NodeType#canSetProperty(String, Value[])
      */
     private final ValueFactory valueFactory;
+    /**
+     * ValueFactory used to convert JCR values to qualified ones in order to
+     * determine value constraints within the NodeType interface.
+     */
+    private final QValueFactory qValueFactory;
 
     /**
      * Package private constructor
@@ -80,11 +86,12 @@
      */
     NodeTypeImpl(EffectiveNodeType ent, QNodeTypeDefinition ntd,
                  NodeTypeManagerImpl ntMgr, NamespaceResolver nsResolver,
-                 ValueFactory valueFactory) {
+                 ValueFactory valueFactory, QValueFactory qValueFactory) {
         this.ent = ent;
         this.ntMgr = ntMgr;
         this.nsResolver = nsResolver;
         this.valueFactory = valueFactory;
+        this.qValueFactory = qValueFactory;
         this.ntd = ntd;
     }
 
@@ -303,19 +310,17 @@
             if (def.isMultiple()) {
                 return false;
             }
-            int targetType;
+            Value v;
             if (def.getRequiredType() != PropertyType.UNDEFINED
                     && def.getRequiredType() != value.getType()) {
                 // type conversion required
-                targetType = def.getRequiredType();
+                v =  ValueHelper.convert(value, def.getRequiredType(), valueFactory);
             } else {
                 // no type conversion required
-                targetType = value.getType();
+                v = value;
             }
-            // create QValue from Value and perform
-            // type conversion as necessary
-            Value v = ValueHelper.convert(value, targetType, valueFactory);
-            QValue qValue = ValueFormat.getQValue(v, nsResolver);
+            // create QValue from Value
+            QValue qValue = ValueFormat.getQValue(v, nsResolver, qValueFactory);
             checkSetPropertyValueConstraints(def, new QValue[]{qValue});
             return true;
         } catch (NameException be) {
@@ -383,7 +388,7 @@
                     // create QValue from Value and perform
                     // type conversion as necessary
                     Value v = ValueHelper.convert(values[i], targetType, valueFactory);
-                    QValue qValue = ValueFormat.getQValue(v, nsResolver);
+                    QValue qValue = ValueFormat.getQValue(v, nsResolver, qValueFactory);
                     list.add(qValue);
                 }
             }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java Fri Jan 19 09:37:03 2007
@@ -28,6 +28,7 @@
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.QValueFactory;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -75,6 +76,11 @@
     private final ValueFactory valueFactory;
 
     /**
+     * The QValueFactory used to convert JCR values to qualified ones.
+     */
+    private final QValueFactory qValueFactory;
+
+    /**
      * A cache for <code>NodeType</code> instances created by this
      * <code>NodeTypeManager</code>
      */
@@ -99,11 +105,12 @@
      * @param nsResolver namespace resolver
      */
     public NodeTypeManagerImpl(NodeTypeRegistry ntReg, NamespaceResolver nsResolver,
-                               ValueFactory valueFactory) {
+                               ValueFactory valueFactory, QValueFactory qValueFactory) {
         this.nsResolver = nsResolver;
         this.ntReg = ntReg;
         this.ntReg.addListener(this);
         this.valueFactory = valueFactory;
+        this.qValueFactory = qValueFactory;
 
         // setup caches with soft references to node type
         ntCache = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
@@ -128,7 +135,7 @@
             if (nt == null) {
                 EffectiveNodeType ent = ntReg.getEffectiveNodeType(name);
                 QNodeTypeDefinition def = ntReg.getNodeTypeDefinition(name);
-                nt = new NodeTypeImpl(ent, def, this, nsResolver, valueFactory);
+                nt = new NodeTypeImpl(ent, def, this, nsResolver, valueFactory, qValueFactory);
                 ntCache.put(name, nt);
             }
             return nt;

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistry.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistry.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistry.java Fri Jan 19 09:37:03 2007
@@ -77,8 +77,7 @@
      * @throws NodeTypeConflictException
      * @throws NoSuchNodeTypeException
      */
-    EffectiveNodeType getEffectiveNodeType(QName[] ntNames,
-                                           Map ntdMap)
+    EffectiveNodeType getEffectiveNodeType(QName[] ntNames, Map ntdMap)
             throws NodeTypeConflictException, NoSuchNodeTypeException;
 
 

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java Fri Jan 19 09:37:03 2007
@@ -22,6 +22,7 @@
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.QValue;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -661,7 +662,7 @@
                     }
                 }
                 ps.println("\t\tValueConstraints\t" + constraints.toString());
-                String[] defVals = pd[i].getDefaultValues();
+                QValue[] defVals = pd[i].getDefaultValues();
                 StringBuffer defaultValues = new StringBuffer();
                 if (defVals == null) {
                     defaultValues.append("<null>");
@@ -670,7 +671,11 @@
                         if (defaultValues.length() > 0) {
                             defaultValues.append(", ");
                         }
-                        defaultValues.append(defVals[n]);
+                        try {
+                            defaultValues.append(defVals[n].getString());
+                        } catch (RepositoryException e) {
+                            defaultValues.append(defVals[n].toString());
+                        }
                     }
                 }
                 ps.println("\t\tDefaultValue\t" + defaultValues.toString());

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/PropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/PropertyDefinitionImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/PropertyDefinitionImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/PropertyDefinitionImpl.java Fri Jan 19 09:37:03 2007
@@ -18,7 +18,7 @@
 
 import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
-import org.apache.jackrabbit.value.QValue;
+import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.value.ValueFormat;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -26,10 +26,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
-import javax.jcr.PropertyType;
 import javax.jcr.nodetype.PropertyDefinition;
-import java.io.IOException;
-import java.io.InputStream;
 
 /**
  * This class implements the <code>PropertyDefinition</code> interface.
@@ -65,27 +62,9 @@
      */
     public Value[] getDefaultValues() {
         QPropertyDefinition pDef = ((QPropertyDefinition) itemDef);
-        QValue[] defVals;
-        if (pDef.getRequiredType() == PropertyType.BINARY) {
-            try {
-                InputStream[] ins = pDef.getDefaultValuesAsStream();
-                if (ins == null) {
-                    return null;
-                } else {
-                    defVals = QValue.create(ins, pDef.getRequiredType());
-                }
-            } catch (IOException e) {
-                String propName = (getName() == null) ? "[null]" : getName();
-                log.error("Illegal default value specified for property " + propName + " in node type " + getDeclaringNodeType(), e);
-                return null;
-            }
-        } else {
-            String[] ss = pDef.getDefaultValues();
-            if (ss == null) {
-                return null;
-            } else {
-                defVals = QValue.create(ss, pDef.getRequiredType());
-            }
+        QValue[] defVals = pDef.getDefaultValues();
+        if (defVals == null) {
+            return null;
         }
 
         Value[] values = new Value[defVals.length];

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ValueConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ValueConstraint.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ValueConstraint.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ValueConstraint.java Fri Jan 19 09:37:03 2007
@@ -27,8 +27,8 @@
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.PathFormat;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.value.DateValue;
-import org.apache.jackrabbit.value.QValue;
 import org.apache.jackrabbit.util.ISO8601;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -169,7 +169,7 @@
     }
 
     /**
-     * 
+     *
      * @param type
      * @param definition
      * @param nsResolver

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddProperty.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddProperty.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddProperty.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AddProperty.java Fri Jan 19 09:37:03 2007
@@ -17,8 +17,8 @@
 package org.apache.jackrabbit.jcr2spi.operation;
 
 import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.value.QValue;
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 
 import javax.jcr.RepositoryException;

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/SetPropertyValue.java Fri Jan 19 09:37:03 2007
@@ -17,14 +17,13 @@
 package org.apache.jackrabbit.jcr2spi.operation;
 
 import org.apache.jackrabbit.jcr2spi.state.PropertyState;
+import org.apache.jackrabbit.spi.QValue;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFormatException;
 import javax.jcr.AccessDeniedException;
 import javax.jcr.ItemExistsException;
 import javax.jcr.UnsupportedRepositoryOperationException;
-import org.apache.jackrabbit.value.QValue;
-
 import javax.jcr.version.VersionException;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java Fri Jan 19 09:37:03 2007
@@ -21,7 +21,6 @@
 
 import javax.jcr.Item;
 import javax.jcr.Node;
-import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.jcr2spi.ItemManager;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateManager;
@@ -72,10 +71,9 @@
      * @param itemStateMgr The <code>ItemStateManager</code> used to build
      * <code>ItemState</code>s from the ids returned by the query.
      * @param queryInfo the query result.
-     * @throws RepositoryException if an error occurs while creating a node iterator.
      */
     public NodeIteratorImpl(ItemManager itemMgr, ItemStateManager itemStateMgr,
-                            QueryInfo queryInfo) throws RepositoryException {
+                            QueryInfo queryInfo) {
         this.itemMgr = itemMgr;
         this.itemStateMgr = itemStateMgr;
         this.rows = queryInfo.getRows();

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java Fri Jan 19 09:37:03 2007
@@ -17,19 +17,19 @@
 package org.apache.jackrabbit.jcr2spi.state;
 
 import org.apache.commons.collections.iterators.IteratorChain;
-import org.apache.jackrabbit.spi.IdFactory;
-import org.apache.jackrabbit.spi.QNodeDefinition;
-import org.apache.jackrabbit.name.Path;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.spi.ItemId;
-import org.apache.jackrabbit.spi.Event;
 import org.apache.jackrabbit.jcr2spi.state.entry.ChildNodeEntry;
 import org.apache.jackrabbit.jcr2spi.state.entry.ChildPropertyEntry;
 import org.apache.jackrabbit.jcr2spi.state.entry.PropertyReference;
 import org.apache.jackrabbit.jcr2spi.state.entry.ChildItemEntry;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
-import org.apache.jackrabbit.value.QValue;
+import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.Event;
+import org.apache.jackrabbit.spi.QNodeDefinition;
+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/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java Fri Jan 19 09:37:03 2007
@@ -27,7 +27,7 @@
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.spi.Event;
-import org.apache.jackrabbit.value.QValue;
+import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.jcr2spi.nodetype.ValueConstraint;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
 import org.slf4j.Logger;

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?view=diff&rev=497885&r1=497884&r2=497885
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java Fri Jan 19 09:37:03 2007
@@ -50,7 +50,8 @@
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.IdFactory;
-import org.apache.jackrabbit.value.QValue;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.uuid.UUID;
 import org.apache.commons.collections.iterators.IteratorChain;
 
@@ -78,7 +79,6 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.io.InputStream;
-import java.io.IOException;
 
 /**
  * <code>SessionItemStateManager</code> ...
@@ -97,13 +97,10 @@
      */
     private final TransientItemStateManager transientStateMgr;
 
-    /**
-     * Hierarchy manager
-     */
-    //private final HierarchyManager hierMgr;
-    //private final NamespaceResolver nsResolver;
     private final ItemStateValidator validator;
 
+    private final QValueFactory qValueFactory;
+
     /**
      * Creates a new <code>SessionItemStateManager</code> instance.
      *
@@ -111,10 +108,12 @@
      */
     public SessionItemStateManager(UpdatableItemStateManager workspaceItemStateMgr,
                                    IdFactory idFactory,
-                                   ItemStateValidator validator) {
+                                   ItemStateValidator validator,
+                                   QValueFactory qValueFactory) {
         this.workspaceItemStateMgr = workspaceItemStateMgr;
         this.transientStateMgr = new TransientItemStateManager(idFactory, workspaceItemStateMgr);
         this.validator = validator;
+        this.qValueFactory = qValueFactory;
     }
 
     //---------------------------------------------------< ItemStateManager >---
@@ -324,7 +323,7 @@
             QValue[] newVals = new QValue[values.length];
             for (int i = 0; i < values.length; i++) {
                 QValue val = values[i];
-                QValue adjusted = refTracker.getMappedReference(val);
+                QValue adjusted = refTracker.getMappedReference(val, qValueFactory);
                 if (adjusted != null) {
                     newVals[i] = adjusted;
                     modified = true;
@@ -483,7 +482,7 @@
                 try {
                     PropertyState pState = nState.getPropertyState(QName.JCR_MIXINTYPES);
                     int options = ItemStateValidator.CHECK_LOCK | ItemStateValidator.CHECK_VERSIONING;
-                    setPropertyStateValue(pState, QValue.create(mixinNames), PropertyType.NAME, options);
+                    setPropertyStateValue(pState, getQValues(mixinNames, qValueFactory), PropertyType.NAME, options);
                 } catch (ItemStateException e) {
                     // should not occur, since existance has been asserted before
                     throw new RepositoryException(e);
@@ -492,7 +491,7 @@
                 // create new jcr:mixinTypes property
                 EffectiveNodeType ent = validator.getEffectiveNodeType(nState);
                 QPropertyDefinition pd = ent.getApplicablePropertyDefinition(QName.JCR_MIXINTYPES, PropertyType.NAME, true);
-                QValue[] mixinValue = QValue.create(mixinNames);
+                QValue[] mixinValue = getQValues(mixinNames, qValueFactory);
                 int options = ItemStateValidator.CHECK_LOCK | ItemStateValidator.CHECK_VERSIONING;
                 addPropertyState(nState, pd.getQName(), pd.getRequiredType(), mixinValue, pd, options);
             }
@@ -730,18 +729,9 @@
     private QValue[] computeSystemGeneratedPropertyValues(NodeState parent,
                                                           QPropertyDefinition def) {
         QValue[] genValues = null;
-        String[] qDefaultValues = def.getDefaultValues();
+        QValue[] qDefaultValues = def.getDefaultValues();
         if (qDefaultValues != null && qDefaultValues.length > 0) {
-            if (def.getRequiredType() == PropertyType.BINARY) {
-                try {
-                    genValues = QValue.create(def.getDefaultValuesAsStream(), def.getRequiredType());
-                } catch (IOException e) {
-                    log.error("Internal error while build QValue from property definition: ", e.getMessage());
-                    return null;
-                }
-            } else {
-               genValues = QValue.create(qDefaultValues, def.getRequiredType());
-            }
+            genValues = qDefaultValues;
         } else if (def.isAutoCreated()) {
             // handle known predefined nodetypes that declare auto-created
             // properties without default values
@@ -753,34 +743,44 @@
                 if (uniqueID == null) {
                     uniqueID = UUID.randomUUID().toString();
                 }
-                genValues = new QValue[]{QValue.create(uniqueID)};
+                genValues = new QValue[]{qValueFactory.create(uniqueID, PropertyType.REFERENCE)};
             } else if (QName.NT_BASE.equals(declaringNT)) {
                 // nt:base node type
                 if (QName.JCR_PRIMARYTYPE.equals(name)) {
                     // jcr:primaryType property
-                    genValues = new QValue[]{QValue.create(parent.getNodeTypeName())};
+                    genValues = new QValue[]{qValueFactory.create(parent.getNodeTypeName())};
                 } else if (QName.JCR_MIXINTYPES.equals(name)) {
                     // jcr:mixinTypes property
                     QName[] mixins = parent.getMixinTypeNames();
-                    genValues = new QValue[mixins.length];
-                    for (int i = 0; i < mixins.length; i++) {
-                        genValues[i] = QValue.create(mixins[i]);
-                    }
+                    genValues = getQValues(mixins, qValueFactory);
                 }
             } else if (QName.NT_HIERARCHYNODE.equals(declaringNT) && QName.JCR_CREATED.equals(name)) {
                 // nt:hierarchyNode node type defines jcr:created property
-                genValues = new QValue[]{QValue.create(Calendar.getInstance())};
+                genValues = new QValue[]{qValueFactory.create(Calendar.getInstance())};
             } else if (QName.NT_RESOURCE.equals(declaringNT) && QName.JCR_LASTMODIFIED.equals(name)) {
                 // nt:resource node type defines jcr:lastModified property
-                genValues = new QValue[]{QValue.create(Calendar.getInstance())};
+                genValues = new QValue[]{qValueFactory.create(Calendar.getInstance())};
             } else if (QName.NT_VERSION.equals(declaringNT) && QName.JCR_CREATED.equals(name)) {
                 // nt:version node type defines jcr:created property
-                genValues = new QValue[]{QValue.create(Calendar.getInstance())};
+                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.getQName() + " without default value.");
             }
         }
         return genValues;
+    }
+
+    /**
+     * @param qNames
+     * @param factory
+     * @return An array of QValue objects from the given <code>QName</code>s
+     */
+    private static QValue[] getQValues(QName[] qNames, QValueFactory factory) {
+        QValue[] ret = new QValue[qNames.length];
+        for (int i = 0; i < qNames.length; i++) {
+            ret[i] = factory.create(qNames[i]);
+        }
+        return ret;
     }
 }



Mime
View raw message