Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java Tue May 05 14:40:58 CEST 2009
@@ -32,6 +32,7 @@
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.NamespaceException;
+import javax.jcr.ValueFactory;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
@@ -59,8 +60,8 @@
*
* @param importer
*/
- DocViewImportHandler(Importer importer) {
- super(importer);
+ DocViewImportHandler(Importer importer, ValueFactory valueFactory) {
+ super(importer, valueFactory);
}
/**
@@ -102,7 +103,7 @@
private void appendCharacters(char[] ch, int start, int length)
throws SAXException {
if (textHandler == null) {
- textHandler = new BufferedStringValue(resolver);
+ textHandler = new BufferedStringValue(resolver, valueFactory);
}
try {
textHandler.append(ch, start, length);
@@ -250,7 +251,7 @@
// see also DocViewSAXEventGenerator#leavingProperties(Node, int)
// todo proper multi-value serialization support
propValues = new TextValue[1];
- propValues[0] = new StringValue(attrValue, resolver);
+ propValues[0] = new StringValue(attrValue, resolver, valueFactory);
if (propName.equals(NameConstants.JCR_PRIMARYTYPE)) {
// jcr:primaryType
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java Thu May 07 08:26:23 CEST 2009
@@ -657,9 +657,11 @@
* @param id child node id
*
* @throws PathNotFoundException if the path was not found
+ * @throws RepositoryException If the path's direct ancestor cannot be determined.
+ * @throws ItemStateException If the id cannot be resolved to a NodeState.
*/
private void nodeAdded(NodeState state, Path path, NodeId id)
- throws PathNotFoundException, ItemStateException {
+ throws RepositoryException, ItemStateException {
// assert: synchronized (cacheMonitor)
PathMap.Element element = null;
@@ -699,10 +701,12 @@
* @param path node path
* @param id node id
*
- * @throws PathNotFoundException if the path was not found
+ * @throws PathNotFoundException if the path was not found.
+ * @throws RepositoryException If the path's direct ancestor cannot be determined.
+ * @throws ItemStateException If the id cannot be resolved to a NodeState.
*/
private void nodeRemoved(NodeState state, Path path, NodeId id)
- throws PathNotFoundException, ItemStateException {
+ throws RepositoryException, ItemStateException {
// assert: synchronized (cacheMonitor)
PathMap.Element parent = pathCache.map(path.getAncestor(1), true);
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/ImportHandler.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/ImportHandler.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/ImportHandler.java Tue May 05 14:40:58 CEST 2009
@@ -20,6 +20,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.ValueFactory;
import org.apache.jackrabbit.commons.NamespaceHelper;
import org.apache.jackrabbit.spi.Name;
@@ -55,6 +56,8 @@
private final NamespaceHelper helper;
+ private final ValueFactory valueFactory;
+
protected Locator locator;
private TargetImportHandler targetHandler = null;
@@ -72,6 +75,7 @@
this.importer = importer;
this.helper = new NamespaceHelper(session);
this.localNamespaceMappings = helper.getNamespaces();
+ this.valueFactory = session.getValueFactory();
}
//---------------------------------------------------------< ErrorHandler >
@@ -149,9 +153,9 @@
// the namespace of the first element determines the type of XML
// (system view/document view)
if (Name.NS_SV_URI.equals(namespaceURI)) {
- targetHandler = new SysViewImportHandler(importer);
+ targetHandler = new SysViewImportHandler(importer, valueFactory);
} else {
- targetHandler = new DocViewImportHandler(importer);
+ targetHandler = new DocViewImportHandler(importer, valueFactory);
}
targetHandler.startDocument();
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java Tue May 05 15:13:42 CEST 2009
@@ -31,7 +31,7 @@
import org.slf4j.Logger;
import javax.jcr.Session;
-import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import java.util.Set;
import java.util.HashSet;
@@ -374,7 +374,7 @@
info.put(DEST_ABS_PATH, InternalValue.create(destPath));
es.setInfo(info);
return es;
- } catch (PathNotFoundException e) {
+ } catch (RepositoryException e) {
// should never happen actually
String msg = "Unable to resolve parent for path: " + destPath;
log.error(msg);
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefinitionImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefinitionImpl.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefinitionImpl.java Tue May 05 15:10:05 CEST 2009
@@ -23,6 +23,7 @@
import org.slf4j.LoggerFactory;
import javax.jcr.NamespaceException;
+import javax.jcr.ValueFactory;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.PropertyDefinition;
@@ -39,10 +40,12 @@
private final NodeTypeDef ntd;
// resolver used to translate qualified names to JCR names
private final NamePathResolver resolver;
+ private final ValueFactory valueFactory;
- public NodeTypeDefinitionImpl(NodeTypeDef ntd, NamePathResolver resolver) {
+ public NodeTypeDefinitionImpl(NodeTypeDef ntd, NamePathResolver resolver, ValueFactory valueFactory) {
this.ntd = ntd;
this.resolver = resolver;
+ this.valueFactory = valueFactory;
}
//---------------------------------------------------< NodeTypeDefinition >
@@ -162,7 +165,7 @@
PropDef[] pda = ntd.getPropertyDefs();
PropertyDefinition[] propDefs = new PropertyDefinition[pda.length];
for (int i = 0; i < pda.length; i++) {
- propDefs[i] = new PropertyDefinitionImpl(pda[i], null, resolver);
+ propDefs[i] = new PropertyDefinitionImpl(pda[i], null, resolver, valueFactory);
}
return propDefs;
}
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/SysViewImportHandler.java Tue May 05 14:40:59 CEST 2009
@@ -28,6 +28,7 @@
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.NamespaceException;
+import javax.jcr.ValueFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
@@ -60,8 +61,8 @@
*
* @param importer
*/
- SysViewImportHandler(Importer importer) {
- super(importer);
+ SysViewImportHandler(Importer importer, ValueFactory valueFactory) {
+ super(importer, valueFactory);
}
private void processNode(ImportState state, boolean start, boolean end)
@@ -172,7 +173,7 @@
}
} else if (name.equals(NameConstants.SV_VALUE)) {
// sv:value element
- currentPropValue = new BufferedStringValue(resolver);
+ currentPropValue = new BufferedStringValue(resolver, valueFactory);
String xsiType = atts.getValue("xsi:type");
currentPropValue.setBase64("xs:base64Binary".equals(xsiType));
} else {
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java Tue May 05 10:34:52 CEST 2009
@@ -53,7 +53,6 @@
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -1069,7 +1068,7 @@
if (parent != null) {
refresh(parent);
}
- } catch (PathNotFoundException e) {
+ } catch (RepositoryException e) {
log.warn("Unable to determine path of added node's parent.", e);
} finally {
release();
@@ -1091,7 +1090,7 @@
if (parent != null) {
refresh(parent);
}
- } catch (PathNotFoundException e) {
+ } catch (RepositoryException e) {
log.warn("Unable to determine path of moved node's parent.", e);
} finally {
release();
@@ -1112,7 +1111,7 @@
if (parent != null) {
refresh(parent);
}
- } catch (PathNotFoundException e) {
+ } catch (RepositoryException e) {
log.warn("Unable to determine path of removed node's parent.", e);
} finally {
release();
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java Tue May 05 12:31:44 CEST 2009
@@ -49,6 +49,7 @@
import org.apache.jackrabbit.core.xml.SessionImporter;
import org.apache.jackrabbit.core.retention.RetentionManagerImpl;
import org.apache.jackrabbit.core.retention.RetentionRegistry;
+import org.apache.jackrabbit.core.value.ValueFactoryImpl;
import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.spi.Path;
import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
@@ -56,9 +57,9 @@
import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
import org.apache.jackrabbit.spi.commons.conversion.NameException;
import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.IdentifierResolver;
import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
import org.apache.jackrabbit.uuid.UUID;
-import org.apache.jackrabbit.value.ValueFactoryImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.ContentHandler;
@@ -107,7 +108,7 @@
* A SessionImpl ...
*/
public class SessionImpl extends AbstractSession
- implements javax.jcr.Session, JackrabbitSession, NamespaceResolver, NamePathResolver, Dumpable {
+ implements javax.jcr.Session, JackrabbitSession, NamespaceResolver, NamePathResolver, IdentifierResolver, Dumpable {
private static Logger log = LoggerFactory.getLogger(SessionImpl.class);
@@ -276,7 +277,7 @@
userId = retrieveUserId(subject);
- namePathResolver = new DefaultNamePathResolver(this, true);
+ namePathResolver = new DefaultNamePathResolver(this, this, true);
ntMgr = new NodeTypeManagerImpl(rep.getNodeTypeRegistry(), this, rep.getDataStore());
String wspName = wspConfig.getName();
wsp = createWorkspaceInstance(wspConfig,
@@ -751,6 +752,33 @@
return namePathResolver.getQPath(path);
}
+ public Path getQPath(String path, boolean normalizeIdentifier) throws MalformedPathException, IllegalNameException, NamespaceException {
+ return namePathResolver.getQPath(path, normalizeIdentifier);
+ }
+
+ //---------------------------------------------------< IdentifierResolver >
+ /**
+ * @see IdentifierResolver#getPath(String)
+ */
+ public Path getPath(String identifier) throws MalformedPathException {
+ try {
+ return getHierarchyManager().getPath(NodeId.valueOf(identifier));
+ } catch (RepositoryException e) {
+ throw new MalformedPathException("Identifier '" + identifier + "' cannot be resolved.");
+ }
+ }
+
+ /**
+ * @see IdentifierResolver#checkFormat(String)
+ */
+ public void checkFormat(String identifier) throws MalformedPathException {
+ try {
+ NodeId.valueOf(identifier);
+ } catch (IllegalArgumentException e) {
+ throw new MalformedPathException("Invalid identifier: " + identifier);
+ }
+ }
+
//----------------------------------------------------< JackrabbitSession >
/**
* @see JackrabbitSession#getPrincipalManager()
@@ -1217,7 +1245,7 @@
public ValueFactory getValueFactory()
throws UnsupportedRepositoryOperationException, RepositoryException {
if (valueFactory == null) {
- valueFactory = ValueFactoryImpl.getInstance();
+ valueFactory = new ValueFactoryImpl(this);
}
return valueFactory;
}
@@ -1568,5 +1596,4 @@
logout();
}
}
-
}
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java Fri Apr 17 10:46:57 CEST 2009
@@ -673,13 +673,25 @@
}
break;
case PropertyType.DOUBLE:
+ try {
- out.writeDouble(val.getDouble());
+ out.writeDouble(val.getDouble());
+ } catch (RepositoryException e) {
+ // will never occur
+ }
break;
case PropertyType.LONG:
+ try {
- out.writeLong(val.getLong());
+ out.writeLong(val.getLong());
+ } catch (RepositoryException e) {
+ // will never occur
+ }
break;
case PropertyType.BOOLEAN:
+ try {
- out.writeBoolean(val.getBoolean());
+ out.writeBoolean(val.getBoolean());
+ } catch (RepositoryException e) {
+ // will never occur
+ }
break;
case PropertyType.NAME:
writeQName(out, val.getQName());
@@ -701,7 +713,6 @@
* Write a small binary value and return the data.
*
* @param out the output stream to write
- * @param size the size
* @param blobVal the binary value
* @param state the property state (for error messages)
* @param i the index (for error messages)
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java Tue May 05 10:34:55 CEST 2009
@@ -301,8 +301,12 @@
break;
case PropertyType.BOOLEAN:
if (isIndexed(name)) {
+ try {
- addBooleanValue(doc, fieldName, Boolean.valueOf(value.getBoolean()));
+ addBooleanValue(doc, fieldName, Boolean.valueOf(value.getBoolean()));
+ } catch (RepositoryException e) {
+ // will never occur
- }
+ }
+ }
break;
case PropertyType.DATE:
if (isIndexed(name)) {
@@ -311,13 +315,21 @@
break;
case PropertyType.DOUBLE:
if (isIndexed(name)) {
+ try {
- addDoubleValue(doc, fieldName, new Double(value.getDouble()));
+ addDoubleValue(doc, fieldName, new Double(value.getDouble()));
+ } catch (RepositoryException e) {
+ // will never occur
- }
+ }
+ }
break;
case PropertyType.LONG:
if (isIndexed(name)) {
+ try {
- addLongValue(doc, fieldName, new Long(value.getLong()));
+ addLongValue(doc, fieldName, new Long(value.getLong()));
+ } catch (RepositoryException e) {
+ // will never occur
- }
+ }
+ }
break;
case PropertyType.REFERENCE:
if (isIndexed(name)) {
@@ -326,21 +338,29 @@
break;
case PropertyType.PATH:
if (isIndexed(name)) {
+ try {
- addPathValue(doc, fieldName, value.getPath());
+ addPathValue(doc, fieldName, value.getPath());
+ } catch (RepositoryException e) {
+ // will never occur
- }
+ }
+ }
break;
case PropertyType.STRING:
if (isIndexed(name)) {
+ try {
- // never fulltext index jcr:uuid String
- if (name.equals(NameConstants.JCR_UUID)) {
- addStringValue(doc, fieldName, value.getString(),
- false, false, DEFAULT_BOOST);
- } else {
- addStringValue(doc, fieldName, value.getString(),
- true, isIncludedInNodeIndex(name),
- getPropertyBoost(name), useInExcerpt(name));
- }
+ // never fulltext index jcr:uuid String
+ if (name.equals(NameConstants.JCR_UUID)) {
+ addStringValue(doc, fieldName, value.getString(),
+ false, false, DEFAULT_BOOST);
+ } else {
+ addStringValue(doc, fieldName, value.getString(),
+ true, isIncludedInNodeIndex(name),
+ getPropertyBoost(name), useInExcerpt(name));
+ }
+ } catch (RepositoryException e) {
+ // getString must never throw.
- }
+ }
+ }
break;
case PropertyType.NAME:
// jcr:primaryType and jcr:mixinTypes are required for correct
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java Wed May 06 19:11:19 CEST 2009
@@ -48,6 +48,7 @@
import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.spi.Path;
import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.value.ValueFormat;
import org.apache.jackrabbit.value.ValueHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -248,10 +249,10 @@
throw new ValueFormatException(msg + this);
}
- // check protected flag and for retention/hold
+ // check protected flag and for retention/hold
int options = ItemValidator.CHECK_CONSTRAINTS;
session.getValidator().checkModify(this, options, Permission.NONE);
-
+
// make sure the parent is checked-out and neither locked nor under retention
options = ItemValidator.CHECK_VERSIONING | ItemValidator.CHECK_LOCK |
ItemValidator.CHECK_HOLD | ItemValidator.CHECK_RETENTION;
@@ -345,7 +346,7 @@
if (reqType != PropertyType.NAME) {
// type conversion required
Value targetValue = ValueHelper.convert(
- InternalValue.create(name).toJCRValue(session),
+ ValueFormat.getJCRValue(InternalValue.create(name), session, session.getValueFactory()),
reqType, session.getValueFactory());
internalValue = InternalValue.create(targetValue, session, rep.getDataStore());
} else {
@@ -396,7 +397,7 @@
if (reqType != PropertyType.NAME) {
// type conversion required
Value targetValue = ValueHelper.convert(
- InternalValue.create(name).toJCRValue(session),
+ ValueFormat.getJCRValue(InternalValue.create(name), session, session.getValueFactory()),
reqType, session.getValueFactory());
internalValue = InternalValue.create(targetValue, session, rep.getDataStore());
} else {
@@ -467,14 +468,14 @@
InternalValue[] internals = internalGetValues();
Value[] values = new Value[internals.length];
for (int i = 0; i < internals.length; i++) {
- values[i] = internals[i].toJCRValue(session);
+ values[i] = ValueFormat.getJCRValue(internals[i], session, session.getValueFactory());
}
return values;
}
public Value getValue() throws RepositoryException {
try {
- return internalGetValue().toJCRValue(session);
+ return ValueFormat.getJCRValue(internalGetValue(), session, session.getValueFactory());
} catch (RuntimeException e) {
String msg = "Internal error while retrieving value of " + this;
log.error(msg, e);
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java Fri Apr 17 17:12:11 CEST 2009
@@ -23,10 +23,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.jcr.RepositoryException;
import java.io.InputStream;
-import javax.jcr.RepositoryException;
-
/**
* Represents binary data which is stored in the data store.
*/
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RowIteratorImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RowIteratorImpl.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RowIteratorImpl.java Tue May 05 18:07:10 CEST 2009
@@ -42,6 +42,7 @@
import javax.jcr.PathNotFoundException;
import javax.jcr.NamespaceException;
import javax.jcr.Node;
+import javax.jcr.ValueFactory;
import javax.jcr.query.Row;
import javax.jcr.query.RowIterator;
import java.util.Arrays;
@@ -64,11 +65,6 @@
private static final Logger log = LoggerFactory.getLogger(RowIteratorImpl.class);
/**
- * The QValue factory.
- */
- private static final QValueFactory QVALUE_FACTORY = QValueFactoryImpl.getInstance();
-
- /**
* The name of the excerpt function without prefix but with left parenthesis.
*/
private static final String EXCERPT_FUNC_LPAR = "excerpt(";
@@ -159,6 +155,7 @@
ItemManager itemMgr,
HierarchyManager hmgr,
NamePathResolver resolver,
+ ValueFactory valueFactory,
ExcerptProvider exProvider,
SpellSuggestion spellSuggestion) {
this.scoreNodes = scoreNodes;
@@ -169,8 +166,13 @@
this.resolver = resolver;
this.excerptProvider = exProvider;
this.spellSuggestion = spellSuggestion;
- this.valueFactory = new ValueFactoryQImpl(QVALUE_FACTORY, resolver);
+ if (valueFactory instanceof ValueFactoryQImpl) {
+ this.valueFactory = (ValueFactoryQImpl) valueFactory;
+ } else {
+ QValueFactory qvf = QValueFactoryImpl.getInstance();
+ this.valueFactory = new ValueFactoryQImpl(qvf, resolver);
- }
+ }
+ }
/**
* Returns the next Row in the iteration.
@@ -362,7 +364,7 @@
}
}
if (NameConstants.JCR_PATH.equals(prop)) {
- QValue p = QVALUE_FACTORY.create(hmgr.getPath(sn[0].getNodeId()));
+ QValue p = valueFactory.getQValueFactory().create(hmgr.getPath(sn[0].getNodeId()));
return valueFactory.createValue(p);
} else if (getNodeImpl().hasProperty(prop)) {
Property p = getNodeImpl().getProperty(prop);
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java Tue May 05 12:44:08 CEST 2009
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java Tue May 05 12:44:08 CEST 2009
@@ -0,0 +1,88 @@
+/*
+ * 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.core.value;
+
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl;
+import org.apache.jackrabbit.spi.QValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.Value;
+import javax.jcr.PropertyType;
+import javax.jcr.ValueFormatException;
+import javax.jcr.RepositoryException;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * ValueFactoryImpl...
+ */
+public class ValueFactoryImpl extends ValueFactoryQImpl {
+
+ /**
+ * logger instance
+ */
+ private static final Logger log = LoggerFactory.getLogger(ValueFactoryImpl.class);
+
+ /**
+ * Constructs a new ValueFactoryQImpl based
+ * on an existing SPI QValueFactory and a
+ * NamePathResolver.
+ *
+ * @param resolver wrapped NamePathResolver
+ */
+ public ValueFactoryImpl(NamePathResolver resolver) {
+ super(InternalValueFactory.getInstance(), resolver);
+ }
+
+ public Value createValue(QValue qvalue) {
+ if (qvalue instanceof InternalValue && PropertyType.BINARY == qvalue.getType()) {
+ try {
+ return new BinaryValueImpl(((InternalValue) qvalue).getBLOBFileValue());
+ } catch (RepositoryException e) {
+ // should not get here
+ log.error(e.getMessage());
+ }
+ }
+ return super.createValue(qvalue);
+ }
+
+ public Value createValue(InputStream value) {
+ try {
+ InternalValue qvalue = (InternalValue) getQValueFactory().create(value);
+ return new BinaryValueImpl(qvalue.getBLOBFileValue());
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ } catch (RepositoryException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public Value createValue(String value, int type) throws ValueFormatException {
+ if (PropertyType.BINARY == type) {
+ try {
+ InternalValue qvalue = (InternalValue) getQValueFactory().create(value, type);
+ return new BinaryValueImpl(qvalue.getBLOBFileValue());
+ } catch (RepositoryException e) {
+ throw new ValueFormatException(e);
+ }
+ } else {
+ return super.createValue(value, type);
+ }
+ }
+}
\ No newline at end of file
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/StringValue.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/StringValue.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/StringValue.java Wed May 06 18:53:34 CEST 2009
@@ -19,13 +19,14 @@
import org.apache.jackrabbit.core.value.InternalValue;
import org.apache.jackrabbit.util.Base64;
import org.apache.jackrabbit.value.ValueHelper;
-import org.apache.jackrabbit.value.ValueFactoryImpl;
import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.value.ValueFormat;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
+import javax.jcr.ValueFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -37,16 +38,20 @@
private final String value;
private final NamePathResolver nsContext;
+ private final ValueFactory valueFactory;
/**
* Constructs a new StringValue representing the given
* value.
*
* @param value
+ * @param nsContext
+ * @param valueFactory
*/
- protected StringValue(String value, NamePathResolver nsContext) {
+ protected StringValue(String value, NamePathResolver nsContext, ValueFactory valueFactory) {
this.value = value;
this.nsContext = nsContext;
+ this.valueFactory = valueFactory;
}
//--------------------------------------------------------< TextValue >
@@ -62,13 +67,13 @@
// current namespace context of xml document
InternalValue ival =
InternalValue.create(ValueHelper.convert(
- value, type, ValueFactoryImpl.getInstance()), nsContext);
+ value, type, valueFactory), nsContext);
// convert InternalValue to Value using this
// session's namespace mappings
- return ival.toJCRValue(resolver);
+ return ValueFormat.getJCRValue(ival, resolver, valueFactory);
} else {
// all other types
- return ValueHelper.deserialize(value, type, false, ValueFactoryImpl.getInstance());
+ return ValueHelper.deserialize(value, type, false, valueFactory);
}
}
@@ -85,7 +90,7 @@
// convert serialized value to InternalValue using
// current namespace context of xml document
return InternalValue.create(ValueHelper.convert(
- value, targetType, ValueFactoryImpl.getInstance()), nsContext);
+ value, targetType, valueFactory), nsContext);
}
} catch (IOException e) {
throw new RepositoryException("Error decoding Base64 content", e);
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java Tue May 05 14:40:59 CEST 2009
@@ -28,6 +28,7 @@
import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
import org.apache.jackrabbit.spi.Path;
import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
+import org.apache.jackrabbit.spi.commons.value.ValueFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -147,7 +148,7 @@
InternalValue value = (InternalValue) entry.getValue();
String strValue = null;
if (value != null) {
- strValue = value.toJCRValue(session).getString();
+ strValue = ValueFormat.getJCRValue(value, session, session.getValueFactory()).getString();
}
info.put(entry.getKey(), strValue);
}
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/BufferedStringValue.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/BufferedStringValue.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/BufferedStringValue.java Wed May 06 19:22:44 CEST 2009
@@ -20,8 +20,8 @@
import org.apache.jackrabbit.util.Base64;
import org.apache.jackrabbit.util.TransientFileFactory;
import org.apache.jackrabbit.value.ValueHelper;
-import org.apache.jackrabbit.value.ValueFactoryImpl;
import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.value.ValueFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -29,6 +29,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
+import javax.jcr.ValueFactory;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -86,6 +87,7 @@
private Writer writer;
private final NamePathResolver nsContext;
+ private final ValueFactory valueFactory;
/**
* Whether the value is base64 encoded.
@@ -96,12 +98,13 @@
* Constructs a new empty BufferedStringValue.
* @param nsContext
*/
- protected BufferedStringValue(NamePathResolver nsContext) {
+ protected BufferedStringValue(NamePathResolver nsContext, ValueFactory valueFactory) {
buffer = new StringWriter();
length = 0;
tmpFile = null;
writer = null;
this.nsContext = nsContext;
+ this.valueFactory = valueFactory;
}
/**
@@ -243,26 +246,26 @@
// current namespace context of xml document
InternalValue ival =
InternalValue.create(ValueHelper.convert(
- retrieve(), targetType, ValueFactoryImpl.getInstance()), nsContext);
+ retrieve(), targetType, valueFactory), nsContext);
// convert InternalValue to Value using this
// session's namespace mappings
- return ival.toJCRValue(resolver);
+ return ValueFormat.getJCRValue(ival, resolver, valueFactory);
} else if (targetType == PropertyType.BINARY) {
if (length() < 0x10000) {
// < 65kb: deserialize BINARY type using String
- return ValueHelper.deserialize(retrieve(), targetType, false, ValueFactoryImpl.getInstance());
+ return ValueHelper.deserialize(retrieve(), targetType, false, valueFactory);
} else {
// >= 65kb: deserialize BINARY type using Reader
Reader reader = reader();
try {
- return ValueHelper.deserialize(reader, targetType, false, ValueFactoryImpl.getInstance());
+ return ValueHelper.deserialize(reader, targetType, false, valueFactory);
} finally {
reader.close();
}
}
} else {
// all other types
- return ValueHelper.deserialize(retrieveString(), targetType, false, ValueFactoryImpl.getInstance());
+ return ValueHelper.deserialize(retrieveString(), targetType, false, valueFactory);
}
} catch (IOException e) {
String msg = "failed to retrieve serialized value";
@@ -307,7 +310,7 @@
// convert serialized value to InternalValue using
// current namespace context of xml document
return InternalValue.create(ValueHelper.convert(
- retrieveString(), type, ValueFactoryImpl.getInstance()), nsContext);
+ retrieveString(), type, valueFactory), nsContext);
}
} catch (IOException e) {
throw new RepositoryException("Error accessing property value", e);
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/TargetImportHandler.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/TargetImportHandler.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/TargetImportHandler.java Tue May 05 14:40:58 CEST 2009
@@ -24,6 +24,7 @@
import java.util.Map;
import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
/**
* TargetImportHandler serves as the base class for the concrete
@@ -34,6 +35,8 @@
protected final Importer importer;
+ protected final ValueFactory valueFactory;
+
/**
* The current namespace context. A new namespace context is created
* for each XML element and the parent reference is used to link the
@@ -45,8 +48,9 @@
protected NamePathResolver resolver;
- protected TargetImportHandler(Importer importer) {
+ protected TargetImportHandler(Importer importer, ValueFactory valueFactory) {
this.importer = importer;
+ this.valueFactory = valueFactory;
}
/**
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java Wed May 06 19:38:53 CEST 2009
@@ -138,8 +138,9 @@
*
* @param value an internal value.
* @return a comparable for the given value.
+ * @throws RepositoryException if retrieving the Comparable fails.
*/
- public static Comparable getComparable(InternalValue value) {
+ public static Comparable getComparable(InternalValue value) throws RepositoryException {
switch (value.getType()) {
case PropertyType.BINARY:
return null;
@@ -152,7 +153,7 @@
case PropertyType.LONG:
return new Long(value.getLong());
case PropertyType.NAME:
- return value.getQName().toString();
+ return value.getName().toString();
case PropertyType.PATH:
return value.getPath().toString();
case PropertyType.REFERENCE:
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java Tue May 05 12:44:08 CEST 2009
@@ -25,29 +25,29 @@
import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
import org.apache.jackrabbit.spi.Path;
import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QValue;
import org.apache.jackrabbit.util.ISO8601;
import org.apache.jackrabbit.uuid.UUID;
-import org.apache.jackrabbit.value.BooleanValue;
-import org.apache.jackrabbit.value.DateValue;
-import org.apache.jackrabbit.value.DoubleValue;
-import org.apache.jackrabbit.value.LongValue;
-import org.apache.jackrabbit.value.NameValue;
-import org.apache.jackrabbit.value.PathValue;
-import org.apache.jackrabbit.value.ReferenceValue;
import org.apache.jackrabbit.value.StringValue;
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;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
+import javax.jcr.Session;
+import javax.jcr.ValueFactory;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
+import java.io.UnsupportedEncodingException;
import java.util.Calendar;
/**
@@ -69,7 +69,7 @@
*
*
*/
-public class InternalValue {
+public class InternalValue extends AbstractQValue {
public static final InternalValue[] EMPTY_ARRAY = new InternalValue[0];
@@ -88,9 +88,6 @@
*/
private static final int MIN_BLOB_FILE_SIZE = 1024;
- private Object val;
- private final int type;
-
//------------------------------------------------------< factory methods >
/**
* Create a new internal value from the given JCR value.
@@ -164,13 +161,31 @@
return create(new UUID(value.getString()));
case PropertyType.NAME:
try {
+ if (value instanceof QValueValue) {
+ QValue qv = ((QValueValue) value).getQValue();
+ if (qv instanceof InternalValue) {
+ return (InternalValue) qv;
+ } else {
+ return create(qv.getName());
+ }
+ } else {
- return create(resolver.getQName(value.getString()));
+ return create(resolver.getQName(value.getString()));
+ }
} catch (NameException e) {
throw new ValueFormatException(e.getMessage());
}
case PropertyType.PATH:
try {
- return create(resolver.getQPath(value.getString()));
+ if (value instanceof QValueValue) {
+ QValue qv = ((QValueValue) value).getQValue();
+ if (qv instanceof InternalValue) {
+ return (InternalValue) qv;
+ } else {
+ return create(qv.getPath());
+ }
+ } else {
+ return create(resolver.getQPath(value.getString(), false));
+ }
} catch (MalformedPathException mpe) {
throw new ValueFormatException(mpe.getMessage());
}
@@ -186,6 +201,9 @@
* @return the created value
*/
public static InternalValue create(String value) {
+ if (value == null) {
+ throw new IllegalArgumentException("null value");
+ }
return new InternalValue(value);
}
@@ -210,6 +228,9 @@
* @return the created value
*/
public static InternalValue create(Calendar value) {
+ if (value == null) {
+ throw new IllegalArgumentException("null value");
+ }
return new InternalValue(value);
}
@@ -239,6 +260,9 @@
* @return the internal value
*/
public static InternalValue createTemporary(InputStream value) throws RepositoryException {
+ if (value == null) {
+ throw new IllegalArgumentException("null value");
+ }
if (USE_DATA_STORE) {
return new InternalValue(getBLOBFileValue(null, value, true));
}
@@ -259,6 +283,9 @@
* @return the internal value
*/
public static InternalValue createTemporary(InputStream value, DataStore store) throws RepositoryException {
+ if (value == null) {
+ throw new IllegalArgumentException("null value");
+ }
if (USE_DATA_STORE) {
return new InternalValue(getBLOBFileValue(store, value, true));
}
@@ -275,6 +302,9 @@
* @throws IOException
*/
public static InternalValue create(InputStream value) throws RepositoryException {
+ if (value == null) {
+ throw new IllegalArgumentException("null value");
+ }
if (USE_DATA_STORE) {
return new InternalValue(getBLOBFileValue(null, value, false));
}
@@ -291,6 +321,9 @@
* @throws IOException
*/
public static InternalValue create(FileSystemResource value) throws IOException {
+ if (value == null) {
+ throw new IllegalArgumentException("null value");
+ }
if (USE_DATA_STORE) {
return new InternalValue(BLOBInResource.getInstance(value));
}
@@ -303,6 +336,9 @@
* @throws IOException
*/
public static InternalValue create(File value) throws IOException {
+ if (value == null) {
+ throw new IllegalArgumentException("null value");
+ }
assert !USE_DATA_STORE;
return new InternalValue(new BLOBValue(value));
}
@@ -324,6 +360,9 @@
* @return the created value
*/
public static InternalValue create(Name value) {
+ if (value == null) {
+ throw new IllegalArgumentException("null value");
+ }
return new InternalValue(value);
}
@@ -356,6 +395,9 @@
* @return the created value
*/
public static InternalValue create(Path value) {
+ if (value == null) {
+ throw new IllegalArgumentException("null value");
+ }
return new InternalValue(value);
}
@@ -364,6 +406,9 @@
* @return the created value
*/
public static InternalValue create(UUID value) {
+ if (value == null) {
+ throw new IllegalArgumentException("null value");
+ }
return new InternalValue(value);
}
@@ -372,32 +417,44 @@
* @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);
+ }
+
+ if (vf instanceof ValueFactoryQImpl) {
+ return ((ValueFactoryQImpl) vf).createValue(this);
+ } else {
- switch (type) {
- case PropertyType.BINARY:
+ switch (type) {
+ case PropertyType.BINARY:
- return new BinaryValueImpl((BLOBFileValue) val);
+ return vf.createValue(((BLOBFileValue) val).getStream());
- case PropertyType.BOOLEAN:
+ case PropertyType.BOOLEAN:
- return new BooleanValue(((Boolean) val));
+ return vf.createValue(((Boolean) val).booleanValue());
- case PropertyType.DATE:
+ case PropertyType.DATE:
- return new DateValue((Calendar) val);
+ return vf.createValue((Calendar) val);
- case PropertyType.DOUBLE:
+ case PropertyType.DOUBLE:
- return new DoubleValue((Double) val);
+ return vf.createValue(((Double) val).doubleValue());
- case PropertyType.LONG:
+ case PropertyType.LONG:
- return new LongValue((Long) val);
+ return vf.createValue(((Long) val).longValue());
- case PropertyType.REFERENCE:
+ case PropertyType.REFERENCE:
- return ReferenceValue.valueOf(val.toString());
+ return vf.createValue(val.toString(), PropertyType.REFERENCE);
- case PropertyType.PATH:
+ case PropertyType.PATH:
- return PathValue.valueOf(resolver.getJCRPath((Path) val));
+ return vf.createValue(resolver.getJCRPath((Path) val), PropertyType.PATH);
- case PropertyType.NAME:
+ case PropertyType.NAME:
- return NameValue.valueOf(resolver.getJCRName((Name) val), false);
+ return vf.createValue(resolver.getJCRName((Name) val), PropertyType.NAME);
- case PropertyType.STRING:
- return new StringValue((String) val);
- default:
- throw new RepositoryException("illegal internal value type");
- }
- }
+ case PropertyType.STRING:
+ return new StringValue((String) val);
+ default:
+ throw new RepositoryException("illegal internal value type");
+ }
+ }
+ }
/**
* @deprecated
@@ -417,51 +474,17 @@
return (UUID) val;
}
- public boolean getBoolean() {
- assert val != null && type == PropertyType.BOOLEAN;
- return ((Boolean) val).booleanValue();
- }
-
public Name getQName() {
assert val != null && type == PropertyType.NAME;
return (Name) val;
}
- public Path getPath() {
- assert val != null && type == PropertyType.PATH;
- return (Path) val;
- }
-
- public long getLong() {
- assert val != null && type == PropertyType.LONG;
- return ((Long) val).longValue();
- }
-
- public double getDouble() {
- assert val != null && type == PropertyType.DOUBLE;
- return ((Double) val).doubleValue();
- }
-
public Calendar getDate() {
assert val != null && type == PropertyType.DATE;
return (Calendar) val;
}
- public String getString() {
- assert val != null && type == PropertyType.STRING;
- return (String) val;
- }
-
/**
- * Get the type of this value.
- *
- * @return the type
- */
- public int getType() {
- return type;
- }
-
- /**
* Create a copy of this object. Immutable values will return itself,
* while mutable values will return a copy.
*
@@ -548,71 +571,42 @@
}
}
- /**
- * {@inheritDoc}
- */
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj instanceof InternalValue) {
- InternalValue other = (InternalValue) obj;
- return val.equals(other.val);
- }
- return false;
- }
- /**
- * {@inheritDoc}
- */
- public int hashCode() {
- return val.hashCode();
- }
-
//-------------------------------------------------------< implementation >
private InternalValue(String value) {
- val = value;
- type = PropertyType.STRING;
+ super(value, PropertyType.STRING);
}
private InternalValue(Name value) {
- val = value;
- type = PropertyType.NAME;
+ super(value);
}
private InternalValue(long value) {
- val = new Long(value);
- type = PropertyType.LONG;
+ super(new Long(value));
}
private InternalValue(double value) {
- val = new Double(value);
- type = PropertyType.DOUBLE;
+ super(new Double(value));
}
private InternalValue(Calendar value) {
- val = value;
- type = PropertyType.DATE;
+ super(value, PropertyType.DATE);
}
private InternalValue(boolean value) {
- val = Boolean.valueOf(value);
- type = PropertyType.BOOLEAN;
+ super(Boolean.valueOf(value));
}
private InternalValue(BLOBFileValue value) {
- val = value;
- type = PropertyType.BINARY;
+ super(value, PropertyType.BINARY);
}
private InternalValue(Path value) {
- val = value;
- type = PropertyType.PATH;
+ super(value);
}
private InternalValue(UUID value) {
- val = value;
- type = PropertyType.REFERENCE;
+ super(value, PropertyType.REFERENCE);
}
/**
@@ -697,4 +691,64 @@
val = getBLOBFileValue(dataStore, v.getStream(), false);
}
+ //-------------------------------------------------------------< QValue >---
+ /**
+ * @see org.apache.jackrabbit.spi.QValue#getLength()
+ */
+ public long getLength() throws RepositoryException {
+ if (PropertyType.BINARY == type) {
+ return ((BLOBFileValue) val).getLength();
+ } else {
+ return super.getLength();
-}
+ }
+ }
+
+ /**
+ * @see org.apache.jackrabbit.spi.QValue#getString()
+ */
+ public String getString() throws RepositoryException {
+ if (type == PropertyType.BINARY) {
+ return ((BLOBFileValue) val).getString();
+ } else if (type == PropertyType.DATE) {
+ return ISO8601.format(((Calendar) val));
+ } else {
+ return toString();
+ }
+ }
+
+ /**
+ * @see org.apache.jackrabbit.spi.QValue#getStream()
+ */
+ public InputStream getStream() throws RepositoryException {
+ if (type == PropertyType.BINARY) {
+ return ((BLOBFileValue) val).getStream();
+ } else {
+ try {
+ // convert via string
+ return new ByteArrayInputStream(getString().getBytes(InternalValueFactory.DEFAULT_ENCODING));
+ } catch (UnsupportedEncodingException e) {
+ throw new RepositoryException(InternalValueFactory.DEFAULT_ENCODING + " is not supported encoding on this platform", e);
+ }
+ }
+ }
+
+ //-------------------------------------------------------------< Object >---
+
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof InternalValue) {
+ InternalValue other = (InternalValue) obj;
+ if (type != other.type) {
+ return false;
+ }
+ if (PropertyType.DATE == type) {
+ return ISO8601.format((Calendar) val).equals(ISO8601.format((Calendar) other.val));
+ } else {
+ return super.equals(obj);
+ }
+ }
+ return false;
+ }
+}
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java Tue May 05 14:40:59 CEST 2009
@@ -175,7 +175,7 @@
if (pdi == null) {
PropDef pd = ntReg.getPropDef(id);
if (pd != null) {
- pdi = new PropertyDefinitionImpl(pd, this, session);
+ pdi = new PropertyDefinitionImpl(pd, this, session, valueFactory);
pdCache.put(id, pdi);
}
}
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java Tue May 05 10:34:56 CEST 2009
@@ -36,7 +36,6 @@
import org.slf4j.LoggerFactory;
import javax.jcr.NamespaceException;
-import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.observation.ObservationManager;
@@ -628,7 +627,7 @@
private Path getParent(Path p) throws ItemStateException {
try {
return p.getAncestor(1);
- } catch (PathNotFoundException e) {
+ } catch (RepositoryException e) {
// should never happen actually
String msg = "Unable to resolve parent for path: " + p;
log.error(msg);
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDefStore.java Wed May 06 19:28:57 CEST 2009
@@ -21,7 +21,6 @@
import org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader;
import org.apache.jackrabbit.core.nodetype.compact.ParseException;
import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
import javax.jcr.NamespaceRegistry;
import javax.jcr.RepositoryException;
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java Fri Apr 17 17:12:12 CEST 2009
@@ -19,6 +19,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.UnsupportedEncodingException;
import javax.jcr.RepositoryException;
@@ -45,6 +47,38 @@
public abstract InputStream getStream() throws RepositoryException;
/**
+ * Returns a String representation of this value.
+ *
+ * @return String representation of this value.
+ * @throws RepositoryException
+ */
+ public String getString() throws RepositoryException {
+ InputStream stream = getStream();
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buffer = new byte[8192];
+ int read;
+ while ((read = stream.read(buffer)) > 0) {
+ out.write(buffer, 0, read);
+ }
+ byte[] data = out.toByteArray();
+ return new String(data, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RepositoryException("UTF-8 not supported on this platform", e);
+ } catch (IOException e) {
+ throw new RepositoryException("conversion from stream to string failed", e);
+ } finally {
+ try {
+ if (stream != null) {
+ stream.close();
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+ /**
* Returns the length of this BLOBFileValue.
*
* @return The length, in bytes, of this BLOBFileValue,
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java Tue May 05 18:07:10 CEST 2009
@@ -225,7 +225,7 @@
}
return new RowIteratorImpl(getScoreNodes(), selectProps,
selectorNames, itemMgr,
- index.getContext().getHierarchyManager(), session,
+ index.getContext().getHierarchyManager(), session, session.getValueFactory(),
excerptProvider, spellSuggestion);
}
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AggregateRuleImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AggregateRuleImpl.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AggregateRuleImpl.java Wed Apr 15 17:30:24 CEST 2009
@@ -101,7 +101,7 @@
NameResolver resolver,
ItemStateManager ism,
HierarchyManager hmgr) throws MalformedPathException,
- IllegalNameException, NamespaceException, PathNotFoundException {
+ IllegalNameException, NamespaceException, RepositoryException {
this.resolver = resolver;
this.nodeTypeName = getNodeTypeName(config);
this.nodeIncludes = getNodeIncludes(config);
@@ -254,7 +254,7 @@
* prefix.
*/
private PropertyInclude[] getPropertyIncludes(Node config) throws
- MalformedPathException, IllegalNameException, NamespaceException,
+ RepositoryException, IllegalNameException, NamespaceException,
PathNotFoundException {
List includes = new ArrayList();
NodeList childNodes = config.getChildNodes();
@@ -442,7 +442,7 @@
private final Name propertyName;
PropertyInclude(Path pattern)
- throws PathNotFoundException {
+ throws RepositoryException {
super(pattern.getAncestor(1), null);
this.propertyName = pattern.getNameElement().getName();
}
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java Wed May 06 18:53:34 CEST 2009
@@ -20,6 +20,7 @@
import org.apache.jackrabbit.core.data.LazyFileInputStream;
import org.apache.jackrabbit.util.TransientFileFactory;
+import javax.jcr.RepositoryException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -27,8 +28,6 @@
import java.io.InputStream;
import java.io.OutputStream;
-import javax.jcr.RepositoryException;
-
/**
* Represents binary data which is stored in a temporary file.
*/
@@ -48,7 +47,8 @@
* The input stream is always closed by this method.
*
* @param in the input stream
- * @throws IOException
+ * @param temp
+ * @throws RepositoryException
*/
private BLOBInTempFile(InputStream in, boolean temp) throws RepositoryException {
this.temp = temp;
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/PropertyDefinitionImpl.java Tue May 05 14:40:58 CEST 2009
@@ -18,11 +18,13 @@
import javax.jcr.RepositoryException;
import javax.jcr.Value;
+import javax.jcr.ValueFactory;
import javax.jcr.nodetype.PropertyDefinition;
import org.apache.jackrabbit.core.value.InternalValue;
import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
import org.apache.jackrabbit.spi.commons.query.qom.Operator;
+import org.apache.jackrabbit.spi.commons.value.ValueFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,16 +42,20 @@
*/
private static Logger log = LoggerFactory.getLogger(PropertyDefinitionImpl.class);
+ private final ValueFactory valueFactory;
+
/**
* Package private constructor
*
* @param propDef property definition
* @param ntMgr node type manager
* @param resolver name resolver
+ * @param valueFactory
*/
PropertyDefinitionImpl(PropDef propDef, NodeTypeManagerImpl ntMgr,
- NamePathResolver resolver) {
+ NamePathResolver resolver, ValueFactory valueFactory) {
super(propDef, ntMgr, resolver);
+ this.valueFactory = valueFactory;
}
/**
@@ -73,7 +79,7 @@
Value[] values = new Value[defVals.length];
for (int i = 0; i < defVals.length; i++) {
try {
- values[i] = defVals[i].toJCRValue(resolver);
+ values[i] = ValueFormat.getJCRValue(defVals[i], resolver, valueFactory);
} catch (RepositoryException re) {
// should never get here
String propName = (getName() == null) ? "[null]" : getName();
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java Thu May 07 08:48:18 CEST 2009
@@ -42,6 +42,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
import javax.jcr.Value;
+import javax.jcr.ValueFactory;
import javax.jcr.version.OnParentVersionAction;
import java.io.Reader;
import java.util.ArrayList;
@@ -193,12 +194,13 @@
* Returns the list of parsed node type definitions.
*
* @param resolver name resolver
+ * @param valueFactory the value factory used to create the property definitions.
* @return a List of NodeTypeDefinitions objects
*/
- public List getNodeTypeDefinitions(NamePathResolver resolver) {
+ public List getNodeTypeDefinitions(NamePathResolver resolver, ValueFactory valueFactory) {
List l = new ArrayList(nodeTypeDefs.size());
for (Iterator iter = nodeTypeDefs.iterator(); iter.hasNext();) {
- l.add(new NodeTypeDefinitionImpl((NodeTypeDef) iter.next(), resolver));
+ l.add(new NodeTypeDefinitionImpl((NodeTypeDef) iter.next(), resolver, valueFactory));
}
return l;
}
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValueFactory.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValueFactory.java Tue May 05 16:38:02 CEST 2009
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValueFactory.java Tue May 05 16:38:02 CEST 2009
@@ -0,0 +1,142 @@
+/*
+ * 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.core.value;
+
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
+import org.apache.jackrabbit.spi.commons.value.AbstractQValueFactory;
+import org.apache.jackrabbit.util.ISO8601;
+import org.apache.jackrabbit.uuid.UUID;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFormatException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.io.FileInputStream;
+import java.util.Calendar;
+
+/**
+ * InternalValueFactory...
+ */
+public final class InternalValueFactory extends AbstractQValueFactory {
+
+ /**
+ * logger instance
+ */
+ private static final Logger log = LoggerFactory.getLogger(InternalValueFactory.class);
+
+ private static final QValueFactory INSTANCE = new InternalValueFactory();
+
+ private InternalValueFactory() {
+ }
+
+ public static QValueFactory getInstance() {
+ return INSTANCE;
+ }
+
+ public QValue create(String value, int type) throws ValueFormatException, RepositoryException {
+ if (value == null) {
+ throw new IllegalArgumentException("Cannot create QValue from null value.");
+ }
+
+ try {
+ switch (type) {
+ case PropertyType.BOOLEAN:
+ return InternalValue.create(Boolean.valueOf(value).booleanValue());
+ case PropertyType.DATE: {
+ Calendar cal = ISO8601.parse(value);
+ if (cal == null) {
+ throw new ValueFormatException("not a valid date: " + value);
+ }
+ return InternalValue.create(cal);
+ }
+ case PropertyType.DOUBLE:
+ return InternalValue.create(Double.parseDouble(value));
+ case PropertyType.LONG:
+ return InternalValue.create(Long.parseLong(value));
+ case PropertyType.PATH:
+ return InternalValue.create(PathFactoryImpl.getInstance().create(value));
+ case PropertyType.NAME:
+ return InternalValue.create(NameFactoryImpl.getInstance().create(value));
+ case PropertyType.STRING:
+ return InternalValue.create(value);
+ case PropertyType.REFERENCE:
+ return InternalValue.create(new UUID(value));
+ case PropertyType.BINARY:
+ return InternalValue.create(value.getBytes("UTF-8"));
+ // default: invalid type specified -> see below.
+ }
+ } catch (IllegalArgumentException ex) {
+ // given String value cannot be converted to Long/Double/Path/Name
+ throw new ValueFormatException(ex);
+ } catch (UnsupportedEncodingException ex) {
+ throw new RepositoryException(ex);
+ }
+
+ // invalid type specified:
+ throw new IllegalArgumentException("illegal type " + type); }
+
+ public QValue create(Calendar value) throws RepositoryException {
+ return InternalValue.create(value);
+ }
+
+ public QValue create(double value) throws RepositoryException {
+ return InternalValue.create(value);
+ }
+
+ public QValue create(long value) throws RepositoryException {
+ return InternalValue.create(value);
+ }
+
+ public QValue create(boolean value) throws RepositoryException {
+ return InternalValue.create(value);
+ }
+
+ public QValue create(Name value) throws RepositoryException {
+ return InternalValue.create(value);
+ }
+
+ public QValue create(Path value) throws RepositoryException {
+ return InternalValue.create(value);
+ }
+
+ public QValue create(byte[] value) throws RepositoryException {
+ return InternalValue.create(value);
+ }
+
+ public QValue create(InputStream value) throws RepositoryException, IOException {
+ return InternalValue.create(value);
+ }
+
+ public QValue create(File value) throws RepositoryException, IOException {
+ if (InternalValue.USE_DATA_STORE) {
+ InputStream in = new FileInputStream(value);
+ return InternalValue.createTemporary(in);
+ } else {
+ return InternalValue.create(value);
+ }
+ }
+}
\ No newline at end of file
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java (revision 772381)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java Fri Apr 17 19:16:34 CEST 2009
@@ -20,8 +20,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.jcr.RepositoryException;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
import java.util.Arrays;
/**
@@ -157,6 +159,17 @@
/**
* {@inheritDoc}
*/
+ public String getString() throws RepositoryException {
+ try {
+ return new String(data, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RepositoryException("UTF-8 not supported on this platform", e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public String toString() {
StringBuffer buff = new StringBuffer(PREFIX.length() + 2 * data.length);
buff.append(PREFIX);