felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r1127547 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: ServiceRegistry.java URLHandlersActivator.java
Date Wed, 25 May 2011 14:51:57 GMT
Author: rickhall
Date: Wed May 25 14:51:57 2011
New Revision: 1127547

URL: http://svn.apache.org/viewvc?rev=1127547&view=rev
Log:
Modify URL Handlers impl to use same hook tracking mechanism as
the other hooks, which was introduced for byte-code weaving hooks.
(FELIX-2959)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/URLHandlersActivator.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java?rev=1127547&r1=1127546&r2=1127547&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java Wed
May 25 14:51:57 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.framework;
 
+import java.net.ContentHandler;
 import java.util.*;
 import org.apache.felix.framework.capabilityset.CapabilitySet;
 import org.apache.felix.framework.capabilityset.SimpleFilter;
@@ -26,8 +27,8 @@ import org.apache.felix.framework.wiring
 import org.osgi.framework.*;
 import org.osgi.framework.hooks.service.*;
 import org.osgi.framework.hooks.weaving.WeavingHook;
-import org.osgi.framework.launch.Framework;
 import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.service.url.URLStreamHandlerService;
 
 public class ServiceRegistry
 {
@@ -54,7 +55,9 @@ public class ServiceRegistry
         EventHook.class,
         FindHook.class,
         ListenerHook.class,
-        WeavingHook.class
+        WeavingHook.class,
+        URLStreamHandlerService.class,
+        ContentHandler.class
     };
     private final Map<Class<?>, Set<ServiceReference<?>>> m_allHooks
=
         new HashMap<Class<?>, Set<ServiceReference<?>>>();

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/URLHandlersActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/URLHandlersActivator.java?rev=1127547&r1=1127546&r2=1127547&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/URLHandlersActivator.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/URLHandlersActivator.java
Wed May 25 14:51:57 2011
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -18,14 +18,17 @@
  */
 package org.apache.felix.framework;
 
+import java.net.ContentHandler;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.felix.framework.util.FelixConstants;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.url.URLStreamHandlerService;
 import org.osgi.util.tracker.ServiceTracker;
 
 /**
@@ -63,10 +66,6 @@ class URLHandlersActivator implements Bu
 
         if (enable)
         {
-            m_streamTracker = new ServiceTracker(context, "org.osgi.service.url.URLStreamHandlerService",
null);
-            m_contentTracker= new ServiceTracker(context, "java.net.ContentHandler", null);
-            m_streamTracker.open();
-            m_contentTracker.open();
             m_framework.setURLHandlersActivator(this);
         }
         URLHandlers.registerFrameworkInstance(m_framework, enable);
@@ -76,66 +75,49 @@ class URLHandlersActivator implements Bu
     {
         URLHandlers.unregisterFrameworkInstance(m_framework);
         m_framework.setURLHandlersActivator(null);
-        if (m_streamTracker != null)
-        {
-            m_streamTracker.close();
-        }
-        if (m_contentTracker != null)
-        {
-            m_contentTracker.close();
-        }
-        m_streamTracker = null;
-        m_contentTracker = null;
     }
 
-    private volatile ServiceTracker m_streamTracker;
-    private volatile ServiceTracker m_contentTracker;
-    
     protected Object getStreamHandlerService(String protocol)
     {
-        return get(m_streamTracker, "url.handler.protocol", protocol);
+        return get(
+            m_framework.getHooks(URLStreamHandlerService.class),
+            "url.handler.protocol", protocol);
     }
 
     protected Object getContentHandlerService(String mimeType)
     {
-        return get(m_contentTracker, "url.content.mimetype", mimeType);
+        return get(
+            m_framework.getHooks(ContentHandler.class),
+            "url.content.mimetype", mimeType);
     }
 
-    private Object get(ServiceTracker tracker, String key, String value)
+    private <S> S get(Set<ServiceReference<S>> hooks, String key, String
value)
     {
     	Object service = null;
-        if (tracker != null)
+        if (!hooks.isEmpty())
         {
-            ServiceReference[] refs = tracker.getServiceReferences();
-
-            if (refs != null)
+            for (ServiceReference<S> ref : hooks)
             {
-                if (refs.length > 1)
-                {
-                    Arrays.sort(refs, Collections.reverseOrder());
-                }
-
-                for (int i = 0;(i < refs.length) && (service == null);i++)
+                Object values = ref.getProperty(key);
+                if (values instanceof String[])
                 {
-                    Object values = refs[i].getProperty(key);
-                    if (values instanceof String[])
+                    for (int valueIdx = 0;
+                        (valueIdx < ((String[]) values).length) && (service ==
null);
+                        valueIdx++)
                     {
-                        for (int j = 0;(j < ((String[]) values).length) && (service
== null);j++)
+                        if (value.equals(((String[]) values)[valueIdx]))
                         {
-                            if (value.equals(((String[]) values)[j]))
-                            {
-                                service = tracker.getService(refs[i]);
-                            }
+                            return m_framework.getService(m_framework, ref);
                         }
                     }
-                    else if (value.equals(values))
-                    {
-                        service = tracker.getService(refs[i]);
-                    }
+                }
+                else if (value.equals(values))
+                {
+                    return m_framework.getService(m_framework, ref);
                 }
             }
         }
 
-        return service;
+        return null;
     }
-}
+}
\ No newline at end of file



Mime
View raw message