incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1336905 - in /sling/trunk/bundles/extensions/adapter: ./ src/main/java/org/apache/sling/adapter/internal/ src/test/java/org/apache/sling/adapter/internal/
Date Thu, 10 May 2012 21:29:31 GMT
Author: cziegeler
Date: Thu May 10 21:29:30 2012
New Revision: 1336905

URL: http://svn.apache.org/viewvc?rev=1336905&view=rev
Log:
SLING-2468 : Use ServiceReference to order adapter factories

Removed:
    sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterFactoryDescriptorKey.java
Modified:
    sling/trunk/bundles/extensions/adapter/pom.xml
    sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterFactoryDescriptorMap.java
    sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java
    sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterWebConsolePlugin.java
    sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java

Modified: sling/trunk/bundles/extensions/adapter/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/pom.xml?rev=1336905&r1=1336904&r2=1336905&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/adapter/pom.xml (original)
+++ sling/trunk/bundles/extensions/adapter/pom.xml Thu May 10 21:29:30 2012
@@ -99,7 +99,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.osgi</artifactId>
-            <version>2.0.2-incubator</version>
+            <version>2.1.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterFactoryDescriptorMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterFactoryDescriptorMap.java?rev=1336905&r1=1336904&r2=1336905&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterFactoryDescriptorMap.java
(original)
+++ sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterFactoryDescriptorMap.java
Thu May 10 21:29:30 2012
@@ -20,10 +20,12 @@ package org.apache.sling.adapter.interna
 
 import java.util.TreeMap;
 
+import org.osgi.framework.ServiceReference;
+
 /**
  * The <code>AdapterFactoryDescriptorMap</code> is a sorted map of
  * {@link AdapterFactoryDescriptor} instances indexed (and ordered) by their
- * {@link AdapterFactoryDescriptorKey}. This map is used to organize the
+ * {@link ServiceReference}. This map is used to organize the
  * registered {@link org.apache.sling.api.adapter.AdapterFactory} services for
  * a given adaptable type.
  * <p>
@@ -34,8 +36,8 @@ import java.util.TreeMap;
  * removed the eventual second instance may actually be used instead.
  */
 public class AdapterFactoryDescriptorMap extends
-        TreeMap<AdapterFactoryDescriptorKey, AdapterFactoryDescriptor> {
+        TreeMap<ServiceReference, AdapterFactoryDescriptor> {
 
-    private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 2L;
 
 }

Modified: sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java?rev=1336905&r1=1336904&r2=1336905&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java
(original)
+++ sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterManagerImpl.java
Thu May 10 21:29:30 2012
@@ -40,7 +40,7 @@ import org.apache.sling.api.SlingConstan
 import org.apache.sling.api.adapter.AdapterFactory;
 import org.apache.sling.api.adapter.AdapterManager;
 import org.apache.sling.api.resource.SyntheticResource;
-import org.apache.sling.commons.osgi.OsgiUtil;
+import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.component.ComponentContext;
@@ -60,7 +60,7 @@ import org.slf4j.LoggerFactory;
 @Properties({
     @Property(name=Constants.SERVICE_DESCRIPTION, value="Sling Adapter Manager"),
     @Property(name=Constants.SERVICE_VENDOR, value="The Apache Software Foundation")
-    
+
 })
 @Reference(name="AdapterFactory", referenceInterface=AdapterFactory.class,
     cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC)
@@ -211,16 +211,14 @@ public class AdapterManagerImpl implemen
      */
     private void registerAdapterFactory(ComponentContext context,
             ServiceReference reference) {
-        final String[] adaptables = OsgiUtil.toStringArray(reference.getProperty(ADAPTABLE_CLASSES));
-        final String[] adapters = OsgiUtil.toStringArray(reference.getProperty(ADAPTER_CLASSES));
+        final String[] adaptables = PropertiesUtil.toStringArray(reference.getProperty(ADAPTABLE_CLASSES));
+        final String[] adapters = PropertiesUtil.toStringArray(reference.getProperty(ADAPTER_CLASSES));
 
         if (adaptables == null || adaptables.length == 0 || adapters == null
             || adapters.length == 0) {
             return;
         }
 
-        final AdapterFactoryDescriptorKey factoryKey = new AdapterFactoryDescriptorKey(
-            reference);
         final AdapterFactoryDescriptor factoryDesc = new AdapterFactoryDescriptor(context,
             reference, adapters);
 
@@ -231,7 +229,7 @@ public class AdapterManagerImpl implemen
                     adfMap = new AdapterFactoryDescriptorMap();
                     factories.put(adaptable, adfMap);
                 }
-                adfMap.put(factoryKey, factoryDesc);
+                adfMap.put(reference, factoryDesc);
             }
         }
 
@@ -257,23 +255,20 @@ public class AdapterManagerImpl implemen
         synchronized ( this.boundAdapterFactories ) {
             boundAdapterFactories.remove(reference);
         }
-        final String[] adaptables = OsgiUtil.toStringArray(reference.getProperty(ADAPTABLE_CLASSES));
-        final String[] adapters = OsgiUtil.toStringArray(reference.getProperty(ADAPTER_CLASSES));
+        final String[] adaptables = PropertiesUtil.toStringArray(reference.getProperty(ADAPTABLE_CLASSES));
+        final String[] adapters = PropertiesUtil.toStringArray(reference.getProperty(ADAPTER_CLASSES));
 
         if (adaptables == null || adaptables.length == 0 || adapters == null
             || adapters.length == 0) {
             return;
         }
 
-        AdapterFactoryDescriptorKey factoryKey = new AdapterFactoryDescriptorKey(
-            reference);
-
         boolean factoriesModified = false;
         synchronized (factories) {
             for (String adaptable : adaptables) {
                 AdapterFactoryDescriptorMap adfMap = factories.get(adaptable);
                 if (adfMap != null) {
-                    factoriesModified |= (adfMap.remove(factoryKey) != null);
+                    factoriesModified |= (adfMap.remove(reference) != null);
                     if (adfMap.isEmpty()) {
                         factories.remove(adaptable);
                     }

Modified: sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterWebConsolePlugin.java?rev=1336905&r1=1336904&r2=1336905&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterWebConsolePlugin.java
(original)
+++ sling/trunk/bundles/extensions/adapter/src/main/java/org/apache/sling/adapter/internal/AdapterWebConsolePlugin.java
Thu May 10 21:29:30 2012
@@ -47,7 +47,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.sling.commons.json.JSONArray;
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.JSONObject;
-import org.apache.sling.commons.osgi.OsgiUtil;
+import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
@@ -94,9 +94,9 @@ public class AdapterWebConsolePlugin ext
     }
 
     private void addServiceMetadata(ServiceReference reference, Object service) {
-        final String[] adapters = OsgiUtil.toStringArray(reference.getProperty(ADAPTER_CLASSES));
-        final String condition = OsgiUtil.toString(reference.getProperty(ADAPTER_CONDITION),
null);
-        final String[] adaptables = OsgiUtil.toStringArray(reference.getProperty(ADAPTABLE_CLASSES));
+        final String[] adapters = PropertiesUtil.toStringArray(reference.getProperty(ADAPTER_CLASSES));
+        final String condition = PropertiesUtil.toString(reference.getProperty(ADAPTER_CONDITION),
null);
+        final String[] adaptables = PropertiesUtil.toStringArray(reference.getProperty(ADAPTABLE_CLASSES));
         final List<AdaptableDescription> descriptions = new ArrayList<AdaptableDescription>(adaptables.length);
         for (final String adaptable : adaptables) {
             descriptions.add(new AdaptableDescription(reference.getBundle(), adaptable, adapters,
condition));

Modified: sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java?rev=1336905&r1=1336904&r2=1336905&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java
(original)
+++ sling/trunk/bundles/extensions/adapter/src/test/java/org/apache/sling/adapter/internal/AdapterManagerTest.java
Thu May 10 21:29:30 2012
@@ -94,37 +94,67 @@ public class AdapterManagerTest {
      * Helper method to create a mock service reference
      */
     protected ServiceReference createServiceReference() {
-        final Bundle bundle = this.createBundle("bundle");
-        final ServiceReference ref = this.context.mock(ServiceReference.class, "serviceReference");
-        this.context.checking(new Expectations() {{
-            allowing(ref).getProperty(Constants.SERVICE_ID);
-            will(returnValue(1L));
-            allowing(ref).getProperty(AdapterFactory.ADAPTABLE_CLASSES);
-            will(returnValue(new String[]{ TestSlingAdaptable.class.getName() }));
-            allowing(ref).getProperty(AdapterFactory.ADAPTER_CLASSES);
-            will(returnValue(ITestAdapter.class.getName()));
-            allowing(ref).getBundle();
-            will(returnValue(bundle));
-        }});
+        final ServiceReference ref = new ServiceReferenceImpl(1, new String[]{ TestSlingAdaptable.class.getName()
}, ITestAdapter.class.getName());
         return ref;
     }
 
+    private static final class ServiceReferenceImpl implements ServiceReference {
+
+        private int ranking;
+        private String[] adapters;
+        private String classes;
+
+        public ServiceReferenceImpl(final int order, final String[] adapters, final String
classes) {
+            this.ranking = order;
+            this.adapters = adapters;
+            this.classes = classes;
+        }
+
+        public boolean isAssignableTo(Bundle bundle, String className) {
+            // TODO Auto-generated method stub
+            return false;
+        }
+
+        public Bundle[] getUsingBundles() {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public String[] getPropertyKeys() {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public Object getProperty(String key) {
+            if ( key.equals(Constants.SERVICE_RANKING) ) {
+                return ranking;
+            }
+            if ( key.equals(AdapterFactory.ADAPTABLE_CLASSES) ) {
+                return adapters;
+            }
+            if ( key.equals(AdapterFactory.ADAPTER_CLASSES) ) {
+                return classes;
+            }
+
+            return null;
+        }
+
+        public Bundle getBundle() {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public int compareTo(Object reference) {
+            Integer ranking1 = (Integer)getProperty(Constants.SERVICE_RANKING);
+            Integer ranking2 = (Integer)((ServiceReference)reference).getProperty(Constants.SERVICE_RANKING);
+            return ranking1.compareTo(ranking2);
+        }
+    };
     /**
      * Helper method to create a mock service reference
      */
     protected ServiceReference createServiceReference2() {
-        final Bundle bundle = this.createBundle("bundle2");
-        final ServiceReference ref = this.context.mock(ServiceReference.class, "serviceReference2");
-        this.context.checking(new Expectations() {{
-            allowing(ref).getProperty(Constants.SERVICE_ID);
-            will(returnValue(2L));
-            allowing(ref).getProperty(AdapterFactory.ADAPTABLE_CLASSES);
-            will(returnValue(new String[]{ TestSlingAdaptable2.class.getName() }));
-            allowing(ref).getProperty(AdapterFactory.ADAPTER_CLASSES);
-            will(returnValue(TestAdapter.class.getName()));
-            allowing(ref).getBundle();
-            will(returnValue(bundle));
-        }});
+        final ServiceReference ref = new ServiceReferenceImpl(2, new String[]{ TestSlingAdaptable2.class.getName()
}, TestAdapter.class.getName());
         return ref;
     }
 
@@ -179,7 +209,7 @@ public class AdapterManagerTest {
         AdapterFactoryDescriptorMap afdm = f.get(TestSlingAdaptable.class.getName());
         assertNotNull(afdm);
 
-        AdapterFactoryDescriptor afd = afdm.get(new AdapterFactoryDescriptorKey(ref));
+        AdapterFactoryDescriptor afd = afdm.get(ref);
         assertNotNull(afd);
         assertNotNull(afd.getFactory());
         assertNotNull(afd.getAdapters());



Mime
View raw message