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

svn commit: r1731720 - in /sling/trunk/bundles/jcr/base/src: main/java/org/apache/sling/jcr/base/ main/java/org/apache/sling/jcr/base/internal/loader/ test/java/org/apache/sling/jcr/base/

Author: cziegeler
Date: Mon Feb 22 19:13:04 2016
New Revision: 1731720

URL: http://svn.apache.org/viewvc?rev=1731720&view=rev
Log:
SLING-5537 : Remove deprecated features from JCR Base

Removed:
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractNamespaceMappingRepository.java
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/NamespaceMappingSupport.java
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/SessionProxyHandler.java
    sling/trunk/bundles/jcr/base/src/test/java/org/apache/sling/jcr/base/SessionProxyHandlerTest.java
Modified:
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository2.java
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/loader/Loader.java
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/package-info.java
    sling/trunk/bundles/jcr/base/src/test/java/org/apache/sling/jcr/base/MockSlingRepositoryManager.java

Modified: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository2.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository2.java?rev=1731720&r1=1731719&r2=1731720&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository2.java (original)
+++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository2.java Mon Feb 22 19:13:04 2016
@@ -121,26 +121,6 @@ public abstract class AbstractSlingRepos
     }
 
     /**
-     * Wraps the given session with support for name spaces defined by bundles
-     * deployed in the OSGi framework. See {@link NamespaceMappingSupport} for
-     * details about namespace support in Sling.
-     * <p>
-     * To fully support namespaces, this method must be called from each
-     * implementation of any of the {@code login} methods implemented by this
-     * class or its extensions.
-     *
-     * @param session The {@code Session} to wrap. This must not be {@code null}
-     * @return The wrapped session
-     * @throws RepositoryException If an error occurrs wrapping the session
-     * @throws NullPointerException If {@code session} is {@code null}
-     * @deprecated as of API version 2.4 (bundle version 2.3)
-     */
-    @Deprecated
-    protected final Session getNamespaceAwareSession(Session session) throws RepositoryException {
-        return this.getSlingRepositoryManager().getNamespaceAwareSession(session);
-    }
-
-    /**
      * Creates an administrative session to access the indicated workspace.
      * <p>
      * This method is called by the {@link #loginAdministrative(String)} and
@@ -286,7 +266,7 @@ public abstract class AbstractSlingRepos
             }
 
             final Session session = repository.login(credentials, workspace);
-            return getNamespaceAwareSession(session);
+            return session;
 
         } catch (final RuntimeException re) {
             // SLING-702: Jackrabbit throws IllegalStateException if the
@@ -393,7 +373,7 @@ public abstract class AbstractSlingRepos
         }
 
         logger.debug("SlingRepository.loginAdministrative is deprecated. Please use SlingRepository.loginService.");
-        return getNamespaceAwareSession(createAdministrativeSession(workspace));
+        return createAdministrativeSession(workspace);
     }
 
     // Remaining Repository service methods all backed by the actual

Modified: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java?rev=1731720&r1=1731719&r2=1731720&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java (original)
+++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepositoryManager.java Mon Feb 22 19:13:04 2016
@@ -25,6 +25,7 @@ import javax.jcr.Repository;
 
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.api.SlingRepositoryInitializer;
+import org.apache.sling.jcr.base.internal.loader.Loader;
 import org.apache.sling.serviceusermapping.ServiceUserMapper;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -77,7 +78,7 @@ import aQute.bnd.annotation.ProviderType
  * @since API version 2.3 (bundle version 2.2.2)
  */
 @ProviderType
-public abstract class AbstractSlingRepositoryManager extends NamespaceMappingSupport {
+public abstract class AbstractSlingRepositoryManager {
 
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
@@ -98,6 +99,8 @@ public abstract class AbstractSlingRepos
 
     private volatile ServiceTracker repoInitializerTracker;
 
+    private volatile Loader loader;
+
     /**
      * Returns the default workspace, which may be <code>null</code> meaning to
      * use the repository provided default workspace.
@@ -320,8 +323,8 @@ public abstract class AbstractSlingRepos
                 this.repository = newRepo;
                 this.masterSlingRepository = this.create(this.bundleContext.getBundle());
 
-                log.debug("start: setting up NamespaceMapping support");
-                this.setup(this.bundleContext, this.masterSlingRepository);
+                log.debug("start: setting up Loader");
+                this.loader = new Loader(this.masterSlingRepository, this.bundleContext);
 
                 log.debug("start: calling SlingRepositoryInitializer");
                 Throwable t = null;
@@ -401,8 +404,12 @@ public abstract class AbstractSlingRepos
                     Repository oldRepo = repository;
                     repository = null;
 
-                    // stop namespace support
-                    this.tearDown();
+                    // stop loader
+                    if ( this.loader != null ) {
+                        this.loader.dispose();
+                        this.loader = null;
+                    }
+                    // destroy repository
                     this.destroy(this.masterSlingRepository);
 
                     try {

Modified: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/loader/Loader.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/loader/Loader.java?rev=1731720&r1=1731719&r2=1731720&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/loader/Loader.java (original)
+++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/loader/Loader.java Mon Feb 22 19:13:04 2016
@@ -33,7 +33,6 @@ import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
-import org.apache.sling.jcr.api.NamespaceMapper;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.base.NodeTypeLoader;
 import org.osgi.framework.Bundle;
@@ -47,7 +46,7 @@ import org.slf4j.LoggerFactory;
 /**
  * The <code>Loader</code> TODO
  */
-public class Loader implements NamespaceMapper, BundleListener {
+public class Loader implements BundleListener {
 
     public static final String NODETYPES_BUNDLE_HEADER = "Sling-Nodetypes";
 
@@ -63,9 +62,6 @@ public class Loader implements Namespace
     // bundles whose registration failed and should be retried
     private final List<Bundle> delayedBundles;
 
-    /** Namespace prefix table. */
-    private final Map<Long, NamespaceEntry[]> namespaceTable = new HashMap<Long, NamespaceEntry[]>();
-
     public Loader(final SlingRepository repository, final BundleContext bundleContext) {
         this.bundleContext = bundleContext;
         this.slingRepository = repository;
@@ -91,43 +87,39 @@ public class Loader implements Namespace
 
     //---------- NamespaceMapper interface
 
-    public void defineNamespacePrefixes(Session session)
+    private void defineNamespacePrefixes(final Session session, final List<NamespaceEntry> entries)
     throws RepositoryException {
-        final Iterator<NamespaceEntry[]> iter = this.namespaceTable.values().iterator();
-        while ( iter.hasNext() ) {
-            final NamespaceEntry[] entries = iter.next();
-            for(int i=0; i<entries.length; i++) {
-
-                // the namespace prefixing is a little bit tricky:
-                String mappedPrefix = null;
-                // first, we check if the namespace is registered with a prefix
+        for(final NamespaceEntry entry : entries) {
+
+            // the namespace prefixing is a little bit tricky:
+            String mappedPrefix = null;
+            // first, we check if the namespace is registered with a prefix
+            try {
+                mappedPrefix = session.getNamespacePrefix(entry.namespace);
+            } catch (NamespaceException ne) {
+                // the namespace is not registered yet, so we should do this
+                // can we directly use the desired prefix?
+                mappedPrefix = entry.prefix + "_new";
                 try {
-                    mappedPrefix = session.getNamespacePrefix(entries[i].namespace);
-                } catch (NamespaceException ne) {
-                    // the namespace is not registered yet, so we should do this
-                    // can we directly use the desired prefix?
-                    mappedPrefix = entries[i].prefix + "_new";
-                    try {
-                        session.getNamespaceURI(entries[i].prefix);
-                    } catch (NamespaceException ne2) {
-                        // as an exception occured we can directly use the new prefix
-                        mappedPrefix = entries[i].prefix;
-                    }
-                    session.getWorkspace().getNamespaceRegistry().registerNamespace(mappedPrefix, entries[i].namespace);
+                    session.getNamespaceURI(entry.prefix);
+                } catch (NamespaceException ne2) {
+                    // as an exception occured we can directly use the new prefix
+                    mappedPrefix = entry.prefix;
                 }
-                // do we have to remap?
-                if ( mappedPrefix != null && !mappedPrefix.equals(entries[i].prefix ) ) {
-                    // check if the prefix is already used?
-                    String oldUri = null;
-                    try {
-                        oldUri = session.getNamespaceURI(entries[i].prefix);
-                        session.setNamespacePrefix(entries[i].prefix + "_old", oldUri);
-                    } catch (NamespaceException ne) {
-                        // ignore: prefix is not used
-                    }
-                    // finally set prefix
-                    session.setNamespacePrefix(entries[i].prefix, entries[i].namespace);
+                session.getWorkspace().getNamespaceRegistry().registerNamespace(mappedPrefix, entry.namespace);
+            }
+            // do we have to remap?
+            if ( mappedPrefix != null && !mappedPrefix.equals(entry.prefix ) ) {
+                // check if the prefix is already used?
+                String oldUri = null;
+                try {
+                    oldUri = session.getNamespaceURI(entry.prefix);
+                    session.setNamespacePrefix(entry.prefix + "_old", oldUri);
+                } catch (NamespaceException ne) {
+                    // ignore: prefix is not used
                 }
+                // finally set prefix
+                session.setNamespacePrefix(entry.prefix, entry.namespace);
             }
         }
     }
@@ -142,6 +134,7 @@ public class Loader implements Namespace
      * @param event The <code>BundleEvent</code> representing the bundle state
      *            change.
      */
+    @Override
     public final void bundleChanged(BundleEvent event) {
         // Take care: This is synchronous - take care to not block the system !!
         switch (event.getType()) {
@@ -162,7 +155,6 @@ public class Loader implements Namespace
     //---------- internal
 
     private void registerBundle(Bundle bundle) {
-        this.registerNamespaces(bundle);
         if (this.registerBundleInternal(bundle, false)) {
             // handle delayed bundles, might help now
             int currentSize = -1;
@@ -183,7 +175,6 @@ public class Loader implements Namespace
     }
 
     private void unregisterBundle(Bundle bundle) {
-        this.unregisterNamespaces(bundle);
         synchronized (delayedBundles) {
             delayedBundles.remove(bundle);
         }
@@ -198,7 +189,7 @@ public class Loader implements Namespace
      * Register namespaces defined in the bundle in the namespace table.
      * @param bundle The bundle.
      */
-    private void registerNamespaces(Bundle bundle) {
+    private void registerNamespaces(Bundle bundle) throws RepositoryException {
         final String definition = (String) bundle.getHeaders().get(NAMESPACES_BUNDLE_HEADER);
         if ( definition != null ) {
             log.debug("registerNamespaces: Bundle {} tries to register: {}",
@@ -219,21 +210,19 @@ public class Loader implements Namespace
                 }
             }
             if ( entries.size() > 0 ) {
-                this.namespaceTable.put(bundle.getBundleId(), entries.toArray(new NamespaceEntry[entries.size()]));
+                final Session session = this.getSession();
+                try {
+                    this.defineNamespacePrefixes(session, entries);
+                } finally {
+                    this.ungetSession(session);
+                }
             }
         }
     }
 
-    /**
-     * Unregister namespaces defined in the bundle.
-     * @param bundle The bundle.
-     */
-    protected void unregisterNamespaces(Bundle bundle) {
-        this.namespaceTable.remove(bundle.getBundleId());
-    }
-
     private boolean registerBundleInternal (Bundle bundle, boolean isRetry) {
         try {
+            this.registerNamespaces(bundle);
             if (this.registerNodeTypes(bundle, isRetry)) {
                 return true;
             }

Modified: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/package-info.java?rev=1731720&r1=1731719&r2=1731720&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/package-info.java (original)
+++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/package-info.java Mon Feb 22 19:13:04 2016
@@ -24,16 +24,8 @@
  * manage the actual JCR repository instance and
  * {@link org.apache.sling.jcr.base.AbstractSlingRepository2} being the
  * basis for the repository service instance handed to using bundles.
- * <p>
- * The old {@link org.apache.sling.jcr.base.AbstractSlingRepository}
- * class is being deprecated in favor of the new method of providing access
- * to JCR repositories. Likewise the
- * {@link org.apache.sling.jcr.base.AbstractNamespaceMappingRepository} is
- * deprecated in favor of the new
- * {@link org.apache.sling.jcr.base.NamespaceMappingSupport} abstract class
- * and said repository manager.
  */
-@Version("2.4")
+@Version("3.0")
 package org.apache.sling.jcr.base;
 
 import aQute.bnd.annotation.Version;

Modified: sling/trunk/bundles/jcr/base/src/test/java/org/apache/sling/jcr/base/MockSlingRepositoryManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/test/java/org/apache/sling/jcr/base/MockSlingRepositoryManager.java?rev=1731720&r1=1731719&r2=1731720&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/src/test/java/org/apache/sling/jcr/base/MockSlingRepositoryManager.java (original)
+++ sling/trunk/bundles/jcr/base/src/test/java/org/apache/sling/jcr/base/MockSlingRepositoryManager.java Mon Feb 22 19:13:04 2016
@@ -26,19 +26,18 @@ import java.util.Hashtable;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 
-import org.apache.sling.jcr.api.NamespaceMapper;
 import org.apache.sling.serviceusermapping.ServiceUserMapper;
 import org.osgi.framework.Bundle;
 
-/** Minimal AbstractSlingRepositoryManager used for testing */ 
+/** Minimal AbstractSlingRepositoryManager used for testing */
 class MockSlingRepositoryManager extends AbstractSlingRepositoryManager {
-    
+
     private final Repository repository;
-    
+
     MockSlingRepositoryManager(Repository repository) {
         this.repository = repository;
     }
-    
+
     @Override
     protected ServiceUserMapper getServiceUserMapper() {
         return null;
@@ -73,9 +72,4 @@ class MockSlingRepositoryManager extends
     @Override
     protected void disposeRepository(Repository repository) {
     }
-
-    @Override
-    protected NamespaceMapper[] getNamespaceMapperServices() {
-        return new NamespaceMapper[0];
-    }
 }
\ No newline at end of file