jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r784013 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ main/java/org/apache/jackrabbit/core/journal/ main/java/org/apache/jackrabbit/core/nodetype/compact/ main/java/org/apache/jackrabbit/core/nodetype/xml...
Date Fri, 12 Jun 2009 07:35:51 GMT
Author: thomasm
Date: Fri Jun 12 07:35:50 2009
New Revision: 784013

URL: http://svn.apache.org/viewvc?rev=784013&view=rev
Log:
JCR-2144 InternalValue refactoring

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefWriter.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BinaryValueImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Fri Jun 12 07:35:50 2009
@@ -210,7 +210,7 @@
      * Retention and Hold Manager
      */
     private RetentionManager retentionManager;
-        
+
     /**
      * The stack trace knows who opened this session. It is logged
      * if the session is finalized, but Session.logout() was never called.
@@ -473,7 +473,7 @@
     /**
      * Returns the internal retention manager used for evaluation of effective
      * retention policies and holds.
-     * 
+     *
      * @return internal retention manager
      * @throws RepositoryException
      */
@@ -679,7 +679,7 @@
         }
         IterablePersistenceManager[] ipmList = new IterablePersistenceManager[pmList.size()];
         for (int i = 0; i < pmList.size(); i++) {
-            pm = (PersistenceManager) pmList.get(i);
+            pm = pmList.get(i);
             if (!(pm instanceof IterablePersistenceManager)) {
                 ipmList = null;
                 break;
@@ -1220,8 +1220,7 @@
     /**
      * {@inheritDoc}
      */
-    public ValueFactory getValueFactory()
-            throws UnsupportedRepositoryOperationException, RepositoryException {
+    public ValueFactory getValueFactory() {
         if (valueFactory == null) {
             valueFactory = new ValueFactoryImpl(this, rep.getDataStore());
         }
@@ -1246,7 +1245,7 @@
      * {@inheritDoc}
      */
     public String[] getAttributeNames() {
-        return (String[]) attributes.keySet().toArray(new String[attributes.size()]);
+        return attributes.keySet().toArray(new String[attributes.size()]);
     }
 
     /**
@@ -1558,10 +1557,10 @@
         ps.println();
         itemStateMgr.dump(ps);
     }
-    
+
     /**
-     * Finalize the session. If the application doesn't close Session.logout(), 
-     * the session is closed automatically; however a warning is written to the log file,

+     * Finalize the session. If the application doesn't call Session.logout(),
+     * the session is closed automatically; however a warning is written to the log file,
      * together with the stack trace of where the session was opened.
      */
     public void finalize() {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java
Fri Jun 12 07:35:50 2009
@@ -144,7 +144,7 @@
     public void writeNodeTypeDef(NodeTypeDef ntd) throws JournalException {
         try {
             StringWriter sw = new StringWriter();
-            CompactNodeTypeDefWriter writer = new CompactNodeTypeDefWriter(sw, nsResolver,
resolver, true);
+            CompactNodeTypeDefWriter writer = new CompactNodeTypeDefWriter(sw, nsResolver,
resolver);
             writer.write(ntd);
             writer.close();
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefWriter.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefWriter.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefWriter.java
Fri Jun 12 07:35:50 2009
@@ -28,6 +28,7 @@
 import javax.jcr.NamespaceException;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
 import javax.jcr.query.qom.QueryObjectModelConstants;
 import javax.jcr.version.OnParentVersionAction;
 
@@ -37,15 +38,19 @@
 import org.apache.jackrabbit.core.nodetype.ValueConstraint;
 import org.apache.jackrabbit.core.nodetype.ItemDef;
 import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.core.value.InternalValueFactory;
+import org.apache.jackrabbit.core.value.ValueFactoryImpl;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.commons.nodetype.compact.Lexer;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.util.ISO9075;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.query.qom.Operator;
+import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
 
 /**
- * Prints node type defs in a compact notation
+ * Prints node type defs in a compact notation.
+ * All used namespace declarations are also written.
  * Print Format:
  * <ex = "http://apache.org/jackrabbit/example">
  * [ex:NodeType] > ex:ParentType1, ex:ParentType2
@@ -96,27 +101,10 @@
      * @param npResolver
      */
     public CompactNodeTypeDefWriter(Writer out, NamespaceResolver r, NamePathResolver npResolver)
{
-        this(out, r, npResolver, false);
-    }
-
-    /**
-     * Creates a new nodetype writer
-     *
-     * @param out the underlaying writer
-     * @param r the naespace resolver
-     * @param npResolver
-     * @param includeNS if <code>true</code> all used namespace decl. are also
-     */
-    public CompactNodeTypeDefWriter(Writer out, NamespaceResolver r, NamePathResolver npResolver,
boolean includeNS) {
         this.resolver = r;
         this.npResolver = npResolver;
-        if (includeNS) {
-            this.out = new StringWriter();
-            this.nsWriter = out;
-        } else {
-            this.out = out;
-            this.nsWriter = null;
-        }
+        this.out = new StringWriter();
+        this.nsWriter = out;
     }
 
     /**
@@ -131,7 +119,7 @@
      */
     public static void write(List l, NamespaceResolver r, NamePathResolver npResolver, Writer
out)
             throws IOException {
-        CompactNodeTypeDefWriter w = new CompactNodeTypeDefWriter(out, r, npResolver, true);
+        CompactNodeTypeDefWriter w = new CompactNodeTypeDefWriter(out, r, npResolver);
         Iterator iter = l.iterator();
         while (iter.hasNext()) {
             NodeTypeDef def = (NodeTypeDef) iter.next();
@@ -315,7 +303,7 @@
                 out.write("'");
             }
         }
-        
+
         writeValueConstraints(pd.getValueConstraints());
     }
 
@@ -325,11 +313,13 @@
      */
     private void writeDefaultValues(InternalValue[] dva) throws IOException {
         if (dva != null && dva.length > 0) {
+            ValueFactoryQImpl factory = ValueFactoryImpl.getInstance(npResolver);
             String delim = " = '";
             for (int i = 0; i < dva.length; i++) {
                 out.write(delim);
                 try {
-                    out.write(escape(dva[i].toJCRValue(npResolver).getString()));
+                    InternalValue v = dva[i];
+                    out.write(escape(factory.createValue(v).getString()));
                 } catch (RepositoryException e) {
                     out.write(escape(dva[i].toString()));
                 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeWriter.java
Fri Jun 12 07:35:50 2009
@@ -22,10 +22,12 @@
 import org.apache.jackrabbit.core.nodetype.ValueConstraint;
 import org.apache.jackrabbit.core.util.DOMBuilder;
 import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.core.value.ValueFactoryImpl;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
 import org.apache.jackrabbit.spi.commons.query.qom.Operator;
+import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
 import org.apache.jackrabbit.spi.Name;
 
 import javax.jcr.NamespaceRegistry;
@@ -255,11 +257,13 @@
         // default values
         InternalValue[] defaults = def.getDefaultValues();
         if (defaults != null && defaults.length > 0) {
+            ValueFactoryQImpl factory = ValueFactoryImpl.getInstance(resolver);
             builder.startElement(Constants.DEFAULTVALUES_ELEMENT);
             for (int i = 0; i < defaults.length; i++) {
+                InternalValue v = defaults[i];
                 builder.addContentElement(
                         Constants.DEFAULTVALUE_ELEMENT,
-                        defaults[i].toJCRValue(resolver).getString());
+                        factory.createValue(v).getString());
             }
             builder.endElement();
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java
Fri Jun 12 07:35:50 2009
@@ -20,7 +20,6 @@
 
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
-import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.core.query.lucene.ScoreNode;
 import org.apache.jackrabbit.core.query.lucene.Util;
@@ -56,17 +55,13 @@
         if (ps == null) {
             return EMPTY;
         } else {
-            try {
-                ValueFactory vf = context.getSession().getValueFactory();
-                InternalValue[] values = ps.getValues();
-                Value[] lengths = new Value[values.length];
-                for (int i = 0; i < lengths.length; i++) {
-                    lengths[i] = vf.createValue(Util.getLength(values[i]));
-                }
-                return lengths;
-            } catch (RepositoryException e) {
-                throw Util.createIOException(e);
+            ValueFactory vf = context.getSession().getValueFactory();
+            InternalValue[] values = ps.getValues();
+            Value[] lengths = new Value[values.length];
+            for (int i = 0; i < lengths.length; i++) {
+                lengths[i] = vf.createValue(Util.getLength(values[i]));
             }
+            return lengths;
         }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
Fri Jun 12 07:35:50 2009
@@ -156,9 +156,6 @@
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
     public long getSize() throws RepositoryException {
         return getLength();
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
Fri Jun 12 07:35:50 2009
@@ -30,7 +30,7 @@
 /**
  * Represents binary data which is stored in the data store.
  */
-public class BLOBInDataStore extends BLOBFileValue {
+class BLOBInDataStore extends BLOBFileValue {
 
     private final DataStore store;
     private final DataIdentifier identifier;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
Fri Jun 12 07:35:50 2009
@@ -29,7 +29,7 @@
 /**
  * Represents binary data which is backed by a byte[] (in memory).
  */
-public class BLOBInMemory extends BLOBFileValue {
+class BLOBInMemory extends BLOBFileValue {
 
     /**
      * Logger instance for this class

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
Fri Jun 12 07:35:50 2009
@@ -29,7 +29,7 @@
 /**
  * Represents binary data which is stored in a file system resource.
  */
-public class BLOBInResource extends BLOBFileValue {
+class BLOBInResource extends BLOBFileValue {
 
     /**
      * The default logger

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
Fri Jun 12 07:35:50 2009
@@ -33,7 +33,7 @@
 /**
  * Represents binary data which is stored in a temporary file.
  */
-public class BLOBInTempFile extends BLOBFileValue {
+class BLOBInTempFile extends BLOBFileValue {
 
     /**
      * the prefix of the string representation of this value

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBValue.java
Fri Jun 12 07:35:50 2009
@@ -42,7 +42,7 @@
  * <code>InputStream</code> instance.
  * <p/>
  */
-public class BLOBValue extends BLOBFileValue {
+class BLOBValue extends BLOBFileValue {
 
     /**
      * The default logger

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BinaryValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BinaryValueImpl.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BinaryValueImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BinaryValueImpl.java
Fri Jun 12 07:35:50 2009
@@ -24,13 +24,13 @@
 /**
  * Represents a binary value that is backed by a blob file value.
  */
-public class BinaryValueImpl extends BinaryValue implements JackrabbitValue {
-    
+class BinaryValueImpl extends BinaryValue implements JackrabbitValue {
+
     private final BLOBFileValue blob;
 
     /**
      * Construct a new object from the given blob.
-     * 
+     *
      * @param blob the blob
      */
     BinaryValueImpl(BLOBFileValue blob) throws RepositoryException {
@@ -48,7 +48,7 @@
 
     /**
      * Get the data identifier if one is available.
-     * 
+     *
      * @return the data identifier or null
      */
     DataIdentifier getDataIdentifier() {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
Fri Jun 12 07:35:50 2009
@@ -31,7 +31,6 @@
 import org.apache.jackrabbit.uuid.UUID;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
-import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
 import org.apache.jackrabbit.spi.commons.value.AbstractQValue;
 import org.apache.jackrabbit.spi.commons.value.QValueValue;
 
@@ -39,8 +38,6 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
-import javax.jcr.Session;
-import javax.jcr.ValueFactory;
 import javax.jcr.Binary;
 
 import java.io.ByteArrayInputStream;
@@ -129,7 +126,7 @@
                         QValue qv = qvv.getQValue();
                         if (qv instanceof InternalValue) {
                             InternalValue iv = (InternalValue) qv;
-                            
+
                             iv.getBLOBFileValue();
                         }
                     }
@@ -439,54 +436,6 @@
     }
 
     //----------------------------------------------------< conversions, etc. >
-    /**
-     * @param resolver
-     * @return
-     * @throws RepositoryException
-     * @deprecated
-     */
-    public Value toJCRValue(NamePathResolver resolver)
-            throws RepositoryException {
-        ValueFactory vf;
-        if (resolver instanceof Session) {
-            vf = ((Session) resolver).getValueFactory();
-        } else {
-            vf = new ValueFactoryImpl(resolver, null);
-        }
-
-        if (vf instanceof ValueFactoryQImpl) {
-            return ((ValueFactoryQImpl) vf).createValue(this);
-        } else {
-            switch (type) {
-                case PropertyType.BINARY:
-                    return vf.createValue((BLOBFileValue) val);
-                case PropertyType.BOOLEAN:
-                    return vf.createValue((Boolean) val);
-                case PropertyType.DATE:
-                    return vf.createValue((Calendar) val);
-                case PropertyType.DOUBLE:
-                    return vf.createValue((Double) val);
-                case PropertyType.LONG:
-                    return vf.createValue(((Long) val).longValue());
-                case PropertyType.DECIMAL:
-                    return vf.createValue((BigDecimal) val);
-                case PropertyType.REFERENCE:
-                    return vf.createValue(val.toString(), PropertyType.REFERENCE);
-                case PropertyType.WEAKREFERENCE:
-                    return vf.createValue(val.toString(), PropertyType.WEAKREFERENCE);
-                case PropertyType.URI:
-                    return vf.createValue(val.toString(),  PropertyType.URI);
-                case PropertyType.PATH:
-                    return vf.createValue(resolver.getJCRPath((Path) val), PropertyType.PATH);
-                case PropertyType.NAME:
-                    return vf.createValue(resolver.getJCRName((Name) val), PropertyType.NAME);
-                case PropertyType.STRING:
-                    return vf.createValue((String) val);
-                default:
-                    throw new RepositoryException("illegal internal value type");
-            }
-        }
-    }
 
     public BLOBFileValue getBLOBFileValue() {
         assert val != null && type == PropertyType.BINARY;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
Fri Jun 12 07:35:50 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.value;
 
+import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.data.DataIdentifier;
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
@@ -41,7 +42,7 @@
      * logger instance
      */
     private static final Logger log = LoggerFactory.getLogger(ValueFactoryImpl.class);
-    
+
     private final DataStore store;
 
     /**
@@ -56,6 +57,23 @@
         this.store = store;
     }
 
+    /**
+     * Constructs a new <code>ValueFactoryQImpl</code>. If possible,
+     * an existing value factory is reused.
+     * @deprecated
+     * If possible this method should not be used, instead the value factory
+     * should be retrieved from the session.
+     *
+     * @param resolver <code>NamePathResolver</code>
+     */
+    public static ValueFactoryQImpl getInstance(NamePathResolver resolver) {
+        if (resolver instanceof SessionImpl) {
+            return (ValueFactoryImpl) ((SessionImpl) resolver).getValueFactory();
+        } else {
+            return new ValueFactoryImpl(resolver, null);
+        }
+    }
+
     public Value createValue(QValue qvalue) {
         if (qvalue instanceof InternalValue && PropertyType.BINARY == qvalue.getType())
{
             try {
@@ -67,7 +85,7 @@
         }
         return super.createValue(qvalue);
     }
-    
+
     public Value createValue(Binary binary) {
         try {
             if (binary instanceof BLOBInDataStore) {
@@ -84,7 +102,7 @@
             // ignore - the super method may be smarter
         }
         return super.createValue(binary);
-    }    
+    }
 
     public Value createValue(InputStream value) {
         try {
@@ -100,7 +118,7 @@
     public Value createValue(String value, int type) throws ValueFormatException {
         if (PropertyType.BINARY == type) {
             try {
-                InternalValue qvalue = (InternalValue) getQValueFactory().create(value, type);
               
+                InternalValue qvalue = (InternalValue) getQValueFactory().create(value, type);
                 return new BinaryValueImpl(qvalue.getBLOBFileValue());
             } catch (RepositoryException e) {
                 throw new ValueFormatException(e);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java?rev=784013&r1=784012&r2=784013&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/nodetype/xml/TestAll.java
Fri Jun 12 07:35:50 2009
@@ -26,12 +26,14 @@
 import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
 import org.apache.jackrabbit.core.nodetype.PropDef;
 import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.core.value.ValueFactoryImpl;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NameFactory;
 import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
 
 import javax.jcr.NamespaceException;
 import javax.jcr.NamespaceRegistry;
@@ -149,7 +151,8 @@
             InternalValue[] values = def.getDefaultValues();
             NamespaceResolver nsResolver = new AdditionalNamespaceResolver(registry);
             NamePathResolver resolver = new DefaultNamePathResolver(nsResolver);
-            return values[index].toJCRValue(resolver).getString();
+            ValueFactoryQImpl factory = ValueFactoryImpl.getInstance(resolver);
+            return factory.createValue(values[index]).getString();
         } catch (RepositoryException e) {
             throw new AssertionFailedError(e.getMessage());
         }



Mime
View raw message