You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2010/02/09 22:20:40 UTC

svn commit: r908232 - in /sling/trunk/bundles/jcr: api/src/main/java/org/apache/sling/jcr/api/ base/ base/src/main/java/org/apache/sling/jcr/base/

Author: justin
Date: Tue Feb  9 21:20:39 2010
New Revision: 908232

URL: http://svn.apache.org/viewvc?rev=908232&view=rev
Log:
SLING-1363 - adding SessionConfigurer interface

Added:
    sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SessionConfigurer.java
Modified:
    sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java
    sling/trunk/bundles/jcr/base/pom.xml
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java

Added: sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SessionConfigurer.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SessionConfigurer.java?rev=908232&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SessionConfigurer.java (added)
+++ sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SessionConfigurer.java Tue Feb  9 21:20:39 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.sling.jcr.api;
+
+import javax.jcr.Session;
+
+/**
+ * Service interface which allows for the JCR Sessions produced by
+ * SlingRepository instances to be configured programmatically.
+ */
+public interface SessionConfigurer {
+
+    static final String SERVICE_NAME = "org.apache.sling.jcr.api.SessionConfigurer";
+
+    /**
+     * Configure the Session instance as necessary.
+     *
+     * @param session the JCR Session
+     */
+    void configure(Session session);
+}

Modified: sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java?rev=908232&r1=908231&r2=908232&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java (original)
+++ sling/trunk/bundles/jcr/api/src/main/java/org/apache/sling/jcr/api/SlingRepository.java Tue Feb  9 21:20:39 2010
@@ -34,6 +34,12 @@
  * Implementations of this interface will generally provide configurability of
  * the default workspace name as well as the access details for the
  * administrative session.
+ * <p>
+ * Implementations of SlingRepository are expected to invoke any available
+ * implementations of the {@link SessionConfigurer} interface <b>before</b>
+ * returning <b>any</b> {@link Session} to callers. This includes the methods
+ * defined in the {@link Repository} interface.
+ *
  */
 public interface SlingRepository extends Repository {
 

Modified: sling/trunk/bundles/jcr/base/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/pom.xml?rev=908232&r1=908231&r2=908232&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/pom.xml (original)
+++ sling/trunk/bundles/jcr/base/pom.xml Tue Feb  9 21:20:39 2010
@@ -7,9 +7,9 @@
     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
@@ -90,7 +90,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.jcr.api</artifactId>
-            <version>2.0.6</version>
+            <version>2.0.7-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>javax.jcr</groupId>

Modified: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java?rev=908232&r1=908231&r2=908232&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java (original)
+++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java Tue Feb  9 21:20:39 2010
@@ -30,6 +30,7 @@
 import javax.jcr.Workspace;
 
 import org.apache.jackrabbit.api.JackrabbitWorkspace;
+import org.apache.sling.jcr.api.SessionConfigurer;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.base.internal.loader.Loader;
 import org.apache.sling.jcr.base.util.RepositoryAccessor;
@@ -39,6 +40,7 @@
 import org.osgi.framework.SynchronousBundleListener;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
 
 /**
  * The <code>AbstractSlingRepository</code> is an abstract implementation of
@@ -131,6 +133,8 @@
     // the background thread constantly checking the repository
     private Thread repositoryPinger;
 
+    private ServiceTracker sessionConfigurerTracker;
+
     protected AbstractSlingRepository() {
     }
 
@@ -215,6 +219,13 @@
                 setDefaultWorkspace(defaultWorkspace);
             }
 
+            Object[] postProcessors = sessionConfigurerTracker.getServices();
+            if (postProcessors != null) {
+                for (int i = 0; i < postProcessors.length; i++) {
+                    ((SessionConfigurer) postProcessors[i]).configure(session);
+                }
+            }
+
             return session;
 
         } catch (NoSuchWorkspaceException nswe) {
@@ -236,7 +247,7 @@
             throw new RepositoryException(re.getMessage(), re);
         }
     }
-    
+
     /**
      * @param anonUser the user name of the anon user.
      * @return a Credentials implementation that represents the anon user.
@@ -245,7 +256,7 @@
         // NB: this method is overridden in the Jackrabbit Service bundle to avoid using the anon password. SLING-1282
         return new SimpleCredentials(anonUser, anonPass);
     }
-    
+
     /**
      * @param adminUser the name of the administrative user.
      * @return a Credentials implementation that represents the administrative user.
@@ -254,7 +265,7 @@
         // NB: this method is overridden in the Jackrabbit Service bundle to avoid using the admin password. SLING-1282
         return new SimpleCredentials(adminUser, adminPass);
     }
-     
+
 
 
     /*
@@ -575,6 +586,9 @@
                 "activate: Unexpected problem starting repository", t);
         }
 
+        this.sessionConfigurerTracker = new ServiceTracker(componentContext.getBundleContext(), SessionConfigurer.SERVICE_NAME, null);
+        this.sessionConfigurerTracker.open();
+
         // launch the background repository checker now
         startRepositoryPinger();
     }
@@ -585,6 +599,7 @@
      * @param componentContext
      */
     protected void deactivate(ComponentContext componentContext) {
+        this.sessionConfigurerTracker.close();
 
         componentContext.getBundleContext().removeBundleListener(this);