jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r553507 [2/2] - in /jackrabbit/trunk/contrib/spi: commons/src/main/java/org/apache/jackrabbit/spi/ commons/src/main/java/org/apache/jackrabbit/spi/commons/ spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/client/ spi-rmi/src/main/java/or...
Date Thu, 05 Jul 2007 13:52:16 GMT
Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/ChildInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/ChildInfoImpl.java?view=diff&rev=553507&r1=553506&r2=553507
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/ChildInfoImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/ChildInfoImpl.java Thu Jul  5 06:52:13 2007
@@ -16,11 +16,10 @@
  */
 package org.apache.jackrabbit.spi2jcr;
 
-import org.apache.jackrabbit.spi.ChildInfo;
-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.name.IllegalNameException;
+import org.apache.jackrabbit.name.UnknownPrefixException;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -30,66 +29,40 @@
  * <code>ChildInfoImpl</code> implements a <code>ChildInfo</code> and provides
  * information about a child node.
  */
-class ChildInfoImpl implements ChildInfo {
-
-    /**
-     * The name of this child info.
-     */
-    private final QName name;
-
-    /**
-     * The unique id for this child info or <code>null</code> if it does not
-     * have a unique id.
-     */
-    private final String uniqueId;
-
-    /**
-     * 1-based index of this child info.
-     */
-    private final int index;
+class ChildInfoImpl extends org.apache.jackrabbit.spi.commons.ChildInfoImpl {
 
     /**
      * Creates a new <code>ChildInfoImpl</code> for <code>node</code>.
      *
      * @param node       the JCR node.
      * @param nsResolver the namespace resolver in use.
-     * @throws RepositoryException if an error occurs while reading from
-     *                             <code>node</code>.
+     * @throws RepositoryException    if an error occurs while reading from
+     *                                <code>node</code>.
+     * @throws IllegalNameException   if the <code>node</code> name is illegal.
+     * @throws UnknownPrefixException if the name of the <code>node</code>
+     *                                contains a prefix not known to
+     *                                <code>nsResolver</code>.
+     */
+    public ChildInfoImpl(Node node, NamespaceResolver nsResolver)
+            throws RepositoryException, IllegalNameException, UnknownPrefixException {
+        super(NameFormat.parse(node.getName(), nsResolver),
+                getUniqueId(node), node.getIndex());
+    }
+
+    /**
+     * @param node the JCR node.
+     * @return the unique id for the <code>node</code> or <code>null</code> if
+     *         the node does not have a unique id.
+     * @throws RepositoryException if an error occurs while reading the unique
+     *                             id.
      */
-    public ChildInfoImpl(Node node, NamespaceResolver nsResolver) throws RepositoryException {
-        try {
-            this.name = NameFormat.parse(node.getName(), nsResolver);
-        } catch (NameException e) {
-            throw new RepositoryException(e.getMessage(), e);
-        }
+    private static String getUniqueId(Node node) throws RepositoryException {
         String uuid = null;
         try {
             uuid = node.getUUID();
         } catch (UnsupportedRepositoryOperationException e) {
             // not referenceable
         }
-        this.uniqueId = uuid;
-        this.index = node.getIndex();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public QName getName() {
-        return name;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String getUniqueID() {
-        return uniqueId;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public int getIndex() {
-        return index;
+        return uuid;
     }
 }

Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java?view=diff&rev=553507&r1=553506&r2=553507
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/EventSubscription.java Thu Jul  5 06:52:13 2007
@@ -22,6 +22,8 @@
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.commons.EventImpl;
+import org.apache.jackrabbit.spi.commons.EventBundleImpl;
 import org.apache.jackrabbit.uuid.UUID;
 import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.name.Path;

Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/LockInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/LockInfoImpl.java?view=diff&rev=553507&r1=553506&r2=553507
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/LockInfoImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/LockInfoImpl.java Thu Jul  5 06:52:13 2007
@@ -16,99 +16,33 @@
  */
 package org.apache.jackrabbit.spi2jcr;
 
-import org.apache.jackrabbit.spi.LockInfo;
-import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.name.NamespaceResolver;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.Node;
 import javax.jcr.lock.Lock;
 
 /**
  * <code>LockInfoImpl</code> implements a <code>LockInfo</code> on top of a
  * JCR repository.
  */
-class LockInfoImpl implements LockInfo {
-
-    /**
-     * The lock token for this lock info.
-     */
-    private final String lockToken;
-
-    /**
-     * The owner of the lock.
-     */
-    private final String lockOwner;
-
-    /**
-     * The isDeep flag.
-     */
-    private final boolean isDeep;
-
-    /**
-     * The isSessionScoped flag.
-     */
-    private final boolean isSessionScoped;
-
-    /**
-     * The <code>NodeId</code> of the locked node.
-     */
-    private final NodeId nodeId;
+class LockInfoImpl extends org.apache.jackrabbit.spi.commons.LockInfoImpl {
 
     /**
      * Creates a new lock info for the given locked <code>node</code>.
      *
-     * @param node       the locked node.
+     * @param lock       the lock.
      * @param idFactory  the id factory.
      * @param nsResolver the namespace resolver in use.
      * @throws RepositoryException if an error occurs while reading from
      *                             <code>node</code> or if <code>node</code> is
      *                             not locked.
      */
-    public LockInfoImpl(Node node,
+    public LockInfoImpl(Lock lock,
                         IdFactoryImpl idFactory,
                         NamespaceResolver nsResolver)
             throws RepositoryException {
-        Lock lock = node.getLock();
-        this.lockToken = lock.getLockToken();
-        this.lockOwner = lock.getLockOwner();
-        this.isDeep = lock.isDeep();
-        this.isSessionScoped = lock.isSessionScoped();
-        this.nodeId = idFactory.createNodeId(lock.getNode(), nsResolver);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String getLockToken() {
-        return lockToken;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String getOwner() {
-        return lockOwner;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isDeep() {
-        return isDeep;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isSessionScoped() {
-        return isSessionScoped;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public NodeId getNodeId() {
-        return nodeId;
+        super(lock.getLockToken(), lock.getLockOwner(),
+                lock.isDeep(), lock.isSessionScoped(),
+                idFactory.createNodeId(lock.getNode(), nsResolver));
     }
 }

Modified: jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/NodeInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/NodeInfoImpl.java?view=diff&rev=553507&r1=553506&r2=553507
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/NodeInfoImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/NodeInfoImpl.java Thu Jul  5 06:52:13 2007
@@ -16,13 +16,13 @@
  */
 package org.apache.jackrabbit.spi2jcr;
 
-import org.apache.jackrabbit.spi.NodeInfo;
-import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.NameFormat;
-import org.apache.jackrabbit.name.NameException;
+import org.apache.jackrabbit.name.IllegalNameException;
+import org.apache.jackrabbit.name.UnknownPrefixException;
+import org.apache.jackrabbit.name.PathFormat;
+import org.apache.jackrabbit.name.MalformedPathException;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Node;
@@ -36,37 +36,7 @@
  * <code>NodeInfoImpl</code> implements a <code>NodeInfo</code> on top of a JCR
  * repository.
  */
-class NodeInfoImpl extends ItemInfoImpl implements NodeInfo {
-
-    /**
-     * The node id of the underlying node.
-     */
-    private final NodeId id;
-
-    /**
-     * 1-based index of the underlying node.
-     */
-    private final int index;
-
-    /**
-     * The name of the primary node type.
-     */
-    private final QName primaryTypeName;
-
-    /**
-     * The names of assigned mixins.
-     */
-    private final QName[] mixinNames;
-
-    /**
-     * The list of {@link PropertyId}s that reference this node info.
-     */
-    private final List references;
-
-    /**
-     * The list of {@link PropertyId}s of this node info.
-     */
-    private final List propertyIds;
+class NodeInfoImpl extends org.apache.jackrabbit.spi.commons.NodeInfoImpl {
 
     /**
      * Creates a new node info for the given <code>node</code>.
@@ -80,80 +50,57 @@
     public NodeInfoImpl(Node node,
                         IdFactoryImpl idFactory,
                         NamespaceResolver nsResolver)
-            throws RepositoryException {
-        super(node, idFactory, nsResolver);
-        try {
-            this.id = idFactory.createNodeId(node, nsResolver);
-            this.index = node.getIndex();
-            this.primaryTypeName = NameFormat.parse(node.getPrimaryNodeType().getName(), nsResolver);
-            NodeType[] mixins = node.getMixinNodeTypes();
-            this.mixinNames = new QName[mixins.length];
-            for (int i = 0; i < mixins.length; i++) {
-                mixinNames[i] = NameFormat.parse(mixins[i].getName(), nsResolver);
-            }
-            this.references = new ArrayList();
-            for (PropertyIterator it = node.getReferences(); it.hasNext(); ) {
-                references.add(idFactory.createPropertyId(it.nextProperty(), nsResolver));
-            }
-            this.propertyIds = new ArrayList();
-            for (PropertyIterator it = node.getProperties(); it.hasNext(); ) {
-                propertyIds.add(idFactory.createPropertyId(it.nextProperty(), nsResolver));
-            }
-        } catch (NameException e) {
-            throw new RepositoryException(e.getMessage(), e);
-        }
-    }
-
-    //-------------------------------< NodeInfo >-------------------------------
-
-    /**
-     * {@inheritDoc}
-     */
-    public NodeId getId() {
-        return id;
+            throws RepositoryException, IllegalNameException, UnknownPrefixException, MalformedPathException {
+        super(node.getName().length() == 0 ? null : idFactory.createNodeId(node.getParent(), nsResolver),
+                node.getName().length() == 0 ? QName.ROOT : NameFormat.parse(node.getName(), nsResolver),
+                PathFormat.parse(node.getPath(), nsResolver),
+                idFactory.createNodeId(node, nsResolver), node.getIndex(),
+                NameFormat.parse(node.getPrimaryNodeType().getName(), nsResolver),
+                getNodeTypeNames(node.getMixinNodeTypes(), nsResolver),
+                getPropertyIds(node.getReferences(), nsResolver, idFactory),
+                getPropertyIds(node.getProperties(), nsResolver, idFactory));
     }
 
     /**
-     * {@inheritDoc}
-     */
-    public int getIndex() {
-        return index;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public QName getNodetype() {
-        return primaryTypeName;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public QName[] getMixins() {
-        QName[] ret = new QName[mixinNames.length];
-        System.arraycopy(mixinNames, 0, ret, 0, mixinNames.length);
-        return ret;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public PropertyId[] getReferences() {
-        return (PropertyId[]) references.toArray(new PropertyId[references.size()]);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Iterator getPropertyIds() {
-        return propertyIds.iterator();
+     * Returns the qualified names of the passed node types using the namespace
+     * resolver to parse the names.
+     *
+     * @param nt         the node types
+     * @param nsResolver the namespace 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>.
+     */
+    private static QName[] getNodeTypeNames(NodeType[] nt,
+                                     NamespaceResolver nsResolver)
+            throws IllegalNameException, UnknownPrefixException {
+        QName[] names = new QName[nt.length];
+        for (int i = 0; i < nt.length; i++) {
+            QName ntName = NameFormat.parse(nt[i].getName(), nsResolver);
+            names[i] = ntName;
+        }
+        return names;
     }
 
     /**
-     * {@inheritDoc}
-     */
-    public boolean denotesNode() {
-        return true;
+     * Returns property ids for the passed JCR properties.
+     *
+     * @param props      the JCR properties.
+     * @param nsResolver the namespace resolver.
+     * @param idFactory  the id factory.
+     * @return the property ids for the passed JCR properties.
+     * @throws RepositoryException if an error occurs while reading from the
+     *                             properties.
+     */
+    private static Iterator getPropertyIds(PropertyIterator props,
+                                              NamespaceResolver nsResolver,
+                                              IdFactoryImpl idFactory)
+            throws RepositoryException {
+        List references = new ArrayList();
+        while (props.hasNext()) {
+            references.add(idFactory.createPropertyId(props.nextProperty(), nsResolver));
+        }
+        return references.iterator();
     }
 }

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?view=diff&rev=553507&r1=553506&r2=553507
==============================================================================
--- 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 Jul  5 06:52:13 2007
@@ -16,11 +16,14 @@
  */
 package org.apache.jackrabbit.spi2jcr;
 
-import org.apache.jackrabbit.spi.PropertyInfo;
-import org.apache.jackrabbit.spi.PropertyId;
 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.value.ValueFormat;
 
 import javax.jcr.RepositoryException;
@@ -31,27 +34,8 @@
  * <code>PropertyInfoImpl</code> implements a <code>PropertyInfo</code> on top
  * of a JCR repository.
  */
-class PropertyInfoImpl extends ItemInfoImpl implements PropertyInfo {
-
-    /**
-     * The property info of the underlying property.
-     */
-    private final PropertyId propertyId;
-
-    /**
-     * The type of the property.
-     */
-    private final int type;
-
-    /**
-     * The multiValued flag.
-     */
-    private final boolean isMultiValued;
-
-    /**
-     * The values of this property info.
-     */
-    private final QValue[] values;
+class PropertyInfoImpl
+        extends org.apache.jackrabbit.spi.commons.PropertyInfoImpl {
 
     /**
      * Creates a new property info for the given <code>property</code>.
@@ -66,57 +50,42 @@
     public PropertyInfoImpl(Property property,
                             IdFactoryImpl idFactory,
                             NamespaceResolver nsResolver,
-                            QValueFactory qValueFactory) throws RepositoryException {
-        super(property, idFactory, nsResolver);
-        this.propertyId = idFactory.createPropertyId(property, nsResolver);
-        // TODO: build QValues upon (first) usage only.
-        this.type = property.getType();
-        this.isMultiValued = property.getDefinition().isMultiple();
+                            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),
+                property.getType(), property.getDefinition().isMultiple(),
+                getValues(property, nsResolver, 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 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,
+                                      QValueFactory factory)
+            throws RepositoryException {
+        boolean isMultiValued = property.getDefinition().isMultiple();
+        QValue[] values;
         if (isMultiValued) {
             Value[] jcrValues = property.getValues();
-            this.values = new QValue[jcrValues.length];
+            values = new QValue[jcrValues.length];
             for (int i = 0; i < jcrValues.length; i++) {
-                this.values[i] = ValueFormat.getQValue(jcrValues[i],
-                        nsResolver, qValueFactory);
+                values[i] = ValueFormat.getQValue(jcrValues[i],
+                        nsResolver, factory);
             }
         } else {
-            this.values = new QValue[]{
-                ValueFormat.getQValue(property.getValue(), nsResolver, qValueFactory)};
+            values = new QValue[]{
+                ValueFormat.getQValue(property.getValue(), nsResolver, factory)};
         }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public PropertyId getId() {
-        return propertyId;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public int getType() {
-        return type;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isMultiValued() {
-        return isMultiValued;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public QValue[] getValues() {
         return values;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean denotesNode() {
-        return false;
     }
 }

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?view=diff&rev=553507&r1=553506&r2=553507
==============================================================================
--- 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 Jul  5 06:52:13 2007
@@ -16,157 +16,63 @@
  */
 package org.apache.jackrabbit.spi2jcr;
 
-import org.apache.jackrabbit.spi.QNodeDefinition;
 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.name.IllegalNameException;
+import org.apache.jackrabbit.name.UnknownPrefixException;
 
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
-import javax.jcr.RepositoryException;
-import java.util.Arrays;
-import java.util.TreeSet;
 
 /**
  * <code>QNodeDefinitionImpl</code> implements a <code>QNodeDefinition</code>.
- * TODO: mostly copied from spi2dav, move common parts to spi-commons.
  */
-class QNodeDefinitionImpl extends QItemDefinitionImpl implements QNodeDefinition {
-
-    /**
-     * The name of the default primary type.
-     */
-    private final QName defaultPrimaryType;
-
-    /**
-     * The names of the required primary types.
-     */
-    private final QName[] requiredPrimaryTypes;
-
-    /**
-     * The 'allowsSameNameSiblings' flag.
-     */
-    private final boolean allowsSameNameSiblings;
+class QNodeDefinitionImpl
+        extends org.apache.jackrabbit.spi.commons.QNodeDefinitionImpl {
 
     /**
      * Creates a new qualified node definition based on a JCR NodeDefinition.
      *
      * @param nodeDef    the node definition.
      * @param nsResolver the namespace resolver in use.
-     * @throws RepositoryException if an error occurs while reading from
-     *                             <code>nodeDef</code>.
+     * @throws IllegalNameException   if <code>nodeDef</code> contains an
+     *                                illegal name.
+     * @throws UnknownPrefixException if <code>nodeDef</code> contains a name
+     *                                with an namespace prefix that is unknown
+     *                                to <code>nsResolver</code>.
      */
     QNodeDefinitionImpl(NodeDefinition nodeDef,
-                        NamespaceResolver nsResolver) throws RepositoryException {
-        super(nodeDef, nsResolver);
-        try {
-            this.allowsSameNameSiblings = nodeDef.allowsSameNameSiblings();
-            NodeType defPrimaryType = nodeDef.getDefaultPrimaryType();
-            if (defPrimaryType == null) {
-                this.defaultPrimaryType = null;
-            } else {
-                this.defaultPrimaryType = NameFormat.parse(nodeDef.getDefaultPrimaryType().getName(), nsResolver);
-            }
-            NodeType[] reqPrimaryTypes = nodeDef.getRequiredPrimaryTypes();
-            this.requiredPrimaryTypes = new QName[reqPrimaryTypes.length];
-            for (int i = 0; i < reqPrimaryTypes.length; i++) {
-                QName ntName = NameFormat.parse(reqPrimaryTypes[i].getName(), nsResolver);
-                this.requiredPrimaryTypes[i] = ntName;
-            }
-        } catch (NameException e) {
-            throw new RepositoryException(e.getMessage());
-        }
+                        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,
+                nodeDef.isAutoCreated(), nodeDef.isMandatory(),
+                nodeDef.getOnParentVersion(), nodeDef.isProtected(),
+                nodeDef.getDefaultPrimaryType() != null ? NameFormat.parse(nodeDef.getDefaultPrimaryType().getName(), nsResolver) : null,
+                getNodeTypeNames(nodeDef.getRequiredPrimaryTypes(), nsResolver),
+                nodeDef.allowsSameNameSiblings());
     }
 
-    //-------------------------------------------------------< QNodeDefinition >
     /**
-     * {@inheritDoc}
-     */
-    public QName getDefaultPrimaryType() {
-        return defaultPrimaryType;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public QName[] getRequiredPrimaryTypes() {
-        return requiredPrimaryTypes;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean allowsSameNameSiblings() {
-        return allowsSameNameSiblings;
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * @return always <code>true</code>
-     */
-    public boolean definesNode() {
-        return true;
-    }
-
-    //-------------------------------------------< java.lang.Object overrides >
-    /**
-     * Compares two node definitions for equality. Returns <code>true</code>
-     * if the given object is a node defintion and has the same attributes
-     * as this node definition.
-     *
-     * @param obj the object to compare this node definition with
-     * @return <code>true</code> if the object is equal to this node definition,
-     *         <code>false</code> otherwise
-     * @see Object#equals(Object)
-     */
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj instanceof QNodeDefinition) {
-            QNodeDefinition other = (QNodeDefinition) obj;
-            return super.equals(obj)
-                    && Arrays.equals(requiredPrimaryTypes, other.getRequiredPrimaryTypes())
-                    && (defaultPrimaryType == null
-                            ? other.getDefaultPrimaryType() == null
-                            : defaultPrimaryType.equals(other.getDefaultPrimaryType()))
-                    && allowsSameNameSiblings == other.allowsSameNameSiblings();
-        }
-        return false;
-    }
-
-    /**
-     * Overwrites {@link QItemDefinitionImpl#hashCode()}.
+     * Returns the qualified names of the passed node types using the namespace
+     * resolver to parse the names.
      *
-     * @return
-     */
-    public int hashCode() {
-        if (hashCode == 0) {
-            // build hashCode (format: <declaringNodeType>/<name>/<requiredPrimaryTypes>)
-            StringBuffer sb = new StringBuffer();
-
-            if (getDeclaringNodeType() != null) {
-                sb.append(getDeclaringNodeType().toString());
-                sb.append('/');
-            }
-            if (definesResidual()) {
-                sb.append('*');
-            } else {
-                sb.append(getQName().toString());
-            }
-            sb.append('/');
-            // set of required node type names, sorted in ascending order
-            TreeSet set = new TreeSet();
-            QName[] names = getRequiredPrimaryTypes();
-            for (int i = 0; i < names.length; i++) {
-                set.add(names[i]);
-            }
-            sb.append(set.toString());
-
-            hashCode = sb.toString().hashCode();
+     * @param nt         the node types
+     * @param nsResolver the namespace 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>.
+     */
+    private static QName[] getNodeTypeNames(NodeType[] nt,
+                                     NamespaceResolver nsResolver)
+            throws IllegalNameException, UnknownPrefixException {
+        QName[] names = new QName[nt.length];
+        for (int i = 0; i < nt.length; i++) {
+            QName ntName = NameFormat.parse(nt[i].getName(), nsResolver);
+            names[i] = ntName;
         }
-        return hashCode;
+        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?view=diff&rev=553507&r1=553506&r2=553507
==============================================================================
--- 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 Jul  5 06:52:13 2007
@@ -16,70 +16,26 @@
  */
 package org.apache.jackrabbit.spi2jcr;
 
-import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 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.NameException;
+import org.apache.jackrabbit.name.IllegalNameException;
+import org.apache.jackrabbit.name.UnknownPrefixException;
 
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.RepositoryException;
-import javax.jcr.PropertyType;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Collections;
 
 /**
  * <code>QNodeTypeDefinitionImpl</code> implements a qualified node type
  * definition based on a JCR {@link NodeType}.
  */
-class QNodeTypeDefinitionImpl implements QNodeTypeDefinition {
-
-    /**
-     * The name of the node definition.
-     */
-    private final QName name;
-
-    /**
-     * The names of the declared super types of this node type definition.
-     */
-    private final QName[] supertypes;
-
-    /**
-     * Indicates whether this is a mixin node type definition.
-     */
-    private final boolean isMixin;
-
-    /**
-     * Indicates whether this node type definition has orderable child nodes.
-     */
-    private final boolean hasOrderableChildNodes;
-
-    /**
-     * The name of the primary item or <code>null</code> if none is defined.
-     */
-    private final QName primaryItemName;
-
-    /**
-     * The list of property definitions.
-     */
-    private final QPropertyDefinition[] propertyDefs;
-
-    /**
-     * The list of child node definitions.
-     */
-    private final QNodeDefinition[] childNodeDefs;
-
-    /**
-     * Unmodifiable collection of dependent node type <code>QName</code>s.
-     * @see #getDependencies()
-     */
-    private Collection dependencies;
+class QNodeTypeDefinitionImpl
+        extends org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl {
 
     /**
      * Creates a new qualified node type definition based on a JCR
@@ -88,141 +44,93 @@
      * @param nt            the JCR node type.
      * @param nsResolver    the namespace resolver in use.
      * @param qValueFactory the QValue factory.
-     * @throws RepositoryException if an error occurs while reading from
-     *                             <code>nt</code>.
+     * @throws RepositoryException    if an error occurs while reading from
+     *                                <code>nt</code>.
+     * @throws IllegalNameException   if <code>nt</code> contains an illegal
+     *                                name.
+     * @throws UnknownPrefixException if <code>nt</code> contains a name with an
+     *                                namespace prefix that is unknown to
+     *                                <code>nsResolver</code>.
      */
     public QNodeTypeDefinitionImpl(NodeType nt,
                                    NamespaceResolver nsResolver,
                                    QValueFactory qValueFactory)
-            throws RepositoryException {
-        try {
-            this.name = NameFormat.parse(nt.getName(), nsResolver);
-            NodeType[] superNts = nt.getDeclaredSupertypes();
-            this.supertypes = new QName[superNts.length];
-            for (int i = 0; i < superNts.length; i++) {
-                supertypes[i] = NameFormat.parse(superNts[i].getName(), nsResolver);
-            }
-            this.isMixin = nt.isMixin();
-            this.hasOrderableChildNodes = nt.hasOrderableChildNodes();
-            String primaryItemJcrName = nt.getPrimaryItemName();
-            if (primaryItemJcrName == null) {
-                this.primaryItemName = null;
-            } else {
-                this.primaryItemName = NameFormat.parse(primaryItemJcrName, nsResolver);
-            }
-        } catch (NameException e) {
-            throw new RepositoryException(e.getMessage(), e);
-        }
-        PropertyDefinition[] propDefs = nt.getDeclaredPropertyDefinitions();
-        this.propertyDefs = new QPropertyDefinition[propDefs.length];
-        for (int i = 0; i < propDefs.length; i++) {
-            this.propertyDefs[i] = new QPropertyDefinitionImpl(
-                    propDefs[i], nsResolver, qValueFactory);
-        }
-        NodeDefinition[] nodeDefs = nt.getDeclaredChildNodeDefinitions();
-        this.childNodeDefs = new QNodeDefinition[nodeDefs.length];
-        for (int i = 0; i < nodeDefs.length; i++) {
-            this.childNodeDefs[i] = new QNodeDefinitionImpl(nodeDefs[i], nsResolver);
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public QName getQName() {
-        return name;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public QName[] getSupertypes() {
-        QName[] sTypes = new QName[supertypes.length];
-        System.arraycopy(supertypes, 0, sTypes, 0, supertypes.length);
-        return sTypes;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isMixin() {
-        return isMixin;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean hasOrderableChildNodes() {
-        return hasOrderableChildNodes;
+            throws RepositoryException, IllegalNameException, UnknownPrefixException {
+        super(NameFormat.parse(nt.getName(), nsResolver),
+                getNodeTypeNames(nt.getDeclaredSupertypes(), nsResolver),
+                nt.isMixin(), nt.hasOrderableChildNodes(),
+                nt.getPrimaryItemName() != null ? NameFormat.parse(nt.getPrimaryItemName(), nsResolver) : null,
+                getQPropertyDefinitions(nt.getDeclaredPropertyDefinitions(), nsResolver, qValueFactory),
+                getQNodeDefinitions(nt.getDeclaredChildNodeDefinitions(), nsResolver));
     }
 
     /**
-     * {@inheritDoc}
-     */
-    public QName getPrimaryItemName() {
-        return primaryItemName;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public QPropertyDefinition[] getPropertyDefs() {
-        QPropertyDefinition[] pDefs = new QPropertyDefinition[propertyDefs.length];
-        System.arraycopy(propertyDefs, 0, pDefs, 0, propertyDefs.length);
-        return pDefs;
+     * Returns the qualified names of the passed node types using the namespace
+     * resolver to parse the names.
+     *
+     * @param nt         the node types
+     * @param nsResolver the namespace 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>.
+     */
+    private static QName[] getNodeTypeNames(NodeType[] nt,
+                                     NamespaceResolver nsResolver)
+            throws IllegalNameException, UnknownPrefixException {
+        QName[] names = new QName[nt.length];
+        for (int i = 0; i < nt.length; i++) {
+            QName ntName = NameFormat.parse(nt[i].getName(), nsResolver);
+            names[i] = ntName;
+        }
+        return names;
     }
 
     /**
-     * {@inheritDoc}
-     */
-    public QNodeDefinition[] getChildNodeDefs() {
-        QNodeDefinition[] cnDefs = new QNodeDefinition[childNodeDefs.length];
-        System.arraycopy(childNodeDefs, 0, cnDefs, 0, childNodeDefs.length);
-        return cnDefs;
+     * Returns qualified property definitions for JCR property definitions.
+     *
+     * @param propDefs   the JCR property definitions.
+     * @param nsResolver the namespace 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 {
+        QPropertyDefinition[] propertyDefs = new QPropertyDefinition[propDefs.length];
+        for (int i = 0; i < propDefs.length; i++) {
+            propertyDefs[i] = new QPropertyDefinitionImpl(propDefs[i], nsResolver, factory);
+        }
+        return propertyDefs;
     }
-
+    
     /**
-     * TODO: generalize (this method is copied from spi2dav)
-     */
-    public Collection getDependencies() {
-        if (dependencies == null) {
-            Collection deps = new HashSet();
-            // supertypes
-            for (int i = 0; i < supertypes.length; i++) {
-                deps.add(supertypes[i]);
-            }
-            // child node definitions
-            for (int i = 0; i < childNodeDefs.length; i++) {
-                // default primary type
-                QName ntName = childNodeDefs[i].getDefaultPrimaryType();
-                if (ntName != null && !name.equals(ntName)) {
-                    deps.add(ntName);
-                }
-                // required primary type
-                QName[] ntNames = childNodeDefs[i].getRequiredPrimaryTypes();
-                for (int j = 0; j < ntNames.length; j++) {
-                    if (ntNames[j] != null && !name.equals(ntNames[j])) {
-                        deps.add(ntNames[j]);
-                    }
-                }
-            }
-            // property definitions
-            for (int i = 0; i < propertyDefs.length; i++) {
-                // REFERENCE value constraints
-                if (propertyDefs[i].getRequiredType() == PropertyType.REFERENCE) {
-                    String[] ca = propertyDefs[i].getValueConstraints();
-                    if (ca != null) {
-                        for (int j = 0; j < ca.length; j++) {
-                            QName ntName = QName.valueOf(ca[j]);
-                            if (!name.equals(ntName)) {
-                                deps.add(ntName);
-                            }
-                        }
-                    }
-                }
-            }
-            dependencies = Collections.unmodifiableCollection(deps);
+     * Returns qualified node definitions for JCR node definitions.
+     *
+     * @param nodeDefs   the JCR node definitions.
+     * @param nsResolver the namespace 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
+     *                                a namespace prefix that is now known to
+     *                                <code>nsResolver</code>.
+     */
+    private static QNodeDefinition[] getQNodeDefinitions(
+            NodeDefinition[] nodeDefs,
+            NamespaceResolver nsResolver) throws IllegalNameException, UnknownPrefixException {
+        QNodeDefinition[] childNodeDefs = new QNodeDefinition[nodeDefs.length];
+        for (int i = 0; i < nodeDefs.length; i++) {
+            childNodeDefs[i] = new QNodeDefinitionImpl(nodeDefs[i], nsResolver);
         }
-        return dependencies;
+        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?view=diff&rev=553507&r1=553506&r2=553507
==============================================================================
--- 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 Jul  5 06:52:13 2007
@@ -16,44 +16,25 @@
  */
 package org.apache.jackrabbit.spi2jcr;
 
-import org.apache.jackrabbit.spi.QPropertyDefinition;
 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.value.ValueFormat;
 
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.PropertyType;
-import java.util.Arrays;
 
 /**
  * <code>QPropertyDefinitionImpl</code> implements a qualified property
  * definition based on a JCR {@link javax.jcr.nodetype.PropertyDefinition}.
- * TODO: mostly copied from spi2dav, move common parts to spi-commons.
  */
-class QPropertyDefinitionImpl extends QItemDefinitionImpl implements QPropertyDefinition {
-
-    /**
-     * The required type.
-     */
-    private final int requiredType;
-
-    /**
-     * The value constraints.
-     */
-    private final String[] valueConstraints;
-
-    /**
-     * The default values.
-     */
-    private final QValue[] defaultValues;
-
-    /**
-     * The 'multiple' flag
-     */
-    private final boolean multiple;
+class QPropertyDefinitionImpl
+        extends org.apache.jackrabbit.spi.commons.QPropertyDefinitionImpl {
 
     /**
      * Creates a new qualified property definition based on
@@ -67,119 +48,68 @@
      */
     QPropertyDefinitionImpl(PropertyDefinition propDef,
                             NamespaceResolver nsResolver,
-                            QValueFactory qValueFactory) throws RepositoryException {
-        super(propDef, nsResolver);
-        Value[] defValues = propDef.getDefaultValues();
-        if (defValues != null) {
-            defaultValues = new QValue[defValues.length];
-            for (int i = 0; i < defValues.length; i++) {
-                defaultValues[i] = ValueFormat.getQValue(defValues[i], nsResolver, qValueFactory);
-            }
-        } else {
-            defaultValues = null;
-        }
-        this.multiple = propDef.isMultiple();
-        this.requiredType = propDef.getRequiredType();
-        this.valueConstraints = propDef.getValueConstraints();
-        if (requiredType == PropertyType.REFERENCE
-                || requiredType == PropertyType.NAME
-                || requiredType == PropertyType.PATH) {
-            for (int i = 0; i < valueConstraints.length; i++) {
-                int type = requiredType == PropertyType.REFERENCE ? PropertyType.NAME : requiredType;
-                this.valueConstraints[i] = ValueFormat.getQValue(
-                        valueConstraints[i], type, nsResolver, qValueFactory).getString();
-            }
-        }
+                            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),
+                propDef.isAutoCreated(), propDef.isMandatory(),
+                propDef.getOnParentVersion(), propDef.isProtected(),
+                convertValues(propDef.getDefaultValues(), nsResolver, qValueFactory),
+                propDef.isMultiple(), propDef.getRequiredType(),
+                convertConstraints(propDef.getValueConstraints(), nsResolver, qValueFactory, propDef.getRequiredType()));
     }
 
-    //------------------------------------------------< QPropertyDefinition >---
     /**
-     * {@inheritDoc}
-     */
-    public int getRequiredType() {
-        return requiredType;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public String[] getValueConstraints() {
-        return valueConstraints;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public QValue[] getDefaultValues() {
-        return defaultValues;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isMultiple() {
-        return multiple;
-    }
-
-    /**
-     * {@inheritDoc}
+     * Convers JCR {@link Value}s to {@link QValue}s.
      *
-     * @return always <code>false</code>
-     */
-    public boolean definesNode() {
-        return false;
-    }
-
-    //-------------------------------------------< java.lang.Object overrides >
-    /**
-     * Compares two property definitions for equality. Returns <code>true</code>
-     * if the given object is a property defintion and has the same attributes
-     * as this property definition.
-     *
-     * @param obj the object to compare this property definition with
-     * @return <code>true</code> if the object is equal to this property definition,
-     *         <code>false</code> otherwise
-     * @see Object#equals(Object)
-     */
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj instanceof QPropertyDefinition) {
-            QPropertyDefinition other = (QPropertyDefinition) obj;
-            return super.equals(obj)
-                    && requiredType == other.getRequiredType()
-                    && Arrays.equals(valueConstraints, other.getValueConstraints())
-                    && Arrays.equals(defaultValues, other.getDefaultValues())
-                    && multiple == other.isMultiple();
+     * @param values     the JCR values.
+     * @param nsResolver the namespace 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,
+                                          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);
+            }
         }
-        return false;
+        return defaultValues;
     }
 
     /**
-     * Overwrites {@link QItemDefinitionImpl#hashCode()}.
+     * Makes sure name and path constraints are parsed correctly using the
+     * namespace resolver.
      *
-     * @return
-     */
-    public int hashCode() {
-        if (hashCode == 0) {
-            // build hashCode (format: <declaringNodeType>/<name>/<requiredType>/<multiple>)
-            StringBuffer sb = new StringBuffer();
-
-            sb.append(getDeclaringNodeType().toString());
-            sb.append('/');
-            if (definesResidual()) {
-                sb.append('*');
-            } else {
-                sb.append(getQName().toString());
+     * @param constraints  the constraint strings from the JCR property
+     *                     definition.
+     * @param nsResolver   the namespace resolver.
+     * @param factory      the QValueFactory.
+     * @param requiredType the required type of the property definition.
+     * @return SPI formatted constraint strings.
+     * @throws RepositoryException if an error occurs while converting the
+     *                             constraint strings.
+     */
+    private static String[] convertConstraints(String[] constraints,
+                                               NamespaceResolver nsResolver,
+                                               QValueFactory factory, 
+                                               int requiredType)
+            throws RepositoryException {
+        if (requiredType == PropertyType.REFERENCE
+                || requiredType == PropertyType.NAME
+                || requiredType == PropertyType.PATH) {
+            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();
             }
-            sb.append('/');
-            sb.append(getRequiredType());
-            sb.append('/');
-            sb.append(isMultiple() ? 1 : 0);
-
-            hashCode = sb.toString().hashCode();
         }
-        return hashCode;
+        return constraints;
     }
 }

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?view=diff&rev=553507&r1=553506&r2=553507
==============================================================================
--- 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 Jul  5 06:52:13 2007
@@ -33,6 +33,7 @@
 import org.apache.jackrabbit.spi.EventFilter;
 import org.apache.jackrabbit.spi.EventBundle;
 import org.apache.jackrabbit.spi.QValue;
+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;
@@ -43,7 +44,6 @@
 import org.apache.jackrabbit.value.QValueFactoryImpl;
 import org.apache.jackrabbit.value.ValueFormat;
 import org.apache.jackrabbit.JcrConstants;
-import org.apache.jackrabbit.util.IteratorHelper;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Credentials;
@@ -76,6 +76,7 @@
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.Query;
 import javax.jcr.lock.LockException;
+import javax.jcr.lock.Lock;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
 import javax.jcr.version.Version;
@@ -112,7 +113,7 @@
 
     /**
      * The configuration map used to determine the maximal depth of child
-     * items to be accessed upon a call to {@link getNodeInfo(SessionInfo, NodeId)}.
+     * items to be accessed upon a call to {@link #getNodeInfo(SessionInfo, NodeId)}.
      */
     private final BatchReadConfig batchReadConfig;
 
@@ -265,8 +266,12 @@
                                              NodeId nodeId)
             throws RepositoryException {
         SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
-        return new QNodeDefinitionImpl(getNode(nodeId, sInfo).getDefinition(),
-                sInfo.getNamespaceResolver());
+        try {
+            return new QNodeDefinitionImpl(getNode(nodeId, sInfo).getDefinition(),
+                    sInfo.getNamespaceResolver());
+        } catch (NameException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     /**
@@ -276,10 +281,14 @@
                                                      PropertyId propertyId)
             throws RepositoryException {
         SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
-        return new QPropertyDefinitionImpl(
-                getProperty(propertyId, sInfo).getDefinition(),
-                sInfo.getNamespaceResolver(),
-                getQValueFactory());
+        try {
+            return new QPropertyDefinitionImpl(
+                    getProperty(propertyId, sInfo).getDefinition(),
+                    sInfo.getNamespaceResolver(),
+                    getQValueFactory());
+        } catch (NameException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     /**
@@ -309,8 +318,11 @@
             throws ItemNotFoundException, RepositoryException {
         SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
         Node node = getNode(nodeId, sInfo);
-        NodeInfo info = new NodeInfoImpl(node, idFactory, sInfo.getNamespaceResolver());
-        return info;
+        try {
+            return new NodeInfoImpl(node, idFactory, sInfo.getNamespaceResolver());
+        } catch (NameException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     /**
@@ -328,16 +340,29 @@
         }
         int depth = batchReadConfig.getDepth(ntName);
         if (depth == BatchReadConfig.DEPTH_DEFAULT) {
-            NodeInfo info = new NodeInfoImpl(node, idFactory, sInfo.getNamespaceResolver());
+            NodeInfo info;
+            try {
+                info = new NodeInfoImpl(node, idFactory, sInfo.getNamespaceResolver());
+            } catch (NameException e) {
+                throw new RepositoryException(e);
+            }
             return Collections.singletonList(info).iterator();
         } else {
             final List itemInfos = new ArrayList();
             ItemVisitor visitor = new TraversingItemVisitor(false, depth) {
                 protected void entering(Property property, int i) throws RepositoryException {
-                    itemInfos.add(new PropertyInfoImpl(property, idFactory, sInfo.getNamespaceResolver(), getQValueFactory()));
+                    try {
+                        itemInfos.add(new PropertyInfoImpl(property, idFactory, sInfo.getNamespaceResolver(), getQValueFactory()));
+                    } catch (NameException e) {
+                        throw new RepositoryException(e);
+                    }
                 }
                 protected void entering(Node node, int i) throws RepositoryException {
-                    itemInfos.add(new NodeInfoImpl(node, idFactory, sInfo.getNamespaceResolver()));
+                    try {
+                        itemInfos.add(new NodeInfoImpl(node, idFactory, sInfo.getNamespaceResolver()));
+                    } catch (NameException e) {
+                        throw new RepositoryException(e);
+                    }
                 }
                 protected void leaving(Property property, int i) {
                     // nothing to do
@@ -359,11 +384,15 @@
         SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
         NodeIterator children = getNode(parentId, sInfo).getNodes();
         List childInfos = new ArrayList();
-        while (children.hasNext()) {
-            childInfos.add(new ChildInfoImpl(children.nextNode(),
-                    sInfo.getNamespaceResolver()));
+        try {
+            while (children.hasNext()) {
+                childInfos.add(new ChildInfoImpl(children.nextNode(),
+                        sInfo.getNamespaceResolver()));
+            }
+        } catch (NameException e) {
+            throw new RepositoryException(e);
         }
-        return new IteratorHelper(childInfos);
+        return childInfos.iterator();
     }
 
     /**
@@ -373,8 +402,12 @@
                                         PropertyId propertyId)
             throws ItemNotFoundException, RepositoryException {
         SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
-        return new PropertyInfoImpl(getProperty(propertyId, sInfo), idFactory,
-                sInfo.getNamespaceResolver(), getQValueFactory());
+        try {
+            return new PropertyInfoImpl(getProperty(propertyId, sInfo), idFactory,
+                    sInfo.getNamespaceResolver(), getQValueFactory());
+        } catch (NameException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     /**
@@ -524,7 +557,7 @@
     public LockInfo getLockInfo(SessionInfo sessionInfo, NodeId nodeId)
             throws LockException, RepositoryException {
         SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
-        return new LockInfoImpl(getNode(nodeId, sInfo), idFactory,
+        return new LockInfoImpl(getNode(nodeId, sInfo).getLock(), idFactory,
                 sInfo.getNamespaceResolver());
     }
 
@@ -540,8 +573,8 @@
         return (LockInfo) executeWithLocalEvents(new Callable() {
             public Object run() throws RepositoryException {
                 Node n = getNode(nodeId, sInfo);
-                n.lock(deep, sessionScoped);
-                return new LockInfoImpl(n, idFactory, sInfo.getNamespaceResolver());
+                Lock lock = n.lock(deep, sessionScoped);
+                return new LockInfoImpl(lock, idFactory, sInfo.getNamespaceResolver());
             }
         }, sInfo);
     }
@@ -964,10 +997,14 @@
         SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
         NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
         List nodeTypes = new ArrayList();
-        for (NodeTypeIterator it = ntMgr.getAllNodeTypes(); it.hasNext(); ) {
-            NodeType nt = it.nextNodeType();
-            nodeTypes.add(new QNodeTypeDefinitionImpl(nt,
-                    sInfo.getNamespaceResolver(), getQValueFactory()));
+        try {
+            for (NodeTypeIterator it = ntMgr.getAllNodeTypes(); it.hasNext(); ) {
+                NodeType nt = it.nextNodeType();
+                nodeTypes.add(new QNodeTypeDefinitionImpl(nt,
+                        sInfo.getNamespaceResolver(), getQValueFactory()));
+            }
+        } catch (NameException e) {
+            throw new RepositoryException(e);
         }
         return nodeTypes.iterator();
     }



Mime
View raw message