You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2015/02/21 10:40:05 UTC

svn commit: r1661311 - in /sling/trunk/testing/mocks/sling-mock: pom.xml src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java

Author: sseifert
Date: Sat Feb 21 09:40:05 2015
New Revision: 1661311

URL: http://svn.apache.org/r1661311
Log:
SLING-4433 remove dependency to org.apache.sling.adapter and inline helper classes instead

Modified:
    sling/trunk/testing/mocks/sling-mock/pom.xml
    sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java

Modified: sling/trunk/testing/mocks/sling-mock/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/pom.xml?rev=1661311&r1=1661310&r2=1661311&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/pom.xml (original)
+++ sling/trunk/testing/mocks/sling-mock/pom.xml Sat Feb 21 09:40:05 2015
@@ -86,12 +86,6 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.adapter</artifactId>
-            <version>2.1.0</version>
-            <scope>compile</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.resourceresolver</artifactId>
             <version>1.1.0</version>
             <scope>compile</scope>

Modified: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java?rev=1661311&r1=1661310&r2=1661311&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockAdapterManagerImpl.java Sat Feb 21 09:40:05 2015
@@ -28,6 +28,7 @@ import java.util.Hashtable;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
@@ -38,8 +39,6 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.ReferencePolicy;
 import org.apache.felix.scr.annotations.Service;
-import org.apache.sling.adapter.internal.AdapterFactoryDescriptor;
-import org.apache.sling.adapter.internal.AdapterFactoryDescriptorMap;
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.adapter.AdapterFactory;
 import org.apache.sling.api.adapter.AdapterManager;
@@ -434,4 +433,64 @@ public class MockAdapterManagerImpl impl
             }
         }
     }
+
+
+    /**
+     * The <code>AdapterFactoryDescriptor</code> is an entry in the
+     * {@link AdapterFactoryDescriptorMap} conveying the list of adapter (target)
+     * types and the respective {@link AdapterFactory}.
+     */
+    private static class AdapterFactoryDescriptor {
+
+        private volatile AdapterFactory factory;
+
+        private final String[] adapters;
+
+        private final ServiceReference reference;
+
+        private final ComponentContext context;
+
+        public AdapterFactoryDescriptor(
+                final ComponentContext context,
+                final ServiceReference reference,
+                final String[] adapters) {
+            this.reference = reference;
+            this.context = context;
+            this.adapters = adapters;
+        }
+
+        public AdapterFactory getFactory() {
+            if ( factory == null ) {
+                factory = (AdapterFactory) context.locateService(
+                        "AdapterFactory", reference);
+            }
+            return factory;
+        }
+
+        public String[] getAdapters() {
+            return adapters;
+        }
+    }
+
+    /**
+     * The <code>AdapterFactoryDescriptorMap</code> is a sorted map of
+     * {@link AdapterFactoryDescriptor} instances indexed (and ordered) by their
+     * {@link ServiceReference}. This map is used to organize the
+     * registered {@link org.apache.sling.api.adapter.AdapterFactory} services for
+     * a given adaptable type.
+     * <p>
+     * Each entry in the map is a {@link AdapterFactoryDescriptor} thus enabling the
+     * registration of multiple factories for the same (adaptable, adapter) type
+     * tuple. Of course only the first entry (this is the reason for having a sorted
+     * map) for such a given tuple is actually being used. If that first instance is
+     * removed the eventual second instance may actually be used instead.
+     */
+    private static class AdapterFactoryDescriptorMap extends
+            TreeMap<ServiceReference, AdapterFactoryDescriptor> {
+
+        private static final long serialVersionUID = 2L;
+
+    }
+
+    
 }