jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r426103 - /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/
Date Thu, 27 Jul 2006 15:32:33 GMT
Author: mreutegg
Date: Thu Jul 27 08:32:32 2006
New Revision: 426103

URL: http://svn.apache.org/viewvc?rev=426103&view=rev
Log:
Add implementations of ChildNodeEntry that allow to transparently load the referenced ItemState.

Added:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildItemReference.java
  (with props)
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java
  (with props)
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
  (with props)
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java
  (with props)
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java
  (with props)
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java
  (with props)
Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildItemReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildItemReference.java?rev=426103&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildItemReference.java
(added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildItemReference.java
Thu Jul 27 08:32:32 2006
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.jcr2spi.state;
+
+import org.apache.jackrabbit.name.QName;
+
+import java.lang.ref.WeakReference;
+
+/**
+ * <code>ChildItemReference</code> implements base functionality for child node
+ * and property references.
+ * @see ChildNodeReference
+ * @see PropertyReference
+ */
+abstract class ChildItemReference {
+
+    /**
+     * Cached weak reference to the target NodeState.
+     */
+    private WeakReference target;
+
+    /**
+     * The parent that owns this <code>ChildItemReference</code>.
+     */
+    protected final NodeState parent;
+
+    /**
+     * The name of the target item state.
+     */
+    protected final QName name;
+
+    /**
+     * Creates a new <code>ChildItemReference</code> with the given parent
+     * <code>NodeState</code>.
+     *
+     * @param parent the <code>NodeState</code> that owns this child node
+     *               reference.
+     * @param name      the name of the child item.
+     */
+    public ChildItemReference(NodeState parent, QName name) {
+        this.parent = parent;
+        this.name = name;
+    }
+
+    /**
+     * Resolves this <code>ChildItemReference</code> and returns the target
+     * <code>ItemState</code> of this reference.
+     *
+     * @param isf    the item state factory responsible for creating node
+     *               states.
+     * @return the <code>ItemState</code> where this reference points to.
+     * @throws NoSuchItemStateException if the referenced <code>ItemState</code>
+     *                                  does not exist.
+     * @throws ItemStateException       if an error occurs.
+     */
+    public ItemState resolve(ItemStateFactory isf)
+            throws NoSuchItemStateException, ItemStateException {
+        // check if cached
+        if (target != null) {
+            ItemState state = (ItemState) target.get();
+            if (state != null) {
+                return state;
+            }
+        }
+        // not cached. retrieve and keep weak reference to state
+        ItemState state = doResolve(isf);
+        target = new WeakReference(state);
+        return state;
+    }
+
+    /**
+     * Returns the parent <code>NodeState</code>. This is the source of this
+     * <code>ChildItemReference</code>.
+     *
+     * @return the parent <code>NodeState</code>.
+     */
+    public NodeState getParent() {
+        return parent;
+    }
+
+    /**
+     * Resolves this <code>ChildItemReference</code> and returns the target
+     * <code>ItemState</code> of this reference.
+     *
+     * @param isf    the item state factory responsible for creating node
+     *               states.
+     * @return the <code>ItemState</code> where this reference points to.
+     * @throws NoSuchItemStateException if the referenced <code>ItemState</code>
+     *                                  does not exist.
+     * @throws ItemStateException       if an error occurs.
+     */
+    protected abstract ItemState doResolve(ItemStateFactory isf)
+            throws NoSuchItemStateException, ItemStateException;
+}

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildItemReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java?rev=426103&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java
(added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java
Thu Jul 27 08:32:32 2006
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.jcr2spi.state;
+
+import org.apache.jackrabbit.name.QName;
+
+/**
+ * <code>ChildNodeReference</code> implements common functionality for child
+ * node entry implementations.
+ */
+abstract class ChildNodeReference extends ChildItemReference implements ChildNodeEntry {
+
+    /**
+     * Creates a new <code>ChildNodeReference</code> with the given parent
+     * <code>NodeState</code>.
+     *
+     * @param parent the <code>NodeState</code> that owns this child node
+     *               reference.
+     * @param name      the name of the child item.
+     */
+    public ChildNodeReference(NodeState parent, QName name) {
+        super(parent, name);
+    }
+
+    /**
+     * @inheritDoc
+     * @see ChildNodeEntry#getIndex()
+     */
+    public int getIndex() {
+        return parent.getChildNodeIndex(getName(), this);
+    }
+
+    /**
+     * @inheritDoc
+     * @see ChildNodeEntry#getName()
+     */
+    public QName getName() {
+        return name;
+    }
+}

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildNodeReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java?rev=426103&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
(added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
Thu Jul 27 08:32:32 2006
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.jcr2spi.state;
+
+import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.name.QName;
+
+/**
+ * <code>ItemStateFactory</code> provides methods to create child
+ * <code>NodeState</code>s and <code>PropertyState</code>s for a
given
+ * <code>NodeState</code>.
+ */
+public interface ItemStateFactory {
+
+    /**
+     * Creates the child <code>NodeState</code> with the given
+     * <code>uuid</code>, which has the given <code>parent</code>.
+     *
+     * @param parent the parent of the <code>NodeState</code> to create.
+     * @param uuid   the uuid of the <code>NodeState</code> to create.
+     * @return the created <code>NodeState</code>.
+     * @throws NoSuchItemStateException if there is no such <code>NodeState</code>.
+     * @throws ItemStateException       if an error occurs while retrieving the
+     *                                  <code>NodeState</code>.
+     */
+    public NodeState createNodeState(NodeState parent, String uuid)
+            throws NoSuchItemStateException, ItemStateException;
+
+    /**
+     * Creates the child <code>NodeState</code> with the given
+     * <code>nameElement</code>, which has the given <code>parent</code>.
+     *
+     * @param parent      the parent of the <code>NodeState</code> to create.
+     * @param nameElement the name element of the <code>NodeState</code> to
+     *                    create.
+     * @return the created <code>NodeState</code>.
+     * @throws NoSuchItemStateException if there is no such <code>NodeState</code>.
+     * @throws ItemStateException       if an error occurs while retrieving the
+     *                                  <code>NodeState</code>.
+     */
+    public NodeState createNodeState(NodeState parent,
+                                     Path.PathElement nameElement)
+            throws NoSuchItemStateException, ItemStateException;
+
+    /**
+     * Creates the <code>PropertyState</code> with the given <code>name</code>,
+     * which has the given <code>parent</code>.
+     *
+     * @param parent       the parent of the <code>PropertyState</code> to
+     *                     create.
+     * @param propertyName the name of the <code>PropertyState</code> to
+     *                     create.
+     * @return the created <code>PropertyState</code>.
+     * @throws NoSuchItemStateException if there is no such <code>PropertyState</code>.
+     * @throws ItemStateException       if an error occurs while retrieving the
+     *                                  <code>PropertyState</code>.
+     */
+    public PropertyState createPropertyState(NodeState parent,
+                                             QName propertyName)
+            throws NoSuchItemStateException, ItemStateException;
+}

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?rev=426103&r1=426102&r2=426103&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
Thu Jul 27 08:32:32 2006
@@ -802,6 +802,21 @@
         super.removeListener(listener);
     }
 
+    /**
+     * TODO: find a better way to provide the index of a child node entry
+     * Returns the index of the given <code>ChildNodeEntry</code> and with
+     * <code>name</code>.
+     *
+     * @param name the name of the child node.
+     * @param cne  the <code>ChildNodeEntry</code> instance.
+     * @return the index of the child node entry or <code>0</code> if it is not
+     *         found in this <code>NodeState</code>.
+     */
+    int getChildNodeIndex(QName name, ChildNodeEntry cne) {
+        List sns = childNodeEntries.get(name);
+        return sns.indexOf(cne) + 1;
+    }
+
     //-------------------------------------------------< misc. helper methods >
     /**
      * Notify the listeners that a child node entry has been added

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java?rev=426103&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java
(added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java
Thu Jul 27 08:32:32 2006
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.jcr2spi.state;
+
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.IdFactory;
+
+/**
+ * <code>PathElementReference</code> implements a {@link ChildNodeEntry} based
+ * on a {@link Path.PathElement}.
+ */
+public class PathElementReference extends ChildNodeReference implements ChildNodeEntry {
+
+    /**
+     * IdFactory to create an ItemId based on the parent NodeId
+     */
+    private final IdFactory idFactory;
+
+    /**
+     * Creates a new <code>PathElementReference</code>
+     *
+     * @param parent    the <code>ItemState</code> that owns this child item
+     *                  reference.
+     * @param name      the name of the child node.
+     * @param idFactory the <code>IdFactory</code> to create new ItemIds
+     */
+    public PathElementReference(NodeState parent, QName name, IdFactory idFactory) {
+        super(parent, name);
+        this.idFactory = idFactory;
+    }
+
+    /**
+     * @inheritDoc
+     * @see ChildItemReference#doResolve(ItemStateFactory)
+     * <p/>
+     * Returns a <code>NodeState</code>.
+     */
+    protected ItemState doResolve(ItemStateFactory isf)
+            throws NoSuchItemStateException, ItemStateException {
+        return isf.createNodeState(parent, Path.create(getName(), getIndex()).getNameElement());
+    }
+
+    /**
+     * @inheritDoc
+     * @see ChildNodeEntry#getId()
+     */
+    public NodeId getId() {
+        return idFactory.createNodeId(parent.getNodeId(),
+                Path.create(getName(), getIndex()));
+    }
+}

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathElementReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java?rev=426103&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java
(added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java
Thu Jul 27 08:32:32 2006
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.jcr2spi.state;
+
+import org.apache.jackrabbit.name.QName;
+
+/**
+ * <code>PropertyReference</code> implements a reference to a property state.
+ */
+public class PropertyReference extends ChildItemReference {
+
+    /**
+     * Creates a new <code>PropertyReference</code>.
+     *
+     * @param parent the parent <code>NodeState</code> where the property
+     *               belongs to.
+     * @param name   the name of the property.
+     */
+    public PropertyReference(NodeState parent, QName name) {
+        super(parent, name);
+    }
+
+    /**
+     * @inheritDoc
+     * @see ChildItemReference#doResolve(ItemStateFactory)
+     * <p/>
+     * Returns a <code>PropertyState</code>.
+     */
+    protected ItemState doResolve(ItemStateFactory isf)
+            throws NoSuchItemStateException, ItemStateException {
+        return isf.createPropertyState(parent, name);
+    }
+}

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java?rev=426103&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java
(added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java
Thu Jul 27 08:32:32 2006
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.jcr2spi.state;
+
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.name.QName;
+
+/**
+ * <code>UUIDReference</code> implements a {@link ChildNodeEntry} based on a
+ * <code>NodeId</code> with just a UUID and no relative path component.
+ */
+class UUIDReference extends ChildNodeReference implements ChildNodeEntry {
+
+    /**
+     * The <code>NodeId</code> with just a UUID that references the child node.
+     */
+    private final NodeId childId;
+
+    /**
+     * Creates a new <code>UUIDReference</code>.
+     *
+     * @param parent  the <code>NodeState</code> that owns this child node
+     *                reference.
+     * @param childId the id of the referenced <code>NodeState</code>. This id
+     *                must not have a relative path component.
+     * @throws IllegalArgumentException if <code>childId</code> has a relative
+     *                                  path component.
+     */
+    public UUIDReference(NodeState parent, NodeId childId, QName name) {
+        super(parent, name);
+        if (childId.getRelativePath() == null) {
+            throw new IllegalArgumentException("childId must not contain a relative path");
+        }
+        this.childId = childId;
+    }
+
+    /**
+     * @inheritDoc
+     * @see ChildItemReference#doResolve(ItemStateFactory)
+     * <p/>
+     * Returns a <code>NodeState</code>.
+     */
+    protected ItemState doResolve(ItemStateFactory isf)
+            throws NoSuchItemStateException, ItemStateException {
+        return isf.createNodeState(parent, childId.getUUID());
+    }
+
+    /**
+     * @inheritDoc
+     * @see ChildNodeEntry#getId()
+     */
+    public NodeId getId() {
+        return childId;
+    }
+}

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/UUIDReference.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message