jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r599778 - in /jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav: RepositoryServiceImpl.java SessionInfoImpl.java URIResolverImpl.java
Date Fri, 30 Nov 2007 11:15:19 GMT
Author: angela
Date: Fri Nov 30 03:15:09 2007
New Revision: 599778

URL: http://svn.apache.org/viewvc?rev=599778&view=rev
Log:
create NamePathResolver per sessionInfo only once

Modified:
    jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
    jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java

Modified: jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?rev=599778&r1=599777&r2=599778&view=diff
==============================================================================
--- jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Fri Nov 30 03:15:09 2007
@@ -228,6 +228,7 @@
         if (uri == null || "".equals(uri)) {
             throw new RepositoryException("Invalid repository uri '" + uri + "'.");
         }
+
         if (idFactory == null || qValueFactory == null) {
             throw new RepositoryException("IdFactory and QValueFactory may not be null.");
         }
@@ -248,17 +249,18 @@
             hostConfig.setHost(repositoryUri);
 
             nsCache = new NamespaceCache();
+            uriResolver = new URIResolverImpl(repositoryUri, this, domFactory);
             NamePathResolver resolver = new NamePathResolverImpl(nsCache);
-            uriResolver = new URIResolverImpl(repositoryUri, this, resolver, domFactory);
             valueFactory = new ValueFactoryQImpl(qValueFactory, resolver);
+            
         } catch (URIException e) {
             throw new RepositoryException(e);
         }
 
-        this.connectionManager = new MultiThreadedHttpConnectionManager();
+        connectionManager = new MultiThreadedHttpConnectionManager();
         HttpConnectionManagerParams params = new HttpConnectionManagerParams();
         params.setMaxConnectionsPerHost(hostConfig, 20);
-        this.connectionManager.setParams(params);
+        connectionManager.setParams(params);
     }
 
     private static void checkSessionInfo(SessionInfo sessionInfo) throws RepositoryException
{
@@ -305,7 +307,17 @@
         return requestURI.equals(href);
     }
 
-    HttpClient getClient(SessionInfo sessionInfo) throws RepositoryException {
+    protected NamePathResolver getNamePathResolver(SessionInfo sessionInfo) throws RepositoryException
{
+        checkSessionInfo(sessionInfo);
+        NamePathResolver resolver = ((SessionInfoImpl) sessionInfo).getNamePathResolver();
+        if (resolver == null) {
+            resolver = new NamePathResolverImpl(sessionInfo);
+            ((SessionInfoImpl) sessionInfo).setNamePathResolver(resolver);
+        }
+        return resolver;
+    }
+    
+    protected HttpClient getClient(SessionInfo sessionInfo) throws RepositoryException {
         HttpClient client = (HttpClient) clients.get(sessionInfo);
         if (client == null) {
             client = new HttpClient(connectionManager);
@@ -337,7 +349,7 @@
 
     private String getItemUri(NodeId parentId, Name childName, SessionInfo sessionInfo) throws
RepositoryException {
         String parentUri = uriResolver.getItemUri(parentId, sessionInfo.getWorkspaceName(),
sessionInfo);
-        NamePathResolver resolver = new NamePathResolverImpl(sessionInfo);
+        NamePathResolver resolver = getNamePathResolver(sessionInfo);
         return parentUri + "/" + Text.escape(resolver.getJCRName(childName));
     }
 
@@ -386,8 +398,8 @@
         }
         return index;
     }
+    
     //--------------------------------------------------------------------------
-
     /**
      * Execute a 'Workspace' operation.
      *
@@ -677,7 +689,7 @@
                 throw new RepositoryException("Internal error: requested node definition
and got property definition.");
             }
 
-            NamePathResolver resolver = new NamePathResolverImpl(sessionInfo);
+            NamePathResolver resolver = getNamePathResolver(sessionInfo);
 
             // build the definition
             QItemDefinition definition = null;
@@ -781,7 +793,7 @@
                 throw new ItemNotFoundException("No node for id " + nodeId);
             }
 
-            NamePathResolver resolver = new NamePathResolverImpl(sessionInfo);
+            NamePathResolver resolver = getNamePathResolver(sessionInfo);
             NodeId parentId = getParentId(propSet, sessionInfo);
 
             NodeInfoImpl nInfo = buildNodeInfo(nodeResponse, parentId, propSet, sessionInfo,
resolver);
@@ -794,7 +806,7 @@
                     // any other resource type than default (empty) is represented by a node
item
                     // --> ignore
                 } else {
-                    PropertyId childId = uriResolver.buildPropertyId(nInfo.getId(), resp,
sessionInfo.getWorkspaceName());
+                    PropertyId childId = uriResolver.buildPropertyId(nInfo.getId(), resp,
sessionInfo.getWorkspaceName(), getNamePathResolver(sessionInfo));
                     nInfo.addPropertyId(childId);
                 }
             }
@@ -828,7 +840,7 @@
                                        NodeId parentId, DavPropertySet propSet,
                                        SessionInfo sessionInfo,
                                        NamePathResolver resolver) throws NameException, RepositoryException
{
-        NodeId id = uriResolver.buildNodeId(parentId, nodeResponse, sessionInfo.getWorkspaceName());
+        NodeId id = uriResolver.buildNodeId(parentId, nodeResponse, sessionInfo.getWorkspaceName(),
getNamePathResolver(sessionInfo));
         NodeInfoImpl nInfo = new NodeInfoImpl(id, parentId, propSet, resolver);
         if (propSet.contains(ItemResourceConstants.JCR_REFERENCES)) {
             HrefProperty refProp = new HrefProperty(propSet.get(ItemResourceConstants.JCR_REFERENCES));
@@ -873,8 +885,6 @@
                 return Collections.EMPTY_LIST.iterator();
             }
 
-            NamePathResolver resolver = new NamePathResolverImpl(sessionInfo);
-
             List childEntries = new ArrayList();
             for (int i = 0; i < responses.length; i++) {
                 if (!isSameResource(uri, responses[i])) {
@@ -883,7 +893,7 @@
                     if (childProps.contains(DavPropertyName.RESOURCETYPE) &&
                         childProps.get(DavPropertyName.RESOURCETYPE).getValue() != null)
{
 
-                        Name qName = getQName(childProps, resolver);
+                        Name qName = getQName(childProps, getNamePathResolver(sessionInfo));
                         int index = getIndex(childProps);
                         String uuid = getUniqueID(childProps);
 
@@ -932,9 +942,9 @@
 
             DavPropertySet propSet = responses[0].getProperties(DavServletResponse.SC_OK);
             NodeId parentId = getParentId(propSet, sessionInfo);
-            PropertyId id = uriResolver.buildPropertyId(parentId, responses[0], sessionInfo.getWorkspaceName());
+            PropertyId id = uriResolver.buildPropertyId(parentId, responses[0], sessionInfo.getWorkspaceName(),
getNamePathResolver(sessionInfo));
 
-            NamePathResolver resolver = new NamePathResolverImpl(sessionInfo);
+            NamePathResolver resolver = getNamePathResolver(sessionInfo);
             PropertyInfo pInfo = new PropertyInfoImpl(id, parentId, propSet,
                     resolver, valueFactory, getQValueFactory());
             return pInfo;
@@ -1320,7 +1330,7 @@
     public void addVersionLabel(SessionInfo sessionInfo, NodeId versionHistoryId, NodeId
versionId, Name label, boolean moveLabel) throws VersionException, RepositoryException {
         try {
             String uri = getItemUri(versionId, sessionInfo);
-            String strLabel = new NamePathResolverImpl(sessionInfo).getJCRName(label);
+            String strLabel = getNamePathResolver(sessionInfo).getJCRName(label);
             LabelMethod method = new LabelMethod(uri, strLabel, (moveLabel) ? LabelInfo.TYPE_SET
: LabelInfo.TYPE_ADD);
             execute(method, sessionInfo);
         } catch (IOException e) {
@@ -1334,7 +1344,7 @@
     public void removeVersionLabel(SessionInfo sessionInfo, NodeId versionHistoryId, NodeId
versionId, Name label) throws VersionException, RepositoryException {
         try {
             String uri = getItemUri(versionId, sessionInfo);
-            String strLabel = new NamePathResolverImpl(sessionInfo).getJCRName(label);
+            String strLabel = getNamePathResolver(sessionInfo).getJCRName(label);
             LabelMethod method = new LabelMethod(uri, strLabel, LabelInfo.TYPE_REMOVE);
             execute(method, sessionInfo);
         } catch (IOException e) {
@@ -1385,7 +1395,7 @@
             method.checkSuccess();
 
             MultiStatus ms = method.getResponseBodyAsMultiStatus();
-            NamePathResolver resolver = new NamePathResolverImpl(sessionInfo);
+            NamePathResolver resolver = getNamePathResolver(sessionInfo);
             return new QueryInfoImpl(ms, sessionInfo, uriResolver, resolver, valueFactory,
getQValueFactory());
         } catch (IOException e) {
             throw new RepositoryException(e);
@@ -1739,7 +1749,6 @@
 
         internalSetNamespaces(sessionInfo, namespaces);
         // adjust internal mappings:
-        // TODO: not correct since nsRegistry is retrieved from each session
         nsCache.remove(prefix, uri);
     }
 
@@ -1809,7 +1818,7 @@
     public Iterator getQNodeTypeDefinitions(SessionInfo sessionInfo, Name[] nodetypeNames)
throws RepositoryException {
         ReportMethod method = null;
         try {
-            NamePathResolver resolver = new NamePathResolverImpl(sessionInfo);
+            NamePathResolver resolver = getNamePathResolver(sessionInfo);
 
             ReportInfo info = new ReportInfo(NodeTypesReport.NODETYPES_REPORT, DEPTH_0);
             for (int i = 0; i < nodetypeNames.length; i++) {
@@ -1838,7 +1847,7 @@
     }
 
     /**
-     * 
+     *
      * @param sessionInfo
      * @param reportDoc
      * @return
@@ -1847,7 +1856,7 @@
     private Iterator retrieveQNodeTypeDefinitions(SessionInfo sessionInfo, Document reportDoc)
throws RepositoryException {
         ElementIterator it = DomUtil.getChildren(reportDoc.getDocumentElement(), NodeTypeConstants.NODETYPE_ELEMENT,
null);
             List ntDefs = new ArrayList();
-            NamePathResolver resolver = new NamePathResolverImpl(sessionInfo);
+            NamePathResolver resolver = getNamePathResolver(sessionInfo);
             while (it.hasNext()) {
                 ntDefs.add(new QNodeTypeDefinitionImpl(it.nextElement(), resolver, getQValueFactory()));
             }
@@ -1884,10 +1893,10 @@
 
         private boolean isConsumed = false;
 
-        private BatchImpl(ItemId targetId, SessionInfo sessionInfo) {
+        private BatchImpl(ItemId targetId, SessionInfo sessionInfo) throws RepositoryException
{
             this.targetId = targetId;
             this.sessionInfo = sessionInfo;
-            this.resolver = new NamePathResolverImpl(sessionInfo);
+            this.resolver = getNamePathResolver(sessionInfo);
         }
 
         private HttpClient start() throws RepositoryException {
@@ -2237,13 +2246,13 @@
 
         private NamePathResolverImpl(SessionInfo sessionInfo) {
             NamespaceResolver nsResolver = new NamespaceResolverImpl(sessionInfo);
-            this.nResolver = new ParsingNameResolver(getNameFactory(), nsResolver);
-            this.pResolver = new ParsingPathResolver(getPathFactory(), nResolver);
+            nResolver = new ParsingNameResolver(getNameFactory(), nsResolver);
+            pResolver = new ParsingPathResolver(getPathFactory(), nResolver);
         }
 
         private NamePathResolverImpl(NamespaceResolver nsResolver) {
-            this.nResolver = new ParsingNameResolver(getNameFactory(), nsResolver);
-            this.pResolver = new ParsingPathResolver(getPathFactory(), nResolver);
+            nResolver = new ParsingNameResolver(getNameFactory(), nsResolver);
+            pResolver = new ParsingPathResolver(getPathFactory(), nResolver);
         }
 
         /**

Modified: jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java?rev=599778&r1=599777&r2=599778&view=diff
==============================================================================
--- jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
(original)
+++ jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
Fri Nov 30 03:15:09 2007
@@ -16,10 +16,8 @@
  */
 package org.apache.jackrabbit.spi2dav;
 
-import org.slf4j.LoggerFactory;
-import org.slf4j.Logger;
-
 import org.apache.jackrabbit.spi.SessionInfo;
+import org.apache.jackrabbit.conversion.NamePathResolver;
 
 import java.util.HashSet;
 import java.util.Set;
@@ -29,20 +27,12 @@
  */
 public class SessionInfoImpl implements SessionInfo {
 
-    private static Logger log = LoggerFactory.getLogger(SessionInfoImpl.class);
-
     private final CredentialsWrapper credentials;
     private final String workspaceName;
-
     private final Set lockTokens = new HashSet();
 
     private String lastBatchId;
-
-    /**
-     * The subscriptionId if this session info is subscribed to observation
-     * events.
-     */
-    private String subscriptionId;
+    private NamePathResolver resolver;
 
     SessionInfoImpl(CredentialsWrapper creds, String workspaceName) {
         this.credentials = creds;
@@ -107,6 +97,14 @@
      * @param batchId the batch id.
      */
     void setLastBatchId(String batchId) {
-        this.lastBatchId = batchId;
+        lastBatchId = batchId;
+    }
+
+    NamePathResolver getNamePathResolver() {
+        return resolver;
+    }
+
+    void setNamePathResolver(NamePathResolver resolver) {
+        this.resolver = resolver;
     }
 }

Modified: jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java?rev=599778&r1=599777&r2=599778&view=diff
==============================================================================
--- jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
(original)
+++ jackrabbit/sandbox/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
Fri Nov 30 03:15:09 2007
@@ -16,62 +16,55 @@
  */
 package org.apache.jackrabbit.spi2dav;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.commons.httpclient.URI;
 import org.apache.jackrabbit.conversion.NameException;
 import org.apache.jackrabbit.conversion.NamePathResolver;
+import org.apache.jackrabbit.name.NameConstants;
+import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.spi.PropertyId;
-import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.util.Text;
-import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
-import org.apache.jackrabbit.webdav.property.DavPropertySet;
-import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
-import org.apache.jackrabbit.webdav.jcr.version.report.LocateByUuidReport;
+import org.apache.jackrabbit.webdav.DavConstants;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.MultiStatus;
+import org.apache.jackrabbit.webdav.MultiStatusResponse;
 import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
 import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
 import org.apache.jackrabbit.webdav.client.methods.ReportMethod;
-import org.apache.jackrabbit.webdav.MultiStatusResponse;
-import org.apache.jackrabbit.webdav.DavException;
-import org.apache.jackrabbit.webdav.MultiStatus;
-import org.apache.jackrabbit.webdav.DavServletResponse;
-import org.apache.jackrabbit.webdav.DavConstants;
-import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.apache.jackrabbit.webdav.jcr.version.report.LocateByUuidReport;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
+import org.apache.jackrabbit.webdav.property.DavPropertySet;
 import org.apache.jackrabbit.webdav.version.report.ReportInfo;
-import org.apache.jackrabbit.name.NameConstants;
-import org.apache.commons.httpclient.URI;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
 import org.w3c.dom.Document;
 
-import javax.jcr.RepositoryException;
 import javax.jcr.ItemNotFoundException;
+import javax.jcr.RepositoryException;
 import java.io.IOException;
-import java.util.Map;
 import java.util.HashMap;
+import java.util.Map;
 
 /**
  * <code>URIResolverImpl</code>...
  */
 class URIResolverImpl implements URIResolver {
 
-    private static Logger log = LoggerFactory.getLogger(URIResolverImpl.class);
-
     private final URI repositoryUri;
     private final RepositoryServiceImpl service;
-    private final NamePathResolver resolver;
     private final Document domFactory;
 
     // TODO: to-be-fixed. uri/id-caches don't get updated
     // for each workspace a separate idUri-cache is created
     private final Map idURICaches = new HashMap();
 
-    URIResolverImpl(URI repositoryUri, RepositoryServiceImpl service,
-                    NamePathResolver resolver, Document domFactory) {
+    URIResolverImpl(URI repositoryUri, RepositoryServiceImpl service, Document domFactory)
{
         this.repositoryUri = repositoryUri;
         this.service = service;
-        this.resolver = resolver;
         this.domFactory = domFactory;
     }
 
@@ -155,7 +148,7 @@
             }
             // resolve relative-path part unless it denotes the root-item
             if (path != null && !path.denotesRoot()) {
-                String jcrPath = resolver.getJCRPath(path);
+                String jcrPath = service.getNamePathResolver(sessionInfo).getJCRPath(path);
                 if (!path.isAbsolute() && !uriBuffer.toString().endsWith("/")) {
                     uriBuffer.append("/");
                 }
@@ -170,7 +163,7 @@
     }
 
     NodeId buildNodeId(NodeId parentId, MultiStatusResponse response,
-                       String workspaceName) throws RepositoryException {
+                       String workspaceName, NamePathResolver resolver) throws RepositoryException
{
         IdURICache cache = getCache(workspaceName);
         
         NodeId nodeId;
@@ -194,7 +187,7 @@
     }
 
     PropertyId buildPropertyId(NodeId parentId, MultiStatusResponse response,
-                               String workspaceName) throws RepositoryException {
+                               String workspaceName, NamePathResolver resolver) throws RepositoryException
{
         IdURICache cache = getCache(workspaceName);
         if (cache.containsUri(response.getHref())) {
             ItemId id = cache.getItemId(response.getHref());
@@ -221,6 +214,19 @@
             cache.remove(itemId);
         }
     }
+
+    private static boolean isSameURI(String uri1, String uri2) {
+        return getCleanURI(uri1).equals(getCleanURI(uri2));
+
+    }
+
+    private static String getCleanURI(String uri) {
+        if (uri.endsWith("/")) {
+            return uri.substring(0, uri.length() - 1);
+        } else {
+            return uri;
+        }
+    }
     //-------------------------------------------------------< URI resolver >---
     /**
      * @inheritDoc
@@ -235,7 +241,7 @@
             jcrPath = uri;
         }
         try {
-            return resolver.getQPath(Text.unescape(jcrPath));
+            return service.getNamePathResolver(sessionInfo).getQPath(Text.unescape(jcrPath));
         } catch (NameException e) {
             throw new RepositoryException(e);
         }
@@ -256,7 +262,7 @@
 
         // retrieve parentId from cache or by recursive calls
         NodeId parentId;
-        if (uri.equals(getRootItemUri(sessionInfo.getWorkspaceName()))) {
+        if (isSameURI(uri, getRootItemUri(sessionInfo.getWorkspaceName()))) {
             parentId = null;
         } else {
             String parentUri = Text.getRelativeParent(uri, 1, true);
@@ -276,7 +282,7 @@
             if (responses.length != 1) {
                 throw new ItemNotFoundException("Unable to retrieve the node with id " +
uri);
             }
-            return buildNodeId(parentId, responses[0], sessionInfo.getWorkspaceName());
+            return buildNodeId(parentId, responses[0], sessionInfo.getWorkspaceName(), service.getNamePathResolver(sessionInfo));
 
         } catch (IOException e) {
             throw new RepositoryException(e);
@@ -309,7 +315,7 @@
         NodeId parentId = getNodeId(parentUri, sessionInfo);
         // build property id
         try {
-            Name name = resolver.getQName(propName);
+            Name name = service.getNamePathResolver(sessionInfo).getQName(propName);
             PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name);
             cache.add(uri, propertyId);
 



Mime
View raw message