jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r779555 - in /jackrabbit/trunk: jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/ ...
Date Thu, 28 May 2009 10:45:05 GMT
Author: angela
Date: Thu May 28 10:45:05 2009
New Revision: 779555

URL: http://svn.apache.org/viewvc?rev=779555&view=rev
Log:
JCR-2003: JCR2SPI / SPI: Add support for JCR 2.0

- Node.getReferences(String)
- Node.getWeakReferences()
- Node.getWeakReferences(String)

JCR-1418: Redesign NodeInfo.getReferences()

- deprecated getReferences on NodeInfo
- added method to RepositoryService as suggested by marcel but including support for the variants
in JCR 2.0
   > weakrefs vs refs
   > name-filter

Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveActivity.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/NodeInfo.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
Thu May 28 10:45:05 2009
@@ -898,6 +898,7 @@
                 properties.add(new NodeTypeProperty(JCR_MIXINNODETYPES, n.getMixinNodeTypes(),
false));
                 properties.add(new DefaultDavProperty(JCR_INDEX, new Integer(n.getIndex()),
true));
                 addHrefProperty(JCR_REFERENCES, n.getReferences(), true);
+                addHrefProperty(JCR_WEAK_REFERENCES, n.getWeakReferences(), true);
                 if (n.isNodeType(JcrConstants.MIX_REFERENCEABLE)) {
                     properties.add(new DefaultDavProperty(JCR_UUID, n.getUUID(), true));
                 }

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java
Thu May 28 10:45:05 2009
@@ -128,6 +128,10 @@
     public static final DavPropertyName JCR_MIXINNODETYPES = DavPropertyName.create("mixinnodetypes",
NAMESPACE);
     public static final DavPropertyName JCR_INDEX = DavPropertyName.create("index", NAMESPACE);
     public static final DavPropertyName JCR_REFERENCES = DavPropertyName.create("references",
NAMESPACE);
+    /**
+     * @since JCR 2.0
+     */
+    public static final DavPropertyName JCR_WEAK_REFERENCES = DavPropertyName.create("weakreferences",
NAMESPACE);
     public static final DavPropertyName JCR_UUID = DavPropertyName.create("uuid", NAMESPACE);
     public static final DavPropertyName JCR_PRIMARYITEM = DavPropertyName.create("primaryitem",
NAMESPACE);
 

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
Thu May 28 10:45:05 2009
@@ -585,23 +585,7 @@
      * @see javax.jcr.Node#getReferences(String)
      */
     public PropertyIterator getReferences(String name) throws RepositoryException {
-        checkStatus();
-        List refs = Arrays.asList(getNodeState().getNodeReferences());
-        if (name != null) {
-            // remove property ids that don't match the given name
-            Name qName = getQName(name);
-            refs = new ArrayList(refs);
-            for (Iterator iter = refs.iterator(); iter.hasNext();) {
-                PropertyId propId = (PropertyId) iter.next();
-                if (!propId.getName().equals(qName)) {
-                    refs.remove(propId);
-                }
-            }
-        } // else: name == null -> return all references
-
-        // create an property iterator for all or the matching property ids
-        // according to the specified name.
-        return new LazyItemIterator(getItemManager(), session.getHierarchyManager(), refs.iterator());
+        return getReferences(name, false);
     }
 
     /**
@@ -615,8 +599,7 @@
      * @see javax.jcr.Node#getWeakReferences()
      */
     public PropertyIterator getWeakReferences(String name) throws RepositoryException {
-        // TODO: implementation missing
-        throw new UnsupportedRepositoryOperationException("JCR-1104");
+        return getReferences(name, true);
     }
 
     /**
@@ -1605,6 +1588,34 @@
         return qName;
     }
 
+    /**
+     * @return the primary node type name.
+     */
+    private Name getPrimaryNodeTypeName() {
+        return getNodeState().getNodeTypeName();
+    }
+
+    /**
+     * 
+     * @param name
+     * @param weak
+     * @return
+     * @throws RepositoryException
+     */
+    private LazyItemIterator getReferences(String name, boolean weak) throws RepositoryException
{
+        checkStatus();
+        Name propName = (name == null) ? null : getQName(name);
+        Iterator<PropertyId> itr = getNodeState().getNodeReferences(propName, weak);
+        return new LazyItemIterator(getItemManager(), session.getHierarchyManager(), itr);
+    }
+
+    /**
+     *
+     * @param mixinName
+     * @return
+     * @throws NoSuchNodeTypeException
+     * @throws ConstraintViolationException
+     */
     private boolean canAddMixin(Name mixinName) throws NoSuchNodeTypeException,
         ConstraintViolationException {
         NodeTypeManagerImpl ntMgr = session.getNodeTypeManager();
@@ -1814,11 +1825,4 @@
             throws ConstraintViolationException, RepositoryException {
         return session.getItemDefinitionProvider().getQPropertyDefinition(getNodeState().getAllNodeTypeNames(),
propertyName, type, multiValued);
     }
-
-    /**
-     * @return the primary node type name.
-     */
-    private Name getPrimaryNodeTypeName() {
-        return getNodeState().getNodeTypeName();
-    }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveActivity.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveActivity.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveActivity.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/RemoveActivity.java
Thu May 28 10:45:05 2009
@@ -28,6 +28,7 @@
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.RepositoryException;
 import javax.jcr.version.VersionException;
+import java.util.Iterator;
 
 /**
  * <code>RemoveVersion</code>...
@@ -36,13 +37,13 @@
 
     private static Logger log = LoggerFactory.getLogger(RemoveActivity.class);
 
-    private final PropertyId[] refs;
+    private final Iterator<PropertyId> refs;
     private final HierarchyManager hMgr;
 
     private RemoveActivity(NodeState removeActivity, HierarchyManager hierarchyMgr)
             throws RepositoryException {
         super(removeActivity, removeActivity.getParent());
-        refs = removeActivity.getNodeReferences();
+        refs = removeActivity.getNodeReferences(null, false);
         hMgr = hierarchyMgr;
     }
 
@@ -66,8 +67,8 @@
         status = STATUS_PERSISTED;
         
         // invalidate all references to the removed activity
-        for (int i = 0; i < refs.length; i++) {
-            HierarchyEntry entry = hMgr.lookup(refs[i]);
+        while (refs.hasNext()) {
+            HierarchyEntry entry = hMgr.lookup(refs.next());
             if (entry != null) {
                 entry.invalidate(false);
             }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateFactory.java
Thu May 28 10:45:05 2009
@@ -18,6 +18,7 @@
 
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry;
 import org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry;
 
@@ -113,9 +114,12 @@
      * the given node.
      *
      * @param nodeState reference target
+     * @param propertyName
+     * @param weak Boolean flag indicating whether weak references should be
+     * returned or not.
      * @return reference property identifiers
      */
-    public PropertyId[] getNodeReferences(NodeState nodeState);
+    public Iterator<PropertyId> getNodeReferences(NodeState nodeState, Name propertyName,
boolean weak);
 
     /**
      * Adds the given <code>ItemStateCreationListener</code>.

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
Thu May 28 10:45:05 2009
@@ -18,6 +18,7 @@
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.Iterator;
 
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.RepositoryException;
@@ -316,10 +317,14 @@
      * Returns the identifiers of all reference properties that point to
      * this node.
      *
+     * @param propertyName name filter of referring properties to be returned;
+     * if <code>null</code> then all references are returned.
+     * @param weak Boolean flag indicating whether weak references should be
+     * returned or not.
      * @return reference property identifiers
      */
-    public PropertyId[] getNodeReferences() {
-        return isf.getNodeReferences(this);
+    public Iterator<PropertyId> getNodeReferences(Name propertyName, boolean weak)
{
+        return isf.getNodeReferences(this, propertyName, weak);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientISFactory.java
Thu May 28 10:45:05 2009
@@ -32,6 +32,7 @@
 import javax.jcr.ItemNotFoundException;
 
 import java.util.Iterator;
+import java.util.Collections;
 
 /**
  * <code>TransientISFactory</code>...
@@ -139,13 +140,13 @@
 
     /**
      * @inheritDoc
-     * @see ItemStateFactory#getNodeReferences(NodeState)
+     * @see ItemStateFactory#getNodeReferences(NodeState,org.apache.jackrabbit.spi.Name,boolean)
      */
-    public PropertyId[] getNodeReferences(NodeState nodeState) {
+    public Iterator<PropertyId> getNodeReferences(NodeState nodeState, Name propertyName,
boolean weak) {
         if (nodeState.getStatus() == Status.NEW) {
-            return new PropertyId[0];
+            return Collections.EMPTY_SET.iterator();
         }
-        return workspaceStateFactory.getNodeReferences(nodeState);
+        return workspaceStateFactory.getNodeReferences(nodeState, propertyName, weak);
     }
 
     //------------------------------------------< ItemStateCreationListener >---

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
Thu May 28 10:45:05 2009
@@ -22,6 +22,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
+import java.util.Collections;
 
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
@@ -158,26 +159,24 @@
 
     /**
      * @inheritDoc
-     * @see ItemStateFactory#getNodeReferences(NodeState)
-     * @param nodeState
+     * @see ItemStateFactory#getNodeReferences(NodeState,org.apache.jackrabbit.spi.Name,boolean)
      */
-    public PropertyId[] getNodeReferences(NodeState nodeState) {
+    public Iterator<PropertyId> getNodeReferences(NodeState nodeState, Name propertyName,
boolean weak) {
         NodeEntry entry = nodeState.getNodeEntry();
         // shortcut
         if (entry.getUniqueID() == null
                 || !entry.hasPropertyEntry(NameConstants.JCR_UUID)) {
             // for sure not referenceable
-            return new PropertyId[0];
+            return Collections.EMPTY_SET.iterator();
         }
 
         // nodestate has a unique ID and is potentially mix:referenceable
         // => try to retrieve references
         try {
-            NodeInfo nInfo = service.getNodeInfo(sessionInfo, entry.getWorkspaceId());
-            return nInfo.getReferences();
+            return service.getReferences(sessionInfo, entry.getWorkspaceId(), propertyName,
weak);
         } catch (RepositoryException e) {
             log.debug("Unable to determine references to {}", nodeState);
-            return new PropertyId[0];
+            return Collections.EMPTY_SET.iterator();
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
Thu May 28 10:45:05 2009
@@ -222,6 +222,14 @@
         }, "getChildInfos(SessionInfo, NodeId)", new Object[]{unwrap(sessionInfo), parentId});
     }
 
+    public Iterator<PropertyId> getReferences(final SessionInfo sessionInfo, final
NodeId nodeId, final Name propertyName, final boolean weakReferences) throws RepositoryException
{
+        return (Iterator) execute(new Callable() {
+            public Object call() throws RepositoryException {
+                return service.getReferences(unwrap(sessionInfo), nodeId, propertyName, weakReferences);
+            }
+        }, "getReferences(SessionInfo, NodeId, Name, boolean)", new Object[]{unwrap(sessionInfo),
nodeId, propertyName, weakReferences});
+    }
+
     public PropertyInfo getPropertyInfo(final SessionInfo sessionInfo, final PropertyId propertyId)
             throws RepositoryException {
 

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/NodeInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/NodeInfo.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/NodeInfo.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/NodeInfo.java
Thu May 28 10:45:05 2009
@@ -61,10 +61,14 @@
     public Name[] getMixins();
 
     /**
+     * Return the {@link PropertyId Id}s of the properties that are referencing the
+     * node based on this info object.
+     * 
      * @return {@link PropertyId Id}s of the properties that are referencing the
      * node based on this info object or an empty array if the node is not
      * referenceable or no references exist.
      * @see PropertyInfo#getId()
+     * @deprecated Use {@link RepositoryService#getReferences(SessionInfo, NodeId, boolean)}
instead.
      */
     public PropertyId[] getReferences();
 

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
Thu May 28 10:45:05 2009
@@ -305,6 +305,30 @@
     public Iterator getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws ItemNotFoundException,
RepositoryException;
 
     /**
+     * Returns the {@link PropertyId Id}s of the properties that are referencing
+     * the node identified by the given <code>nodeId</code>. If
+     * <code>weakReferences</code> is <code>true</code> the ids of
+     * {@link javax.jcr.PropertyType#WEAKREFERENCE WEAKREFERENCE} properties are
+     * returned, otherwise the property must be of type {@link javax.jcr.PropertyType#REFERENCE
REFERENCE}.
+     *
+     * @param sessionInfo
+     * @param nodeId
+     * @param propertyName name filter of referring properties to be returned;
+     * if <code>null</code> then all references are returned.
+     * @param weakReferences If <code>true</code> the properties must be of type
+     * {@link javax.jcr.PropertyType#WEAKREFERENCE}, otherwise of type
+     * {@link javax.jcr.PropertyType#REFERENCE}.
+     * @return An Iterator of {@link PropertyId Id}s of the properties that are
+     * referencing the node identified by the given <code>nodeId</code> or an
+     * empty iterator if the node is not eferenceable or no references exist.
+     * @throws ItemNotFoundException
+     * @throws RepositoryException
+     * @see PropertyInfo#getId()
+     * @since JCR 2.0
+     */
+    public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId,
Name propertyName, boolean weakReferences) throws ItemNotFoundException, RepositoryException;
+
+    /**
      * Returns the <code>PropertyInfo</code> for the <code>Property</code>
      * identified by the given id.
      *

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Thu May 28 10:45:05 2009
@@ -985,6 +985,68 @@
     }
 
     /**
+     * @see RepositoryService#getReferences(SessionInfo, NodeId, Name, boolean)
+     */
+    public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId,
Name propertyName, boolean weakReferences) throws ItemNotFoundException, RepositoryException
{
+        // set of properties to be retrieved
+        DavPropertyNameSet nameSet = new DavPropertyNameSet();
+        if (weakReferences) {
+            nameSet.add(ItemResourceConstants.JCR_WEAK_REFERENCES);
+        } else {
+            nameSet.add(ItemResourceConstants.JCR_REFERENCES);
+        }
+
+        DavMethodBase method = null;
+        try {
+            String uri = getItemUri(nodeId, sessionInfo);
+            method = new PropFindMethod(uri, nameSet, DEPTH_0);
+            getClient(sessionInfo).executeMethod(method);
+            method.checkSuccess();
+
+            MultiStatusResponse[] responses = method.getResponseBodyAsMultiStatus().getResponses();
+            if (responses.length < 1) {
+                throw new ItemNotFoundException("Unable to retrieve the node with id " +
saveGetIdString(nodeId, sessionInfo));
+            }
+
+            List<PropertyId> refIds = new ArrayList<PropertyId>();
+            for (int i = 0; i < responses.length; i++) {
+                if (isSameResource(uri, responses[i])) {
+                    MultiStatusResponse resp = responses[i];
+                    DavPropertySet props = resp.getProperties(DavServletResponse.SC_OK);
+                    DavProperty p;
+                    if (weakReferences) {
+                        p = props.get(ItemResourceConstants.JCR_WEAK_REFERENCES);
+                    } else {
+                        p = props.get(ItemResourceConstants.JCR_REFERENCES);
+                    }
+
+                    if (p == null) {
+                        return Collections.EMPTY_LIST.iterator();
+                    } else {
+                        HrefProperty hp = new HrefProperty(p);
+                        for (Iterator it = hp.getHrefs().iterator(); it.hasNext();) {
+                            String propHref = it.next().toString();
+                            PropertyId propId = uriResolver.getPropertyId(propHref, sessionInfo);
+                            if (propertyName == null || propertyName.equals(propId.getName()))
{
+                                refIds.add(propId);
+                            }
+                        }
+                    }
+                }
+            }
+            return refIds.iterator();
+        } catch (IOException e) {
+            throw new RepositoryException(e);
+        } catch (DavException e) {
+            throw ExceptionConverter.generate(e);
+        } finally {
+            if (method != null) {
+                method.releaseConnection();
+            }
+        }
+    }
+
+    /**
      * @see RepositoryService#getPropertyInfo(SessionInfo, PropertyId)
      */
     public PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId) throws
RepositoryException {

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java?rev=779555&r1=779554&r2=779555&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
Thu May 28 10:45:05 2009
@@ -79,6 +79,7 @@
 import javax.jcr.ItemVisitor;
 import javax.jcr.ValueFactory;
 import javax.jcr.GuestCredentials;
+import javax.jcr.PropertyIterator;
 import javax.jcr.util.TraversingItemVisitor;
 import javax.jcr.observation.ObservationManager;
 import javax.jcr.observation.EventListener;
@@ -412,6 +413,27 @@
     /**
      * {@inheritDoc}
      */
+    public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId,
Name propertyName, boolean weakReferences) throws ItemNotFoundException, RepositoryException
{
+        SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
+        Node node = getNode(nodeId, sInfo);
+        String jcrName = (propertyName == null) ? null : sInfo.getNamePathResolver().getJCRName(propertyName);
+
+        List<PropertyId> ids = new ArrayList<PropertyId>();
+        PropertyIterator it;
+        if (weakReferences) {
+            it = node.getWeakReferences(jcrName);
+        } else {
+            it = node.getReferences(jcrName);
+        }
+        while (it.hasNext()) {
+            ids.add(idFactory.createPropertyId(it.nextProperty(), sInfo.getNamePathResolver()));
+        }
+        return ids.iterator();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public PropertyInfo getPropertyInfo(SessionInfo sessionInfo,
                                         PropertyId propertyId)
             throws ItemNotFoundException, RepositoryException {



Mime
View raw message