jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r792142 [27/35] - in /jackrabbit/sandbox/JCR-1456: ./ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/ jackrabbit-core/ jackrabbit-core/src/main/java/org/apache/jackrab...
Date Wed, 08 Jul 2009 13:57:46 GMT
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntryImpl.java Wed Jul  8 13:57:13 2009
@@ -41,6 +41,7 @@
 import org.apache.jackrabbit.jcr2spi.operation.Remove;
 import org.apache.jackrabbit.jcr2spi.operation.ReorderNodes;
 import org.apache.jackrabbit.jcr2spi.operation.SetMixin;
+import org.apache.jackrabbit.jcr2spi.operation.SetPrimaryType;
 import org.apache.jackrabbit.jcr2spi.state.ItemState;
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.state.PropertyState;
@@ -278,6 +279,8 @@
             complete((AddProperty) operation);
         } else if (operation instanceof SetMixin) {
             complete((SetMixin) operation);
+        } else if (operation instanceof SetPrimaryType) {
+            complete((SetPrimaryType) operation);
         } else if (operation instanceof Remove) {
             complete((Remove) operation);
         } else if (operation instanceof ReorderNodes) {
@@ -967,6 +970,13 @@
                     }
                 } // else: existing entry but state not yet built -> ignore event
                 break;
+            case Event.NODE_MOVED:
+                // TODO: implementation missing
+                throw new UnsupportedOperationException("Implementation missing");
+                //break;
+            case Event.PERSIST:
+                // TODO: implementation missing
+                throw new UnsupportedOperationException("Implementation missing");
             default:
                 // ILLEGAL
                 throw new IllegalArgumentException("Illegal event type " + childEvent.getType() + " for NodeState.");
@@ -1489,7 +1499,7 @@
                 break;
             case Operation.STATUS_UNDO:
                 if (!rmEntry.denotesNode()) {
-                    Name propName = ((PropertyEntry) rmEntry).getName();
+                    Name propName = rmEntry.getName();
                     if (propertiesInAttic.containsKey(propName)) {
                         properties.add((PropertyEntry) propertiesInAttic.remove(propName));
                     } // else: propEntry has never been moved to the attic (see 'addPropertyEntry')
@@ -1524,6 +1534,30 @@
         } // else: no such prop-Entry (should not occur)
     }
 
+    private void complete(SetPrimaryType operation) throws RepositoryException {
+        if (operation.getNodeState().getHierarchyEntry() != this) {
+            throw new IllegalArgumentException();
+        }
+        PropertyEntry pe = getPropertyEntry(NameConstants.JCR_PRIMARYTYPE);
+        if (pe != null) {
+            PropertyState pState = pe.getPropertyState();
+            switch (operation.getStatus()) {
+                case Operation.STATUS_PERSISTED:
+                    // NOTE: invalidation of this node entry is performed by
+                    // ChangeLog.persisted...
+                    // TODO: check if correct
+                    if (pState.getStatus() == Status.NEW || pState.getStatus() == Status.EXISTING_MODIFIED) {
+                        pState.setStatus(Status.EXISTING);
+                    }
+                    break;
+                case Operation.STATUS_UNDO:
+                    pe.revert();
+                    break;
+                default: // ignore
+            }
+        } // else: no such prop-Entry (should not occur)
+    }
+
     private void complete(ReorderNodes operation) throws RepositoryException {
         HierarchyEntry he = operation.getInsertNode().getHierarchyEntry();
         if (he != this) {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java Wed Jul  8 13:57:13 2009
@@ -33,7 +33,6 @@
 import org.apache.jackrabbit.spi.LockInfo;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
-import org.apache.jackrabbit.spi.commons.conversion.PathResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,6 +41,7 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.lock.Lock;
 import javax.jcr.lock.LockException;
 import java.util.HashMap;
@@ -192,7 +192,7 @@
      *
      * @see LockStateManager#getLockTokens()
      */
-    public String[] getLockTokens() {
+    public String[] getLockTokens() throws UnsupportedRepositoryOperationException, RepositoryException {
         return wspManager.getLockTokens();
     }
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockStateManager.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockStateManager.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockStateManager.java Wed Jul  8 13:57:13 2009
@@ -114,7 +114,7 @@
      * @return The lock tokens associated with the <code>Session</code> this
      * lock manager has been created for.
      */
-    public String[] getLockTokens();
+    public String[] getLockTokens() throws RepositoryException;
 
     /**
      * Invoked by a session to inform that a lock token has been added.

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/DefinitionValidator.java Wed Jul  8 13:57:13 2009
@@ -21,7 +21,8 @@
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QValue;
-import org.apache.jackrabbit.spi.commons.nodetype.ValueConstraint;
+import org.apache.jackrabbit.spi.QValueConstraint;
+import org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 import org.slf4j.LoggerFactory;
@@ -118,7 +119,7 @@
     /**
      *
      * @param ntDef
-     * @param validatedDefs Map of qualified nodetype names and nodetype definitions
+     * @param validatedDefs Map of nodetype names and nodetype definitions
      * that are known to be valid or are already registered. This map is used to
      * validated dependencies and check for circular inheritance
      * @return
@@ -263,13 +264,13 @@
              * the specified node type must be registered, with one notable
              * exception: the node type just being registered
              */
-            String[] constraints = pd.getValueConstraints();
+            QValueConstraint[] constraints = pd.getValueConstraints();
             if (constraints != null && constraints.length > 0) {
 
                 if (pd.getRequiredType() == PropertyType.REFERENCE) {
-                    for (int j = 0; j < constraints.length; j++) {
+                    for (QValueConstraint constraint : constraints) {
                         // TODO improve. don't rely on a specific factory impl
-                        Name ntName = NameFactoryImpl.getInstance().create(constraints[j]);
+                        Name ntName = NameFactoryImpl.getInstance().create(constraint.getString());
                         /* compare to given ntd map and not registered nts only */
                         if (!name.equals(ntName) && !validatedDefs.containsKey(ntName)) {
                             String msg = "[" + name + "#" + pd.getName()

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeType.java Wed Jul  8 13:57:13 2009
@@ -19,6 +19,7 @@
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -93,12 +94,10 @@
 
     /**
      * @param name
-     * @param nodeTypeName
-     * @param definitionProvider
-     * @throws ConstraintViolationException
-     * @throws NoSuchNodeTypeException
+     * @param nodeTypeDefinition
+     *@param definitionProvider  @throws ConstraintViolationException  @throws NoSuchNodeTypeException
      */
-    public void checkAddNodeConstraints(Name name, Name nodeTypeName, ItemDefinitionProvider definitionProvider)
+    public void checkAddNodeConstraints(Name name, QNodeTypeDefinition nodeTypeDefinition, ItemDefinitionProvider definitionProvider)
             throws ConstraintViolationException, NoSuchNodeTypeException;
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeImpl.java Wed Jul  8 13:57:13 2009
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -406,13 +407,19 @@
 
     /**
      * @inheritDoc
-     * @see EffectiveNodeType#checkAddNodeConstraints(Name, ItemDefinitionProvider)
+     * @see EffectiveNodeType#checkAddNodeConstraints(org.apache.jackrabbit.spi.Name,QNodeTypeDefinition, ItemDefinitionProvider)
      */
-    public void checkAddNodeConstraints(Name name, Name nodeTypeName, ItemDefinitionProvider definitionProvider)
+    public void checkAddNodeConstraints(Name name, QNodeTypeDefinition nodeTypeDefinition, ItemDefinitionProvider definitionProvider)
             throws ConstraintViolationException, NoSuchNodeTypeException {
-        QNodeDefinition nd = definitionProvider.getQNodeDefinition(this, name, nodeTypeName);
+        if (nodeTypeDefinition.isAbstract()) {
+            throw new ConstraintViolationException(name + " is abstract  be used as primary node type.");
+        }
+        if (nodeTypeDefinition.isMixin()) {
+            throw new ConstraintViolationException(name + " is abstract and cannot be used as primary node type.");
+        }
+        QNodeDefinition nd = definitionProvider.getQNodeDefinition(this, name, nodeTypeDefinition.getName());
         if (nd.isProtected()) {
-            throw new ConstraintViolationException(name + " is protected");
+            throw new ConstraintViolationException(name + " is protected.");
         }
         if (nd.isAutoCreated()) {
             throw new ConstraintViolationException(name + " is auto-created and can not be manually added");

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/EffectiveNodeTypeProvider.java Wed Jul  8 13:57:13 2009
@@ -29,7 +29,7 @@
 public interface EffectiveNodeTypeProvider {
 
     /**
-     * Build the <code>EffectiveNodeType</code> from the given qualified
+     * Build the <code>EffectiveNodeType</code> from the given
      * <code>NodeType</code> name.
      *
      * @param ntName
@@ -40,7 +40,7 @@
             throws NoSuchNodeTypeException;
 
     /**
-     * Build the <code>EffectiveNodeType</code> from the given qualified
+     * Build the <code>EffectiveNodeType</code> from the given array of
      * <code>NodeType</code> names.
      *
      * @param ntNames

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/ItemDefinitionProvider.java Wed Jul  8 13:57:13 2009
@@ -27,7 +27,7 @@
 import javax.jcr.nodetype.ConstraintViolationException;
 
 /**
- * <code>ItemDefinitionManager</code>...
+ * <code>ItemDefinitionProvider</code>...
  */
 public interface ItemDefinitionProvider {
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeImpl.java Wed Jul  8 13:57:13 2009
@@ -22,11 +22,10 @@
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QValue;
-import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
-import org.apache.jackrabbit.spi.commons.nodetype.ValueConstraint;
+import org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint;
 import org.apache.jackrabbit.spi.commons.nodetype.AbstractNodeType;
 import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 import org.apache.jackrabbit.value.ValueHelper;
@@ -37,7 +36,6 @@
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
-import javax.jcr.ValueFactory;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeDefinition;
@@ -92,31 +90,6 @@
     }
 
     /**
-     * ValueFactory used to convert JCR values from one type to another in order
-     * to determine whether a property specified by name and value(s) would be
-     * allowed.
-     *
-     * @see NodeType#canSetProperty(String, Value)
-     * @see NodeType#canSetProperty(String, Value[])
-     * @return ValueFactory used to convert JCR values.
-     * @throws javax.jcr.RepositoryException If an error occurs.
-     */
-    private ValueFactory valueFactory() throws RepositoryException {
-        return mgrProvider.getJcrValueFactory();
-    }
-
-    /**
-     * ValueFactory used to convert JCR values to qualified ones in order to
-     * determine value constraints within the NodeType interface.
-     *
-     * @return ValueFactory used to convert JCR values to qualified ones.
-     * @throws javax.jcr.RepositoryException If an error occurs.
-     */
-    private QValueFactory qValueFactory() throws RepositoryException {
-        return mgrProvider.getQValueFactory();
-    }
-
-    /**
      * Returns the applicable property definition for a property with the
      * specified name and type.
      *
@@ -129,7 +102,7 @@
      */
     private QPropertyDefinition getApplicablePropDef(Name propertyName, int type, boolean multiValued)
             throws RepositoryException {
-        return definitionProvider().getQPropertyDefinition(getQName(), propertyName, type, multiValued);
+        return definitionProvider().getQPropertyDefinition(ntd.getName(), propertyName, type, multiValued);
     }
 
     /**
@@ -148,12 +121,12 @@
     }
 
     /**
-     * Returns the 'internal', i.e. the fully qualified name.
+     * Returns the node type definition.
      *
-     * @return the qualified name
+     * @return the internal node type definition.
      */
-    private Name getQName() {
-        return ntd.getName();
+    QNodeTypeDefinition getDefinition() {
+        return ntd;
     }
 
     /**
@@ -384,13 +357,13 @@
             if (def.getRequiredType() != PropertyType.UNDEFINED
                     && def.getRequiredType() != value.getType()) {
                 // type conversion required
-                v =  ValueHelper.convert(value, def.getRequiredType(), valueFactory());
+                v =  ValueHelper.convert(value, def.getRequiredType(), mgrProvider.getJcrValueFactory());
             } else {
                 // no type conversion required
                 v = value;
             }
             // create QValue from Value
-            QValue qValue = ValueFormat.getQValue(v, resolver(), qValueFactory());
+            QValue qValue = ValueFormat.getQValue(v, resolver(), mgrProvider.getQValueFactory());
             checkSetPropertyValueConstraints(def, new QValue[]{qValue});
             return true;
         } catch (NameException re) {
@@ -457,8 +430,8 @@
                 if (values[i] != null) {
                     // create QValue from Value and perform
                     // type conversion as necessary
-                    Value v = ValueHelper.convert(values[i], targetType, valueFactory());
-                    QValue qValue = ValueFormat.getQValue(v, resolver(), qValueFactory());
+                    Value v = ValueHelper.convert(values[i], targetType, mgrProvider.getJcrValueFactory());
+                    QValue qValue = ValueFormat.getQValue(v, resolver(), mgrProvider.getQValueFactory());
                     list.add(qValue);
                 }
             }
@@ -493,8 +466,9 @@
      */
     public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
         try {
-            ent.checkAddNodeConstraints(resolver().getQName(childNodeName),
-                resolver().getQName(nodeTypeName), definitionProvider());
+            Name ntName = resolver().getQName(nodeTypeName);
+            QNodeTypeDefinition def = ntMgr.getNodeTypeDefinition(ntName);
+            ent.checkAddNodeConstraints(resolver().getQName(childNodeName), def, definitionProvider());
             return true;
         } catch (NameException be) {
             // implementation specific exception, fall through

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeManagerImpl.java Wed Jul  8 13:57:13 2009
@@ -60,7 +60,7 @@
  * A <code>NodeTypeManagerImpl</code> implements a session dependant
  * NodeTypeManager.
  */
-public class NodeTypeManagerImpl extends AbstractNodeTypeManager implements NodeTypeRegistryListener, Dumpable {
+public class NodeTypeManagerImpl extends AbstractNodeTypeManager implements NodeTypeDefinitionProvider, NodeTypeRegistryListener, Dumpable {
 
     /**
      * Logger instance for this class
@@ -78,7 +78,7 @@
     private final NodeTypeRegistry ntReg;
 
     /**
-     * The ValueFactory used to convert qualified values to JCR values.
+     * The ValueFactory used to build property definitions.
      */
     private final ValueFactory valueFactory;
 
@@ -105,15 +105,14 @@
      *
      * @param ntReg        node type registry
      * @param mgrProvider  the manager provider
-     * @param valueFactory the JCR value factory
+     * @throws RepositoryException If an error occurs.
      */
     public NodeTypeManagerImpl(NodeTypeRegistry ntReg,
-                               ManagerProvider mgrProvider,
-                               ValueFactory valueFactory) {
+                               ManagerProvider mgrProvider) throws RepositoryException {
         this.mgrProvider = mgrProvider;
         this.ntReg = ntReg;
         this.ntReg.addListener(this);
-        this.valueFactory = valueFactory;
+        this.valueFactory = mgrProvider.getJcrValueFactory();
 
         // setup caches with soft references to node type
         ntCache = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT);
@@ -207,7 +206,16 @@
     NodeTypeRegistry getNodeTypeRegistry() {
         return ntReg;
     }
-    
+
+    //-----------------------------------------< NodeTypeDefinitionProvider >---
+    /**
+     * @see NodeTypeDefinitionProvider#getNodeTypeDefinition(org.apache.jackrabbit.spi.Name) 
+     */
+    public QNodeTypeDefinition getNodeTypeDefinition(Name ntName) throws NoSuchNodeTypeException, RepositoryException {
+        NodeTypeImpl nt = getNodeType(ntName);
+        return nt.getDefinition();
+    }
+
     //-------------------------------------------< NodeTypeRegistryListener >---
     /**
      * {@inheritDoc}

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/nodetype/NodeTypeRegistryImpl.java Wed Jul  8 13:57:13 2009
@@ -25,6 +25,7 @@
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QItemDefinition;
+import org.apache.jackrabbit.spi.QValueConstraint;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -806,7 +807,7 @@
                     ps.println("\t\tName\t\t" + (pd[i].definesResidual() ? "*" : pd[i].getName().toString()));
                     String type = pd[i].getRequiredType() == 0 ? "null" : PropertyType.nameFromValue(pd[i].getRequiredType());
                     ps.println("\t\tRequiredType\t" + type);
-                    String[] vca = pd[i].getValueConstraints();
+                    QValueConstraint[] vca = pd[i].getValueConstraints();
                     StringBuffer constraints = new StringBuffer();
                     if (vca == null) {
                         constraints.append("<null>");
@@ -815,7 +816,7 @@
                             if (constraints.length() > 0) {
                                 constraints.append(", ");
                             }
-                            constraints.append(vca[n]);
+                            constraints.append(vca[n].getString());
                         }
                     }
                     ps.println("\t\tValueConstraints\t" + constraints.toString());
@@ -824,14 +825,14 @@
                     if (defVals == null) {
                         defaultValues.append("<null>");
                     } else {
-                        for (int n = 0; n < defVals.length; n++) {
+                        for (QValue defVal : defVals) {
                             if (defaultValues.length() > 0) {
                                 defaultValues.append(", ");
                             }
                             try {
-                                defaultValues.append(defVals[n].getString());
+                                defaultValues.append(defVal.getString());
                             } catch (RepositoryException e) {
-                                defaultValues.append(defVals[n].toString());
+                                defaultValues.append(defVal.toString());
                             }
                         }
                     }
@@ -843,25 +844,25 @@
                     ps.println("\t\tMultiple\t" + pd[i].isMultiple());
                 }
                 QNodeDefinition[] nd = ntd.getChildNodeDefs();
-                for (int i = 0; i < nd.length; i++) {
+                for (QNodeDefinition aNd : nd) {
                     ps.print("\tNodeDefinition");
-                    ps.println(" (declared in " + nd[i].getDeclaringNodeType() + ") ");
-                    ps.println("\t\tName\t\t" + (nd[i].definesResidual() ? "*" : nd[i].getName().toString()));
-                    Name[] reqPrimaryTypes = nd[i].getRequiredPrimaryTypes();
+                    ps.println(" (declared in " + aNd.getDeclaringNodeType() + ") ");
+                    ps.println("\t\tName\t\t" + (aNd.definesResidual() ? "*" : aNd.getName().toString()));
+                    Name[] reqPrimaryTypes = aNd.getRequiredPrimaryTypes();
                     if (reqPrimaryTypes != null && reqPrimaryTypes.length > 0) {
                         for (int n = 0; n < reqPrimaryTypes.length; n++) {
                             ps.print("\t\tRequiredPrimaryType\t" + reqPrimaryTypes[n]);
                         }
                     }
-                    Name defPrimaryType = nd[i].getDefaultPrimaryType();
+                    Name defPrimaryType = aNd.getDefaultPrimaryType();
                     if (defPrimaryType != null) {
                         ps.print("\n\t\tDefaultPrimaryType\t" + defPrimaryType);
                     }
-                    ps.println("\n\t\tAutoCreated\t" + nd[i].isAutoCreated());
-                    ps.println("\t\tMandatory\t" + nd[i].isMandatory());
-                    ps.println("\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(nd[i].getOnParentVersion()));
-                    ps.println("\t\tProtected\t" + nd[i].isProtected());
-                    ps.println("\t\tAllowsSameNameSiblings\t" + nd[i].allowsSameNameSiblings());
+                    ps.println("\n\t\tAutoCreated\t" + aNd.isAutoCreated());
+                    ps.println("\t\tMandatory\t" + aNd.isMandatory());
+                    ps.println("\t\tOnVersion\t" + OnParentVersionAction.nameFromValue(aNd.getOnParentVersion()));
+                    ps.println("\t\tProtected\t" + aNd.isProtected());
+                    ps.println("\t\tAllowsSameNameSiblings\t" + aNd.allowsSameNameSiblings());
                 }
             }
         }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/EventImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/EventImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/EventImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/EventImpl.java Wed Jul  8 13:57:13 2009
@@ -17,13 +17,21 @@
 package org.apache.jackrabbit.jcr2spi.observation;
 
 import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
 
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.value.ValueFormat;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.PropertyId;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.observation.Event;
 
 /**
@@ -43,6 +51,11 @@
     private final NamePathResolver resolver;
 
     /**
+     * The IdFactory
+     */
+    private final IdFactory idFactory;
+    
+    /**
      * The underlying SPI event.
      */
     private final org.apache.jackrabbit.spi.Event event;
@@ -56,12 +69,15 @@
      * Creates a new {@link javax.jcr.observation.Event} instance based on an
      * {@link org.apache.jackrabbit.spi.Event SPI Event}.
      *
-     * @param resolver
      * @param event   the underlying SPI <code>Event</code>.
+     * @param resolver
+     * @param idFactory
      */
-    EventImpl(NamePathResolver resolver, org.apache.jackrabbit.spi.Event event) {
-        this.resolver = resolver;
+    EventImpl(org.apache.jackrabbit.spi.Event event,
+              NamePathResolver resolver, IdFactory idFactory) {
         this.event = event;
+        this.resolver = resolver;
+        this.idFactory = idFactory;
     }
 
     //--------------------------------------------------------------< Event >---
@@ -90,32 +106,45 @@
      * @see javax.jcr.observation.Event#getIdentifier()
      */
     public String getIdentifier() throws RepositoryException {
-        // TODO
-        throw new UnsupportedRepositoryOperationException("JCR-2108");
+        ItemId itemId = event.getItemId();
+        if (itemId == null) {
+            return null;
+        } else {
+            NodeId nodeId = (itemId.denotesNode()) ? (NodeId) itemId : ((PropertyId) itemId).getParentId();
+            return idFactory.toJcrIdentifier(nodeId);
+        }
     }
 
     /**
      * @see javax.jcr.observation.Event#getInfo()
      */
     public Map getInfo() throws RepositoryException {
-        // TODO
-        throw new UnsupportedRepositoryOperationException("JCR-2108");
+        Map<String, String> jcrInfo = new HashMap();
+        Map<Name, QValue> infos = event.getInfo();
+        for (Iterator<Name> it = event.getInfo().keySet().iterator(); it.hasNext(); ) {
+            Name key = it.next();
+            QValue value = infos.get(key);
+            String strValue = null;
+            if (value != null) {
+                strValue = ValueFormat.getJCRString(value, resolver);
+            }
+            jcrInfo.put(resolver.getJCRName(key), strValue);
+        }
+        return jcrInfo;
     }
 
     /**
      * @see javax.jcr.observation.Event#getUserData()
      */
     public String getUserData() throws RepositoryException {
-        // TODO
-        throw new UnsupportedRepositoryOperationException("JCR-2108");
+        return event.getUserData();
     }
 
     /**
      * @see javax.jcr.observation.Event#getDate()
      */
     public long getDate() throws RepositoryException {
-        // TODO
-        throw new UnsupportedRepositoryOperationException("JCR-2108");
+        return event.getDate();
     }
 
     //-------------------------------------------------------------< Object >---
@@ -160,6 +189,10 @@
             return "PropertyChanged";
         } else if (eventType == Event.PROPERTY_REMOVED) {
             return "PropertyRemoved";
+        } else if (eventType == Event.NODE_MOVED) {
+            return "NodeMoved";
+        } else if (eventType == Event.PERSIST) {
+            return "Persist";
         } else {
             return "UnknownEventType";
         }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/FilteredEventIterator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/FilteredEventIterator.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/FilteredEventIterator.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/FilteredEventIterator.java Wed Jul  8 13:57:13 2009
@@ -16,33 +16,27 @@
  */
 package org.apache.jackrabbit.jcr2spi.observation;
 
-import java.util.Calendar;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
 import javax.jcr.observation.Event;
 import javax.jcr.observation.EventIterator;
 
-import org.apache.jackrabbit.spi.EventBundle;
 import org.apache.jackrabbit.spi.EventFilter;
+import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
+ * Implements an event iterator that converts SPI events into JCR events and
+ * filters out the ones that are not accepted by an {@link EventFilter}.
  */
 class FilteredEventIterator implements EventIterator {
 
     /**
-     * Logger instance for this class
-     */
-    private static final Logger log = LoggerFactory.getLogger(FilteredEventIterator.class);
-
-    /**
      * The actual {@link org.apache.jackrabbit.spi.Event}s fired by the repository service
      * (unfiltered).
      */
-    private final Iterator actualEvents;
+    protected final Iterator<org.apache.jackrabbit.spi.Event> actualEvents;
 
     /**
      * For filtering the {@link javax.jcr.observation.Event}s.
@@ -60,6 +54,11 @@
     private final NamePathResolver resolver;
 
     /**
+     * The IdFactory
+     */
+    private final IdFactory idFactory;
+
+    /**
      * The next {@link javax.jcr.observation.Event} in this iterator
      */
     private Event next;
@@ -72,19 +71,24 @@
     /**
      * Creates a new <code>FilteredEventIterator</code>.
      *
-     * @param events     the {@link org.apache.jackrabbit.spi.Event}s as a
-     *                   bundle.
-     * @param filter     only event that pass the filter will be dispatched to
-     *                   the event listener.
-     * @param resolver
+     * @param events    the {@link org.apache.jackrabbit.spi.Event}s as an
+     *                  iterator.
+     * @param isLocal   whether the events were caused by the local session.
+     * @param filter    only event that pass the filter will be dispatched to
+     *                  the event listener.
+     * @param resolver  the name path resolver.
+     * @param idFactory the id factory.
      */
-    public FilteredEventIterator(EventBundle events,
+    public FilteredEventIterator(Iterator<org.apache.jackrabbit.spi.Event> events,
+                                 boolean isLocal,
                                  EventFilter filter,
-                                 NamePathResolver resolver) {
-        this.actualEvents = events.getEvents();
+                                 NamePathResolver resolver,
+                                 IdFactory idFactory) {
+        this.actualEvents = events;
         this.filter = filter;
-        this.isLocal = events.isLocal();
+        this.isLocal = isLocal;
         this.resolver = resolver;
+        this.idFactory = idFactory;
         fetchNext();
     }
 
@@ -109,14 +113,6 @@
     }
 
     /**
-     * @see javax.jcr.observation.EventIterator#getDate()
-     */
-    public Calendar getDate() {
-        // TODO
-        throw new UnsupportedOperationException("JCR-2108. Implementation Missing");
-    }
-
-    /**
      * {@inheritDoc}
      */
     public void skip(long skipNum) {
@@ -169,8 +165,8 @@
         org.apache.jackrabbit.spi.Event event;
         next = null;
         while (next == null && actualEvents.hasNext()) {
-            event = (org.apache.jackrabbit.spi.Event) actualEvents.next();
-            next = filter.accept(event, isLocal) ? new EventImpl(resolver, event) : null;
+            event = actualEvents.next();
+            next = filter.accept(event, isLocal) ? new EventImpl(event, resolver, idFactory) : null;
         }
     }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/InternalEventListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/InternalEventListener.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/InternalEventListener.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/InternalEventListener.java Wed Jul  8 13:57:13 2009
@@ -44,5 +44,5 @@
      * @return an unmodifiable collection of {@link EventFilter}s currently
      * in use by this event listener.
      */
-    public Collection getEventFilters();
+    public Collection<EventFilter> getEventFilters();
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java Wed Jul  8 13:57:13 2009
@@ -19,12 +19,10 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.observation.EventJournal;
 import javax.jcr.observation.EventListener;
 import javax.jcr.observation.EventListenerIterator;
@@ -37,6 +35,7 @@
 import org.apache.jackrabbit.spi.EventFilter;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.Event;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.slf4j.Logger;
@@ -58,7 +57,8 @@
     private final WorkspaceManager wspManager;
 
     /**
-     * The session this observation manager belongs to.
+     * The name and path resolver associated with the session this observation
+     * manager belongs to.
      */
     private final NamePathResolver resolver;
 
@@ -70,20 +70,22 @@
     /**
      * Live mapping of <code>EventListener</code> to <code>EventFilter</code>.
      */
-    private final Map subscriptions = new HashMap();
+    private final Map<EventListener, EventFilter> subscriptions = new HashMap<EventListener, EventFilter>();
 
     /**
      * A read only mapping of <code>EventListener</code> to <code>EventFilter</code>.
      */
-    private Map readOnlySubscriptions;
+    private Map<EventListener, EventFilter> readOnlySubscriptions;
 
     /**
      * Creates a new observation manager for <code>session</code>.
+     *
      * @param wspManager the WorkspaceManager.
-     * @param resolver
+     * @param resolver   the name path resolver for this session.
      * @param ntRegistry The <code>NodeTypeRegistry</code> of the session.
      */
-    public ObservationManagerImpl(WorkspaceManager wspManager, NamePathResolver resolver,
+    public ObservationManagerImpl(WorkspaceManager wspManager,
+                                  NamePathResolver resolver,
                                   NodeTypeRegistry ntRegistry) {
         this.wspManager = wspManager;
         this.resolver = resolver;
@@ -100,33 +102,8 @@
                                  String[] uuids,
                                  String[] nodeTypeNames,
                                  boolean noLocal) throws RepositoryException {
-        Path path;
-        try {
-            path = resolver.getQPath(absPath).getCanonicalPath();
-        } catch (NameException e) {
-            throw new RepositoryException("Malformed path: " + absPath);
-        }
-
-        // create NodeType instances from names
-        Name[] qNodeTypeNames;
-        if (nodeTypeNames == null) {
-            qNodeTypeNames = null;
-        } else {
-            try {
-                qNodeTypeNames = new Name[nodeTypeNames.length];
-                for (int i = 0; i < nodeTypeNames.length; i++) {
-                    Name ntName = resolver.getQName(nodeTypeNames[i]);
-                    if (!ntRegistry.isRegistered(ntName)) {
-                        throw new RepositoryException("unknown node type: " + nodeTypeNames[i]);
-                    }
-                    qNodeTypeNames[i] = ntName;
-                }
-            } catch (NameException e) {
-                throw new RepositoryException(e.getMessage());
-            }
-        }
-
-        EventFilter filter = wspManager.createEventFilter(eventTypes, path, isDeep, uuids, qNodeTypeNames, noLocal);
+        EventFilter filter = createEventFilter(eventTypes, absPath,
+                isDeep, uuids, nodeTypeNames, noLocal);
         synchronized (subscriptions) {
             subscriptions.put(listener, filter);
             readOnlySubscriptions = null;
@@ -171,22 +148,31 @@
      * @see javax.jcr.observation.ObservationManager#getEventJournal()
      */
     public EventJournal getEventJournal() throws RepositoryException {
-        // TODO
-        throw new UnsupportedRepositoryOperationException("JCR-2108");
+        return getEventJournal(Event.ALL_TYPES, "/", true, null, null);
+    }
+
+    /**
+     * @see javax.jcr.observation.ObservationManager#getEventJournal(int, String, boolean, String[], String[])
+     */
+    public EventJournal getEventJournal(
+            int eventTypes, String absPath, boolean isDeep,
+            String[] uuid, String[] nodeTypeName)
+            throws RepositoryException {
+        EventFilter filter = createEventFilter(eventTypes, absPath, isDeep, uuid, nodeTypeName, false);
+        return new EventJournalImpl(wspManager, filter, resolver);
     }
 
     /**
      * @see javax.jcr.observation.ObservationManager#setUserData(String) 
      */
     public void setUserData(String userData) throws RepositoryException {
-        // TODO
-        throw new UnsupportedRepositoryOperationException("JCR-2108");
+        wspManager.setUserData(userData);
     }
 
     //-----------------------< InternalEventListener >--------------------------
 
-    public Collection getEventFilters() {
-        List filters = new ArrayList();
+    public Collection<EventFilter> getEventFilters() {
+        List<EventFilter> filters = new ArrayList<EventFilter>();
         synchronized (subscriptions) {
             ensureReadOnlyMap();
             filters.addAll(readOnlySubscriptions.values());
@@ -196,16 +182,17 @@
 
     public void onEvent(EventBundle eventBundle) {
         // get active listeners
-        Map activeListeners;
+        Map<EventListener, EventFilter> activeListeners;
         synchronized (subscriptions) {
             ensureReadOnlyMap();
             activeListeners = readOnlySubscriptions;
         }
-        for (Iterator it = activeListeners.entrySet().iterator(); it.hasNext(); ) {
-            Map.Entry entry = (Map.Entry) it.next();
-            EventListener listener = (EventListener) entry.getKey();
-            EventFilter filter = (EventFilter) entry.getValue();
-            FilteredEventIterator eventIter = new FilteredEventIterator(eventBundle, filter, resolver);
+        for (Map.Entry<EventListener, EventFilter> entry : activeListeners.entrySet()) {
+            EventListener listener = entry.getKey();
+            EventFilter filter = entry.getValue();
+            FilteredEventIterator eventIter = new FilteredEventIterator(
+                    eventBundle.getEvents(), eventBundle.isLocal(), filter,
+                    resolver, wspManager.getIdFactory());
             if (eventIter.hasNext()) {
                 try {
                     listener.onEvent(eventIter);
@@ -227,8 +214,58 @@
      */
     private void ensureReadOnlyMap() {
         if (readOnlySubscriptions == null) {
-            readOnlySubscriptions = new HashMap(subscriptions);
+            readOnlySubscriptions = new HashMap<EventListener, EventFilter>(subscriptions);
         }
     }
 
+    /**
+     * Creates an SPI event filter from the given list of constraints.
+     *
+     * @param eventTypes    the event types.
+     * @param absPath       an absolute path.
+     * @param isDeep        whether to include events for descendant items of
+     *                      the node at absPath.
+     * @param uuids         uuid filters.
+     * @param nodeTypeNames node type filters.
+     * @param noLocal       whether to exclude changes from the local session.
+     * @return the SPI event filter instance.
+     * @throws RepositoryException if an error occurs while creating the event
+     *                             filter.
+     */
+    private EventFilter createEventFilter(int eventTypes,
+                                          String absPath,
+                                          boolean isDeep,
+                                          String[] uuids,
+                                          String[] nodeTypeNames,
+                                          boolean noLocal)
+            throws RepositoryException {
+        Path path;
+        try {
+            path = resolver.getQPath(absPath).getCanonicalPath();
+        } catch (NameException e) {
+            throw new RepositoryException("Malformed path: " + absPath);
+        }
+
+        // create NodeType instances from names
+        Name[] qNodeTypeNames;
+        if (nodeTypeNames == null) {
+            qNodeTypeNames = null;
+        } else {
+            try {
+                qNodeTypeNames = new Name[nodeTypeNames.length];
+                for (int i = 0; i < nodeTypeNames.length; i++) {
+                    Name ntName = resolver.getQName(nodeTypeNames[i]);
+                    if (!ntRegistry.isRegistered(ntName)) {
+                        throw new RepositoryException("unknown node type: " + nodeTypeNames[i]);
+                    }
+                    qNodeTypeNames[i] = ntName;
+                }
+            } catch (NameException e) {
+                throw new RepositoryException(e.getMessage());
+            }
+        }
+
+        return wspManager.createEventFilter(eventTypes, path, isDeep,
+                uuids, qNodeTypeNames, noLocal);
+    }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java Wed Jul  8 13:57:13 2009
@@ -49,7 +49,7 @@
         throws RepositoryException {
 
         NodeState srcItemState = getNodeState(srcPath, srcMgrProvider.getHierarchyManager());
-        this.srcState = (NodeState)srcItemState;
+        this.srcState = srcItemState;
         this.destParentState = getNodeState(destPath.getAncestor(1), destMgrProvider.getHierarchyManager());
 
         // check for illegal index present in destination path

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Checkin.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Checkin.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Checkin.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Checkin.java Wed Jul  8 13:57:13 2009
@@ -88,7 +88,7 @@
     
     /**
      *
-     * @return The nodeState to be checked in.
+     * @return The <code>NodeId</code> of the nodeState to be checked in.
      */
     public NodeId getNodeId() throws RepositoryException {
         return nodeState.getNodeEntry().getWorkspaceId();

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockRefresh.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockRefresh.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockRefresh.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/LockRefresh.java Wed Jul  8 13:57:13 2009
@@ -60,7 +60,7 @@
 
     //----------------------------------------< Access Operation Parameters >---
     public NodeId getNodeId() throws RepositoryException {
-        return (NodeId) nodeState.getNodeId();
+        return nodeState.getNodeId();
     }
 
     //------------------------------------------------------------< Factory >---

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Merge.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Merge.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Merge.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Merge.java Wed Jul  8 13:57:13 2009
@@ -74,15 +74,19 @@
     public void persisted() {
         assert status == STATUS_PENDING;
         status = STATUS_PERSISTED;
-        try {
-            NodeEntry vhe = mgr.getVersionHistoryEntry(nodeState);
-            if (vhe != null) {
-                vhe.invalidate(true);
+        if (isActivityMerge()) {
+            // TODO invalidate
+        } else {
+            try {
+                NodeEntry vhe = mgr.getVersionHistoryEntry(nodeState);
+                if (vhe != null) {
+                    vhe.invalidate(true);
+                }
+            } catch (RepositoryException e) {
+                log.warn("Error while retrieving VersionHistory entry:", e.getMessage());
             }
-        } catch (RepositoryException e) {
-            log.warn("Error while retrieving VersionHistory entry:", e.getMessage());
+            nodeState.getHierarchyEntry().invalidate(true);
         }
-        nodeState.getHierarchyEntry().invalidate(true);
     }
 
     //----------------------------------------< Access Operation Parameters >---
@@ -102,6 +106,10 @@
         return isShallow;
     }
 
+    public boolean isActivityMerge() {
+        return srcWorkspaceName == null;
+    }
+
     public void setFailedIds(Iterator failedIds) {
         if (failedIds == null) {
             throw new IllegalArgumentException("IdIterator must not be null.");

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/OperationVisitor.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/OperationVisitor.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/OperationVisitor.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/OperationVisitor.java Wed Jul  8 13:57:13 2009
@@ -42,6 +42,11 @@
 
     public void visit(SetMixin operation) throws RepositoryException;
 
+    /**
+     * @since JCR 2.0
+     */
+    public void visit(SetPrimaryType operation) throws RepositoryException;
+
     public void visit(SetPropertyValue operation) throws RepositoryException;
 
     public void visit(ReorderNodes operation) throws RepositoryException;
@@ -58,6 +63,9 @@
 
     public void visit(Checkin operation) throws UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException;
 
+    /**
+     * @since JCR 2.0
+     */
     public void visit(Checkpoint operation) throws RepositoryException;
 
     public void visit(Restore operation) throws VersionException, PathNotFoundException, ItemExistsException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException;
@@ -79,4 +87,19 @@
     public void visit(RemoveVersion operation) throws VersionException, AccessDeniedException, ReferentialIntegrityException, RepositoryException;
 
     public void visit(WorkspaceImport operation) throws RepositoryException;
+
+    /**
+     * @since JCR 2.0
+     */
+    public void visit(CreateActivity operation) throws RepositoryException;
+
+    /**
+     * @since JCR 2.0
+     */
+    public void visit(RemoveActivity operation) throws RepositoryException;
+
+    /**
+     * @since JCR 2.0
+     */
+    public void visit(CreateConfiguration operation) throws RepositoryException;
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveVersion.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveVersion.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveVersion.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveVersion.java Wed Jul  8 13:57:13 2009
@@ -40,7 +40,7 @@
 
     private NodeEntry versionableEntry = null;
 
-    protected RemoveVersion(ItemState removeState, NodeState parent, VersionManager mgr)
+    private RemoveVersion(ItemState removeState, NodeState parent, VersionManager mgr)
             throws RepositoryException {
         super(removeState, parent);
         try {
@@ -79,8 +79,8 @@
         }
 
         // invalidate the versionhistory entry and all its children
-        // in order to the the v-graph recalculated
-        removeState.getHierarchyEntry().getParent().invalidate(true);
+        // in order to have the v-graph recalculated
+        parent.getNodeEntry().invalidate(true);
     }
 
     //----------------------------------------< Access Operation Parameters >---

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Restore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Restore.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Restore.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Restore.java Wed Jul  8 13:57:13 2009
@@ -96,8 +96,8 @@
     }
 
     /**
-     * Relative qualified path to the non-existing restore target or <code>null</code>
-     * if the state returned by {@link #getNodeState()} is the target.
+     * Relative path to the non-existing restore target or <code>null</code>
+     * if the state identified by {@link #getNodeId()} is the target.
      *
      * @return
      * @see javax.jcr.Node#restore(Version, String, boolean)

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java Wed Jul  8 13:57:13 2009
@@ -213,12 +213,12 @@
         while (next == null && rows.hasNext()) {
             try {
                 QueryResultRow row = (QueryResultRow) rows.next();
-                nextId = row.getNodeId();
+                nextId = row.getNodeId(null);
                 Item tmp = itemMgr.getItem(hierarchyMgr.getNodeEntry(nextId));
 
                 if (tmp.isNode()) {
                     next = (Node) tmp;
-                    nextScore = row.getScore();
+                    nextScore = row.getScore(null);
                 } else {
                     log.warn("Item with Id is not a Node: " + nextId);
                     // try next

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java Wed Jul  8 13:57:13 2009
@@ -18,6 +18,8 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Arrays;
+import java.util.Collection;
 
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
@@ -39,9 +41,11 @@
 import org.apache.jackrabbit.jcr2spi.WorkspaceManager;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.QueryInfo;
+import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 
 /**
  * Provides the default implementation for a JCR query.
@@ -85,20 +89,47 @@
     private WorkspaceManager wspManager;
 
     /**
+     * The maximum result size
+     */
+    private long limit = -1;
+
+    /**
+     * The offset in the total result set
+     */
+    private long offset = -1;
+
+    /**
+     * The name/value pairs collected upon calls to {@link #bindValue(String, Value)}.
+     */
+    private final Map<String, QValue> boundValues = new HashMap<String, QValue>();
+
+    /**
+     * The names of the bind variables as returned by the SPI implementation
+     * after checking the query statement.
+     */
+    private final Collection<String> varNames;
+
+    /**
      * Creates a new query.
      *
-     * @param session          the session that created this query.
+     * @param session     the session that created this query.
      * @param mgrProvider the manager provider.
-     * @param itemMgr          the item manager of that session.
-     * @param wspManager       the workspace manager that belongs to the
-     *                         session.
-     * @param statement        the query statement.
-     * @param language         the language of the query statement.
+     * @param itemMgr     the item manager of that session.
+     * @param wspManager  the workspace manager that belongs to the session.
+     * @param statement   the query statement.
+     * @param language    the language of the query statement.
+     * @param node        the node from where the query was read or
+     *                    <code>null</code> if this query is not a stored
+     *                    query.
      * @throws InvalidQueryException if the query is invalid.
      */
-    public QueryImpl(Session session, ManagerProvider mgrProvider,
-                     ItemManager itemMgr, WorkspaceManager wspManager,
-                     String statement, String language)
+    public QueryImpl(Session session,
+                     ManagerProvider mgrProvider,
+                     ItemManager itemMgr,
+                     WorkspaceManager wspManager,
+                     String statement,
+                     String language,
+                     Node node)
             throws InvalidQueryException, RepositoryException {
         this.session = session;
         this.mgrProvider = mgrProvider;
@@ -106,44 +137,9 @@
         this.statement = statement;
         this.language = language;
         this.wspManager = wspManager;
-        this.wspManager.checkQueryStatement(
-                statement, language, getNamespaceMappings());
-    }
-
-    /**
-     * Creates a query from a node.
-     *
-     * @param session    the session that created this query.
-     * @param mgrProvider the manager provider.
-     * @param itemMgr    the item manager of that session.
-     * @param wspManager the workspace manager that belongs to the session.
-     * @param node       the node from where to read the query.
-     * @throws InvalidQueryException if the query is invalid.
-     * @throws RepositoryException   if another error occurs while reading from
-     *                               the node.
-     */
-    public QueryImpl(Session session, ManagerProvider mgrProvider,
-                     ItemManager itemMgr, WorkspaceManager wspManager,
-                     Node node)
-        throws InvalidQueryException, RepositoryException {
-
-        this.session = session;
-        this.mgrProvider = mgrProvider;
-        this.itemManager = itemMgr;
+        this.varNames = Arrays.asList(this.wspManager.checkQueryStatement(
+                statement, language, getNamespaceMappings()));
         this.node = node;
-        this.wspManager = wspManager;
-
-        NamePathResolver resolver = mgrProvider.getNamePathResolver();
-        if (!node.isNodeType(resolver.getJCRName(NameConstants.NT_QUERY))) {
-            throw new InvalidQueryException("Node is not of type nt:query");
-        }
-        if (node.getSession() != session) {
-            throw new InvalidQueryException("Node belongs to a different session.");
-        }
-        statement = node.getProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT)).getString();
-        language = node.getProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE)).getString();
-        this.wspManager.checkQueryStatement(
-                statement, language, getNamespaceMappings());
     }
 
     /**
@@ -151,7 +147,7 @@
      */
     public QueryResult execute() throws RepositoryException {
         QueryInfo qI = wspManager.executeQuery(
-                statement, language, getNamespaceMappings());
+                statement, language, getNamespaceMappings(), limit, offset, boundValues);
         return new QueryResultImpl(itemManager, mgrProvider, qI);
     }
 
@@ -162,11 +158,10 @@
      * @return namespace mappings (prefix -&gt; uri)
      * @throws RepositoryException if a repository error occurs
      */
-    private Map getNamespaceMappings() throws RepositoryException {
-        Map mappings = new HashMap();
-        String[] prefixes = session.getNamespacePrefixes();
-        for (int i = 0; i < prefixes.length; i++) {
-            mappings.put(prefixes[i], session.getNamespaceURI(prefixes[i]));
+    private Map<String, String> getNamespaceMappings() throws RepositoryException {
+        Map<String, String> mappings = new HashMap<String, String>();
+        for (String prefix : session.getNamespacePrefixes()) {
+            mappings.put(prefix, session.getNamespaceURI(prefix));
         }
         return mappings;
     }
@@ -216,8 +211,8 @@
             String ntName = resolver.getJCRName(NameConstants.NT_QUERY);
             Node queryNode = session.getRootNode().addNode(relPath, ntName);
             // set properties
-            queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE), language);
-            queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT), statement);
+            queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE), getLanguage());
+            queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT), getStatement());
             node = queryNode;
             return node;
         } catch (NameException e) {
@@ -229,23 +224,27 @@
      * @see Query#bindValue(String, Value)
      */
     public void bindValue(String varName, Value value) throws RepositoryException {
-        //TODO
-        throw new UnsupportedOperationException("JCR-2107: Implementation missing");
+        if (!varNames.contains(varName)) {
+            throw new IllegalArgumentException(varName + " is not a known bind variable name in this query");
+        }
+        if (value == null) {
+            boundValues.remove(varName);
+        } else {
+            boundValues.put(varName, ValueFormat.getQValue(value, mgrProvider.getNamePathResolver(), mgrProvider.getQValueFactory()));
+        }
     }
 
     /**
      * @see Query#setLimit(long)
      */
     public void setLimit(long limit) {
-        // TODO
-        throw new UnsupportedOperationException("JCR-2107: Implementation missing");
+        this.limit = limit;
     }
 
     /**
      * @see Query#setOffset(long)
      */
     public void setOffset(long offset) {
-        // TODO
-        throw new UnsupportedOperationException("JCR-2107: Implementation missing");
+        this.offset = offset;
     }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryManagerImpl.java Wed Jul  8 13:57:13 2009
@@ -19,14 +19,22 @@
 import org.apache.jackrabbit.jcr2spi.ItemManager;
 import org.apache.jackrabbit.jcr2spi.WorkspaceManager;
 import org.apache.jackrabbit.jcr2spi.ManagerProvider;
+import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelFactoryImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
+import org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilderRegistry;
+import org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilder;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.ValueFactory;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.qom.QueryObjectModel;
 
 /**
  * This class implements the {@link QueryManager} interface.
@@ -39,6 +47,11 @@
     private final Session session;
 
     /**
+     * The value factory.
+     */
+    private final ValueFactory valueFactory;
+
+    /**
      * Provides various managers.
      */
     private final ManagerProvider mgrProvider;
@@ -57,16 +70,19 @@
      * Creates a new <code>QueryManagerImpl</code> for the passed
      * <code>Session</code>.
      *
-     * @param session the current session.
+     * @param session     the current session.
      * @param mgrProvider the manager provider.
-     * @param itemMgr the item manager of the current session.
-     * @param wspManager the workspace manager.
+     * @param itemMgr     the item manager of the current session.
+     * @param wspManager  the workspace manager.
+     * @throws RepositoryException if an error occurs while initializing this
+     *                             query manager.
      */
     public QueryManagerImpl(Session session,
                             ManagerProvider mgrProvider,
                             ItemManager itemMgr,
-                            WorkspaceManager wspManager) {
+                            WorkspaceManager wspManager) throws RepositoryException {
         this.session = session;
+        this.valueFactory = mgrProvider.getJcrValueFactory();
         this.mgrProvider = mgrProvider;
         this.itemMgr = itemMgr;
         this.wspManager = wspManager;
@@ -78,7 +94,8 @@
     public Query createQuery(String statement, String language)
             throws InvalidQueryException, RepositoryException {
         checkIsAlive();
-        return new QueryImpl(session, mgrProvider, itemMgr, wspManager, statement, language);
+        return new QueryImpl(session, mgrProvider, itemMgr, wspManager,
+                statement, language, null);
     }
 
     /**
@@ -87,7 +104,26 @@
     public Query getQuery(Node node)
             throws InvalidQueryException, RepositoryException {
         checkIsAlive();
-        return new QueryImpl(session, mgrProvider, itemMgr, wspManager, node);
+
+        NamePathResolver resolver = mgrProvider.getNamePathResolver();
+        if (!node.isNodeType(resolver.getJCRName(NameConstants.NT_QUERY))) {
+            throw new InvalidQueryException("Node is not of type nt:query");
+        }
+        if (node.getSession() != session) {
+            throw new InvalidQueryException("Node belongs to a different session.");
+        }
+        String statement = node.getProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT)).getString();
+        String language = node.getProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE)).getString();
+
+        if (Query.JCR_JQOM.equals(language)) {
+            QueryObjectModelFactory qomFactory = new QOMFactory(
+                    node, resolver, valueFactory);
+            QueryObjectModelBuilder builder = QueryObjectModelBuilderRegistry.getQueryObjectModelBuilder(language);
+            return builder.createQueryObjectModel(statement, qomFactory, valueFactory);
+        } else {
+            return new QueryImpl(session, mgrProvider, itemMgr, wspManager,
+                    statement, language, node);
+        }
     }
 
     /**
@@ -101,8 +137,7 @@
      * @see QueryManager#getQOMFactory()
      */
     public QueryObjectModelFactory getQOMFactory() {
-        // TODO
-        throw new UnsupportedOperationException("JCR-2107: Implementation missing");        
+        return new QOMFactory(null, mgrProvider.getNamePathResolver(), valueFactory);
     }
 
     //------------------------------------------------------------< private >---
@@ -119,4 +154,21 @@
         }
     }
 
+    private class QOMFactory extends QueryObjectModelFactoryImpl {
+
+        private final Node node;
+
+        public QOMFactory(Node node,
+                          NamePathResolver resolver,
+                          ValueFactory factory) {
+            super(resolver, factory);
+            this.node = node;
+        }
+
+        protected QueryObjectModel createQuery(QueryObjectModelTree qomTree)
+                throws InvalidQueryException, RepositoryException {
+            return new QueryObjectModelImpl(session, mgrProvider, itemMgr,
+                    wspManager, qomTree, node);
+        }
+    }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java Wed Jul  8 13:57:13 2009
@@ -18,9 +18,7 @@
 
 import org.apache.jackrabbit.jcr2spi.ItemManager;
 import org.apache.jackrabbit.jcr2spi.ManagerProvider;
-import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QueryInfo;
-import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
@@ -66,13 +64,7 @@
      * {@inheritDoc}
      */
     public String[] getColumnNames() throws RepositoryException {
-        Name[] names = queryInfo.getColumnNames();
-        String[] propNames = new String[names.length];
-        NamePathResolver resolver = mgrProvider.getNamePathResolver();
-        for (int i = 0; i < names.length; i++) {
-            propNames[i] = resolver.getJCRName(names[i]);
-        }
-        return propNames;
+        return queryInfo.getColumnNames();
     }
 
     /**
@@ -87,7 +79,8 @@
      */
     public RowIterator getRows() throws RepositoryException {
         return new RowIteratorImpl(queryInfo, mgrProvider.getNamePathResolver(),
-                mgrProvider.getJcrValueFactory());
+                mgrProvider.getJcrValueFactory(), itemMgr,
+                mgrProvider.getHierarchyManager());
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java Wed Jul  8 13:57:13 2009
@@ -25,19 +25,20 @@
 import javax.jcr.Node;
 import javax.jcr.RangeIterator;
 import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 import javax.jcr.query.Row;
 import javax.jcr.query.RowIterator;
 
-import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QueryInfo;
 import org.apache.jackrabbit.spi.QueryResultRow;
+import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.value.ValueFormat;
+import org.apache.jackrabbit.jcr2spi.ItemManager;
+import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyManager;
 
 /**
  * Implements the {@link javax.jcr.query.RowIterator} interface returned by
@@ -53,7 +54,7 @@
     /**
      * The column names.
      */
-    private final Name[] columnNames;
+    private final String[] columnNames;
 
     /**
      * The <code>NamePathResolver</code> of the user <code>Session</code>.
@@ -66,6 +67,16 @@
     private final ValueFactory vFactory;
 
     /**
+     * The item manager.
+     */
+    private final ItemManager itemMgr;
+
+    /**
+     * The hierarchy manager.
+     */
+    private final HierarchyManager hmgr;
+
+    /**
      * Creates a new <code>RowIteratorImpl</code> that iterates over the result
      * nodes.
      *
@@ -73,12 +84,18 @@
      * @param resolver  <code>NameResolver</code> of the user
      *                  <code>Session</code>.
      * @param vFactory  the JCR value factory.
+     * @param itemMgr   the item manager.
+     * @param hmgr      the hierarchy manager.
      */
-    RowIteratorImpl(QueryInfo queryInfo, NamePathResolver resolver, ValueFactory vFactory) {
+    RowIteratorImpl(QueryInfo queryInfo, NamePathResolver resolver,
+                    ValueFactory vFactory, ItemManager itemMgr,
+                    HierarchyManager hmgr) {
         this.rows = queryInfo.getRows();
         this.columnNames = queryInfo.getColumnNames();
         this.resolver = resolver;
         this.vFactory = vFactory;
+        this.itemMgr = itemMgr;
+        this.hmgr = hmgr;
     }
 
     //--------------------------------------------------------< RowIterator >---
@@ -180,10 +197,10 @@
         private Value[] values;
 
         /**
-         * Map of select property <code>Name</code>s. Key: Name, Value:
+         * Map of select property names. Key: String, Value:
          * Integer, which refers to the array index in {@link #values}.
          */
-        private Map propertyMap;
+        private Map<String, Integer> propertyMap;
 
         /**
          * Creates a new <code>RowImpl</code> instance based on a SPI result
@@ -242,15 +259,14 @@
         public Value getValue(String propertyName) throws ItemNotFoundException, RepositoryException {
             if (propertyMap == null) {
                 // create the map first
-                Map tmp = new HashMap();
+                Map<String, Integer> tmp = new HashMap<String, Integer>();
                 for (int i = 0; i < columnNames.length; i++) {
-                    tmp.put(columnNames[i], new Integer(i));
+                    tmp.put(columnNames[i], i);
                 }
                 propertyMap = tmp;
             }
             try {
-                Name prop = resolver.getQName(propertyName);
-                Integer idx = (Integer) propertyMap.get(prop);
+                Integer idx = propertyMap.get(propertyName);
                 if (idx == null) {
                     throw new ItemNotFoundException(propertyName);
                 }
@@ -258,7 +274,7 @@
                 if (values == null) {
                     getValues();
                 }
-                return values[idx.intValue()];
+                return values[idx];
             } catch (NameException e) {
                 throw new RepositoryException(e.getMessage(), e);
             }
@@ -268,50 +284,69 @@
          * @see Row#getNode()
          */
         public Node getNode() throws RepositoryException {
-            // TODO
-            throw new UnsupportedRepositoryOperationException("JCR-1104");
+            return getNode(row.getNodeId(null));
         }
 
         /**
          * @see Row#getNode(String)
          */
         public Node getNode(String selectorName) throws RepositoryException {
-            // TODO
-            throw new UnsupportedRepositoryOperationException("JCR-1104");
+            return getNode(row.getNodeId(resolver.getQName(selectorName)));
         }
 
         /**
          * @see Row#getPath()
          */
         public String getPath() throws RepositoryException {
-            // TODO
-            throw new UnsupportedRepositoryOperationException("JCR-1104");
+            String path = null;
+            Node n = getNode();
+            if (n != null) {
+                path = n.getPath();
+            }
+            return path;
         }
 
         /**
          * @see Row#getPath(String)
          */
         public String getPath(String selectorName) throws RepositoryException {
-            // TODO
-            throw new UnsupportedRepositoryOperationException("JCR-1104");
+            String path = null;
+            Node n = getNode(selectorName);
+            if (n != null) {
+                path = n.getPath();
+            }
+            return path;
         }
 
         /**
          * @see Row#getScore()
          */
         public double getScore() throws RepositoryException {
-            // TODO
-            throw new UnsupportedRepositoryOperationException("JCR-1104");
+            return row.getScore(null);
         }
 
         /**
          * @see Row#getScore(String)
          */
         public double getScore(String selectorName) throws RepositoryException {
-            // TODO
-            throw new UnsupportedRepositoryOperationException("JCR-1104");
+            return row.getScore(resolver.getQName(selectorName));
         }
 
+        /**
+         * Returns the node with the given <code>id</code> or <code>null</code>
+         * if <code>id</code> is <code>null</code>.
+         *
+         * @param id a node id or <code>null</code>.
+         * @return the node with the given id or <code>null</code>.
+         * @throws RepositoryException if an error occurs while retrieving the
+         *                             node.
+         */
+        private Node getNode(NodeId id) throws RepositoryException {
+            Node node = null;
+            if (id != null) {
+                node = (Node) itemMgr.getItem(hmgr.getNodeEntry(id));
+            }
+            return node;
+        }
     }
-
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java Wed Jul  8 13:57:13 2009
@@ -18,6 +18,7 @@
 
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
 import org.apache.jackrabbit.jcr2spi.operation.SetMixin;
+import org.apache.jackrabbit.jcr2spi.operation.SetPrimaryType;
 import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -79,12 +80,16 @@
      * states to EXISTING.
      */
     public void persisted() throws RepositoryException {
-        List changedMixins = new ArrayList();
+        List<NodeState> changedMixins = new ArrayList<NodeState>();
+        List<NodeState> changedPrimaryTypes = new ArrayList<NodeState>();
+
         Operation[] ops = (Operation[]) operations.toArray(new Operation[operations.size()]);
         for (int i = 0; i < ops.length; i++) {
             ops[i].persisted();
             if (ops[i] instanceof SetMixin) {
                 changedMixins.add(((SetMixin) ops[i]).getNodeState());
+            } else if (ops[i] instanceof SetPrimaryType) {
+                changedPrimaryTypes.add(((SetPrimaryType) ops[i]).getNodeState());
             }
         }
         // process all remaining states that were not covered by the
@@ -96,10 +101,16 @@
             switch (state.getStatus()) {
                 case Status.EXISTING_MODIFIED:
                     state.setStatus(Status.EXISTING);
-                    if (state.isNode() && changedMixins.contains(state)) {
-                        // mixin changed for a node -> force reloading upon next
-                        // access in order to be aware of modified uniqueID.
-                        he.invalidate(false);
+                    if (state.isNode()) {
+                        if (changedPrimaryTypes.contains(state)) {
+                            // primary type changed for a node -> force reloading upon next
+                            // access in order to be aware of modified definition etc...
+                            he.invalidate(true);
+                        } else if (changedMixins.contains(state)) {
+                            // mixin changed for a node -> force reloading upon next
+                            // access in order to be aware of modified uniqueID.
+                            he.invalidate(false);
+                        }
                     }
                     break;
                 case Status.EXISTING_REMOVED:

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java Wed Jul  8 13:57:13 2009
@@ -186,13 +186,13 @@
 
     /**
      * Utility method:
-     * Returns the qualified path of this item state. Shortcut for calling
+     * Returns the path of this item state. Shortcut for calling
      * 'getPath' on the {@link ItemState#getHierarchyEntry() hierarchy entry}.
      *
      * @return
      * @throws RepositoryException if an error occurs
      */
-    public Path getQPath() throws RepositoryException {
+    public Path getPath() throws RepositoryException {
         return getHierarchyEntry().getPath();
     }
 



Mime
View raw message