You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2007/10/18 20:41:57 UTC
svn commit: r586065 [8/8] - in /jackrabbit/trunk/contrib/spi:
client/src/test/java/org/apache/jackrabbit/jcr2spi/
jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/
jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/
jcr2spi/src/main/java/...
Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/PropertyInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/PropertyInfoImpl.java?rev=586065&r1=586064&r2=586065&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/PropertyInfoImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/PropertyInfoImpl.java Thu Oct 18 11:41:45 2007
@@ -18,12 +18,8 @@
import org.apache.jackrabbit.spi.QValue;
import org.apache.jackrabbit.spi.QValueFactory;
-import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.name.NameFormat;
-import org.apache.jackrabbit.name.PathFormat;
-import org.apache.jackrabbit.name.MalformedPathException;
-import org.apache.jackrabbit.name.IllegalNameException;
-import org.apache.jackrabbit.name.UnknownPrefixException;
+import org.apache.jackrabbit.conversion.NamePathResolver;
+import org.apache.jackrabbit.conversion.NameException;
import org.apache.jackrabbit.value.ValueFormat;
import javax.jcr.RepositoryException;
@@ -42,35 +38,35 @@
*
* @param property the JCR property.
* @param idFactory the id factory.
- * @param nsResolver the namespace resolver in use.
+ * @param resolver
* @param qValueFactory the QValue factory.
* @throws RepositoryException if an error occurs while reading from
* <code>property</code>.
*/
public PropertyInfoImpl(Property property,
IdFactoryImpl idFactory,
- NamespaceResolver nsResolver,
+ NamePathResolver resolver,
QValueFactory qValueFactory)
- throws RepositoryException, MalformedPathException, IllegalNameException, UnknownPrefixException {
- super(idFactory.createNodeId(property.getParent(), nsResolver),
- NameFormat.parse(property.getName(), nsResolver),
- PathFormat.parse(property.getPath(), nsResolver),
- idFactory.createPropertyId(property, nsResolver),
+ throws RepositoryException, NameException {
+ super(idFactory.createNodeId(property.getParent(), resolver),
+ resolver.getQName(property.getName()),
+ resolver.getQPath(property.getPath()),
+ idFactory.createPropertyId(property, resolver),
property.getType(), property.getDefinition().isMultiple(),
- getValues(property, nsResolver, qValueFactory)); // TODO: build QValues upon (first) usage only.
+ getValues(property, resolver, qValueFactory)); // TODO: build QValues upon (first) usage only.
}
/**
* Returns the QValues for the <code>property</code>.
*
* @param property the property.
- * @param nsResolver the namespace resolver.
+ * @param resolver the name and path resolver.
* @param factory the value factory.
* @return the values of the property.
* @throws RepositoryException if an error occurs while reading the values.
*/
private static QValue[] getValues(Property property,
- NamespaceResolver nsResolver,
+ NamePathResolver resolver,
QValueFactory factory)
throws RepositoryException {
boolean isMultiValued = property.getDefinition().isMultiple();
@@ -79,12 +75,11 @@
Value[] jcrValues = property.getValues();
values = new QValue[jcrValues.length];
for (int i = 0; i < jcrValues.length; i++) {
- values[i] = ValueFormat.getQValue(jcrValues[i],
- nsResolver, factory);
+ values[i] = ValueFormat.getQValue(jcrValues[i], resolver, factory);
}
} else {
values = new QValue[]{
- ValueFormat.getQValue(property.getValue(), nsResolver, factory)};
+ ValueFormat.getQValue(property.getValue(), resolver, factory)};
}
return values;
}
Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QNodeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QNodeDefinitionImpl.java?rev=586065&r1=586064&r2=586065&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QNodeDefinitionImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QNodeDefinitionImpl.java Thu Oct 18 11:41:45 2007
@@ -16,14 +16,13 @@
*/
package org.apache.jackrabbit.spi2jcr;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.name.NameFormat;
-import org.apache.jackrabbit.name.IllegalNameException;
-import org.apache.jackrabbit.name.UnknownPrefixException;
+import org.apache.jackrabbit.conversion.NamePathResolver;
+import org.apache.jackrabbit.conversion.NameException;
+import org.apache.jackrabbit.spi.Name;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
+import javax.jcr.NamespaceException;
/**
* <code>QNodeDefinitionImpl</code> implements a <code>QNodeDefinition</code>.
@@ -35,22 +34,22 @@
* Creates a new qualified node definition based on a JCR NodeDefinition.
*
* @param nodeDef the node definition.
- * @param nsResolver the namespace resolver in use.
- * @throws IllegalNameException if <code>nodeDef</code> contains an
+ * @param resolver
+ * @throws NameException if <code>nodeDef</code> contains an
* illegal name.
- * @throws UnknownPrefixException if <code>nodeDef</code> contains a name
+ * @throws NamespaceException if <code>nodeDef</code> contains a name
* with an namespace prefix that is unknown
- * to <code>nsResolver</code>.
+ * to <code>resolver</code>.
*/
QNodeDefinitionImpl(NodeDefinition nodeDef,
- NamespaceResolver nsResolver)
- throws IllegalNameException, UnknownPrefixException {
- super(nodeDef.getName().equals(ANY_NAME.getLocalName()) ? ANY_NAME : NameFormat.parse(nodeDef.getName(), nsResolver),
- nodeDef.getDeclaringNodeType() != null ? NameFormat.parse(nodeDef.getDeclaringNodeType().getName(), nsResolver) : null,
+ NamePathResolver resolver)
+ throws NameException, NamespaceException {
+ super(nodeDef.getName().equals(ANY_NAME.getLocalName()) ? ANY_NAME : resolver.getQName(nodeDef.getName()),
+ nodeDef.getDeclaringNodeType() != null ? resolver.getQName(nodeDef.getDeclaringNodeType().getName()) : null,
nodeDef.isAutoCreated(), nodeDef.isMandatory(),
nodeDef.getOnParentVersion(), nodeDef.isProtected(),
- nodeDef.getDefaultPrimaryType() != null ? NameFormat.parse(nodeDef.getDefaultPrimaryType().getName(), nsResolver) : null,
- getNodeTypeNames(nodeDef.getRequiredPrimaryTypes(), nsResolver),
+ nodeDef.getDefaultPrimaryType() != null ? resolver.getQName(nodeDef.getDefaultPrimaryType().getName()) : null,
+ getNodeTypeNames(nodeDef.getRequiredPrimaryTypes(), resolver),
nodeDef.allowsSameNameSiblings());
}
@@ -59,18 +58,18 @@
* resolver to parse the names.
*
* @param nt the node types
- * @param nsResolver the namespace resolver.
+ * @param resolver
* @return the qualified names of the node types.
- * @throws IllegalNameException if a node type returns an illegal name.
- * @throws UnknownPrefixException if the nameo of a node type contains a
- * prefix that is not known to <code>nsResolver</code>.
+ * @throws NameException if a node type returns an illegal name.
+ * @throws NamespaceException if the name of a node type contains a
+ * prefix that is not known to <code>resolver</code>.
*/
- private static QName[] getNodeTypeNames(NodeType[] nt,
- NamespaceResolver nsResolver)
- throws IllegalNameException, UnknownPrefixException {
- QName[] names = new QName[nt.length];
+ private static Name[] getNodeTypeNames(NodeType[] nt,
+ NamePathResolver resolver)
+ throws NameException, NamespaceException {
+ Name[] names = new Name[nt.length];
for (int i = 0; i < nt.length; i++) {
- QName ntName = NameFormat.parse(nt[i].getName(), nsResolver);
+ Name ntName = resolver.getQName(nt[i].getName());
names[i] = ntName;
}
return names;
Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QNodeTypeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QNodeTypeDefinitionImpl.java?rev=586065&r1=586064&r2=586065&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QNodeTypeDefinitionImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QNodeTypeDefinitionImpl.java Thu Oct 18 11:41:45 2007
@@ -19,16 +19,16 @@
import org.apache.jackrabbit.spi.QPropertyDefinition;
import org.apache.jackrabbit.spi.QNodeDefinition;
import org.apache.jackrabbit.spi.QValueFactory;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.name.NameFormat;
-import org.apache.jackrabbit.name.IllegalNameException;
-import org.apache.jackrabbit.name.UnknownPrefixException;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.conversion.IllegalNameException;
+import org.apache.jackrabbit.conversion.NamePathResolver;
+import org.apache.jackrabbit.conversion.NameException;
import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.PropertyDefinition;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.RepositoryException;
+import javax.jcr.NamespaceException;
/**
* <code>QNodeTypeDefinitionImpl</code> implements a qualified node type
@@ -42,26 +42,27 @@
* <code>NodeType</code>.
*
* @param nt the JCR node type.
- * @param nsResolver the namespace resolver in use.
+ * @param resolver
* @param qValueFactory the QValue factory.
- * @throws RepositoryException if an error occurs while reading from
- * <code>nt</code>.
- * @throws IllegalNameException if <code>nt</code> contains an illegal
+ *
+ * @throws NameException if <code>nt</code> contains an illegal
* name.
- * @throws UnknownPrefixException if <code>nt</code> contains a name with an
+ * @throws NamespaceException if <code>nt</code> contains a name with an
* namespace prefix that is unknown to
* <code>nsResolver</code>.
+ * @throws RepositoryException if an error occurs while reading from
+ * <code>nt</code>.
*/
public QNodeTypeDefinitionImpl(NodeType nt,
- NamespaceResolver nsResolver,
+ NamePathResolver resolver,
QValueFactory qValueFactory)
- throws RepositoryException, IllegalNameException, UnknownPrefixException {
- super(NameFormat.parse(nt.getName(), nsResolver),
- getNodeTypeNames(nt.getDeclaredSupertypes(), nsResolver),
+ throws NamespaceException, RepositoryException, NameException {
+ super(resolver.getQName(nt.getName()),
+ getNodeTypeNames(nt.getDeclaredSupertypes(), resolver),
nt.isMixin(), nt.hasOrderableChildNodes(),
- nt.getPrimaryItemName() != null ? NameFormat.parse(nt.getPrimaryItemName(), nsResolver) : null,
- getQPropertyDefinitions(nt.getDeclaredPropertyDefinitions(), nsResolver, qValueFactory),
- getQNodeDefinitions(nt.getDeclaredChildNodeDefinitions(), nsResolver));
+ nt.getPrimaryItemName() != null ? resolver.getQName(nt.getPrimaryItemName()) : null,
+ getQPropertyDefinitions(nt.getDeclaredPropertyDefinitions(), resolver, qValueFactory),
+ getQNodeDefinitions(nt.getDeclaredChildNodeDefinitions(), resolver));
}
/**
@@ -69,18 +70,18 @@
* resolver to parse the names.
*
* @param nt the node types
- * @param nsResolver the namespace resolver.
+ * @param resolver
* @return the qualified names of the node types.
* @throws IllegalNameException if a node type returns an illegal name.
- * @throws UnknownPrefixException if the nameo of a node type contains a
- * prefix that is not known to <code>nsResolver</code>.
+ * @throws NamespaceException if the name of a node type contains a
+ * prefix that is not known to <code>rResolver</code>.
*/
- private static QName[] getNodeTypeNames(NodeType[] nt,
- NamespaceResolver nsResolver)
- throws IllegalNameException, UnknownPrefixException {
- QName[] names = new QName[nt.length];
+ private static Name[] getNodeTypeNames(NodeType[] nt,
+ NamePathResolver resolver)
+ throws NameException, NamespaceException {
+ Name[] names = new Name[nt.length];
for (int i = 0; i < nt.length; i++) {
- QName ntName = NameFormat.parse(nt[i].getName(), nsResolver);
+ Name ntName = resolver.getQName(nt[i].getName());
names[i] = ntName;
}
return names;
@@ -90,46 +91,41 @@
* Returns qualified property definitions for JCR property definitions.
*
* @param propDefs the JCR property definitions.
- * @param nsResolver the namespace resolver.
+ * @param resolver
* @param factory the value factory.
* @return qualified property definitions.
* @throws RepositoryException if an error occurs while converting the
* definitions.
- * @throws IllegalNameException if a property definition contains an
- * illegal name.
- * @throws UnknownPrefixException if the name of a property definition
- * contains a namespace prefix that is now
- * known to <code>nsResolver</code>.
*/
private static QPropertyDefinition[] getQPropertyDefinitions(
PropertyDefinition[] propDefs,
- NamespaceResolver nsResolver,
- QValueFactory factory) throws RepositoryException, IllegalNameException, UnknownPrefixException {
+ NamePathResolver resolver,
+ QValueFactory factory) throws RepositoryException, NameException {
QPropertyDefinition[] propertyDefs = new QPropertyDefinition[propDefs.length];
for (int i = 0; i < propDefs.length; i++) {
- propertyDefs[i] = new QPropertyDefinitionImpl(propDefs[i], nsResolver, factory);
+ propertyDefs[i] = new QPropertyDefinitionImpl(propDefs[i], resolver, factory);
}
return propertyDefs;
}
-
+
/**
* Returns qualified node definitions for JCR node definitions.
*
- * @param nodeDefs the JCR node definitions.
- * @param nsResolver the namespace resolver.
+ * @param nodeDefs the JCR node definitions.
+ * @param resolver the name and path resolver.
* @return qualified node definitions.
* @throws IllegalNameException if the node definition contains an illegal
* name.
- * @throws UnknownPrefixException if the name of a node definition contains
+ * @throws NamespaceException if the name of a node definition contains
* a namespace prefix that is now known to
* <code>nsResolver</code>.
*/
- private static QNodeDefinition[] getQNodeDefinitions(
- NodeDefinition[] nodeDefs,
- NamespaceResolver nsResolver) throws IllegalNameException, UnknownPrefixException {
+ private static QNodeDefinition[] getQNodeDefinitions (NodeDefinition[] nodeDefs,
+ NamePathResolver resolver)
+ throws NameException, NamespaceException {
QNodeDefinition[] childNodeDefs = new QNodeDefinition[nodeDefs.length];
for (int i = 0; i < nodeDefs.length; i++) {
- childNodeDefs[i] = new QNodeDefinitionImpl(nodeDefs[i], nsResolver);
+ childNodeDefs[i] = new QNodeDefinitionImpl(nodeDefs[i], resolver);
}
return childNodeDefs;
}
Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QPropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QPropertyDefinitionImpl.java?rev=586065&r1=586064&r2=586065&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QPropertyDefinitionImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QPropertyDefinitionImpl.java Thu Oct 18 11:41:45 2007
@@ -18,10 +18,8 @@
import org.apache.jackrabbit.spi.QValue;
import org.apache.jackrabbit.spi.QValueFactory;
-import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.name.NameFormat;
-import org.apache.jackrabbit.name.IllegalNameException;
-import org.apache.jackrabbit.name.UnknownPrefixException;
+import org.apache.jackrabbit.conversion.NamePathResolver;
+import org.apache.jackrabbit.conversion.NameException;
import org.apache.jackrabbit.value.ValueFormat;
import javax.jcr.nodetype.PropertyDefinition;
@@ -41,43 +39,43 @@
* <code>propDef</code>.
*
* @param propDef the JCR property definition.
- * @param nsResolver the namespace resolver in use.
+ * @param resolver
* @param qValueFactory the QValue factory.
* @throws RepositoryException if an error occurs while reading from
* <code>propDef</code>.
*/
QPropertyDefinitionImpl(PropertyDefinition propDef,
- NamespaceResolver nsResolver,
+ NamePathResolver resolver,
QValueFactory qValueFactory)
- throws RepositoryException, IllegalNameException, UnknownPrefixException {
- super(propDef.getName().equals(ANY_NAME.getLocalName()) ? ANY_NAME : NameFormat.parse(propDef.getName(), nsResolver),
- NameFormat.parse(propDef.getDeclaringNodeType().getName(), nsResolver),
+ throws RepositoryException, NameException {
+ super(propDef.getName().equals(ANY_NAME.getLocalName()) ? ANY_NAME : resolver.getQName(propDef.getName()),
+ resolver.getQName(propDef.getDeclaringNodeType().getName()),
propDef.isAutoCreated(), propDef.isMandatory(),
propDef.getOnParentVersion(), propDef.isProtected(),
- convertValues(propDef.getDefaultValues(), nsResolver, qValueFactory),
+ convertValues(propDef.getDefaultValues(), resolver, qValueFactory),
propDef.isMultiple(), propDef.getRequiredType(),
- convertConstraints(propDef.getValueConstraints(), nsResolver, qValueFactory, propDef.getRequiredType()));
+ convertConstraints(propDef.getValueConstraints(), resolver, qValueFactory, propDef.getRequiredType()));
}
/**
* Convers JCR {@link Value}s to {@link QValue}s.
*
* @param values the JCR values.
- * @param nsResolver the namespace resolver.
+ * @param resolver
* @param factory the QValue factory.
* @return the converted values.
* @throws RepositoryException if an error occurs while converting the
* values.
*/
private static QValue[] convertValues(Value[] values,
- NamespaceResolver nsResolver,
+ NamePathResolver resolver,
QValueFactory factory)
throws RepositoryException {
QValue[] defaultValues = null;
if (values != null) {
defaultValues = new QValue[values.length];
for (int i = 0; i < values.length; i++) {
- defaultValues[i] = ValueFormat.getQValue(values[i], nsResolver, factory);
+ defaultValues[i] = ValueFormat.getQValue(values[i], resolver, factory);
}
}
return defaultValues;
@@ -89,7 +87,7 @@
*
* @param constraints the constraint strings from the JCR property
* definition.
- * @param nsResolver the namespace resolver.
+ * @param resolver
* @param factory the QValueFactory.
* @param requiredType the required type of the property definition.
* @return SPI formatted constraint strings.
@@ -97,7 +95,7 @@
* constraint strings.
*/
private static String[] convertConstraints(String[] constraints,
- NamespaceResolver nsResolver,
+ NamePathResolver resolver,
QValueFactory factory,
int requiredType)
throws RepositoryException {
@@ -107,7 +105,7 @@
int type = requiredType == PropertyType.REFERENCE ? PropertyType.NAME : requiredType;
for (int i = 0; i < constraints.length; i++) {
constraints[i] = ValueFormat.getQValue(
- constraints[i], type, nsResolver, factory).getString();
+ constraints[i], type, resolver, factory).getString();
}
}
return constraints;
Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java?rev=586065&r1=586064&r2=586065&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java Thu Oct 18 11:41:45 2007
@@ -18,11 +18,11 @@
import org.apache.jackrabbit.spi.QueryInfo;
import org.apache.jackrabbit.spi.QValueFactory;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.name.NameFormat;
-import org.apache.jackrabbit.name.NameException;
+import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.util.IteratorHelper;
+import org.apache.jackrabbit.name.NameConstants;
+import org.apache.jackrabbit.conversion.NameException;
+import org.apache.jackrabbit.conversion.NamePathResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,7 +58,7 @@
/**
* The namespace resolver.
*/
- private final NamespaceResolver nsResolver;
+ private final NamePathResolver resolver;
/**
* The QValue factory.
@@ -68,7 +68,7 @@
/**
* The names of the columns in the query result.
*/
- private final QName[] columnNames;
+ private final Name[] columnNames;
/**
* The resolved name of the jcr:score column.
@@ -85,28 +85,28 @@
*
* @param result the JCR query result.
* @param idFactory the id factory.
- * @param nsResolver the namespace resolver in use.
+ * @param resolver
* @param qValueFactory the QValue factory.
* @throws RepositoryException if an error occurs while reading from
* <code>result</code>.
*/
public QueryInfoImpl(QueryResult result,
IdFactoryImpl idFactory,
- NamespaceResolver nsResolver,
+ NamePathResolver resolver,
QValueFactory qValueFactory)
throws RepositoryException {
this.result = result;
this.idFactory = idFactory;
- this.nsResolver = nsResolver;
+ this.resolver = resolver;
this.qValueFactory = qValueFactory;
String[] jcrNames = result.getColumnNames();
- this.columnNames = new QName[jcrNames.length];
+ this.columnNames = new Name[jcrNames.length];
try {
for (int i = 0; i < jcrNames.length; i++) {
- columnNames[i] = NameFormat.parse(jcrNames[i], nsResolver);
+ columnNames[i] = resolver.getQName(jcrNames[i]);
}
- this.scoreName = NameFormat.format(QName.JCR_SCORE, nsResolver);
- this.pathName = NameFormat.format(QName.JCR_PATH, nsResolver);
+ this.scoreName = resolver.getJCRName(NameConstants.JCR_SCORE);
+ this.pathName = resolver.getJCRName(NameConstants.JCR_PATH);
} catch (NameException e) {
throw new RepositoryException(e.getMessage(), e);
}
@@ -137,7 +137,7 @@
try {
Row row = rows.nextRow();
return new QueryResultRowImpl(row, columnJcrNames, scoreName,
- pathName, idFactory, nsResolver, qValueFactory);
+ pathName, idFactory, resolver, qValueFactory);
} catch (RepositoryException e) {
log.warn("Exception when creating QueryResultRowImpl: " +
e.getMessage(), e);
@@ -150,8 +150,8 @@
/**
* {@inheritDoc}
*/
- public QName[] getColumnNames() {
- QName[] names = new QName[columnNames.length];
+ public Name[] getColumnNames() {
+ Name[] names = new Name[columnNames.length];
System.arraycopy(columnNames, 0, names, 0, columnNames.length);
return names;
}
Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java?rev=586065&r1=586064&r2=586065&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java Thu Oct 18 11:41:45 2007
@@ -20,11 +20,10 @@
import org.apache.jackrabbit.spi.NodeId;
import org.apache.jackrabbit.spi.QValue;
import org.apache.jackrabbit.spi.QValueFactory;
-import org.apache.jackrabbit.name.PathFormat;
-import org.apache.jackrabbit.name.Path;
-import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.name.MalformedPathException;
+import org.apache.jackrabbit.spi.Path;
import org.apache.jackrabbit.value.ValueFormat;
+import org.apache.jackrabbit.conversion.NamePathResolver;
+import org.apache.jackrabbit.conversion.NameException;
import javax.jcr.query.Row;
import javax.jcr.RepositoryException;
@@ -59,7 +58,7 @@
* @param scoreName the name of the jcr:score column.
* @param pathName the name of the jcr:path column
* @param idFactory the id factory.
- * @param nsResolver the namespace resolver in use.
+ * @param resolver
* @param qValueFactory the QValue factory.
* @throws RepositoryException if an error occurs while reading from
* <code>row</code>.
@@ -69,13 +68,13 @@
String scoreName,
String pathName,
IdFactoryImpl idFactory,
- NamespaceResolver nsResolver,
+ NamePathResolver resolver,
QValueFactory qValueFactory) throws RepositoryException {
String jcrPath = row.getValue(pathName).getString();
Path path;
try {
- path = PathFormat.parse(jcrPath, nsResolver);
- } catch (MalformedPathException e) {
+ path = resolver.getQPath(jcrPath);
+ } catch (NameException e) {
throw new RepositoryException(e.getMessage(), e);
}
this.nodeId = idFactory.createNodeId((String) null, path);
@@ -86,7 +85,7 @@
if (v == null) {
values[i] = null;
} else {
- values[i] = ValueFormat.getQValue(v, nsResolver, qValueFactory);
+ values[i] = ValueFormat.getQValue(v, resolver, qValueFactory);
}
}
}
Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java?rev=586065&r1=586064&r2=586065&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java Thu Oct 18 11:41:45 2007
@@ -33,14 +33,18 @@
import org.apache.jackrabbit.spi.EventFilter;
import org.apache.jackrabbit.spi.EventBundle;
import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
import org.apache.jackrabbit.spi.commons.EventFilterImpl;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.Path;
-import org.apache.jackrabbit.name.PathFormat;
-import org.apache.jackrabbit.name.NoPrefixDeclaredException;
-import org.apache.jackrabbit.name.NameFormat;
-import org.apache.jackrabbit.name.MalformedPathException;
-import org.apache.jackrabbit.name.NameException;
+import org.apache.jackrabbit.name.NameFactoryImpl;
+import org.apache.jackrabbit.name.PathFactoryImpl;
+import org.apache.jackrabbit.name.NameConstants;
+import org.apache.jackrabbit.name.PathBuilder;
+import org.apache.jackrabbit.conversion.NameException;
+import org.apache.jackrabbit.conversion.NamePathResolver;
+import org.apache.jackrabbit.conversion.MalformedPathException;
import org.apache.jackrabbit.value.QValueFactoryImpl;
import org.apache.jackrabbit.value.ValueFormat;
import org.apache.jackrabbit.JcrConstants;
@@ -157,6 +161,20 @@
/**
* {@inheritDoc}
*/
+ public NameFactory getNameFactory() {
+ return NameFactoryImpl.getInstance();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PathFactory getPathFactory() {
+ return PathFactoryImpl.getInstance();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public QValueFactory getQValueFactory() {
return QValueFactoryImpl.getInstance();
}
@@ -183,7 +201,7 @@
public SessionInfo obtain(Credentials credentials, String workspaceName)
throws LoginException, NoSuchWorkspaceException, RepositoryException {
Credentials duplicate = SessionInfoImpl.duplicateCredentials(credentials);
- return new SessionInfoImpl(repository.login(credentials, workspaceName), duplicate);
+ return new SessionInfoImpl(repository.login(credentials, workspaceName), duplicate, getNameFactory(), getPathFactory());
}
/**
@@ -193,7 +211,7 @@
throws LoginException, NoSuchWorkspaceException, RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
Session s = repository.login(sInfo.getCredentials(), workspaceName);
- return new SessionInfoImpl(s, sInfo.getCredentials());
+ return new SessionInfoImpl(s, sInfo.getCredentials(), getNameFactory(), getPathFactory());
}
/**
@@ -202,7 +220,7 @@
public SessionInfo impersonate(SessionInfo sessionInfo, Credentials credentials) throws LoginException, RepositoryException {
Credentials duplicate = SessionInfoImpl.duplicateCredentials(credentials);
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
- return new SessionInfoImpl(sInfo.getSession().impersonate(credentials), duplicate);
+ return new SessionInfoImpl(sInfo.getSession().impersonate(credentials), duplicate, getNameFactory(), getPathFactory());
}
/**
@@ -258,9 +276,10 @@
*/
public NodeId getRootId(SessionInfo sessionInfo)
throws RepositoryException {
+
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
return idFactory.createNodeId(sInfo.getSession().getRootNode(),
- sInfo.getNamespaceResolver());
+ sInfo.getNamePathResolver());
}
/**
@@ -272,8 +291,8 @@
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
try {
return new QNodeDefinitionImpl(getNode(nodeId, sInfo).getDefinition(),
- sInfo.getNamespaceResolver());
- } catch (NameException e) {
+ sInfo.getNamePathResolver());
+ } catch (org.apache.jackrabbit.conversion.NameException e) {
throw new RepositoryException(e);
}
}
@@ -288,7 +307,7 @@
try {
return new QPropertyDefinitionImpl(
getProperty(propertyId, sInfo).getDefinition(),
- sInfo.getNamespaceResolver(),
+ sInfo.getNamePathResolver(),
getQValueFactory());
} catch (NameException e) {
throw new RepositoryException(e);
@@ -323,8 +342,8 @@
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
Node node = getNode(nodeId, sInfo);
try {
- return new NodeInfoImpl(node, idFactory, sInfo.getNamespaceResolver());
- } catch (NameException e) {
+ return new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver());
+ } catch (org.apache.jackrabbit.conversion.NameException e) {
throw new RepositoryException(e);
}
}
@@ -336,9 +355,9 @@
throws ItemNotFoundException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
Node node = getNode(nodeId, sInfo);
- QName ntName = null;
+ Name ntName = null;
try {
- ntName = NameFormat.parse(node.getProperty(JcrConstants.JCR_PRIMARYTYPE).getString(), sInfo.getNamespaceResolver());
+ ntName = sInfo.getNamePathResolver().getQName(node.getProperty(JcrConstants.JCR_PRIMARYTYPE).getString());
} catch (NameException e) {
// ignore. should never occur
}
@@ -346,8 +365,8 @@
if (depth == BatchReadConfig.DEPTH_DEFAULT) {
NodeInfo info;
try {
- info = new NodeInfoImpl(node, idFactory, sInfo.getNamespaceResolver());
- } catch (NameException e) {
+ info = new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver());
+ } catch (org.apache.jackrabbit.conversion.NameException e) {
throw new RepositoryException(e);
}
return Collections.singletonList(info).iterator();
@@ -356,15 +375,15 @@
ItemVisitor visitor = new TraversingItemVisitor(false, depth) {
protected void entering(Property property, int i) throws RepositoryException {
try {
- itemInfos.add(new PropertyInfoImpl(property, idFactory, sInfo.getNamespaceResolver(), getQValueFactory()));
- } catch (NameException e) {
+ itemInfos.add(new PropertyInfoImpl(property, idFactory, sInfo.getNamePathResolver(), getQValueFactory()));
+ } catch (org.apache.jackrabbit.conversion.NameException e) {
throw new RepositoryException(e);
}
}
protected void entering(Node node, int i) throws RepositoryException {
try {
- itemInfos.add(new NodeInfoImpl(node, idFactory, sInfo.getNamespaceResolver()));
- } catch (NameException e) {
+ itemInfos.add(new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver()));
+ } catch (org.apache.jackrabbit.conversion.NameException e) {
throw new RepositoryException(e);
}
}
@@ -391,9 +410,9 @@
try {
while (children.hasNext()) {
childInfos.add(new ChildInfoImpl(children.nextNode(),
- sInfo.getNamespaceResolver()));
+ sInfo.getNamePathResolver()));
}
- } catch (NameException e) {
+ } catch (org.apache.jackrabbit.conversion.NameException e) {
throw new RepositoryException(e);
}
return childInfos.iterator();
@@ -408,8 +427,8 @@
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
try {
return new PropertyInfoImpl(getProperty(propertyId, sInfo), idFactory,
- sInfo.getNamespaceResolver(), getQValueFactory());
- } catch (NameException e) {
+ sInfo.getNamePathResolver(), getQValueFactory());
+ } catch (org.apache.jackrabbit.conversion.NameException e) {
throw new RepositoryException(e);
}
}
@@ -461,20 +480,16 @@
public void move(final SessionInfo sessionInfo,
final NodeId srcNodeId,
final NodeId destParentNodeId,
- final QName destName) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
+ final Name destName) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
executeWithLocalEvents(new Callable() {
public Object run() throws RepositoryException {
String srcPath = pathForId(srcNodeId, sInfo);
StringBuffer destPath = new StringBuffer(pathForId(destParentNodeId, sInfo));
- try {
- if (destPath.length() > 1) {
- destPath.append("/");
- }
- destPath.append(NameFormat.format(destName, sInfo.getNamespaceResolver()));
- } catch (NoPrefixDeclaredException e) {
- throw new RepositoryException(e.getMessage(), e);
+ if (destPath.length() > 1) {
+ destPath.append("/");
}
+ destPath.append(sInfo.getNamePathResolver().getJCRName(destName));
sInfo.getSession().getWorkspace().move(srcPath, destPath.toString());
return null;
}
@@ -488,7 +503,7 @@
final String srcWorkspaceName,
final NodeId srcNodeId,
final NodeId destParentNodeId,
- final QName destName) throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, UnsupportedRepositoryOperationException, RepositoryException {
+ final Name destName) throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, UnsupportedRepositoryOperationException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
executeWithLocalEvents(new Callable() {
public Object run() throws RepositoryException {
@@ -535,7 +550,7 @@
final String srcWorkspaceName,
final NodeId srcNodeId,
final NodeId destParentNodeId,
- final QName destName,
+ final Name destName,
final boolean removeExisting) throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, UnsupportedRepositoryOperationException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
executeWithLocalEvents(new Callable() {
@@ -563,7 +578,7 @@
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
try {
Lock lock = getNode(nodeId, sInfo).getLock();
- return new LockInfoImpl(lock, idFactory, sInfo.getNamespaceResolver());
+ return new LockInfoImpl(lock, idFactory, sInfo.getNamePathResolver());
} catch (LockException e) {
// no lock present on this node.
return null;
@@ -583,7 +598,7 @@
public Object run() throws RepositoryException {
Node n = getNode(nodeId, sInfo);
Lock lock = n.lock(deep, sessionScoped);
- return new LockInfoImpl(lock, idFactory, sInfo.getNamespaceResolver());
+ return new LockInfoImpl(lock, idFactory, sInfo.getNamePathResolver());
}
}, sInfo);
}
@@ -675,35 +690,29 @@
Node n = getNode(nodeId, sInfo);
n.restore(v, removeExisting);
} else {
- try {
- // restore with rel-Path part
- Node n = null;
- Path relPath = null;
- Path path = nodeId.getPath();
- if (nodeId.getUniqueID() != null) {
- n = getNode(idFactory.createNodeId(nodeId.getUniqueID()), sInfo);
- relPath = (path.isAbsolute()) ? Path.ROOT.computeRelativePath(nodeId.getPath()) : path;
- } else {
- int degree = 0;
- while (degree < path.getLength()) {
- Path ancestorPath = path.getAncestor(degree);
- NodeId parentId = idFactory.createNodeId(nodeId.getUniqueID(), ancestorPath);
- if (exists(sessionInfo, parentId)) {
- n = getNode(parentId, sInfo);
- relPath = ancestorPath.computeRelativePath(path);
- }
- degree++;
+ // restore with rel-Path part
+ Node n = null;
+ Path relPath = null;
+ Path path = nodeId.getPath();
+ if (nodeId.getUniqueID() != null) {
+ n = getNode(idFactory.createNodeId(nodeId.getUniqueID()), sInfo);
+ relPath = (path.isAbsolute()) ? getPathFactory().getRootPath().computeRelativePath(nodeId.getPath()) : path;
+ } else {
+ int degree = 0;
+ while (degree < path.getLength()) {
+ Path ancestorPath = path.getAncestor(degree);
+ NodeId parentId = idFactory.createNodeId(nodeId.getUniqueID(), ancestorPath);
+ if (exists(sessionInfo, parentId)) {
+ n = getNode(parentId, sInfo);
+ relPath = ancestorPath.computeRelativePath(path);
}
+ degree++;
}
- if (n == null) {
- throw new PathNotFoundException("Path not found " + nodeId);
- } else {
- n.restore(v, PathFormat.format(relPath, sInfo.getNamespaceResolver()), removeExisting);
- }
- } catch (MalformedPathException e) {
- throw new RepositoryException(e);
- } catch (NoPrefixDeclaredException e) {
- throw new RepositoryException(e);
+ }
+ if (n == null) {
+ throw new PathNotFoundException("Path not found " + nodeId);
+ } else {
+ n.restore(v, sInfo.getNamePathResolver().getJCRPath(relPath), removeExisting);
}
}
return null;
@@ -752,7 +761,7 @@
List ids = new ArrayList();
while (it.hasNext()) {
ids.add(idFactory.createNodeId(it.nextNode(),
- sInfo.getNamespaceResolver()));
+ sInfo.getNamePathResolver()));
}
return ids.iterator();
}
@@ -773,30 +782,27 @@
Node node = getNode(nodeId, sInfo);
Version version = null;
boolean cancel;
- try {
- List l = Arrays.asList(mergeFailedIds);
- Property mergeFailed = node.getProperty(NameFormat.format(QName.JCR_MERGEFAILED, sInfo.getNamespaceResolver()));
- Value[] values = mergeFailed.getValues();
- for (int i = 0; i < values.length; i++) {
- String uuid = values[i].getString();
- if (!l.contains(idFactory.createNodeId(uuid))) {
- version = (Version) sInfo.getSession().getNodeByUUID(uuid);
- break;
- }
+ NamePathResolver resolver = sInfo.getNamePathResolver();
+ List l = Arrays.asList(mergeFailedIds);
+ Property mergeFailed = node.getProperty(resolver.getJCRName(NameConstants.JCR_MERGEFAILED));
+ Value[] values = mergeFailed.getValues();
+ for (int i = 0; i < values.length; i++) {
+ String uuid = values[i].getString();
+ if (!l.contains(idFactory.createNodeId(uuid))) {
+ version = (Version) sInfo.getSession().getNodeByUUID(uuid);
+ break;
}
+ }
- l = new ArrayList(predecessorIds.length);
- l.addAll(Arrays.asList(predecessorIds));
- Property predecessors = node.getProperty(NameFormat.format(QName.JCR_PREDECESSORS, sInfo.getNamespaceResolver()));
- values = predecessors.getValues();
- for (int i = 0; i < values.length; i++) {
- NodeId vId = idFactory.createNodeId(values[i].getString());
- l.remove(vId);
- }
- cancel = l.isEmpty();
- } catch (NoPrefixDeclaredException e) {
- throw new RepositoryException (e);
+ l = new ArrayList(predecessorIds.length);
+ l.addAll(Arrays.asList(predecessorIds));
+ Property predecessors = node.getProperty(resolver.getJCRName(NameConstants.JCR_PREDECESSORS));
+ values = predecessors.getValues();
+ for (int i = 0; i < values.length; i++) {
+ NodeId vId = idFactory.createNodeId(values[i].getString());
+ l.remove(vId);
}
+ cancel = l.isEmpty();
if (cancel) {
node.cancelMerge(version);
} else {
@@ -813,17 +819,13 @@
public void addVersionLabel(final SessionInfo sessionInfo,
final NodeId versionHistoryId,
final NodeId versionId,
- final QName label,
+ final Name label,
final boolean moveLabel) throws VersionException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
executeWithLocalEvents(new Callable() {
public Object run() throws RepositoryException {
String jcrLabel;
- try {
- jcrLabel = NameFormat.format(label, sInfo.getNamespaceResolver());
- } catch (NoPrefixDeclaredException e) {
- throw new RepositoryException(e.getMessage(), e);
- }
+ jcrLabel = sInfo.getNamePathResolver().getJCRName(label);
Node version = getNode(versionId, sInfo);
Node vHistory = getNode(versionHistoryId, sInfo);
if (vHistory instanceof VersionHistory) {
@@ -843,16 +845,12 @@
public void removeVersionLabel(final SessionInfo sessionInfo,
final NodeId versionHistoryId,
final NodeId versionId,
- final QName label) throws VersionException, RepositoryException {
+ final Name label) throws VersionException, RepositoryException {
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
executeWithLocalEvents(new Callable() {
public Object run() throws RepositoryException {
String jcrLabel;
- try {
- jcrLabel = NameFormat.format(label, sInfo.getNamespaceResolver());
- } catch (NoPrefixDeclaredException e) {
- throw new RepositoryException(e.getMessage(), e);
- }
+ jcrLabel = sInfo.getNamePathResolver().getJCRName((label));
Node vHistory = getNode(versionHistoryId, sInfo);
if (vHistory instanceof VersionHistory) {
((VersionHistory) vHistory).removeVersionLabel(jcrLabel);
@@ -896,7 +894,7 @@
Query query = createQuery(sInfo.getSession(), statement,
language, namespaces);
return new QueryInfoImpl(query.execute(), idFactory,
- sInfo.getNamespaceResolver(), getQValueFactory());
+ sInfo.getNamePathResolver(), getQValueFactory());
}
/**
@@ -907,7 +905,7 @@
Path absPath,
boolean isDeep,
String[] uuid,
- QName[] nodeTypeName,
+ Name[] nodeTypeName,
boolean noLocal)
throws UnsupportedRepositoryOperationException, RepositoryException {
// make sure there is an event subscription for this session info
@@ -995,9 +993,9 @@
for (NodeTypeIterator it = ntMgr.getAllNodeTypes(); it.hasNext(); ) {
NodeType nt = it.nextNodeType();
nodeTypes.add(new QNodeTypeDefinitionImpl(nt,
- sInfo.getNamespaceResolver(), getQValueFactory()));
+ sInfo.getNamePathResolver(), getQValueFactory()));
}
- } catch (NameException e) {
+ } catch (org.apache.jackrabbit.conversion.NameException e) {
throw new RepositoryException(e);
}
return nodeTypes.iterator();
@@ -1006,20 +1004,20 @@
/**
* {@inheritDoc}
*/
- public Iterator getQNodeTypeDefinitions(SessionInfo sessionInfo, QName[] nodetypeNames) throws RepositoryException {
+ public Iterator getQNodeTypeDefinitions(SessionInfo sessionInfo, Name[] nodetypeNames) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
List defs = new ArrayList();
for (int i = 0; i < nodetypeNames.length; i++) {
try {
- String ntName = NameFormat.format(nodetypeNames[i], sInfo.getNamespaceResolver());
+ String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeNames[i]);
NodeType nt = ntMgr.getNodeType(ntName);
- defs.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamespaceResolver(), getQValueFactory()));
+ defs.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
// in addition pack all supertypes into the return value
NodeType[] supertypes = nt.getSupertypes();
for (int st = 0; st < supertypes.length; st++) {
- defs.add(new QNodeTypeDefinitionImpl(supertypes[i], sInfo.getNamespaceResolver(), getQValueFactory()));
+ defs.add(new QNodeTypeDefinitionImpl(supertypes[i], sInfo.getNamePathResolver(), getQValueFactory()));
}
} catch (NameException e) {
throw new RepositoryException(e);
@@ -1065,8 +1063,8 @@
}
public void addNode(final NodeId parentId,
- final QName nodeName,
- final QName nodetypeName,
+ final Name nodeName,
+ final Name nodetypeName,
final String uuid) throws RepositoryException {
executeGuarded(new Callable() {
public Object run() throws RepositoryException {
@@ -1096,7 +1094,7 @@
}
public void addProperty(final NodeId parentId,
- final QName propertyName,
+ final Name propertyName,
final QValue value)
throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
executeGuarded(new Callable() {
@@ -1104,7 +1102,7 @@
Session s = sInfo.getSession();
Node parent = getParent(parentId, sInfo);
Value jcrValue = ValueFormat.getJCRValue(value,
- sInfo.getNamespaceResolver(), s.getValueFactory());
+ sInfo.getNamePathResolver(), s.getValueFactory());
parent.setProperty(getJcrName(propertyName), jcrValue);
return null;
}
@@ -1112,7 +1110,7 @@
}
public void addProperty(final NodeId parentId,
- final QName propertyName,
+ final Name propertyName,
final QValue[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, ItemExistsException, AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
executeGuarded(new Callable() {
public Object run() throws RepositoryException {
@@ -1121,7 +1119,7 @@
Value[] jcrValues = new Value[values.length];
for (int i = 0; i < jcrValues.length; i++) {
jcrValues[i] = ValueFormat.getJCRValue(values[i],
- sInfo.getNamespaceResolver(), s.getValueFactory());
+ sInfo.getNamePathResolver(), s.getValueFactory());
}
n.setProperty(getJcrName(propertyName), jcrValues);
return null;
@@ -1135,7 +1133,7 @@
public Object run() throws RepositoryException {
Session s = sInfo.getSession();
Value jcrValue = ValueFormat.getJCRValue(value,
- sInfo.getNamespaceResolver(), s.getValueFactory());
+ sInfo.getNamePathResolver(), s.getValueFactory());
getProperty(propertyId, sInfo).setValue(jcrValue);
return null;
}
@@ -1150,7 +1148,7 @@
Value[] jcrValues = new Value[values.length];
for (int i = 0; i < jcrValues.length; i++) {
jcrValues[i] = ValueFormat.getJCRValue(values[i],
- sInfo.getNamespaceResolver(), s.getValueFactory());
+ sInfo.getNamePathResolver(), s.getValueFactory());
}
getProperty(propertyId, sInfo).setValue(jcrValues);
return null;
@@ -1182,28 +1180,25 @@
});
}
- private NodeId calcRemoveNodeId(ItemId itemId) {
+ private NodeId calcRemoveNodeId(ItemId itemId) throws MalformedPathException {
NodeId nodeId = (NodeId) itemId;
- try {
- Path p = itemId.getPath();
- if (p != null) {
- removedNodeIds.add(itemId);
- int index = p.getNameElement().getNormalizedIndex();
- if (index > Path.INDEX_DEFAULT && !removedNodeIds.isEmpty()) {
- Path.PathElement[] elems = p.getElements();
- Path.PathBuilder pb = new Path.PathBuilder();
- for (int i = 0; i <= elems.length - 2; i++) {
- pb.addLast(elems[i]);
- }
- pb.addLast(p.getNameElement().getName(), index - 1);
- NodeId prevSibling = idFactory.createNodeId(itemId.getUniqueID(), pb.getPath());
- if (removedNodeIds.contains(prevSibling)) {
- nodeId = prevSibling;
- }
+ Path p = itemId.getPath();
+ if (p != null) {
+ removedNodeIds.add(itemId);
+ int index = p.getNameElement().getNormalizedIndex();
+ if (index > Path.INDEX_DEFAULT && !removedNodeIds.isEmpty()) {
+ Path.Element[] elems = p.getElements();
+ PathBuilder pb = new PathBuilder();
+ for (int i = 0; i <= elems.length - 2; i++) {
+ pb.addLast(elems[i]);
+ }
+ pb.addLast(p.getNameElement().getName(), index - 1);
+
+ NodeId prevSibling = idFactory.createNodeId(itemId.getUniqueID(), pb.getPath());
+ if (removedNodeIds.contains(prevSibling)) {
+ nodeId = prevSibling;
}
}
- } catch (MalformedPathException e) {
- // ignore
}
return nodeId;
}
@@ -1238,7 +1233,7 @@
}
public void setMixins(final NodeId nodeId,
- final QName[] mixinNodeTypeIds)
+ final Name[] mixinNodeTypeIds)
throws RepositoryException {
executeGuarded(new Callable() {
public Object run() throws RepositoryException {
@@ -1268,7 +1263,7 @@
public void move(final NodeId srcNodeId,
final NodeId destParentNodeId,
- final QName destName) throws RepositoryException {
+ final Name destName) throws RepositoryException {
executeGuarded(new Callable() {
public Object run() throws RepositoryException {
String srcPath = pathForId(srcNodeId, sInfo);
@@ -1300,15 +1295,11 @@
}
}
- private String getJcrName(QName name) throws RepositoryException {
+ private String getJcrName(Name name) throws RepositoryException {
if (name == null) {
return null;
}
- try {
- return NameFormat.format(name, sInfo.getNamespaceResolver());
- } catch (NoPrefixDeclaredException e) {
- throw new RepositoryException(e.getMessage(), e);
- }
+ return sInfo.getNamePathResolver().getJCRName((name));
}
private String createXMLFragment(String nodeName, String ntName, String uuid) {
@@ -1360,16 +1351,12 @@
}
}
- private String getDestinationPath(NodeId destParentNodeId, QName destName, SessionInfoImpl sessionInfo) throws RepositoryException {
+ private String getDestinationPath(NodeId destParentNodeId, Name destName, SessionInfoImpl sessionInfo) throws RepositoryException {
StringBuffer destPath = new StringBuffer(pathForId(destParentNodeId, sessionInfo));
- try {
- if (destPath.length() > 1) {
- destPath.append("/");
- }
- destPath.append(NameFormat.format(destName, sessionInfo.getNamespaceResolver()));
- } catch (NoPrefixDeclaredException e) {
- throw new RepositoryException(e.getMessage(), e);
+ if (destPath.length() > 1) {
+ destPath.append("/");
}
+ destPath.append(sessionInfo.getNamePathResolver().getJCRName(destName));
return destPath.toString();
}
@@ -1388,23 +1375,18 @@
return path.toString();
}
- try {
- if (id.getPath().isAbsolute()) {
- if (path.length() == 1) {
- // root path ends with slash
- path.setLength(0);
- }
- } else {
- // path is relative
- if (path.length() > 1) {
- path.append("/");
- }
+ if (id.getPath().isAbsolute()) {
+ if (path.length() == 1) {
+ // root path ends with slash
+ path.setLength(0);
+ }
+ } else {
+ // path is relative
+ if (path.length() > 1) {
+ path.append("/");
}
- path.append(PathFormat.format(id.getPath(),
- sessionInfo.getNamespaceResolver()));
- } catch (NoPrefixDeclaredException e) {
- throw new RepositoryException(e.getMessage());
}
+ path.append(sessionInfo.getNamePathResolver().getJCRPath(id.getPath()));
return path.toString();
}
@@ -1431,11 +1413,7 @@
return n;
}
String jcrPath;
- try {
- jcrPath = PathFormat.format(path, sessionInfo.getNamespaceResolver());
- } catch (NoPrefixDeclaredException e) {
- throw new RepositoryException(e.getMessage(), e);
- }
+ jcrPath = sessionInfo.getNamePathResolver().getJCRPath(path);
if (path.isAbsolute()) {
jcrPath = jcrPath.substring(1, jcrPath.length());
}
@@ -1451,12 +1429,7 @@
n = session.getRootNode();
}
Path path = id.getPath();
- String jcrPath;
- try {
- jcrPath = PathFormat.format(path, sessionInfo.getNamespaceResolver());
- } catch (NoPrefixDeclaredException e) {
- throw new RepositoryException(e.getMessage(), e);
- }
+ String jcrPath = sessionInfo.getNamePathResolver().getJCRPath(path);
if (path.isAbsolute()) {
jcrPath = jcrPath.substring(1, jcrPath.length());
}
Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/SessionInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/SessionInfoImpl.java?rev=586065&r1=586064&r2=586065&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/SessionInfoImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/SessionInfoImpl.java Thu Oct 18 11:41:45 2007
@@ -17,8 +17,16 @@
package org.apache.jackrabbit.spi2jcr;
import org.apache.jackrabbit.spi.SessionInfo;
-import org.apache.jackrabbit.name.AbstractNamespaceResolver;
-import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.namespace.NamespaceResolver;
+import org.apache.jackrabbit.conversion.NamePathResolver;
+import org.apache.jackrabbit.conversion.ParsingNameResolver;
+import org.apache.jackrabbit.conversion.NameResolver;
+import org.apache.jackrabbit.conversion.PathResolver;
+import org.apache.jackrabbit.conversion.ParsingPathResolver;
+import org.apache.jackrabbit.conversion.DefaultNamePathResolver;
+import org.apache.jackrabbit.namespace.AbstractNamespaceResolver;
import javax.jcr.NamespaceException;
import javax.jcr.NamespaceRegistry;
@@ -44,7 +52,7 @@
/**
* The namespace resolver for this session info.
*/
- private final NamespaceResolver resolver;
+ private final NamePathResolver resolver;
/**
* A copy of the credentials that were used to obtain the JCR session.
@@ -56,16 +64,17 @@
*
* @param session the JCR session.
* @param credentials a copy of the credentials that were used to obtain the
- * JCR session.
+ * @param nameFactory
+ * @param pathFactory
* @throws RepositoryException
*/
- SessionInfoImpl(Session session, Credentials credentials) throws RepositoryException {
+ SessionInfoImpl(Session session, Credentials credentials,
+ NameFactory nameFactory, PathFactory pathFactory) throws RepositoryException {
this.session = session;
this.credentials = credentials;
final NamespaceRegistry nsReg = session.getWorkspace().getNamespaceRegistry();
-
- this.resolver = new AbstractNamespaceResolver() {
+ final NamespaceResolver nsResolver = new AbstractNamespaceResolver() {
public String getPrefix(String uri) throws NamespaceException {
try {
return nsReg.getPrefix(uri);
@@ -86,7 +95,11 @@
}
}
};
-
+
+ final NameResolver nResolver = new ParsingNameResolver(nameFactory, nsResolver);
+ final PathResolver pResolver = new ParsingPathResolver(pathFactory, nResolver);
+
+ this.resolver = new DefaultNamePathResolver(nResolver, pResolver);
}
/**
@@ -99,7 +112,7 @@
/**
* @return the namespace resolver for this session info.
*/
- NamespaceResolver getNamespaceResolver() {
+ NamePathResolver getNamePathResolver() {
return resolver;
}